From 9728e60753cb9e1629dabccc2709a5a21ce074b2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 23 Sep 2023 13:52:32 +0200 Subject: [PATCH] Gui: fixes #10782: Unable to cancel Select module Open obj messagebox --- src/Gui/FileDialog.cpp | 30 +++++++++++++++++------------- src/Gui/FileDialog.h | 3 ++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp index d340197489..fc24dec76f 100644 --- a/src/Gui/FileDialog.cpp +++ b/src/Gui/FileDialog.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include # include @@ -889,16 +890,17 @@ SelectModule::SelectModule (const QString& type, const SelectModule::Dict& types spacerItem1 = new QSpacerItem(131, 31, QSizePolicy::Expanding, QSizePolicy::Minimum); hboxLayout->addItem(spacerItem1); - okButton = new QPushButton(this); - okButton->setObjectName(QString::fromUtf8("okButton")); - okButton->setText(tr("Select")); - okButton->setEnabled(false); + buttonBox = new QDialogButtonBox(this); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setStandardButtons(QDialogButtonBox::Open | QDialogButtonBox::Cancel); + buttonBox->button(QDialogButtonBox::Open)->setEnabled(false); - hboxLayout->addWidget(okButton); + hboxLayout->addWidget(buttonBox); gridLayout->addLayout(hboxLayout, 2, 0, 1, 1); // connections - connect(okButton, &QPushButton::clicked, this, &SelectModule::accept); + connect(buttonBox, &QDialogButtonBox::accepted, this, &SelectModule::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &SelectModule::reject); #if QT_VERSION < QT_VERSION_CHECK(5,15,0) connect(group, qOverload(&QButtonGroup::buttonClicked), this, &SelectModule::onButtonClicked); #else @@ -916,16 +918,13 @@ void SelectModule::accept() void SelectModule::reject() { - if (group->checkedButton()) - QDialog::reject(); + QDialog::reject(); } void SelectModule::onButtonClicked() { - if (group->checkedButton()) - okButton->setEnabled(true); - else - okButton->setEnabled(false); + QWidget* button = buttonBox->button(QDialogButtonBox::Open); + button->setEnabled(group->checkedButton() != nullptr); } QString SelectModule::getModule() const @@ -1049,8 +1048,13 @@ SelectModule::Dict SelectModule::importHandler(const QStringList& fileNames, con if (dlg.exec()) { QString mod = dlg.getModule(); const QStringList& files = fileExtension[it.key()]; - for (const auto & file : files) + for (const auto & file : files) { dict[file] = mod; + } + } + else { + // Cancelled + return {}; } } } diff --git a/src/Gui/FileDialog.h b/src/Gui/FileDialog.h index e80d366d79..62f0ddfb83 100644 --- a/src/Gui/FileDialog.h +++ b/src/Gui/FileDialog.h @@ -32,6 +32,7 @@ #include class QButtonGroup; +class QDialogButtonBox; class QGridLayout; class QGroupBox; class QHBoxLayout; @@ -269,7 +270,7 @@ private Q_SLOTS: void onButtonClicked(); private: - QPushButton *okButton; + QDialogButtonBox *buttonBox; QButtonGroup* group; QGridLayout *gridLayout; QHBoxLayout *hboxLayout;