diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2019-10-01 14:01:42 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-10-14 11:15:11 +0200 |
commit | 67ef2583e481a37d51cb9d5d4d6046069559a754 (patch) | |
tree | 4a5e9f72664ba44ff13370f97e09c3f12e503377 /src/qmlmodels | |
parent | ee62b2824fe91e95a3f8218b93ba55a2ef6660d0 (diff) |
VDMAbstractItemModelDataType: ensure meta-type is initialized
Since the delegate chooser can call value() on a delegate model
before the first call to createItem(), we need to ensure
that all structures (and in particular, m_rolenames) are
populated also in this case.
This is especially important for cases where value() is called
for every item in the model, as is the case for e.g. auto-completion
for combo boxes, as delegate creation is particularly expensive
there.
Task-number: QTBUG-78858
Change-Id: I66138d74839b9645d11c69c29f2e70264c65a68d
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/qmlmodels')
-rw-r--r-- | src/qmlmodels/qqmladaptormodel.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/qmlmodels/qqmladaptormodel.cpp b/src/qmlmodels/qqmladaptormodel.cpp index 48ff4e7d5b..012540244f 100644 --- a/src/qmlmodels/qqmladaptormodel.cpp +++ b/src/qmlmodels/qqmladaptormodel.cpp @@ -459,6 +459,11 @@ public: QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override { + if (!metaObject) { + VDMAbstractItemModelDataType *dataType = const_cast<VDMAbstractItemModelDataType *>(this); + dataType->initializeMetaType(model); + } + QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8()); if (it != roleNames.end()) { return model.aim()->index(model.rowAt(index), model.columnAt(index), model.rootIndex).data(*it); @@ -505,7 +510,7 @@ public: return new QQmlDMAbstractItemModelData(metaType, dataType, index, row, column); } - void initializeMetaType(QQmlAdaptorModel &model) + void initializeMetaType(const QQmlAdaptorModel &model) { QMetaObjectBuilder builder; setModelDataType<QQmlDMAbstractItemModelData>(&builder, this); |