diff --git a/src/Gui/Dialogs/DlgAddProperty.cpp b/src/Gui/Dialogs/DlgAddProperty.cpp index 4ba786ac22..cabf0455ff 100644 --- a/src/Gui/Dialogs/DlgAddProperty.cpp +++ b/src/Gui/Dialogs/DlgAddProperty.cpp @@ -349,12 +349,21 @@ void DlgAddProperty::addEnumEditor(PropertyItem* propertyItem) void DlgAddProperty::addNormalEditor(PropertyItem* propertyItem) { - editor.reset(propertyItem->createEditor(this, []() {}, - FrameOption::WithFrame)); + editor.reset(propertyItem->createEditor(this, [this]() { + this->valueChanged(); + }, FrameOption::WithFrame)); } void DlgAddProperty::addEditor(PropertyItem* propertyItem) { + if (isSubLinkPropertyItem()) { + // Since sublinks need the 3D view to select an object and the dialog + // is modal, we do not provide an editor for sublinks. It is possible + // to create a property of this type though and the property can be set + // in the property view later which does give access to the 3D view. + return; + } + if (isEnumPropertyItem()) { addEnumEditor(propertyItem); } @@ -404,6 +413,10 @@ bool DlgAddProperty::isTypeWithEditor(const Base::Type& type) App::PropertyFloatList::getClassTypeId(), App::PropertyFont::getClassTypeId(), App::PropertyIntegerList::getClassTypeId(), + App::PropertyLink::getClassTypeId(), + App::PropertyLinkSub::getClassTypeId(), + App::PropertyLinkList::getClassTypeId(), + App::PropertyLinkSubList::getClassTypeId(), App::PropertyMaterialList::getClassTypeId(), App::PropertyPath::getClassTypeId(), App::PropertyString::getClassTypeId(), @@ -619,6 +632,13 @@ bool DlgAddProperty::isEnumPropertyItem() const QString::fromLatin1(App::PropertyEnumeration::getClassTypeId().getName()); } +bool DlgAddProperty::isSubLinkPropertyItem() const +{ + const QString& type = ui->comboBoxType->currentText(); + return type == QString::fromLatin1(App::PropertyLinkSub::getClassTypeId().getName()) || + type == QString::fromLatin1(App::PropertyLinkSubList::getClassTypeId().getName()); +} + QVariant DlgAddProperty::getEditorData() const { if (isEnumPropertyItem()) { @@ -663,6 +683,11 @@ void DlgAddProperty::setEditor(bool valueNeedsReset) else { initializeValue(); } + + if (editor) { + QVariant data = propertyItem->editorData(editor.get()); + propertyItem->setData(data); + } } void DlgAddProperty::setPropertyItem(App::Property* prop, bool supportsExpressions) @@ -807,6 +832,12 @@ void DlgAddProperty::valueChangedEnum() propEnum->setEnums(enumValuesVec); } +void DlgAddProperty::valueChanged() +{ + QVariant data = propertyItem->editorData(editor.get()); + propertyItem->setData(data); +} + /* We use these functions rather than the functions provided by App::Document * because this dialog may be opened when another transaction is in progress. * An example is opening a sketch. If this dialog uses the functions provided @@ -924,10 +955,6 @@ void DlgAddProperty::addDocumentation() { void DlgAddProperty::accept() { - if (editor) { - QVariant data = propertyItem->editorData(editor.get()); - propertyItem->setData(data); - } addDocumentation(); auto* object = freecad_cast(container); if (object) { diff --git a/src/Gui/Dialogs/DlgAddProperty.h b/src/Gui/Dialogs/DlgAddProperty.h index 325110f964..6fc72c7a76 100644 --- a/src/Gui/Dialogs/DlgAddProperty.h +++ b/src/Gui/Dialogs/DlgAddProperty.h @@ -95,6 +95,7 @@ public: QLayout* layout); public Q_SLOTS: + void valueChanged(); void valueChangedEnum(); private: @@ -122,6 +123,7 @@ private: void removeSelectionEditor(); QVariant getEditorData() const; void setEditorData(const QVariant& data); + bool isSubLinkPropertyItem() const; bool isEnumPropertyItem() const; void addEnumEditor(PropertyEditor::PropertyItem* propertyItem); void addNormalEditor(PropertyEditor::PropertyItem* propertyItem);