From: Simon Hausmann Date: Wed, 12 Jun 2013 07:19:37 +0000 (+0200) Subject: Implement iteration on QObject properties X-Git-Tag: upstream/5.2.1~669^2~259 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc7ad77b06f1e9ffa8a33557c8f323242c58f2ff;p=platform%2Fupstream%2Fqtdeclarative.git Implement iteration on QObject properties Change-Id: I036e3d835f1c0375460acf142738123c1728279e Reviewed-by: Lars Knoll --- diff --git a/src/qml/qml/v4/qv4qobjectwrapper.cpp b/src/qml/qml/v4/qv4qobjectwrapper.cpp index 815c278..bbdcbe9 100644 --- a/src/qml/qml/v4/qv4qobjectwrapper.cpp +++ b/src/qml/qml/v4/qv4qobjectwrapper.cpp @@ -696,42 +696,26 @@ PropertyAttributes QObjectWrapper::query(const Managed *m, String *name) return QV4::Object::query(m, name); } -QV4::Value QObjectWrapper::enumerateProperties(Object *object) +Property *QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes) { - QObjectWrapper *that = static_cast(object); + *name = 0; + *index = UINT_MAX; - if (that->m_object.isNull()) - return QV4::Value::undefinedValue(); - - QStringList result; - - QV8Engine *v8Engine = that->engine()->v8Engine; - QQmlEnginePrivate *ep = v8Engine->engine() - ? QQmlEnginePrivate::get(v8Engine->engine()) - : 0; - - QQmlPropertyCache *cache = 0; - QQmlData *ddata = QQmlData::get(that->m_object); - if (ddata) - cache = ddata->propertyCache; + QObjectWrapper *that = static_cast(m); - if (!cache) { - cache = ep ? ep->cache(that->m_object) : 0; - if (cache) { - if (ddata) { cache->addref(); ddata->propertyCache = cache; } - } else { - // Not cachable - fall back to QMetaObject (eg. dynamic meta object) - const QMetaObject *mo = that->m_object->metaObject(); - int pc = mo->propertyCount(); - int po = mo->propertyOffset(); - for (int i=po; iproperty(i).name()); - } - } else { - result = cache->propertyNames(); + if (!that->m_object) + return QV4::Object::advanceIterator(m, it, name, index, attributes); + + const QMetaObject *mo = that->m_object->metaObject(); + if (it->arrayIndex < mo->propertyCount()) { + *name = that->engine()->newString(QString::fromUtf8(mo->property(it->arrayIndex).name())); + ++it->arrayIndex; + if (attributes) + *attributes = QV4::Attr_Data; + it->tmpDynamicProperty.value = that->get(*name); + return &it->tmpDynamicProperty; } - - return QV4::Value::fromObject(that->engine()->newArrayObject(result)); + return QV4::Object::advanceIterator(m, it, name, index, attributes); } namespace QV4 { diff --git a/src/qml/qml/v4/qv4qobjectwrapper_p.h b/src/qml/qml/v4/qv4qobjectwrapper_p.h index 5729b70..97d2fb4 100644 --- a/src/qml/qml/v4/qv4qobjectwrapper_p.h +++ b/src/qml/qml/v4/qv4qobjectwrapper_p.h @@ -96,6 +96,8 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object static Value wrap(ExecutionEngine *engine, QObject *object); + using Object::get; + private: static Value create(ExecutionEngine *engine, QQmlData *ddata, QObject *object); @@ -110,10 +112,9 @@ private: static Value get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty); static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value); static PropertyAttributes query(const Managed *, String *name); + static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes); static void markObjects(Managed *that); - static Value enumerateProperties(Object *m_object); - static void destroy(Managed *that) { static_cast(that)->~QObjectWrapper();