From 097ff50d57bbd0e2087a110ec65a2cc78d22726f Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Wed, 19 Mar 2025 23:00:52 +0100 Subject: [PATCH] DesignSystem: Update valid bindings only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QDS-14670 Change-Id: I1008e6855f874bf4f9d6c2f415ecf6b628747c35 Reviewed-by: Henning Gründl Reviewed-by: Thomas Hartmann --- .../designsystemview/collectionmodel.cpp | 42 +++++++++++++++++-- .../designsystemview/collectionmodel.h | 2 + 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmldesigner/components/designsystemview/collectionmodel.cpp b/src/plugins/qmldesigner/components/designsystemview/collectionmodel.cpp index b6013a53488..dcffa13631f 100644 --- a/src/plugins/qmldesigner/components/designsystemview/collectionmodel.cpp +++ b/src/plugins/qmldesigner/components/designsystemview/collectionmodel.cpp @@ -37,8 +37,10 @@ void CollectionModel::setActiveTheme(const QString &themeName) aboutToSave(); // Update the active status - if (rowCount() && columnCount()) + if (rowCount() && columnCount()) { emit headerDataChanged(Qt::Horizontal, 0, columnCount() - 1); + updateBoundValues(); + } } } @@ -227,9 +229,16 @@ void CollectionModel::addProperty(GroupType group, const QString &name, const QV bool CollectionModel::setData(const QModelIndex &index, const QVariant &value, int role) { + bool result = false; + + ThemeProperty p = value.value(); switch (role) { case Qt::EditRole: { - ThemeProperty p = value.value(); + if (p.isBinding) { + if (!m_store->resolvedDSBinding(p.value.toString()).isValid()) + return false; // Invalid binding, it must resolved to a valid property. + } + const auto [groupType, propName] = m_propertyInfoList[index.row()]; p.name = propName; const ThemeId id = m_themeIdList[index.column()]; @@ -237,15 +246,20 @@ bool CollectionModel::setData(const QModelIndex &index, const QVariant &value, i updateCache(); emit dataChanged(index, index); + result = true; } } default: break; } - aboutToSave(); + if (result) { + aboutToSave(); + if (p.isBinding) + updateBoundValues(); + } - return false; + return result; } bool CollectionModel::setHeaderData(int section, @@ -323,4 +337,24 @@ void CollectionModel::aboutToSave() m_saveCompressionTimer.start(); } +void CollectionModel::updateBoundValues() +{ + // Re-evaluate the value of the all bound properties. + for (int themeIdCol = 0; themeIdCol < columnCount(); ++themeIdCol) { + const auto themeId = findThemeId(themeIdCol); + for (int propIndex = 0; propIndex < rowCount(); ++propIndex) { + const auto propInfo = findPropertyName(propIndex); + if (!propInfo) + continue; + const auto &[groupType, propName] = *propInfo; + if (auto property = m_collection->property(themeId, groupType, propName)) { + if (property->isValid() && property->isBinding) { + auto modelIndex = index(propIndex, themeIdCol); + emit dataChanged(modelIndex, modelIndex); + } + } + } + } +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/designsystemview/collectionmodel.h b/src/plugins/qmldesigner/components/designsystemview/collectionmodel.h index c1395fb7178..12d496cb79c 100644 --- a/src/plugins/qmldesigner/components/designsystemview/collectionmodel.h +++ b/src/plugins/qmldesigner/components/designsystemview/collectionmodel.h @@ -82,6 +82,8 @@ private: void save(); void aboutToSave(); + void updateBoundValues(); + private: DSThemeManager *m_collection = nullptr; DSStore *m_store;