From 855d3e53250df0c0f4cdc438bd79ef9762378a7a Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Thu, 4 Jul 2024 00:07:47 +0200 Subject: [PATCH] Gui: Handle property types better in VarSet dialog This makes a distinction between types that cannot be instantiated and types without an editor (editing values can be done in the property view). It adapts to DlgAddProperty.* using the same mechanism to filter properties. --- src/Gui/DlgAddPropertyVarSet.cpp | 23 +++++++++++++++++------ src/Gui/DlgAddPropertyVarSet.h | 11 ++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Gui/DlgAddPropertyVarSet.cpp b/src/Gui/DlgAddPropertyVarSet.cpp index b3b477c3e5..d44e5a9747 100644 --- a/src/Gui/DlgAddPropertyVarSet.cpp +++ b/src/Gui/DlgAddPropertyVarSet.cpp @@ -101,6 +101,18 @@ void DlgAddPropertyVarSet::initializeGroup() comboBoxGroup.setEditText(QString::fromStdString(groupNamesSorted[0])); } +void DlgAddPropertyVarSet::getSupportedTypes(std::vector& types) +{ + std::vector proptypes; + Base::Type::getAllDerivedFrom(Base::Type::fromName("App::Property"), proptypes); + std::copy_if(proptypes.begin(), proptypes.end(), std::back_inserter(types), [](const Base::Type& type) { + return type.canInstantiate(); + }); + std::sort(types.begin(), types.end(), [](Base::Type a, Base::Type b) { + return strcmp(a.getName(), b.getName()) < 0; + }); +} + void DlgAddPropertyVarSet::initializeTypes() { auto paramGroup = App::GetApplication().GetParameterGroupByPath( @@ -112,8 +124,7 @@ void DlgAddPropertyVarSet::initializeTypes() } std::vector types; - Base::Type::getAllDerivedFrom(Base::Type::fromName("App::Property"),types); - std::sort(types.begin(), types.end(), [](Base::Type a, Base::Type b) { return strcmp(a.getName(), b.getName()) < 0; }); + getSupportedTypes(types); for(const auto& type : types) { ui->comboBoxType->addItem(QString::fromLatin1(type.getName())); @@ -183,7 +194,6 @@ void DlgAddPropertyVarSet::clearEditors() removeEditor(); setOkEnabled(false); namePropertyToAdd.clear(); - editor = nullptr; } void DlgAddPropertyVarSet::removeEditor() @@ -191,6 +201,7 @@ void DlgAddPropertyVarSet::removeEditor() if (editor) { layout()->removeWidget(editor.get()); QWidget::setTabOrder(ui->comboBoxType, ui->checkBoxAdd); + editor = nullptr; // FC_ERR("remove editor"); // printFocusChain(ui->comboBoxType); @@ -228,9 +239,9 @@ void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, // printFocusChain(editor.get()); } -bool DlgAddPropertyVarSet::isSupportedType(std::string& type) +bool DlgAddPropertyVarSet::isTypeWithEditor(const std::string& type) { - return unsupportedTypes.find(type) == unsupportedTypes.end(); + return typesWithoutEditor.find(type) == typesWithoutEditor.end(); } void DlgAddPropertyVarSet::createProperty(std::string& name, std::string& group) @@ -260,7 +271,7 @@ void DlgAddPropertyVarSet::createProperty(std::string& name, std::string& group) // editors that we can reuse removeEditor(); propertyItem.reset(createPropertyItem(prop)); - if (propertyItem && isSupportedType(type)) { + if (propertyItem && isTypeWithEditor(type)) { propertyItem->setPropertyData({prop}); propertyItem->bind(*objectIdentifier); addEditor(propertyItem.get(), type); diff --git a/src/Gui/DlgAddPropertyVarSet.h b/src/Gui/DlgAddPropertyVarSet.h index d5909e14f3..5143510342 100644 --- a/src/Gui/DlgAddPropertyVarSet.h +++ b/src/Gui/DlgAddPropertyVarSet.h @@ -84,17 +84,22 @@ private: void removeEditor(); void addEditor(PropertyEditor::PropertyItem* propertyItem, std::string& type); - bool isSupportedType(std::string& type); + bool isTypeWithEditor(const std::string& type); void createProperty(std::string& name, std::string& group); void onNamePropertyDetermined(); void onGroupDetermined(); void onTypePropertyDetermined(); + void getSupportedTypes(std::vector& types); + private: - std::unordered_set unsupportedTypes = { + std::unordered_set typesWithoutEditor = { "App::PropertyVector", "App::PropertyVectorDistance", "App::PropertyMatrix", - "App::PropertyRotation", "App::PropertyPlacement", "App::PropertyEnumeration"}; + "App::PropertyRotation", "App::PropertyPlacement", "App::PropertyEnumeration", + "App::PropertyDirection", "App::PropertyPlacementList", "App::PropertyPosition", + "App::PropertyExpressionEngine", "App::PropertyIntegerSet", + "Sketcher::PropertyConstraintList"}; App::VarSet* varSet; std::unique_ptr ui;