diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-05-11 03:21:05 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-05-11 03:21:05 (GMT) |
commit | 865c022c2df25496055de897f37f8206cb4fc730 (patch) | |
tree | 09ae77903c25ba420b2a595a9e338c1cf423c144 /src/declarative/util | |
parent | 9c907d1267c3357d07e39a05fa4b323676792698 (diff) | |
download | Qt-865c022c2df25496055de897f37f8206cb4fc730.zip Qt-865c022c2df25496055de897f37f8206cb4fc730.tar.gz Qt-865c022c2df25496055de897f37f8206cb4fc730.tar.bz2 |
d-pointerize QmlOpenMetaObject
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qmlopenmetaobject.cpp | 120 | ||||
-rw-r--r-- | src/declarative/util/qmlopenmetaobject.h | 17 |
2 files changed, 76 insertions, 61 deletions
diff --git a/src/declarative/util/qmlopenmetaobject.cpp b/src/declarative/util/qmlopenmetaobject.cpp index fc20fa9..d0dd817 100644 --- a/src/declarative/util/qmlopenmetaobject.cpp +++ b/src/declarative/util/qmlopenmetaobject.cpp @@ -40,102 +40,124 @@ ****************************************************************************/ #include "qmlopenmetaobject.h" +#include "private/qmetaobjectbuilder_p.h" #include <QDebug> QT_BEGIN_NAMESPACE + +class QmlOpenMetaObjectPrivate +{ +public: + QmlOpenMetaObjectPrivate() : parent(0), mem(0) {} + + bool autoCreate; + QAbstractDynamicMetaObject *parent; + int propertyOffset; + int signalOffset; + QList<QVariant> data; + QHash<QByteArray, int> names; + QMetaObjectBuilder mob; + QMetaObject *mem; + QObject *object; +}; + QmlOpenMetaObject::QmlOpenMetaObject(QObject *obj, bool automatic) -: autoCreate(automatic), parent(0), mem(0), _object(obj) +: d(new QmlOpenMetaObjectPrivate) { - mob.setSuperClass(obj->metaObject()); - mob.setClassName(obj->metaObject()->className()); - mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); + d->autoCreate = automatic; + d->object = obj; + + d->mob.setSuperClass(obj->metaObject()); + d->mob.setClassName(obj->metaObject()->className()); + d->mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); QObjectPrivate *op = QObjectPrivate::get(obj); if (op->metaObject) - mob.setSuperClass(op->metaObject); + d->mob.setSuperClass(op->metaObject); - mem = mob.toMetaObject(); - *static_cast<QMetaObject *>(this) = *mem; + d->mem = d->mob.toMetaObject(); + *static_cast<QMetaObject *>(this) = *d->mem; op->metaObject = this; - _propertyOffset = propertyOffset(); - _signalOffset = methodOffset(); + d->propertyOffset = propertyOffset(); + d->signalOffset = methodOffset(); } QmlOpenMetaObject::~QmlOpenMetaObject() { - if (parent) - delete parent; - qFree(mem); + if (d->parent) + delete d->parent; + qFree(d->mem); + delete d; } int QmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a) { if (( c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty) - && id >= _propertyOffset) { - int propId = id - _propertyOffset; + && id >= d->propertyOffset) { + int propId = id - d->propertyOffset; if (c == QMetaObject::ReadProperty) { propertyRead(propId); - *reinterpret_cast<QVariant *>(a[0]) = data[propId]; + *reinterpret_cast<QVariant *>(a[0]) = d->data[propId]; } else if (c == QMetaObject::WriteProperty) { - if (data[propId] != *reinterpret_cast<QVariant *>(a[0])) { + if (d->data[propId] != *reinterpret_cast<QVariant *>(a[0])) { propertyWrite(propId); - data[propId] = *reinterpret_cast<QVariant *>(a[0]); - activate(_object, _signalOffset + propId, 0); + d->data[propId] = *reinterpret_cast<QVariant *>(a[0]); + activate(d->object, d->signalOffset + propId, 0); } } return -1; } else { - if (parent) - return parent->metaCall(c, id, a); + if (d->parent) + return d->parent->metaCall(c, id, a); else - return _object->qt_metacall(c, id, a); + return d->object->qt_metacall(c, id, a); } } QVariant QmlOpenMetaObject::value(int id) const { - Q_ASSERT(id >= 0 && id < data.count()); - return data.at(id); + Q_ASSERT(id >= 0 && id < d->data.count()); + return d->data.at(id); } void QmlOpenMetaObject::setValue(int id, const QVariant &value) { - Q_ASSERT(id >= 0 && id < data.count()); - data[id] = value; - activate(_object, id + _signalOffset, 0); + Q_ASSERT(id >= 0 && id < d->data.count()); + d->data[id] = value; + activate(d->object, id + d->signalOffset, 0); } QVariant QmlOpenMetaObject::value(const QByteArray &name) const { - QHash<QByteArray, int>::ConstIterator iter = names.find(name); - if (iter == names.end()) + QHash<QByteArray, int>::ConstIterator iter = d->names.find(name); + if (iter == d->names.end()) return QVariant(); - return data.at(*iter); + return d->data.at(*iter); } void QmlOpenMetaObject::setValue(const QByteArray &name, const QVariant &val) { - QHash<QByteArray, int>::ConstIterator iter = names.find(name); + QHash<QByteArray, int>::ConstIterator iter = d->names.find(name); int id = -1; - if (iter == names.end()) { - id = doCreateProperty(name.constData()) - _propertyOffset; + if (iter == d->names.end()) { + id = doCreateProperty(name.constData()) - d->propertyOffset; } else { id = *iter; } - if (data[id] == val) + if (d->data[id] == val) return; - data[id] = val; - activate(_object, id + _signalOffset, 0); + d->data[id] = val; + activate(d->object, id + d->signalOffset, 0); } int QmlOpenMetaObject::createProperty(const char *name, const char *) { - if (autoCreate) + if (d->autoCreate) return doCreateProperty(name); else return -1; @@ -143,17 +165,17 @@ int QmlOpenMetaObject::createProperty(const char *name, const char *) int QmlOpenMetaObject::doCreateProperty(const char *name) { - int id = mob.propertyCount(); - mob.addSignal("__" + QByteArray::number(id) + "()"); - QMetaPropertyBuilder build = mob.addProperty(name, "QVariant", id); + int id = d->mob.propertyCount(); + d->mob.addSignal("__" + QByteArray::number(id) + "()"); + QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id); build.setDynamic(true); - data << propertyCreated(id, build); - qFree(mem); - mem = mob.toMetaObject(); - *static_cast<QMetaObject *>(this) = *mem; - names.insert(name, id); + d->data << propertyCreated(id, build); + qFree(d->mem); + d->mem = d->mob.toMetaObject(); + *static_cast<QMetaObject *>(this) = *d->mem; + d->names.insert(name, id); - return _propertyOffset + id; + return d->propertyOffset + id; } void QmlOpenMetaObject::propertyRead(int) @@ -171,19 +193,19 @@ QVariant QmlOpenMetaObject::propertyCreated(int, QMetaPropertyBuilder &) int QmlOpenMetaObject::count() const { - return data.count(); + return d->data.count(); } QByteArray QmlOpenMetaObject::name(int idx) const { - Q_ASSERT(idx >= 0 && idx < data.count()); + Q_ASSERT(idx >= 0 && idx < d->data.count()); - return mob.property(idx).name(); + return d->mob.property(idx).name(); } QObject *QmlOpenMetaObject::object() const { - return _object; + return d->object; } QT_END_NAMESPACE diff --git a/src/declarative/util/qmlopenmetaobject.h b/src/declarative/util/qmlopenmetaobject.h index 17cecd87..f842f96 100644 --- a/src/declarative/util/qmlopenmetaobject.h +++ b/src/declarative/util/qmlopenmetaobject.h @@ -43,16 +43,16 @@ #define QMLOPENMETAOBJECT_H #include <QMetaObject> -#include "private/qmetaobjectbuilder_p.h" -#include <private/qobject_p.h> +#include <QtCore/private/qobject_p.h> #include <QObject> - QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +class QmlOpenMetaObjectPrivate; +class QMetaPropertyBuilder; class Q_DECLARATIVE_EXPORT QmlOpenMetaObject : public QAbstractDynamicMetaObject { public: @@ -78,15 +78,8 @@ protected: private: int doCreateProperty(const char *); - bool autoCreate; - QAbstractDynamicMetaObject *parent; - int _propertyOffset; - int _signalOffset; - QList<QVariant> data; - QHash<QByteArray, int> names; - QMetaObjectBuilder mob; - QMetaObject *mem; - QObject *_object; + + QmlOpenMetaObjectPrivate *d; }; |