aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/types/qqmllistmodel.cpp17
-rw-r--r--src/qml/types/qqmllistmodel_p_p.h11
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp1
3 files changed, 19 insertions, 10 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index 40e7be6f56..0df243b3b0 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -1350,7 +1350,7 @@ void ModelObject::put(Managed *m, String *name, const Value &value)
ModelObject *that = static_cast<ModelObject*>(m);
ExecutionEngine *eng = that->engine();
- const int elementIndex = that->d()->m_elementIndex;
+ const int elementIndex = that->d()->elementIndex();
const QString propName = name->toQString();
int roleIndex = that->d()->m_model->m_listModel->setExistingProperty(elementIndex, propName, value, eng);
if (roleIndex != -1) {
@@ -1384,7 +1384,7 @@ ReturnedValue ModelObject::get(const Managed *m, String *name, bool *hasProperty
}
}
- const int elementIndex = that->d()->m_elementIndex;
+ const int elementIndex = that->d()->elementIndex();
QVariant value = that->d()->m_model->data(elementIndex, role->index);
return that->engine()->fromVariant(value);
}
@@ -1402,7 +1402,7 @@ void ModelObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, u
ScopedString roleName(scope, v4->newString(role.name));
name->setM(roleName->d());
*attributes = QV4::Attr_Data;
- QVariant value = that->d()->m_model->data(that->d()->m_elementIndex, role.index);
+ QVariant value = that->d()->m_model->data(that->d()->elementIndex(), role.index);
p->value = v4->fromVariant(value);
return;
}
@@ -2338,9 +2338,14 @@ QQmlV4Handle QQmlListModel::get(int index) const
result = QV4::QObjectWrapper::wrap(scope.engine, object);
} else {
QObject *object = m_listModel->getOrCreateModelObject(const_cast<QQmlListModel *>(this), index);
- result = scope.engine->memoryManager->allocObject<QV4::ModelObject>(object, const_cast<QQmlListModel *>(this), index);
- // Keep track of the QObjectWrapper in persistent value storage
- QQmlData::get(object)->jsWrapper.set(scope.engine, result);
+ QQmlData *ddata = QQmlData::get(object);
+ if (ddata->jsWrapper.isNullOrUndefined()) {
+ result = scope.engine->memoryManager->allocObject<QV4::ModelObject>(object, const_cast<QQmlListModel *>(this));
+ // Keep track of the QObjectWrapper in persistent value storage
+ ddata->jsWrapper.set(scope.engine, result);
+ } else {
+ result = ddata->jsWrapper.value();
+ }
}
}
diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h
index 983394e68b..633ddae43d 100644
--- a/src/qml/types/qqmllistmodel_p_p.h
+++ b/src/qml/types/qqmllistmodel_p_p.h
@@ -157,13 +157,16 @@ namespace QV4 {
namespace Heap {
struct ModelObject : public QObjectWrapper {
- ModelObject(QObject *object, QQmlListModel *model, int elementIndex)
+ ModelObject(QObject *object, QQmlListModel *model)
: QObjectWrapper(object)
, m_model(model)
- , m_elementIndex(elementIndex)
- {}
+ {
+ QObjectPrivate *op = QObjectPrivate::get(object);
+ m_nodeModelMetaObject = static_cast<ModelNodeMetaObject *>(op->metaObject);
+ }
+ int elementIndex() const { return m_nodeModelMetaObject->m_elementIndex; }
QQmlListModel *m_model;
- int m_elementIndex;
+ ModelNodeMetaObject *m_nodeModelMetaObject;
};
}
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index a881072c16..bab2f8e3a2 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -453,6 +453,7 @@ void tst_qqmllistmodel::dynamic_data()
QTest::newRow("get2") << "{get(-1) === undefined}" << 1 << "" << dr;
QTest::newRow("get3") << "{append({'foo':123});get(0) != undefined}" << 1 << "" << dr;
QTest::newRow("get4") << "{append({'foo':123});get(0).foo}" << 123 << "" << dr;
+ QTest::newRow("get5") << "{append({'foo':123});get(0) == get(0)}" << 1 << "" << dr;
QTest::newRow("get-modify1") << "{append({'foo':123,'bar':456});get(0).foo = 333;get(0).foo}" << 333 << "" << dr;
QTest::newRow("get-modify2") << "{append({'z':1});append({'foo':123,'bar':456});get(1).bar = 999;get(1).bar}" << 999 << "" << dr;