diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-07-14 12:09:23 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-07-25 09:26:38 +0000 |
commit | 007ae316a62670eeff8b08526fad9110fff0bbd4 (patch) | |
tree | 142aa98565878d394935e85b91edf499279c9d8a /src/qml/qml/qqmlpropertycache_p.h | |
parent | 4c1a51006e5936dc69e3373539787120092f6719 (diff) |
QML: Unify property reads/writes and use accessors
Pass property reads/writes through utility functions in QQmlProperty,
which in turn will try to use accessors when available (and no
interceptors have to be called).
Change-Id: I60ecfc202b6024bfe4a33206a46299787b152546
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache_p.h')
-rw-r--r-- | src/qml/qml/qqmlpropertycache_p.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index baba5347a7..ad6db9756f 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -61,6 +61,7 @@ #include <QtCore/qvector.h> #include <private/qv4value_p.h> +#include <private/qqmlaccessors_p.h> QT_BEGIN_NAMESPACE @@ -228,6 +229,13 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyRawData::Flags) class QQmlPropertyData : public QQmlPropertyRawData { public: + enum WriteFlag { + BypassInterceptor = 0x01, + DontRemoveBinding = 0x02, + RemoveBindingOnAliasWrite = 0x04 + }; + Q_DECLARE_FLAGS(WriteFlags, WriteFlag) + inline QQmlPropertyData(); inline QQmlPropertyData(const QQmlPropertyRawData &); @@ -241,6 +249,33 @@ public: void markAsOverrideOf(QQmlPropertyData *predecessor); + inline void readProperty(QObject *target, void *property) const + { + void *args[] = { property, 0 }; + readPropertyWithArgs(target, args); + } + + inline void readPropertyWithArgs(QObject *target, void *args[]) const + { + if (hasAccessors()) { + accessors->read(target, args[0]); + } else { + QMetaObject::metacall(target, QMetaObject::ReadProperty, coreIndex, args); + } + } + + bool writeProperty(QObject *target, void *value, WriteFlags flags) const + { + if (flags.testFlag(BypassInterceptor) && hasAccessors() && accessors->write) { + accessors->write(target, value); + } else { + int status = -1; + void *argv[] = { value, 0, &status, &flags }; + QMetaObject::metacall(target, QMetaObject::WriteProperty, coreIndex, argv); + } + return true; + } + private: friend class QQmlPropertyCache; void lazyLoad(const QMetaProperty &); @@ -770,6 +805,8 @@ private: QVector<QFlagPointer<QQmlPropertyCache>> data; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyData::WriteFlags) + QT_END_NAMESPACE #endif // QQMLPROPERTYCACHE_P_H |