aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2019-12-27 11:12:23 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-01-24 05:15:40 +0000
commit6dce8c470ca9711fc874b32519cefdcca40f149f (patch)
tree9d8174b320f00511bdf8d31e466c0fe786a01aba /src/imports
parent04e855d5e2639be8acd91f4a581f1500a2908282 (diff)
Add support to match against QObject properties in DelegateChooser
Views could use an array of QObject instances as a model, as an alterative to a QAIM subclass; but DelegateChooser only supported querying the value based on the model role name. Now a QObject property name can also be used as roleValue. [ChangeLog][QtQuick][Item Views] DelegateChooser now supports using a property name as roleValue when an array of QObject instances is used as the model for a view. Fixes: QTBUG-81580 Change-Id: I3e5b57ce0456520667e342741efbe46417f0843c Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/labsmodels/qqmldelegatecomponent.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/imports/labsmodels/qqmldelegatecomponent.cpp b/src/imports/labsmodels/qqmldelegatecomponent.cpp
index 4698287fe3..aaf3fea5da 100644
--- a/src/imports/labsmodels/qqmldelegatecomponent.cpp
+++ b/src/imports/labsmodels/qqmldelegatecomponent.cpp
@@ -218,7 +218,7 @@ bool QQmlDelegateChoice::match(int row, int column, const QVariant &value) const
/*!
\qmlproperty string QtQml.Models::DelegateChooser::role
- This property holds the role used to determine the delegate for a given model item.
+ This property holds the role or the property name used to determine the delegate for a given model item.
\sa DelegateChoice
*/
@@ -289,9 +289,15 @@ QQmlComponent *QQmlDelegateChooser::delegate(QQmlAdaptorModel *adaptorModel, int
v = value(adaptorModel, row, column, m_role);
if (!v.isValid()) { // check if the row only has modelData, for example if the row is a QVariantMap
v = value(adaptorModel, row, column, QStringLiteral("modelData"));
- if (v.isValid())
- v = v.toMap().value(m_role);
+
+ if (v.isValid()) {
+ if (v.canConvert(QMetaType::QVariantMap))
+ v = v.toMap().value(m_role);
+ else if (v.canConvert(QMetaType::QObjectStar))
+ v = v.value<QObject*>()->property(m_role.toUtf8());
+ }
}
+
// loop through choices, finding first one that fits
for (int i = 0; i < m_choices.count(); ++i) {
const QQmlDelegateChoice *choice = m_choices.at(i);