diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-03-29 11:57:41 +1000 |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-03-29 11:59:00 +1000 |
commit | 418bd7fa550da97ac27a34c72e75ec7ab0448d78 (patch) | |
tree | 47883d96f4ca1b786af5f18d56e943662a6acf38 | |
parent | 059a91650d7fdb7491108c07e3eda0e79e2d9203 (diff) | |
download | qt4-tools-418bd7fa550da97ac27a34c72e75ec7ab0448d78.tar.gz |
Don't emit QDeclarativePropertyMap::valueChanged() before the value has
changed.
Task-number: QTBUG-9386
5 files changed, 25 insertions, 11 deletions
diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp index 8c2335401f..70ecf95920 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject.cpp +++ b/src/declarative/util/qdeclarativeopenmetaobject.cpp @@ -225,6 +225,7 @@ int QDeclarativeOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a) if (d->data[propId].first != *reinterpret_cast<QVariant *>(a[0])) { propertyWrite(propId); d->writeData(propId, *reinterpret_cast<QVariant *>(a[0])); + propertyWritten(propId); activate(d->object, d->type->d->signalOffset + propId, 0); } } @@ -270,6 +271,11 @@ QVariant &QDeclarativeOpenMetaObject::operator[](const QByteArray &name) return d->getData(*iter); } +QVariant &QDeclarativeOpenMetaObject::operator[](int id) +{ + return d->getData(id); +} + void QDeclarativeOpenMetaObject::setValue(const QByteArray &name, const QVariant &val) { QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.find(name); @@ -326,6 +332,10 @@ void QDeclarativeOpenMetaObject::propertyWrite(int) { } +void QDeclarativeOpenMetaObject::propertyWritten(int) +{ +} + void QDeclarativeOpenMetaObject::propertyCreated(int, QMetaPropertyBuilder &) { } diff --git a/src/declarative/util/qdeclarativeopenmetaobject_p.h b/src/declarative/util/qdeclarativeopenmetaobject_p.h index ec5ac17b20..9bb4c34529 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject_p.h +++ b/src/declarative/util/qdeclarativeopenmetaobject_p.h @@ -90,6 +90,7 @@ public: QVariant value(int) const; void setValue(int, const QVariant &); QVariant &operator[](const QByteArray &); + QVariant &operator[](int); int count() const; QByteArray name(int) const; @@ -109,6 +110,7 @@ protected: virtual void propertyRead(int); virtual void propertyWrite(int); + virtual void propertyWritten(int); virtual void propertyCreated(int, QMetaPropertyBuilder &); QAbstractDynamicMetaObject *parent() const; diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp index fcea515769..d3e1d7c2ba 100644 --- a/src/declarative/util/qdeclarativepropertymap.cpp +++ b/src/declarative/util/qdeclarativepropertymap.cpp @@ -55,7 +55,7 @@ public: QDeclarativePropertyMapMetaObject(QDeclarativePropertyMap *obj, QDeclarativePropertyMapPrivate *objPriv); protected: - virtual void propertyWrite(int index); + virtual void propertyWritten(int index); private: QDeclarativePropertyMap *map; @@ -68,13 +68,13 @@ class QDeclarativePropertyMapPrivate : public QObjectPrivate public: QDeclarativePropertyMapMetaObject *mo; QStringList keys; - void emitChanged(const QString &key); + void emitChanged(const QString &key, const QVariant &value); }; -void QDeclarativePropertyMapPrivate::emitChanged(const QString &key) +void QDeclarativePropertyMapPrivate::emitChanged(const QString &key, const QVariant &value) { Q_Q(QDeclarativePropertyMap); - emit q->valueChanged(key); + emit q->valueChanged(key, value); } QDeclarativePropertyMapMetaObject::QDeclarativePropertyMapMetaObject(QDeclarativePropertyMap *obj, QDeclarativePropertyMapPrivate *objPriv) : QDeclarativeOpenMetaObject(obj) @@ -83,14 +83,14 @@ QDeclarativePropertyMapMetaObject::QDeclarativePropertyMapMetaObject(QDeclarativ priv = objPriv; } -void QDeclarativePropertyMapMetaObject::propertyWrite(int index) +void QDeclarativePropertyMapMetaObject::propertyWritten(int index) { - priv->emitChanged(QString::fromUtf8(name(index))); + priv->emitChanged(QString::fromUtf8(name(index)), operator[](index)); } /*! \class QDeclarativePropertyMap - \since 4.7 + \since 4.7 \brief The QDeclarativePropertyMap class allows you to set key-value pairs that can be used in bindings. QDeclarativePropertyMap provides a convenient way to expose domain data to the UI layer. @@ -268,9 +268,9 @@ const QVariant QDeclarativePropertyMap::operator[](const QString &key) const } /*! - \fn void QDeclarativePropertyMap::valueChanged(const QString &key) + \fn void QDeclarativePropertyMap::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 value that was changed. + is the key corresponding to the \a value that was changed. \note valueChanged() is \bold NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML. diff --git a/src/declarative/util/qdeclarativepropertymap.h b/src/declarative/util/qdeclarativepropertymap.h index 513089f120..e0b7ce394f 100644 --- a/src/declarative/util/qdeclarativepropertymap.h +++ b/src/declarative/util/qdeclarativepropertymap.h @@ -76,7 +76,7 @@ public: const QVariant operator[](const QString &key) const; Q_SIGNALS: - void valueChanged(const QString &key); + void valueChanged(const QString &key, const QVariant &value); private: Q_DECLARE_PRIVATE(QDeclarativePropertyMap) diff --git a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp index 22c5581f2e..d23de43845 100644 --- a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp +++ b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp @@ -123,7 +123,7 @@ void tst_QDeclarativePropertyMap::clear() void tst_QDeclarativePropertyMap::changed() { QDeclarativePropertyMap map; - QSignalSpy spy(&map, SIGNAL(valueChanged(const QString&))); + QSignalSpy spy(&map, SIGNAL(valueChanged(const QString&, const QVariant&))); map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); QCOMPARE(spy.count(), 0); @@ -144,7 +144,9 @@ void tst_QDeclarativePropertyMap::changed() QCOMPARE(txt->text(), QString('X')); QCOMPARE(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); + QCOMPARE(arguments.count(), 2); QCOMPARE(arguments.at(0).toString(),QLatin1String("key1")); + QCOMPARE(arguments.at(1).value<QVariant>(),QVariant("Hello World")); QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); } |