summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qdeclarativepropertymap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/util/qdeclarativepropertymap.cpp')
-rw-r--r--src/declarative/util/qdeclarativepropertymap.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp
index fcea515..0bdd91b 100644
--- a/src/declarative/util/qdeclarativepropertymap.cpp
+++ b/src/declarative/util/qdeclarativepropertymap.cpp
@@ -41,6 +41,7 @@
#include "qdeclarativepropertymap.h"
+#include <private/qmetaobjectbuilder_p.h>
#include "qdeclarativeopenmetaobject_p.h"
#include <QDebug>
@@ -55,7 +56,8 @@ public:
QDeclarativePropertyMapMetaObject(QDeclarativePropertyMap *obj, QDeclarativePropertyMapPrivate *objPriv);
protected:
- virtual void propertyWrite(int index);
+ virtual void propertyWritten(int index);
+ virtual void propertyCreated(int, QMetaPropertyBuilder &);
private:
QDeclarativePropertyMap *map;
@@ -68,13 +70,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 +85,19 @@ 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));
+}
+
+void QDeclarativePropertyMapMetaObject::propertyCreated(int, QMetaPropertyBuilder &b)
+{
+ priv->keys.append(QString::fromUtf8(b.name()));
}
/*!
\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.
@@ -172,8 +179,6 @@ QVariant QDeclarativePropertyMap::value(const QString &key) const
void QDeclarativePropertyMap::insert(const QString &key, const QVariant &value)
{
Q_D(QDeclarativePropertyMap);
- if (!d->keys.contains(key))
- d->keys.append(key);
d->mo->setValue(key.toUtf8(), value);
}
@@ -249,10 +254,8 @@ QVariant &QDeclarativePropertyMap::operator[](const QString &key)
//### optimize
Q_D(QDeclarativePropertyMap);
QByteArray utf8key = key.toUtf8();
- if (!d->keys.contains(key)) {
- d->keys.append(key);
+ if (!d->keys.contains(key))
d->mo->setValue(utf8key, QVariant()); //force creation -- needed below
- }
return (*(d->mo))[utf8key];
}
@@ -268,9 +271,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.