DesignSystem: Update valid bindings only

Task-number: QDS-14670
Change-Id: I1008e6855f874bf4f9d6c2f415ecf6b628747c35
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Vikas Pachdha
2025-03-19 23:00:52 +01:00
committed by Thomas Hartmann
parent a6c9fbb98e
commit 097ff50d57
2 changed files with 40 additions and 4 deletions

View File

@@ -37,8 +37,10 @@ void CollectionModel::setActiveTheme(const QString &themeName)
aboutToSave(); aboutToSave();
// Update the active status // Update the active status
if (rowCount() && columnCount()) if (rowCount() && columnCount()) {
emit headerDataChanged(Qt::Horizontal, 0, columnCount() - 1); 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 CollectionModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
bool result = false;
ThemeProperty p = value.value<ThemeProperty>();
switch (role) { switch (role) {
case Qt::EditRole: { case Qt::EditRole: {
ThemeProperty p = value.value<ThemeProperty>(); 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()]; const auto [groupType, propName] = m_propertyInfoList[index.row()];
p.name = propName; p.name = propName;
const ThemeId id = m_themeIdList[index.column()]; const ThemeId id = m_themeIdList[index.column()];
@@ -237,15 +246,20 @@ bool CollectionModel::setData(const QModelIndex &index, const QVariant &value, i
updateCache(); updateCache();
emit dataChanged(index, index); emit dataChanged(index, index);
result = true;
} }
} }
default: default:
break; break;
} }
aboutToSave(); if (result) {
aboutToSave();
if (p.isBinding)
updateBoundValues();
}
return false; return result;
} }
bool CollectionModel::setHeaderData(int section, bool CollectionModel::setHeaderData(int section,
@@ -323,4 +337,24 @@ void CollectionModel::aboutToSave()
m_saveCompressionTimer.start(); 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 } // namespace QmlDesigner

View File

@@ -82,6 +82,8 @@ private:
void save(); void save();
void aboutToSave(); void aboutToSave();
void updateBoundValues();
private: private:
DSThemeManager *m_collection = nullptr; DSThemeManager *m_collection = nullptr;
DSStore *m_store; DSStore *m_store;