aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmllistwrapper.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-06-10 17:11:52 +0200
committerLars Knoll <lars.knoll@digia.com>2013-06-11 16:00:28 +0200
commit83ede4249bf24b8a88db0ce957de27052b7aba7c (patch)
treefb9111175436970caba292b6feaeb4842e3d6768 /src/qml/qml/qqmllistwrapper.cpp
parenta5d8e134b201a27cdeec7faf2529d69343406405 (diff)
Implement objectiterator on top of an iterator method in the vtbl
This makes it easier to implement the array-like wrapper classes for qml lists and qt lists. Change-Id: I169025a3e9c76951c0778bcda4bbb1f9a8afc8a0 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmllistwrapper.cpp')
-rw-r--r--src/qml/qml/qqmllistwrapper.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp
index ec34905ca3..719119cc05 100644
--- a/src/qml/qml/qqmllistwrapper.cpp
+++ b/src/qml/qml/qqmllistwrapper.cpp
@@ -108,6 +108,10 @@ Value QmlListWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool
return Value::fromUInt32(count);
}
+ uint idx = name->asArrayIndex();
+ if (idx != UINT_MAX)
+ return getIndexed(m, ctx, idx, hasProperty);
+
return Value::undefinedValue();
}
@@ -139,23 +143,21 @@ void QmlListWrapper::destroy(Managed *that)
w->~QmlListWrapper();
}
-#if 0
-// ### does this need porting?
-v8::Handle<v8::Array> QV8ListWrapper::Enumerator(const v8::AccessorInfo &info)
+Property *QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attrs)
{
- QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This());
-
- if (!resource || resource->object.isNull()) return v8::Array::New();
-
- quint32 count = resource->property.count?resource->property.count(&resource->property):0;
-
- v8::Handle<v8::Array> rv = v8::Array::New(count);
-
- for (uint ii = 0; ii < count; ++ii)
- rv->Set(ii, Value::fromDouble(ii));
-
- return rv;
+ *name = 0;
+ *index = UINT_MAX;
+ QmlListWrapper *w = m->as<QmlListWrapper>();
+ quint32 count = w->property.count ? w->property.count(&w->property) : 0;
+ if (it->arrayIndex < count) {
+ if (attrs)
+ *attrs = QV4::Attr_Data;
+ *index = it->arrayIndex;
+ ++it->arrayIndex;
+ it->tmpDynamicProperty.value = QV4::QObjectWrapper::wrap(w->engine(), w->property.at(&w->property, *index));
+ return &it->tmpDynamicProperty;
+ }
+ return QV4::Object::advanceIterator(m, it, name, index, attrs);
}
-#endif
QT_END_NAMESPACE