aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/util/qqmlpropertymap.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-07-26 14:15:49 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-27 06:09:11 +0200
commit54c2d685512fdeac2d5b6eeaf25ed738c4fd99ba (patch)
tree27acf485b787f825525d20b7a160d45fde678360 /src/qml/util/qqmlpropertymap.cpp
parent73842034aac7b9788add4f1ba6cf7a9ec6057598 (diff)
Allow access to signals and slots in QQmlPropertyMap inheritors
Allow inheritors of QQmlPropertyMap to pass the static meta object information needed to support their signals and slots. If the correct pointer is not provided to the constructor, it is not accessible via the virtual metaObject() function during construction. Task-number: QTBUG-26400 Change-Id: Ide8c6d3568e4abd4c48e0aa60e6fa05a9c2a11cf Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/qml/util/qqmlpropertymap.cpp')
-rw-r--r--src/qml/util/qqmlpropertymap.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/qml/util/qqmlpropertymap.cpp b/src/qml/util/qqmlpropertymap.cpp
index cdc82fe86e..37f9e3118a 100644
--- a/src/qml/util/qqmlpropertymap.cpp
+++ b/src/qml/util/qqmlpropertymap.cpp
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
class QQmlPropertyMapMetaObject : public QQmlOpenMetaObject
{
public:
- QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv);
+ QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv, const QMetaObject *staticMetaObject);
protected:
virtual QVariant propertyWriteValue(int, const QVariant &);
@@ -110,7 +110,8 @@ const QString &QQmlPropertyMapPrivate::propertyName(int index) const
return keys[index];
}
-QQmlPropertyMapMetaObject::QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv) : QQmlOpenMetaObject(obj)
+QQmlPropertyMapMetaObject::QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv, const QMetaObject *staticMetaObject)
+ : QQmlOpenMetaObject(obj, staticMetaObject)
{
map = obj;
priv = objPriv;
@@ -176,16 +177,20 @@ int QQmlPropertyMapMetaObject::createProperty(const char *name, const char *valu
\note It is not possible to remove keys from the map; once a key has been added, you can only
modify or clear its associated value.
+
+ \note When deriving a class from QQmlPropertyMap, use the
+ \l {QQmlPropertyMap::QQmlPropertyMap(DerivedType *derived, QObject *parent)}
+ {protected two-argument constructor}
+ which ensures that the class is correctly registered with the Qt \l {Meta-Object System}.
*/
/*!
Constructs a bindable map with parent object \a parent.
*/
QQmlPropertyMap::QQmlPropertyMap(QObject *parent)
-: QObject(*(new QQmlPropertyMapPrivate), parent)
+: QObject(*allocatePrivate(), parent)
{
- Q_D(QQmlPropertyMap);
- d->mo = new QQmlPropertyMapMetaObject(this, d);
+ init(metaObject());
}
/*!
@@ -331,9 +336,23 @@ QVariant QQmlPropertyMap::operator[](const QString &key) const
*/
QVariant QQmlPropertyMap::updateValue(const QString &key, const QVariant &input)
{
+ Q_UNUSED(key)
return input;
}
+/*! \internal */
+void QQmlPropertyMap::init(const QMetaObject *staticMetaObject)
+{
+ Q_D(QQmlPropertyMap);
+ d->mo = new QQmlPropertyMapMetaObject(this, d, staticMetaObject);
+}
+
+/*! \internal */
+QObjectPrivate *QQmlPropertyMap::allocatePrivate()
+{
+ return new QQmlPropertyMapPrivate;
+}
+
/*!
\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
@@ -343,4 +362,15 @@ QVariant QQmlPropertyMap::updateValue(const QString &key, const QVariant &input)
or clear() - it is only emitted when a value is updated from QML.
*/
+/*!
+ \fn QQmlPropertyMap::QQmlPropertyMap(DerivedType *derived, QObject *parent)
+
+ Constructs a bindable map with parent object \a parent. Use this constructor
+ in classes derived from QQmlPropertyMap.
+
+ The type of \a derived is used to register the property map with the \l {Meta-Object System},
+ which is necessary to ensure that properties of the derived class are accessible.
+ This type must be derived from QQmlPropertyMap.
+*/
+
QT_END_NAMESPACE