QmlDesigner: Fix flag binding design system

* Fix setting bindings on flag types via the context menu
* Clear edit delegate input when creating a binding
* Remove comments

Change-Id: Ibfd281ee37500db88480c7c0f7820c00214d46ed
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
(cherry picked from commit dde640d75b)
This commit is contained in:
Henning Gruendl
2025-03-21 17:32:19 +01:00
committed by Thomas Hartmann
parent ae7567e2ba
commit a60a027254
3 changed files with 42 additions and 24 deletions

View File

@@ -345,6 +345,8 @@ Rectangle {
}
component Cell: Rectangle {
id: cell
required property var display
required property int row
required property int column
@@ -356,9 +358,7 @@ Rectangle {
required property bool isBinding
required property var propertyValue
property bool creatingBinding: false
readonly property bool bindingEditor: isBinding || creatingBinding
readonly property bool bindingEditor: cell.isBinding || tableView.model.editableOverride
color: root.backgroundColor
implicitWidth: root.cellWidth
@@ -425,11 +425,12 @@ Rectangle {
horizontalAlignment: TextInput.AlignLeft
verticalAlignment: TextInput.AlignVCenter
text: stringDelegate.bindingEditor ? stringDelegate.propertyValue
: stringDelegate.resolvedValue
text: stringDelegate.isBinding ? stringDelegate.propertyValue
: tableView.model.editableOverride ? ""
: stringDelegate.resolvedValue
Component.onCompleted: stringEditDelegate.selectAll()
Component.onDestruction: stringDelegate.creatingBinding = false
Component.onDestruction: tableView.model.editableOverride = false
TableView.onCommit: {
root.setValue(stringEditDelegate.text,
@@ -438,8 +439,6 @@ Rectangle {
stringDelegate.bindingEditor)
}
}
//Component.onCompleted: console.log("DelegateChoice - string", stringDelegate.resolvedValue)
}
}
@@ -521,13 +520,13 @@ Rectangle {
horizontalAlignment: TextInput.AlignLeft
verticalAlignment: TextInput.AlignVCenter
text: numberDelegate.propertyValue
text: numberDelegate.isBinding ? numberDelegate.propertyValue : ""
focus: numberDelegate.bindingEditor
visible: numberDelegate.bindingEditor
Component.onCompleted: numberBindingEditDelegate.selectAll()
Component.onDestruction: numberDelegate.creatingBinding = false
Component.onDestruction: tableView.model.editableOverride = false
}
TableView.onCommit: {
@@ -551,8 +550,6 @@ Rectangle {
numberEditDelegateFocusScope.alreadyCommited = true
}
}
//Component.onCompleted: console.log("DelegateChoice - number", numberDelegate.resolvedValue)
}
}
@@ -611,10 +608,12 @@ Rectangle {
horizontalAlignment: TextInput.AlignLeft
verticalAlignment: TextInput.AlignVCenter
text: flagDelegate.bindingEditor ? flagDelegate.propertyValue
: flagDelegate.resolvedValue
text: flagDelegate.isBinding ? flagDelegate.propertyValue
: tableView.model.editableOverride ? ""
: flagDelegate.resolvedValue
Component.onCompleted: flagBindingEditDelegate.selectAll()
Component.onDestruction: flagDelegate.creatingBinding = false
Component.onDestruction: tableView.model.editableOverride = false
TableView.onCommit: {
root.setValue(flagBindingEditDelegate.text,
@@ -623,8 +622,6 @@ Rectangle {
true)
}
}
//Component.onCompleted: console.log("DelegateChoice - bool", flagDelegate.resolvedValue)
}
}
@@ -709,8 +706,9 @@ Rectangle {
horizontalAlignment: TextInput.AlignLeft
verticalAlignment: TextInput.AlignVCenter
text: colorDelegate.bindingEditor ? colorDelegate.propertyValue
: colorDelegate.resolvedValue
text: colorDelegate.isBinding ? colorDelegate.propertyValue
: tableView.model.editableOverride ? ""
: colorDelegate.resolvedValue
RegularExpressionValidator {
id: hexValidator
@@ -720,7 +718,7 @@ Rectangle {
validator: colorDelegate.bindingEditor ? null : hexValidator
Component.onCompleted: colorEditDelegate.selectAll()
Component.onDestruction: colorDelegate.creatingBinding = false
Component.onDestruction: tableView.model.editableOverride = false
TableView.onCommit: {
root.setValue(colorEditDelegate.text,
@@ -758,8 +756,6 @@ Rectangle {
}
}
}
//Component.onCompleted: console.log("DelegateChoice - color", colorDelegate.resolvedValue)
}
}
}
@@ -795,7 +791,7 @@ Rectangle {
text: qsTr("Set Binding")
onTriggered: {
let cell = tableView.itemAtIndex(menu.modelIndex)
cell.creatingBinding = true
tableView.model.editableOverride = true
tableView.edit(menu.modelIndex)
}
}

View File

@@ -124,7 +124,7 @@ Qt::ItemFlags CollectionModel::flags(const QModelIndex &index) const
{
// If group type is FLAGS and not binding block editable
if (data(index, Roles::GroupRole).value<GroupType>() == GroupType::Flags
&& !data(index, Roles::BindingRole).toBool())
&& !data(index, Roles::BindingRole).toBool() && !m_editableOverride)
return QAbstractItemModel::flags(index);
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
@@ -282,6 +282,20 @@ bool CollectionModel::setHeaderData(int section,
return success;
}
bool CollectionModel::editableOverride() const
{
return m_editableOverride;
}
void CollectionModel::setEditableOverride(bool value)
{
if (value == m_editableOverride)
return;
m_editableOverride = value;
emit editableOverrideChanged();
}
ThemeId CollectionModel::findThemeId(int column) const
{
QTC_ASSERT(column > -1 && column < static_cast<int>(m_themeIdList.size()), return 0);

View File

@@ -29,6 +29,8 @@ public:
Q_ENUM(Roles)
Q_PROPERTY(QStringList themeNames READ themeNameList NOTIFY themeNameChanged FINAL)
Q_PROPERTY(bool editableOverride READ editableOverride WRITE setEditableOverride NOTIFY
editableOverrideChanged FINAL)
CollectionModel(DSThemeManager *collection, DSStore *store);
@@ -66,8 +68,12 @@ public:
const QVariant &value,
int role = Qt::EditRole) override;
bool editableOverride() const;
void setEditableOverride(bool value);
signals:
void themeNameChanged();
void editableOverrideChanged();
private:
ThemeId findThemeId(int column) const;
@@ -85,5 +91,7 @@ private:
std::vector<PropInfo> m_propertyInfoList;
QTimer m_saveCompressionTimer;
bool m_editableOverride = false;
};
} // namespace QmlDesigner