summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-03-29 01:57:41 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-03-29 01:59:00 (GMT)
commit418bd7fa550da97ac27a34c72e75ec7ab0448d78 (patch)
tree47883d96f4ca1b786af5f18d56e943662a6acf38
parent059a91650d7fdb7491108c07e3eda0e79e2d9203 (diff)
downloadQt-418bd7fa550da97ac27a34c72e75ec7ab0448d78.zip
Qt-418bd7fa550da97ac27a34c72e75ec7ab0448d78.tar.gz
Qt-418bd7fa550da97ac27a34c72e75ec7ab0448d78.tar.bz2
Don't emit QDeclarativePropertyMap::valueChanged() before the value has
changed. Task-number: QTBUG-9386
-rw-r--r--src/declarative/util/qdeclarativeopenmetaobject.cpp10
-rw-r--r--src/declarative/util/qdeclarativeopenmetaobject_p.h2
-rw-r--r--src/declarative/util/qdeclarativepropertymap.cpp18
-rw-r--r--src/declarative/util/qdeclarativepropertymap.h2
-rw-r--r--tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp4
5 files changed, 25 insertions, 11 deletions
diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp
index 8c23354..70ecf95 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 ec5ac17..9bb4c34 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 fcea515..d3e1d7c 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 513089f..e0b7ce3 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 22c5581..d23de43 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"));
}