Skip to content

Commit 84d0b16

Browse files
committed
Qt: Remove a few more instances of QDialog::exec()
1 parent fa965cf commit 84d0b16

24 files changed

+350
-303
lines changed

src/duckstation-qt/aboutdialog.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ AboutDialog::~AboutDialog() = default;
5757

5858
void AboutDialog::showThirdPartyNotices(QWidget* parent)
5959
{
60-
QDialog dialog(parent);
61-
dialog.setMinimumSize(700, 400);
62-
dialog.setWindowTitle(tr("DuckStation Third-Party Notices"));
60+
QDialog* const dialog = new QDialog(parent);
61+
dialog->setAttribute(Qt::WA_DeleteOnClose);
62+
dialog->setMinimumSize(700, 400);
63+
dialog->setWindowTitle(tr("DuckStation Third-Party Notices"));
6364

6465
QIcon icon;
6566
icon.addFile(QString::fromUtf8(":/icons/duck.png"), QSize(), QIcon::Normal, QIcon::Off);
66-
dialog.setWindowIcon(icon);
67+
dialog->setWindowIcon(icon);
6768

68-
QVBoxLayout* layout = new QVBoxLayout(&dialog);
69+
QVBoxLayout* layout = new QVBoxLayout(dialog);
6970

70-
QTextBrowser* tb = new QTextBrowser(&dialog);
71+
QTextBrowser* tb = new QTextBrowser;
7172
tb->setAcceptRichText(true);
7273
tb->setReadOnly(true);
7374
tb->setOpenExternalLinks(true);
@@ -83,9 +84,9 @@ void AboutDialog::showThirdPartyNotices(QWidget* parent)
8384
}
8485
layout->addWidget(tb, 1);
8586

86-
QDialogButtonBox* bb = new QDialogButtonBox(QDialogButtonBox::Close, &dialog);
87-
connect(bb, &QDialogButtonBox::rejected, &dialog, &QDialog::accept);
87+
QDialogButtonBox* bb = new QDialogButtonBox(QDialogButtonBox::Close);
88+
connect(bb, &QDialogButtonBox::rejected, dialog, &QDialog::accept);
8889
layout->addWidget(bb, 0);
8990

90-
dialog.exec();
91+
dialog->open();
9192
}

src/duckstation-qt/aboutdialog.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ class AboutDialog final : public QDialog
1818

1919
private:
2020
Ui::AboutDialog m_ui;
21-
2221
};

src/duckstation-qt/achievementlogindialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AchievementLoginDialog::AchievementLoginDialog(QWidget* parent, Achievements::Lo
2020
title_font.setPixelSize(20);
2121
m_ui.titleLabel->setFont(title_font);
2222
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
23-
setAttribute(Qt::WA_DeleteOnClose, true);
23+
setAttribute(Qt::WA_DeleteOnClose);
2424

2525
// Adjust text if needed based on reason.
2626
if (reason == Achievements::LoginRequestReason::TokenInvalid)

src/duckstation-qt/achievementlogindialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Achievements {
1010
enum class LoginRequestReason;
1111
}
1212

13-
class AchievementLoginDialog : public QDialog
13+
class AchievementLoginDialog final : public QDialog
1414
{
1515
Q_OBJECT
1616

src/duckstation-qt/achievementsettingswidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void AchievementSettingsWidget::onLoginLogoutPressed()
240240

241241
AchievementLoginDialog* login = new AchievementLoginDialog(this, Achievements::LoginRequestReason::UserInitiated);
242242
connect(login, &AchievementLoginDialog::accepted, this, &AchievementSettingsWidget::onLoginCompleted);
243-
login->show();
243+
login->open();
244244
}
245245

246246
void AchievementSettingsWidget::onLoginCompleted()

src/duckstation-qt/audiosettingswidget.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -279,31 +279,44 @@ void AudioSettingsWidget::onOutputMutedChanged(int new_state)
279279
g_emu_thread->setAudioOutputMuted(muted);
280280
}
281281

282+
namespace {
283+
class AudioStretchSettingsDialog final : public QDialog
284+
{
285+
public:
286+
AudioStretchSettingsDialog(SettingsInterface* sif, QWidget* parent) : QDialog(parent)
287+
{
288+
m_ui.setupUi(this);
289+
m_ui.icon->setPixmap(QIcon::fromTheme(QStringLiteral("volume-up-line")).pixmap(32));
290+
m_ui.buttonBox->button(QDialogButtonBox::Close)->setDefault(true);
291+
292+
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.sequenceLength, "Audio", "StretchSequenceLengthMS",
293+
AudioStreamParameters::DEFAULT_STRETCH_SEQUENCE_LENGTH, 0);
294+
QtUtils::BindLabelToSlider(m_ui.sequenceLength, m_ui.sequenceLengthLabel);
295+
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.seekWindowSize, "Audio", "StretchSeekWindowMS",
296+
AudioStreamParameters::DEFAULT_STRETCH_SEEKWINDOW, 0);
297+
QtUtils::BindLabelToSlider(m_ui.seekWindowSize, m_ui.seekWindowSizeLabel);
298+
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.overlap, "Audio", "StretchOverlapMS",
299+
AudioStreamParameters::DEFAULT_STRETCH_OVERLAP, 0);
300+
QtUtils::BindLabelToSlider(m_ui.overlap, m_ui.overlapLabel);
301+
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.useQuickSeek, "Audio", "StretchUseQuickSeek",
302+
AudioStreamParameters::DEFAULT_STRETCH_USE_QUICKSEEK);
303+
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.useAAFilter, "Audio", "StretchUseAAFilter",
304+
AudioStreamParameters::DEFAULT_STRETCH_USE_AA_FILTER);
305+
306+
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::accept);
307+
}
308+
309+
Ui::AudioStretchSettingsDialog m_ui;
310+
};
311+
} // namespace
312+
282313
void AudioSettingsWidget::onStretchSettingsClicked()
283314
{
284-
QDialog dlg(QtUtils::GetRootWidget(this));
285-
Ui::AudioStretchSettingsDialog dlgui;
286-
dlgui.setupUi(&dlg);
287-
dlgui.icon->setPixmap(QIcon::fromTheme(QStringLiteral("volume-up-line")).pixmap(32));
288-
dlgui.buttonBox->button(QDialogButtonBox::Close)->setDefault(true);
289-
290-
SettingsInterface* sif = m_dialog->getSettingsInterface();
291-
SettingWidgetBinder::BindWidgetToIntSetting(sif, dlgui.sequenceLength, "Audio", "StretchSequenceLengthMS",
292-
AudioStreamParameters::DEFAULT_STRETCH_SEQUENCE_LENGTH, 0);
293-
QtUtils::BindLabelToSlider(dlgui.sequenceLength, dlgui.sequenceLengthLabel);
294-
SettingWidgetBinder::BindWidgetToIntSetting(sif, dlgui.seekWindowSize, "Audio", "StretchSeekWindowMS",
295-
AudioStreamParameters::DEFAULT_STRETCH_SEEKWINDOW, 0);
296-
QtUtils::BindLabelToSlider(dlgui.seekWindowSize, dlgui.seekWindowSizeLabel);
297-
SettingWidgetBinder::BindWidgetToIntSetting(sif, dlgui.overlap, "Audio", "StretchOverlapMS",
298-
AudioStreamParameters::DEFAULT_STRETCH_OVERLAP, 0);
299-
QtUtils::BindLabelToSlider(dlgui.overlap, dlgui.overlapLabel);
300-
SettingWidgetBinder::BindWidgetToBoolSetting(sif, dlgui.useQuickSeek, "Audio", "StretchUseQuickSeek",
301-
AudioStreamParameters::DEFAULT_STRETCH_USE_QUICKSEEK);
302-
SettingWidgetBinder::BindWidgetToBoolSetting(sif, dlgui.useAAFilter, "Audio", "StretchUseAAFilter",
303-
AudioStreamParameters::DEFAULT_STRETCH_USE_AA_FILTER);
304-
305-
connect(dlgui.buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::accept);
306-
connect(dlgui.buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, [this, &dlg]() {
315+
AudioStretchSettingsDialog* const dlg =
316+
new AudioStretchSettingsDialog(m_dialog->getSettingsInterface(), QtUtils::GetRootWidget(this));
317+
dlg->setAttribute(Qt::WA_DeleteOnClose);
318+
319+
connect(dlg->m_ui.buttonBox->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, [this, dlg] {
307320
m_dialog->setIntSettingValue("Audio", "StretchSequenceLengthMS",
308321
m_dialog->isPerGameSettings() ?
309322
std::nullopt :
@@ -325,12 +338,12 @@ void AudioSettingsWidget::onStretchSettingsClicked()
325338
std::nullopt :
326339
std::optional<bool>(AudioStreamParameters::DEFAULT_STRETCH_USE_AA_FILTER));
327340

328-
dlg.reject();
341+
dlg->reject();
329342

330343
QMetaObject::invokeMethod(this, &AudioSettingsWidget::onStretchSettingsClicked, Qt::QueuedConnection);
331344
});
332345

333-
dlg.exec();
346+
dlg->open();
334347
}
335348

336349
void AudioSettingsWidget::resetVolume(bool fast_forward)

src/duckstation-qt/consolesettingswidget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ void ConsoleSettingsWidget::onEnableCPUClockSpeedControlChecked(int state)
194194

195195
QMessageBox* const mb = QtUtils::NewMessageBox(QMessageBox::Warning, tr("CPU Overclocking Warning"), message,
196196
QMessageBox::NoButton, QMessageBox::NoButton, Qt::WindowModal, this);
197-
mb->setAttribute(Qt::WA_DeleteOnClose, true);
198197
const QPushButton* const yes_button =
199198
mb->addButton(tr("Yes, I will confirm bugs without overclocking before reporting."), QMessageBox::YesRole);
200199
const QPushButton* const no_button = mb->addButton(tr("No, take me back to safety."), QMessageBox::NoRole);

src/duckstation-qt/controllerbindingwidgets.cpp

Lines changed: 100 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -370,101 +370,13 @@ void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
370370

371371
void ControllerBindingWidget::onMultipleDeviceAutomaticBindingTriggered()
372372
{
373-
// force a refresh after mapping
374-
if (doMultipleDeviceAutomaticBinding(this, m_dialog, m_port_number))
375-
onTypeChanged();
376-
}
377-
378-
bool ControllerBindingWidget::doMultipleDeviceAutomaticBinding(QWidget* parent, ControllerSettingsWindow* parent_dialog,
379-
u32 port)
380-
{
381-
QDialog dialog(parent);
382-
383-
QVBoxLayout* layout = new QVBoxLayout(&dialog);
384-
QLabel help(tr("Select the devices from the list below that you want to bind to this controller."), &dialog);
385-
layout->addWidget(&help);
386-
387-
QListWidget list(&dialog);
388-
list.setSelectionMode(QListWidget::SingleSelection);
389-
layout->addWidget(&list);
390-
391-
for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel()->getDeviceList())
392-
{
393-
QListWidgetItem* item = new QListWidgetItem;
394-
item->setText(QStringLiteral("%1 (%2)").arg(dev.identifier).arg(dev.display_name));
395-
item->setData(Qt::UserRole, dev.identifier);
396-
item->setIcon(InputDeviceListModel::getIconForKey(dev.key));
397-
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
398-
item->setCheckState(Qt::Unchecked);
399-
list.addItem(item);
400-
}
401-
402-
QDialogButtonBox bb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
403-
connect(&bb, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
404-
connect(&bb, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
405-
layout->addWidget(&bb);
406-
407-
if (dialog.exec() == QDialog::Rejected)
408-
return false;
409-
410-
auto lock = Host::GetSettingsLock();
411-
const bool global = (!parent_dialog || parent_dialog->isEditingGlobalSettings());
412-
SettingsInterface& si =
413-
*(global ? Host::Internal::GetBaseSettingsLayer() : parent_dialog->getEditingSettingsInterface());
414-
415-
// first device should clear mappings
416-
bool tried_any = false;
417-
bool mapped_any = false;
418-
const int count = list.count();
419-
for (int i = 0; i < count; i++)
420-
{
421-
QListWidgetItem* item = list.item(i);
422-
if (item->checkState() != Qt::Checked)
423-
continue;
424-
425-
tried_any = true;
426-
427-
const QString identifier = item->data(Qt::UserRole).toString();
428-
std::vector<std::pair<GenericInputBinding, std::string>> mapping =
429-
InputManager::GetGenericBindingMapping(identifier.toStdString());
430-
if (mapping.empty())
431-
{
432-
lock.unlock();
433-
QtUtils::MessageBoxCritical(
434-
parent, tr("Automatic Mapping"),
435-
tr("No generic bindings were generated for device '%1'. The controller/source may not "
436-
"support automatic mapping.")
437-
.arg(identifier));
438-
lock.lock();
439-
continue;
440-
}
441-
442-
mapped_any |= InputManager::MapController(si, port, mapping, !mapped_any);
443-
}
444-
445-
lock.unlock();
446-
447-
if (!tried_any)
448-
{
449-
QtUtils::MessageBoxInformation(parent, tr("Automatic Mapping"), tr("No devices were selected."));
450-
return false;
451-
}
373+
QDialog* const dialog = new MultipleDeviceAutobindDialog(this, m_dialog, m_port_number);
374+
dialog->setAttribute(Qt::WA_DeleteOnClose);
452375

453-
if (mapped_any)
454-
{
455-
if (global)
456-
{
457-
QtHost::SaveGameSettings(&si, false);
458-
g_emu_thread->reloadGameSettings(false);
459-
}
460-
else
461-
{
462-
QtHost::QueueSettingsSave();
463-
g_emu_thread->reloadInputBindings();
464-
}
465-
}
376+
// force a refresh after mapping
377+
connect(dialog, &QDialog::accepted, this, [this] { onTypeChanged(); });
466378

467-
return mapped_any;
379+
dialog->open();
468380
}
469381

470382
void ControllerBindingWidget::saveAndRefresh()
@@ -1079,3 +991,98 @@ ControllerCustomSettingsDialog::ControllerCustomSettingsDialog(QWidget* parent,
1079991
}
1080992

1081993
ControllerCustomSettingsDialog::~ControllerCustomSettingsDialog() = default;
994+
995+
MultipleDeviceAutobindDialog::MultipleDeviceAutobindDialog(QWidget* parent, ControllerSettingsWindow* settings_window,
996+
u32 port)
997+
: QDialog(parent), m_settings_window(settings_window), m_port(port)
998+
{
999+
QVBoxLayout* layout = new QVBoxLayout(this);
1000+
layout->addWidget(new QLabel(tr("Select the devices from the list below that you want to bind to this controller.")));
1001+
1002+
m_list = new QListWidget;
1003+
m_list->setSelectionMode(QListWidget::SingleSelection);
1004+
layout->addWidget(m_list);
1005+
1006+
for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel()->getDeviceList())
1007+
{
1008+
QListWidgetItem* item = new QListWidgetItem;
1009+
item->setIcon(InputDeviceListModel::getIconForKey(dev.key));
1010+
item->setText(QStringLiteral("%1 (%2)").arg(dev.identifier).arg(dev.display_name));
1011+
item->setData(Qt::UserRole, dev.identifier);
1012+
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
1013+
item->setCheckState(Qt::Unchecked);
1014+
m_list->addItem(item);
1015+
}
1016+
1017+
QDialogButtonBox* bb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
1018+
connect(bb, &QDialogButtonBox::accepted, this, &MultipleDeviceAutobindDialog::doAutomaticBinding);
1019+
connect(bb, &QDialogButtonBox::rejected, this, &QDialog::reject);
1020+
layout->addWidget(bb);
1021+
}
1022+
1023+
MultipleDeviceAutobindDialog::~MultipleDeviceAutobindDialog() = default;
1024+
1025+
void MultipleDeviceAutobindDialog::doAutomaticBinding()
1026+
{
1027+
auto lock = Host::GetSettingsLock();
1028+
const bool global = (!m_settings_window || m_settings_window->isEditingGlobalSettings());
1029+
SettingsInterface* si =
1030+
global ? Host::Internal::GetBaseSettingsLayer() : m_settings_window->getEditingSettingsInterface();
1031+
1032+
// first device should clear mappings
1033+
bool tried_any = false;
1034+
bool mapped_any = false;
1035+
const int count = m_list->count();
1036+
for (int i = 0; i < count; i++)
1037+
{
1038+
const QListWidgetItem* item = m_list->item(i);
1039+
if (item->checkState() != Qt::Checked)
1040+
continue;
1041+
1042+
tried_any = true;
1043+
1044+
const QString identifier = item->data(Qt::UserRole).toString();
1045+
std::vector<std::pair<GenericInputBinding, std::string>> mapping =
1046+
InputManager::GetGenericBindingMapping(identifier.toStdString());
1047+
if (mapping.empty())
1048+
{
1049+
lock.unlock();
1050+
QtUtils::MessageBoxCritical(
1051+
this, tr("Automatic Mapping"),
1052+
tr("No generic bindings were generated for device '%1'. The controller/source may not "
1053+
"support automatic mapping.")
1054+
.arg(identifier));
1055+
lock.lock();
1056+
continue;
1057+
}
1058+
1059+
mapped_any |= InputManager::MapController(*si, m_port, mapping, !mapped_any);
1060+
}
1061+
1062+
lock.unlock();
1063+
1064+
if (!tried_any)
1065+
{
1066+
QtUtils::MessageBoxInformation(this, tr("Automatic Mapping"), tr("No devices were selected."));
1067+
return;
1068+
}
1069+
1070+
if (mapped_any)
1071+
{
1072+
if (global)
1073+
{
1074+
QtHost::SaveGameSettings(si, false);
1075+
g_emu_thread->reloadGameSettings(false);
1076+
}
1077+
else
1078+
{
1079+
QtHost::QueueSettingsSave();
1080+
g_emu_thread->reloadInputBindings();
1081+
}
1082+
accept();
1083+
}
1084+
else
1085+
{
1086+
reject();
1087+
}
1088+
}

0 commit comments

Comments
 (0)