diff options
author | Anton Kreuzkamp <anton.kreuzkamp@kdab.com> | 2017-04-26 16:31:48 +0200 |
---|---|---|
committer | Anton Kreuzkamp <anton.kreuzkamp@kdab.com> | 2017-08-13 04:07:30 +0000 |
commit | 17513266b81e88b84fda250734f07c94a198fabc (patch) | |
tree | 2bb498ba41df15971035fb040bf4c07e8369fbc3 /src/qml/qml/qqmlbinding.cpp | |
parent | 041c8d28eaa0e516a0c6502fa801781aa8ebe5a6 (diff) |
Add API to learn about QQmlBinding's dependencies
Adds a method `dependencies()` to QQmlBinding, that returns a
QVector<QQmlProperty> of all properties the binding depends on. The API is
meant to be used in debugging tools (e.g. in GammaRay).
Also adds a public method subBindings() to QQmlValueTypeProxyBinding in
order to be able to access their dependencies.
Change-Id: Ib833703ec9e632661626c4532b8d73997f38e62b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlbinding.cpp')
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 84f30af066..566fbb86ac 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -54,6 +54,7 @@ #include <QVariant> #include <QtCore/qdebug.h> +#include <QVector> QT_BEGIN_NAMESPACE @@ -579,6 +580,37 @@ void QQmlBinding::getPropertyData(QQmlPropertyData **propertyData, QQmlPropertyD } } +QVector<QQmlProperty> QQmlBinding::dependencies() const +{ + QVector<QQmlProperty> dependencies; + if (!m_target.data()) + return dependencies; + + for (const auto &guardList : { permanentGuards, activeGuards }) { + for (QQmlJavaScriptExpressionGuard *guard = guardList.first(); guard; guard = guardList.next(guard)) { + if (guard->signalIndex() == -1) // guard's sender is a QQmlNotifier, not a QObject*. + continue; + + QObject *senderObject = guard->senderAsObject(); + if (!senderObject) + continue; + + const QMetaObject *senderMeta = senderObject->metaObject(); + if (!senderMeta) + continue; + + for (int i = 0; i < senderMeta->propertyCount(); i++) { + QMetaProperty property = senderMeta->property(i); + if (property.notifySignalIndex() == QMetaObjectPrivate::signal(senderMeta, guard->signalIndex()).methodIndex()) { + dependencies.push_back(QQmlProperty(senderObject, QString::fromUtf8(senderObject->metaObject()->property(i).name()))); + } + } + } + } + + return dependencies; +} + class QObjectPointerBinding: public QQmlNonbindingBinding { QQmlMetaObject targetMetaObject; |