diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-10-21 00:57:02 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-10-21 01:43:24 (GMT) |
commit | 2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d (patch) | |
tree | d00f145d9c4cd72bfcb6038aa86a22c9efb83a73 /src/declarative | |
parent | b8c939903b8afc0abe38ab2e315a5bda32221aae (diff) | |
download | Qt-2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d.zip Qt-2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d.tar.gz Qt-2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d.tar.bz2 |
Rename QBindableMap to QmlPropertyMap.
Task-number: QT-2316
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/extra/extra.pri | 2 | ||||
-rw-r--r-- | src/declarative/util/qmlpropertymap.cpp (renamed from src/declarative/extra/qbindablemap.cpp) | 88 | ||||
-rw-r--r-- | src/declarative/util/qmlpropertymap.h (renamed from src/declarative/extra/qbindablemap.h) | 21 | ||||
-rw-r--r-- | src/declarative/util/util.pri | 6 |
4 files changed, 65 insertions, 52 deletions
diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index 726f099..502504a 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -6,7 +6,6 @@ SOURCES += \ extra/qfxanimatedimageitem.cpp \ extra/qfxparticles.cpp \ extra/qmlbehavior.cpp \ - extra/qbindablemap.cpp \ extra/qmlfontloader.cpp HEADERS += \ @@ -18,7 +17,6 @@ HEADERS += \ extra/qfxanimatedimageitem_p.h \ extra/qfxparticles.h \ extra/qmlbehavior.h \ - extra/qbindablemap.h \ extra/qmlfontloader.h contains(QT_CONFIG, xmlpatterns) { diff --git a/src/declarative/extra/qbindablemap.cpp b/src/declarative/util/qmlpropertymap.cpp index 5254e2a..e23eebf 100644 --- a/src/declarative/extra/qbindablemap.cpp +++ b/src/declarative/util/qmlpropertymap.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qbindablemap.h" +#include "qmlpropertymap.h" #include <qmlopenmetaobject.h> #include <QDebug> @@ -47,24 +47,45 @@ QT_BEGIN_NAMESPACE //QBindableMapMetaObject lets us listen for changes coming from QML //so we can emit the changed signal. -class QBindableMapMetaObject : public QmlOpenMetaObject +class QmlPropertyMapMetaObject : public QmlOpenMetaObject { public: - QBindableMapMetaObject(QBindableMap *obj) : QmlOpenMetaObject(obj) - { - map = obj; - } + QmlPropertyMapMetaObject(QmlPropertyMap *obj, QmlPropertyMapPrivate *objPriv); protected: - virtual void propertyWrite(int index) - { - map->emitChanged(QString::fromUtf8(name(index))); - } + virtual void propertyWrite(int index); private: - QBindableMap *map; + QmlPropertyMap *map; + QmlPropertyMapPrivate *priv; }; +class QmlPropertyMapPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlPropertyMap) +public: + QmlPropertyMapMetaObject *mo; + QStringList keys; + void emitChanged(const QString &key); +}; + +void QmlPropertyMapPrivate::emitChanged(const QString &key) +{ + Q_Q(QmlPropertyMap); + emit q->changed(key); +} + +QmlPropertyMapMetaObject::QmlPropertyMapMetaObject(QmlPropertyMap *obj, QmlPropertyMapPrivate *objPriv) : QmlOpenMetaObject(obj) +{ + map = obj; + priv = objPriv; +} + +void QmlPropertyMapMetaObject::propertyWrite(int index) +{ + priv->emitChanged(QString::fromUtf8(name(index))); +} + /*! \class QBindableMap \brief The QBindableMap class allows you to set key-value pairs that can be used in bindings. @@ -104,34 +125,31 @@ private: // can we provide a way to clear keys? // do we want to make any claims regarding key ordering? // should we have signals for insertion and and deletion -- becoming more model like -// should we emit change for our own changes as well? -// Bug or Feature?: values can be created in QML (owner.somethingElse = "Hello") will create somethingElse property. (need to verify if this is actually the case) -// Bug or Feature?: all values are read-write (there are no read-only values) /*! Constructs a bindable map with parent object \a parent. */ -QBindableMap::QBindableMap(QObject *parent) -: QObject(parent) +QmlPropertyMap::QmlPropertyMap(QObject *parent) +: QObject(*(new QmlPropertyMapPrivate), parent) { - m_mo = new QBindableMapMetaObject(this); + Q_D(QmlPropertyMap); + d->mo = new QmlPropertyMapMetaObject(this, d); } /*! Destroys the bindable map. */ -QBindableMap::~QBindableMap() +QmlPropertyMap::~QmlPropertyMap() { } /*! Clears the value (if any) associated with \a key. */ -void QBindableMap::clearValue(const QString &key) +void QmlPropertyMap::clearValue(const QString &key) { - //m_keys.remove(); //### - m_mo->setValue(key.toUtf8(), QVariant()); - //emit changed(key); + Q_D(QmlPropertyMap); + d->mo->setValue(key.toUtf8(), QVariant()); } /*! @@ -140,9 +158,10 @@ void QBindableMap::clearValue(const QString &key) If no value has been set for this key (or if the value has been cleared), an invalid QVariant is returned. */ -QVariant QBindableMap::value(const QString &key) const +QVariant QmlPropertyMap::value(const QString &key) const { - return m_mo->value(key.toUtf8()); + Q_D(const QmlPropertyMap); + return d->mo->value(key.toUtf8()); } /*! @@ -150,12 +169,12 @@ QVariant QBindableMap::value(const QString &key) const If the key doesn't exist, it is automatically created. */ -void QBindableMap::setValue(const QString &key, QVariant value) +void QmlPropertyMap::setValue(const QString &key, const QVariant &value) { - if (!m_keys.contains(key)) - m_keys.append(key); - m_mo->setValue(key.toUtf8(), value); - //emit changed(key); + Q_D(QmlPropertyMap); + if (!d->keys.contains(key)) + d->keys.append(key); + d->mo->setValue(key.toUtf8(), value); } /*! @@ -164,19 +183,16 @@ void QBindableMap::setValue(const QString &key, QVariant value) Keys that have been cleared will still appear in this list, even though their associated values are invalid QVariants. */ -QStringList QBindableMap::keys() const +QStringList QmlPropertyMap::keys() const { - return m_keys; + Q_D(const QmlPropertyMap); + return d->keys; } /*! \fn void QBindableMap::changed(const QString &key) 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. - */ +*/ -void QBindableMap::emitChanged(const QString &key) -{ - emit changed(key); -} QT_END_NAMESPACE diff --git a/src/declarative/extra/qbindablemap.h b/src/declarative/util/qmlpropertymap.h index aa1908e..295f4b7 100644 --- a/src/declarative/extra/qbindablemap.h +++ b/src/declarative/util/qmlpropertymap.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QBINDABLEMAP_H -#define QBINDABLEMAP_H +#ifndef QMLPROPERTYMAP_H +#define QMLPROPERTYMAP_H #include <QtDeclarative/qfxglobal.h> #include <QtCore/QObject> @@ -54,16 +54,16 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QBindableMapMetaObject; -class Q_DECLARATIVE_EXPORT QBindableMap : public QObject +class QmlPropertyMapPrivate; +class Q_DECLARATIVE_EXPORT QmlPropertyMap : public QObject { Q_OBJECT public: - QBindableMap(QObject *parent = 0); - virtual ~QBindableMap(); + QmlPropertyMap(QObject *parent = 0); + virtual ~QmlPropertyMap(); QVariant value(const QString &key) const; - void setValue(const QString &key, QVariant value); + void setValue(const QString &key, const QVariant &value); void clearValue(const QString &key); Q_INVOKABLE QStringList keys() const; @@ -72,11 +72,8 @@ Q_SIGNALS: void changed(const QString &key); private: - Q_DISABLE_COPY(QBindableMap) - void emitChanged(const QString &key); - QBindableMapMetaObject *m_mo; - QStringList m_keys; - friend class QBindableMapMetaObject; + Q_DECLARE_PRIVATE(QmlPropertyMap) + Q_DISABLE_COPY(QmlPropertyMap) }; QT_END_NAMESPACE diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index ec9967c..01ad898 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -19,7 +19,8 @@ SOURCES += \ util/qmlopenmetaobject.cpp \ util/qmltimeline.cpp \ util/qmltimer.cpp \ - util/qmlbind.cpp + util/qmlbind.cpp \ + util/qmlpropertymap.cpp HEADERS += \ util/qmlview.h \ @@ -46,4 +47,5 @@ HEADERS += \ util/qmlnullablevalue_p.h \ util/qmltimeline_p.h \ util/qmltimer.h \ - util/qmlbind.h + util/qmlbind.h \ + util/qmlpropertymap.h |