Merge pull request #15172 from Ondsel-Development/varset-property-types

Gui: Handle various property types better in VarSet dialog
This commit is contained in:
Chris Hennes
2024-07-15 11:24:46 -05:00
committed by GitHub
2 changed files with 30 additions and 11 deletions

View File

@@ -101,6 +101,18 @@ void DlgAddPropertyVarSet::initializeGroup()
comboBoxGroup.setEditText(QString::fromStdString(groupNamesSorted[0]));
}
void DlgAddPropertyVarSet::getSupportedTypes(std::vector<Base::Type>& types)
{
std::vector<Base::Type> 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<Base::Type> 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<QFormLayout*>(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);

View File

@@ -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<Base::Type>& types);
private:
std::unordered_set<std::string> unsupportedTypes = {
std::unordered_set<std::string> 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_DlgAddPropertyVarSet> ui;