aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlopenmetaobject.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-07-17 11:14:43 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-18 05:48:43 +0200
commit884bc89e9fe765a7be245b3009339f999936a761 (patch)
treea8ecc8df740a3e93a8ab30de96f7a4e4a2e091e9 /src/qml/qml/qqmlopenmetaobject.cpp
parent1ce3a17ef51e10c03627842b9cdd0bb543ee8c83 (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/qml/qqmlopenmetaobject.cpp')
-rw-r--r--src/qml/qml/qqmlopenmetaobject.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp
index 221cb3a314..4774f7e126 100644
--- a/src/qml/qml/qqmlopenmetaobject.cpp
+++ b/src/qml/qml/qqmlopenmetaobject.cpp
@@ -145,10 +145,14 @@ public:
QQmlOpenMetaObjectPrivate(QQmlOpenMetaObject *_q)
: q(_q), parent(0), type(0), cacheProperties(false) {}
- inline QVariant &getData(int idx) {
+ inline QPair<QVariant, bool> &getDataRef(int idx) {
while (data.count() <= idx)
data << QPair<QVariant, bool>(QVariant(), false);
- QPair<QVariant, bool> &prop = data[idx];
+ return data[idx];
+ }
+
+ inline QVariant &getData(int idx) {
+ QPair<QVariant, bool> &prop = getDataRef(idx);
if (!prop.second) {
prop.first = q->initialValue(idx);
prop.second = true;
@@ -156,14 +160,6 @@ public:
return prop.first;
}
- inline void writeData(int idx, const QVariant &value) {
- while (data.count() <= idx)
- data << QPair<QVariant, bool>(QVariant(), false);
- QPair<QVariant, bool> &prop = data[idx];
- prop.first = value;
- prop.second = true;
- }
-
inline bool hasData(int idx) const {
if (idx >= data.count())
return false;
@@ -235,7 +231,9 @@ int QQmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a)
} else if (c == QMetaObject::WriteProperty) {
if (propId <= d->data.count() || d->data[propId].first != *reinterpret_cast<QVariant *>(a[0])) {
propertyWrite(propId);
- d->writeData(propId, *reinterpret_cast<QVariant *>(a[0]));
+ QPair<QVariant, bool> &prop = d->getDataRef(propId);
+ prop.first = propertyWriteValue(propId, *reinterpret_cast<QVariant *>(a[0]));
+ prop.second = true;
propertyWritten(propId);
activate(d->object, d->type->d->signalOffset + propId, 0);
}
@@ -261,7 +259,9 @@ QVariant QQmlOpenMetaObject::value(int id) const
void QQmlOpenMetaObject::setValue(int id, const QVariant &value)
{
- d->writeData(id, value);
+ QPair<QVariant, bool> &prop = d->getDataRef(id);
+ prop.first = propertyWriteValue(id, value);
+ prop.second = true;
activate(d->object, id + d->type->d->signalOffset, 0);
}
@@ -354,6 +354,11 @@ void QQmlOpenMetaObject::propertyWrite(int)
{
}
+QVariant QQmlOpenMetaObject::propertyWriteValue(int, const QVariant &value)
+{
+ return value;
+}
+
void QQmlOpenMetaObject::propertyWritten(int)
{
}