diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp index 1b505e7365..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,13 +245,27 @@ 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(); })); - propertyItem->setEditorData(editor.get(), QVariant()); + editor->blockSignals(true); + 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()); @@ -260,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); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 48733f4826..37031fd741 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -296,7 +296,7 @@ int PropertyItem::childCount() const int PropertyItem::columnCount() const { - return 2; + return PropertyItem::ColumnCount; } void PropertyItem::setReadOnly(bool ro) @@ -650,7 +650,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 @@ -743,9 +743,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;