forked from qt-creator/qt-creator
Core: Use QDialog::open instead of exec
Task-number: QTBUG-117814 Change-Id: If92d627c2ae71721e61916cf50c26f5a41e35725 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -455,7 +455,6 @@ private:
|
|||||||
QCheckBox *m_sortCheckBox;
|
QCheckBox *m_sortCheckBox;
|
||||||
QListView *m_categoryList;
|
QListView *m_categoryList;
|
||||||
QLabel *m_headerLabel;
|
QLabel *m_headerLabel;
|
||||||
std::vector<QEventLoop *> m_eventLoops;
|
|
||||||
bool m_running = false;
|
bool m_running = false;
|
||||||
bool m_applied = false;
|
bool m_applied = false;
|
||||||
bool m_finished = false;
|
bool m_finished = false;
|
||||||
@@ -757,11 +756,6 @@ void SettingsDialog::done(int val)
|
|||||||
|
|
||||||
ICore::saveSettings(ICore::SettingsDialogDone); // save all settings
|
ICore::saveSettings(ICore::SettingsDialogDone); // save all settings
|
||||||
|
|
||||||
// exit event loops in reverse order of addition
|
|
||||||
for (QEventLoop *eventLoop : m_eventLoops)
|
|
||||||
eventLoop->exit();
|
|
||||||
m_eventLoops.clear();
|
|
||||||
|
|
||||||
QDialog::done(val);
|
QDialog::done(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -773,29 +767,28 @@ bool SettingsDialog::execDialog()
|
|||||||
static const char kPreferenceDialogSize[] = "Core/PreferenceDialogSize";
|
static const char kPreferenceDialogSize[] = "Core/PreferenceDialogSize";
|
||||||
const QSize initialSize(kInitialWidth, kInitialHeight);
|
const QSize initialSize(kInitialWidth, kInitialHeight);
|
||||||
resize(ICore::settings()->value(kPreferenceDialogSize, initialSize).toSize());
|
resize(ICore::settings()->value(kPreferenceDialogSize, initialSize).toSize());
|
||||||
exec();
|
|
||||||
m_running = false;
|
// We call open here as exec is no longer the preferred method of displaying
|
||||||
m_instance = nullptr;
|
// modal dialogs. The issue that triggered the change here was QTBUG-117814
|
||||||
ICore::settings()->setValueWithDefault(kPreferenceDialogSize,
|
// (on macOS: Caps Lock indicator does not update)
|
||||||
size(),
|
open();
|
||||||
initialSize);
|
connect(this, &QDialog::finished, this, [this, initialSize] {
|
||||||
// make sure that the current "single" instance is deleted
|
m_running = false;
|
||||||
// we can't delete right away, since we still access the m_applied member
|
m_instance = nullptr;
|
||||||
deleteLater();
|
ICore::settings()->setValueWithDefault(kPreferenceDialogSize, size(), initialSize);
|
||||||
} else {
|
// make sure that the current "single" instance is deleted
|
||||||
// exec dialog is called while the instance is already running
|
// we can't delete right away, since we still access the m_applied member
|
||||||
// this can happen when a event triggers a code path that wants to
|
deleteLater();
|
||||||
// show the settings dialog again
|
});
|
||||||
// e.g. when starting the debugger (with non-built debugging helpers),
|
|
||||||
// and manually opening the settings dialog, after the debugger hit
|
|
||||||
// a break point it will complain about missing helper, and offer the
|
|
||||||
// option to open the settings dialog.
|
|
||||||
// Keep the UI running by creating another event loop.
|
|
||||||
QEventLoop eventLoop;
|
|
||||||
m_eventLoops.emplace(m_eventLoops.begin(), &eventLoop);
|
|
||||||
eventLoop.exec();
|
|
||||||
QTC_ASSERT(m_eventLoops.empty(), return m_applied;);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function needs to be blocking, so we need to wait for the dialog to finish.
|
||||||
|
// We cannot use QDialog::exec due to the issue described above at "open()".
|
||||||
|
// Since execDialog can be called multiple times, we need to run potentially multiple
|
||||||
|
// loops here, to have every invocation of execDialog() wait for the dialog to finish.
|
||||||
|
while (m_running)
|
||||||
|
QApplication::processEvents(QEventLoop::WaitForMoreEvents);
|
||||||
|
|
||||||
return m_applied;
|
return m_applied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user