From 4bbc59d3094a109b7fa8945375f98725675e841f Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Tue, 1 Apr 2025 10:32:18 +0200 Subject: [PATCH 1/3] [Core] Make PropertyItem column usage more clear - Renamed dataProperty -> dataPropertyName because the function returns variants for the property name. - Add an enum for the column to remove magic numbers --- src/Gui/propertyeditor/PropertyItem.cpp | 9 ++++----- src/Gui/propertyeditor/PropertyItem.h | 8 +++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 94bbd659f7..e7852c02a2 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -295,7 +295,7 @@ int PropertyItem::childCount() const int PropertyItem::columnCount() const { - return 2; + return PropertyItem::ColumnCount; } void PropertyItem::setReadOnly(bool ro) @@ -649,7 +649,7 @@ void PropertyItem::setPropertyValue(const QString& value) setPropertyValue(value.toStdString()); } -QVariant PropertyItem::dataProperty(int role) const +QVariant PropertyItem::dataPropertyName(int role) const { if (role == Qt::ForegroundRole && linked) { return QVariant::fromValue(QColor(0x20, 0xaa, 0x20)); // NOLINT @@ -742,9 +742,8 @@ QVariant PropertyItem::dataValue(int role) const QVariant PropertyItem::data(int column, int role) const { - // property name - if (column == 0) { - return dataProperty(role); + if (column == PropertyItem::NameColumn) { + return dataPropertyName(role); } return dataValue(role); diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index b8182c4fd8..cfdcc21a1b 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -130,6 +130,12 @@ class GuiExport PropertyItem: public QObject, public ExpressionBinding PROPERTYITEM_HEADER public: + enum Column { + NameColumn = 0, + ValueColumn = 1, + ColumnCount + }; + ~PropertyItem() override; /** Sets the current property objects. */ @@ -216,7 +222,7 @@ protected: void onChange() override; private: - QVariant dataProperty(int role) const; + QVariant dataPropertyName(int role) const; QVariant dataValue(int role) const; QString toString(const Py::Object&) const; QString asNone(const Py::Object&) const; From 84468fbc25bdf1272fb68d98f7e2b28b1dffa4a8 Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Tue, 1 Apr 2025 10:34:19 +0200 Subject: [PATCH 2/3] [Core] Show units in value editor VarSet dialog Before this change, the units were not shown in the editor for values. With this change the units (if applicable) are shown in the editor. --- src/Gui/Dialogs/DlgAddPropertyVarSet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp index 1b505e7365..a974ac4fdf 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp @@ -251,7 +251,9 @@ void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, editor.reset(propertyItem->createEditor(this, [this]() { this->valueChanged(); })); - propertyItem->setEditorData(editor.get(), QVariant()); + propertyItem->setEditorData( + editor.get(), + propertyItem->data(PropertyEditor::PropertyItem::ValueColumn, Qt::EditRole)); editor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); editor->setObjectName(QStringLiteral("editor")); auto formLayout = qobject_cast(layout()); From efcd78777759eb63224dae7a51352026fe5652df Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Tue, 1 Apr 2025 12:25:44 +0200 Subject: [PATCH 3/3] [Core] Fix value field unit selection Qt automatically selects the text in the value field on creation. This interferes with the selection when the field has focus. This commit ensures that the automatic selection is undone. --- src/Gui/Dialogs/DlgAddPropertyVarSet.cpp | 17 ++++++++++++++++- src/Gui/Dialogs/DlgAddPropertyVarSet.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp index a974ac4fdf..6a654898bf 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp @@ -153,7 +153,7 @@ static void printFocusChain(QWidget *widget) { QWidget* start = widget; int i = 0; do { - FC_ERR(" " << widget->objectName().toStdString(); + FC_ERR(" " << widget->objectName().toStdString()); widget = widget->nextInFocusChain(); i++; } while (widget != nullptr && i < 30 && start != widget); @@ -245,12 +245,24 @@ static PropertyEditor::PropertyItem *createPropertyItem(App::Property *prop) return item; } +void DlgAddPropertyVarSet::removeSelectionEditor() +{ + // If the editor has a lineedit, then Qt selects the string inside it when + // the editor is created. This interferes with the editor getting focus. + // For example, units will then be selected as well, whereas this is not + // the behavior we want. We therefore deselect the text in the lineedit. + if (auto lineEdit = editor->findChild()) { + lineEdit->deselect(); + } +} + void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, [[maybe_unused]]std::string& type) { editor.reset(propertyItem->createEditor(this, [this]() { this->valueChanged(); })); + editor->blockSignals(true); propertyItem->setEditorData( editor.get(), propertyItem->data(PropertyEditor::PropertyItem::ValueColumn, Qt::EditRole)); @@ -262,6 +274,9 @@ void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, QWidget::setTabOrder(ui->comboBoxType, editor.get()); QWidget::setTabOrder(editor.get(), ui->checkBoxAdd); + removeSelectionEditor(); + editor->blockSignals(false); + // FC_ERR("add editor"); // printFocusChain(editor.get()); } diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.h b/src/Gui/Dialogs/DlgAddPropertyVarSet.h index d59a684cf6..3c797db686 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.h +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.h @@ -92,6 +92,7 @@ private: void clearCurrentProperty(); void removeEditor(); + void removeSelectionEditor(); void addEditor(PropertyEditor::PropertyItem* propertyItem, std::string& type); bool isTypeWithEditor(const std::string& type);