Make SettingsDialog robust against multiple accept()/rejects()

That can happen if the user clicks very fast due to the multiple
levels of event loops.

Task-Nr: QTCREATORBUG-4818

Change-Id: I9c00dbf957a587c6e5839afebdd71e84b8c4a3c8
Reviewed-on: http://codereview.qt.nokia.com/16
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
dt_
2011-05-19 14:08:41 +02:00
committed by Daniel Teske
parent 9f7fdc5551
commit c960be456d
2 changed files with 10 additions and 1 deletions

View File

@@ -290,7 +290,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
m_categoryList(new CategoryListView), m_categoryList(new CategoryListView),
m_headerLabel(new QLabel), m_headerLabel(new QLabel),
m_running(false), m_running(false),
m_applied(false) m_applied(false),
m_finished(false)
{ {
m_applied = false; m_applied = false;
@@ -507,6 +508,9 @@ void SettingsDialog::filter(const QString &text)
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
if (m_finished)
return;
m_finished = true;
disconnectTabWidgets(); disconnectTabWidgets();
m_applied = true; m_applied = true;
foreach (IOptionsPage *page, m_visitedPages) foreach (IOptionsPage *page, m_visitedPages)
@@ -518,6 +522,9 @@ void SettingsDialog::accept()
void SettingsDialog::reject() void SettingsDialog::reject()
{ {
if (m_finished)
return;
m_finished = true;
disconnectTabWidgets(); disconnectTabWidgets();
foreach (IOptionsPage *page, m_pages) foreach (IOptionsPage *page, m_pages)
page->finish(); page->finish();
@@ -571,6 +578,7 @@ bool SettingsDialog::execDialog()
{ {
if (!m_running) { if (!m_running) {
m_running = true; m_running = true;
m_finished = false;
exec(); exec();
m_running = false; m_running = false;
m_instance = 0; m_instance = 0;

View File

@@ -113,6 +113,7 @@ private:
QLabel *m_headerLabel; QLabel *m_headerLabel;
bool m_running; bool m_running;
bool m_applied; bool m_applied;
bool m_finished;
QList<QEventLoop *> m_eventLoops; QList<QEventLoop *> m_eventLoops;
static QPointer<SettingsDialog> m_instance; static QPointer<SettingsDialog> m_instance;
}; };