diff options
author | Santhosh Kumar <[email protected]> | 2024-07-02 11:28:25 +0200 |
---|---|---|
committer | Santhosh Kumar <[email protected]> | 2024-07-04 06:53:29 +0200 |
commit | 43f7e0a656fa38c51ed6fbb64853eb6953ab11a3 (patch) | |
tree | 3d1c1c847ebe43f732640c933e46b5d2b5bd2d74 /src/labs/models/qqmltablemodel.cpp | |
parent | 0aabb7c36910d5f4349c4d58c2e4a0e06633aae1 (diff) |
Support parsing variant map in qml table model APIs
In general, the quick compiler generates native code when AOT enabled
for better performance. This can cause issues in the qml table model
APIs (such as insertRow(), appendRow(), setRow()), as these can parse
only js object but not a variant map (even though internally these APIs
convert those js object to variant map).
In this patch, the qml table model APIs are enabled to parse both js
and variant map objects.
Fixes: QTBUG-126723
Pick-to: 6.8 6.7 6.5
Change-Id: I927feb9e3ee83004ff044a9cf33848452ff1f3cd
Reviewed-by: Ulf Hermann <[email protected]>
Diffstat (limited to 'src/labs/models/qqmltablemodel.cpp')
-rw-r--r-- | src/labs/models/qqmltablemodel.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/labs/models/qqmltablemodel.cpp b/src/labs/models/qqmltablemodel.cpp index adf187f225..5f31352cf9 100644 --- a/src/labs/models/qqmltablemodel.cpp +++ b/src/labs/models/qqmltablemodel.cpp @@ -415,7 +415,8 @@ void QQmlTableModel::doInsert(int rowIndex, const QVariant &row) // Adding rowAsVariant.toList() will add each invidual variant in the list, // which is definitely not what we want. - const QVariant rowAsVariant = row.value<QJSValue>().toVariant(); + const QVariant rowAsVariant = row.userType() == QMetaType::QVariantMap ? row : row.value<QJSValue>().toVariant(); + mRows.insert(rowIndex, rowAsVariant); ++mRowCount; @@ -955,9 +956,11 @@ bool QQmlTableModel::validateNewRow(const char *functionName, const QVariant &ro return true; } + const bool isVariantMap = (row.userType() == QMetaType::QVariantMap); + // Don't require each row to be a QJSValue when setting all rows, // as they won't be; they'll be QVariantMap. - if (operation != SetRowsOperation && !validateRowType(functionName, row)) + if (operation != SetRowsOperation && (!isVariantMap && !validateRowType(functionName, row))) return false; if (operation == OtherOperation) { @@ -974,7 +977,7 @@ bool QQmlTableModel::validateNewRow(const char *functionName, const QVariant &ro } } - const QVariant rowAsVariant = operation == SetRowsOperation + const QVariant rowAsVariant = operation == SetRowsOperation || isVariantMap ? row : row.value<QJSValue>().toVariant(); if (rowAsVariant.userType() != QMetaType::QVariantMap) { qmlWarning(this) << functionName << ": row manipulation functions " |