From c5a765428522771efc0d728ea73b0c5a50fb6cd9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 22 Oct 2022 18:36:52 +0200 Subject: [PATCH] Gui: create modal dialog on the heap if its parent widget is used in the property editor For more details see: https://forum.freecadweb.org/viewtopic.php?f=23&t=70655 --- src/Gui/Widgets.cpp | 22 +++++++++++++--------- src/Gui/propertyeditor/PropertyItem.cpp | 15 +++++++++------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Gui/Widgets.cpp b/src/Gui/Widgets.cpp index 23aa09f01e..c69b2ca8f3 100644 --- a/src/Gui/Widgets.cpp +++ b/src/Gui/Widgets.cpp @@ -1441,24 +1441,28 @@ void LabelEditor::setText(const QString& s) void LabelEditor::changeText() { - PropertyListDialog dlg(static_cast(type), this); - dlg.setWindowTitle(tr("List")); - auto hboxLayout = new QVBoxLayout(&dlg); - auto buttonBox = new QDialogButtonBox(&dlg); + PropertyListDialog* dlg = new PropertyListDialog(static_cast(type), this); + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->setWindowTitle(tr("List")); + + auto hboxLayout = new QVBoxLayout(dlg); + auto buttonBox = new QDialogButtonBox(dlg); buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - auto edit = new PropertyListEditor(&dlg); + auto edit = new PropertyListEditor(dlg); edit->setPlainText(this->plainText); hboxLayout->addWidget(edit); hboxLayout->addWidget(buttonBox); - connect(buttonBox, SIGNAL(accepted()), &dlg, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), &dlg, SLOT(reject())); - if (dlg.exec() == QDialog::Accepted) { + connect(buttonBox, &QDialogButtonBox::accepted, dlg, &PropertyListDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, dlg, &PropertyListDialog::reject); + connect(dlg, &PropertyListDialog::accepted, this, [&] { QString inputText = edit->toPlainText(); QString text = QString::fromLatin1("[%1]").arg(inputText); lineEdit->setText(text); - } + }); + + dlg->exec(); } /** diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 9a3fa493f4..8c1a841615 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1568,15 +1568,18 @@ VectorListWidget::VectorListWidget(int decimals, QWidget *parent) void VectorListWidget::buttonClicked() { - VectorListEditor dlg(decimals, this); - dlg.setValues(value().value>()); + VectorListEditor* dlg = new VectorListEditor(decimals, this); + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->setValues(value().value>()); QPoint p(0, 0); p = this->mapToGlobal(p); - dlg.move(p); - if (dlg.exec() == QDialog::Accepted) { - QVariant data = QVariant::fromValue>(dlg.getValues()); + dlg->move(p); + connect(dlg, &VectorListEditor::accepted, this, [&] { + QVariant data = QVariant::fromValue>(dlg->getValues()); setValue(data); - } + }); + + dlg->exec(); } void VectorListWidget::showValue(const QVariant& d)