Skip to content

Commit

Permalink
Gui: create modal dialog on the heap if its parent widget is used in …
Browse files Browse the repository at this point in the history
…the property editor

For more details see: https://forum.freecadweb.org/viewtopic.php?f=23&t=70655
  • Loading branch information
wwmayer committed Oct 22, 2022
1 parent 916891c commit c5a7654
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
22 changes: 13 additions & 9 deletions src/Gui/Widgets.cpp
Expand Up @@ -1441,24 +1441,28 @@ void LabelEditor::setText(const QString& s)

void LabelEditor::changeText()
{
PropertyListDialog dlg(static_cast<int>(type), this);
dlg.setWindowTitle(tr("List"));
auto hboxLayout = new QVBoxLayout(&dlg);
auto buttonBox = new QDialogButtonBox(&dlg);
PropertyListDialog* dlg = new PropertyListDialog(static_cast<int>(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();
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -1568,15 +1568,18 @@ VectorListWidget::VectorListWidget(int decimals, QWidget *parent)

void VectorListWidget::buttonClicked()
{
VectorListEditor dlg(decimals, this);
dlg.setValues(value().value<QList<Base::Vector3d>>());
VectorListEditor* dlg = new VectorListEditor(decimals, this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setValues(value().value<QList<Base::Vector3d>>());
QPoint p(0, 0);
p = this->mapToGlobal(p);
dlg.move(p);
if (dlg.exec() == QDialog::Accepted) {
QVariant data = QVariant::fromValue<QList<Base::Vector3d>>(dlg.getValues());
dlg->move(p);
connect(dlg, &VectorListEditor::accepted, this, [&] {
QVariant data = QVariant::fromValue<QList<Base::Vector3d>>(dlg->getValues());
setValue(data);
}
});

dlg->exec();
}

void VectorListWidget::showValue(const QVariant& d)
Expand Down

0 comments on commit c5a7654

Please sign in to comment.