diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-07-17 11:14:43 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-18 05:48:43 +0200 |
commit | 884bc89e9fe765a7be245b3009339f999936a761 (patch) | |
tree | a8ecc8df740a3e93a8ab30de96f7a4e4a2e091e9 /src/qml/util/qqmlpropertymap.cpp | |
parent | 1ce3a17ef51e10c03627842b9cdd0bb543ee8c83 (diff) |
Allow QQmlPropertyMap property updates to be controlled
Allow clients to control updates made from QML to types derived from
QQmlPropertyMap, by overriding the updateValue() function.
Task-number: QTBUG-23183
Change-Id: I0169093779ebfe50dc9349f5aaac08ed85c80a8f
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: abcd <amos.choy@nokia.com>
Diffstat (limited to 'src/qml/util/qqmlpropertymap.cpp')
-rw-r--r-- | src/qml/util/qqmlpropertymap.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/qml/util/qqmlpropertymap.cpp b/src/qml/util/qqmlpropertymap.cpp index 1571d2dfc9..cdc82fe86e 100644 --- a/src/qml/util/qqmlpropertymap.cpp +++ b/src/qml/util/qqmlpropertymap.cpp @@ -56,9 +56,13 @@ public: QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv); protected: + virtual QVariant propertyWriteValue(int, const QVariant &); virtual void propertyWritten(int index); virtual void propertyCreated(int, QMetaPropertyBuilder &); virtual int createProperty(const char *, const char *); + + const QString &propertyName(int index); + private: QQmlPropertyMap *map; QQmlPropertyMapPrivate *priv; @@ -70,8 +74,12 @@ class QQmlPropertyMapPrivate : public QObjectPrivate public: QQmlPropertyMapMetaObject *mo; QStringList keys; + + QVariant updateValue(const QString &key, const QVariant &input); void emitChanged(const QString &key, const QVariant &value); bool validKeyName(const QString& name); + + const QString &propertyName(int index) const; }; bool QQmlPropertyMapPrivate::validKeyName(const QString& name) @@ -84,21 +92,38 @@ bool QQmlPropertyMapPrivate::validKeyName(const QString& name) && name != QLatin1String("deleteLater"); } +QVariant QQmlPropertyMapPrivate::updateValue(const QString &key, const QVariant &input) +{ + Q_Q(QQmlPropertyMap); + return q->updateValue(key, input); +} + void QQmlPropertyMapPrivate::emitChanged(const QString &key, const QVariant &value) { Q_Q(QQmlPropertyMap); emit q->valueChanged(key, value); } +const QString &QQmlPropertyMapPrivate::propertyName(int index) const +{ + Q_ASSERT(index < keys.size()); + return keys[index]; +} + QQmlPropertyMapMetaObject::QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv) : QQmlOpenMetaObject(obj) { map = obj; priv = objPriv; } +QVariant QQmlPropertyMapMetaObject::propertyWriteValue(int index, const QVariant &input) +{ + return priv->updateValue(priv->propertyName(index), input); +} + void QQmlPropertyMapMetaObject::propertyWritten(int index) { - priv->emitChanged(QString::fromUtf8(name(index)), operator[](index)); + priv->emitChanged(priv->propertyName(index), operator[](index)); } void QQmlPropertyMapMetaObject::propertyCreated(int, QMetaPropertyBuilder &b) @@ -298,6 +323,18 @@ QVariant QQmlPropertyMap::operator[](const QString &key) const } /*! + Returns the new value to be stored for the key \a key. This function is provided + to intercept updates to a property from QML, where the value provided from QML is \a input. + + Override this function to manipulate the property value as it is updated. Note that + this function is only invoked when the value is updated from QML. +*/ +QVariant QQmlPropertyMap::updateValue(const QString &key, const QVariant &input) +{ + return input; +} + +/*! \fn void QQmlPropertyMap::valueChanged(const QString &key, const QVariant &value) This signal is emitted whenever one of the values in the map is changed. \a key is the key corresponding to the \a value that was changed. |