Gui: fixes #10782: Unable to cancel Select module Open obj messagebox

This commit is contained in:
wmayer
2023-09-23 13:52:32 +02:00
committed by Chris Hennes
parent 83d4080fe8
commit 9728e60753
2 changed files with 19 additions and 14 deletions

View File

@@ -27,6 +27,7 @@
# include <QButtonGroup>
# include <QCompleter>
# include <QCryptographicHash>
# include <QDialogButtonBox>
# include <QDir>
# include <QGridLayout>
# include <QGroupBox>
@@ -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<int>(&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 {};
}
}
}

View File

@@ -32,6 +32,7 @@
#include <FCGlobal.h>
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;