diff --git a/src/Gui/DlgAddPropertyVarSet.cpp b/src/Gui/DlgAddPropertyVarSet.cpp index bf97649bd4..8f1576abd9 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())); @@ -185,7 +196,6 @@ void DlgAddPropertyVarSet::clearEditors() removeEditor(); setOkEnabled(false); namePropertyToAdd.clear(); - editor = nullptr; } void DlgAddPropertyVarSet::removeEditor() @@ -193,6 +203,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); @@ -213,11 +224,14 @@ static PropertyEditor::PropertyItem *createPropertyItem(App::Property *prop) return item; } -void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, std::string& /*type*/) +void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, std::string& type) { editor.reset(propertyItem->createEditor(this, [this]() { this->valueChanged(); })); + if (type == "App::PropertyFont") { + propertyItem->setEditorData(editor.get(), QVariant()); + } editor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); editor->setObjectName(QString::fromUtf8("editor")); auto formLayout = qobject_cast(layout()); @@ -230,9 +244,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) @@ -262,10 +276,10 @@ 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); + addEditor(propertyItem.get(), type); } setOkEnabled(true); diff --git a/src/Gui/DlgAddPropertyVarSet.h b/src/Gui/DlgAddPropertyVarSet.h index ad69082d82..5db09b6b05 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(const QString& text); 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;