aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-10-31 13:02:51 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2019-02-21 10:55:03 +0000
commit99e2356a734fa3eb55ffc2e983658d17ab4c3e9f (patch)
tree6bcb7aa33c0cee20a363fb4c0378acd635cefbd2 /src/qml/types
parent3b9ecd6174a7a6eacf22b5088b66b203160bfdbd (diff)
QQmlAdaptorModel::Accessors: create a propertyCache for all accessors, not just for QAIM
From before, only accessors for wrapping a QAbstractItemModel had to create a dynamic QMetaObject together with a shared QQmlPropertyCache (for enabling model roles in the delegate). Each model item in the view would get a QQmlData with the dynamic property cache assigned, which would then later be used by the v4 runtime during property lookup. But after we added the properties 'row' and 'column' to the model items, we now always need to create a property cache, regardless of the Accessor used. That way we can we specify the correct metaObject revision of the model item in the cache, which will also allow us to revision the new properties so that they will be respected by the v4 runtime. In this patch we hard-code the revision (modelItemRevision) to be 0, but this will change in a subsequent patch. This patch will move the 'metaObject' and 'propertyCache' up to the base class (Accessor), and ensure that we create a property cache for each of the non-pure-virtual sub classes. The model item wrappers will then, when creating a QQmlData, assign the shared cache from the associated Accessor. Task-number: QTBUG-70031 Change-Id: If6a67d5968d360d4a2b23d8291669c0549e8a342 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/types')
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp19
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h4
2 files changed, 21 insertions, 2 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 48cc77bc3d..53e3f65553 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -2036,7 +2036,9 @@ void QV4::Heap::QQmlDelegateModelItemObject::destroy()
}
-QQmlDelegateModelItem::QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType, int modelIndex, int row, int column)
+QQmlDelegateModelItem::QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType,
+ QQmlAdaptorModel::Accessors *accessor,
+ int modelIndex, int row, int column)
: v4(metaType->v4Engine)
, metaType(metaType)
, contextData(nullptr)
@@ -2053,6 +2055,21 @@ QQmlDelegateModelItem::QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *meta
, column(column)
{
metaType->addref();
+
+ if (accessor->propertyCache) {
+ // The property cache in the accessor is common for all the model
+ // items in the model it wraps. It describes available model roles,
+ // together with revisioned properties like row, column and index, all
+ // which should be available in the delegate. We assign this cache to the
+ // model item so that the QML engine can use the revision information
+ // when resolving the properties (rather than falling back to just
+ // inspecting the QObject in the model item directly).
+ QQmlData *qmldata = QQmlData::get(this, true);
+ if (qmldata->propertyCache)
+ qmldata->propertyCache->release();
+ qmldata->propertyCache = accessor->propertyCache.data();
+ qmldata->propertyCache->addref();
+ }
}
QQmlDelegateModelItem::~QQmlDelegateModelItem()
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 5e480f4df6..0cd772ede0 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -100,7 +100,9 @@ class QQmlDelegateModelItem : public QObject
Q_PROPERTY(int column MEMBER column NOTIFY columnChanged)
Q_PROPERTY(QObject *model READ modelObject CONSTANT)
public:
- QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType, int modelIndex, int row, int column);
+ QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType,
+ QQmlAdaptorModel::Accessors *accessor, int modelIndex,
+ int row, int column);
~QQmlDelegateModelItem();
void referenceObject() { ++objectRef; }