From fad1730d19b573661b6527146fe13661e5ae1f72 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 27 Jun 2012 14:43:05 +0200 Subject: [PATCH] Designer: Fix crash when switching from docked to multiple windows. Make sure the preference dialog is destroyed before changing the UI mode by introducing a flag that is set on UI mode changes, triggering the update afterwards. Change-Id: I9c488ba6b1b24faccb0a1606994aaf0474b56fc2 Reviewed-by: Oswald Buddenhagen Reviewed-by: Jarek Kobus --- src/designer/src/designer/qdesigner_actions.cpp | 7 +++++-- .../src/designer/qdesigner_appearanceoptions.cpp | 2 +- .../src/designer/qdesigner_appearanceoptions.h | 8 ++------ src/designer/src/designer/qdesigner_workbench.cpp | 24 ++++++++++++++++++++-- src/designer/src/designer/qdesigner_workbench.h | 3 +++ 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp index 0b02045..87039d5 100644 --- a/src/designer/src/designer/qdesigner_actions.cpp +++ b/src/designer/src/designer/qdesigner_actions.cpp @@ -1294,8 +1294,11 @@ bool QDesignerActions::ensureBackupDirectories() { void QDesignerActions::showPreferencesDialog() { - PreferencesDialog preferencesDialog(workbench()->core(), m_core->topLevel()); - preferencesDialog.exec(); + { + PreferencesDialog preferencesDialog(workbench()->core(), m_core->topLevel()); + preferencesDialog.exec(); + } // Make sure the preference dialog is destroyed before switching UI modes. + m_workbench->applyUiSettings(); } void QDesignerActions::showAppFontDialog() diff --git a/src/designer/src/designer/qdesigner_appearanceoptions.cpp b/src/designer/src/designer/qdesigner_appearanceoptions.cpp index 58bda38..40c9c09 100644 --- a/src/designer/src/designer/qdesigner_appearanceoptions.cpp +++ b/src/designer/src/designer/qdesigner_appearanceoptions.cpp @@ -153,8 +153,8 @@ void QDesignerAppearanceOptionsPage::apply() if (newOptions != m_initialOptions) { QDesignerSettings settings(m_core); newOptions.toSettings(settings); - QTimer::singleShot(0, this, SIGNAL(settingsChangedDelayed())); m_initialOptions = newOptions; + emit settingsChanged(); } } } diff --git a/src/designer/src/designer/qdesigner_appearanceoptions.h b/src/designer/src/designer/qdesigner_appearanceoptions.h index af85c16..ac2ccd9 100644 --- a/src/designer/src/designer/qdesigner_appearanceoptions.h +++ b/src/designer/src/designer/qdesigner_appearanceoptions.h @@ -105,11 +105,7 @@ private: UIMode m_initialUIMode; }; -/* The options page for appearance options. Emits a Timer-0 delayed changed - * signal to allow the preferences dialog to close (and be deleted) before a - * possible switch from docked mode to top-level mode happens. (The switch - * would delete the main window, which the preference dialog is a child of - * -> BOOM) */ +/* The options page for appearance options. */ class QDesignerAppearanceOptionsPage : public QObject, public QDesignerOptionsPageInterface { @@ -124,7 +120,7 @@ public: virtual void finish(); signals: - void settingsChangedDelayed(); + void settingsChanged(); private: QDesignerFormEditorInterface *m_core; diff --git a/src/designer/src/designer/qdesigner_workbench.cpp b/src/designer/src/designer/qdesigner_workbench.cpp index cbb1e83..5202a80 100644 --- a/src/designer/src/designer/qdesigner_workbench.cpp +++ b/src/designer/src/designer/qdesigner_workbench.cpp @@ -182,7 +182,8 @@ QDesignerWorkbench::QDesignerWorkbench() : m_globalMenuBar(new QMenuBar), m_mode(NeutralMode), m_dockedMainWindow(0), - m_state(StateInitializing) + m_state(StateInitializing), + m_uiSettingsChanged(false) { QDesignerSettings settings(m_core); @@ -246,7 +247,7 @@ QDesignerWorkbench::QDesignerWorkbench() : { // Add application specific options pages QDesignerAppearanceOptionsPage *appearanceOptions = new QDesignerAppearanceOptionsPage(m_core); - connect(appearanceOptions, SIGNAL(settingsChangedDelayed()), this, SLOT(restoreUISettings())); + connect(appearanceOptions, SIGNAL(settingsChanged()), this, SLOT(notifyUISettingsChanged())); QList optionsPages = m_core->optionsPages(); optionsPages.push_front(appearanceOptions); m_core->setOptionsPages(optionsPages); @@ -1061,6 +1062,25 @@ void QDesignerWorkbench::setFormWindowMinimized(QDesignerFormWindow *fw, bool mi } } +/* Applies UI mode changes using Timer-0 delayed signal + * signal to make sure the preferences dialog is closed and destroyed + * before a possible switch from docked mode to top-level mode happens. + * (The switch deletes the main window, which the preference dialog is + * a child of -> BOOM) */ + +void QDesignerWorkbench::applyUiSettings() +{ + if (m_uiSettingsChanged) { + m_uiSettingsChanged = false; + QTimer::singleShot(0, this, SLOT(restoreUISettings())); + } +} + +void QDesignerWorkbench::notifyUISettingsChanged() +{ + m_uiSettingsChanged = true; +} + void QDesignerWorkbench::restoreUISettings() { UIMode mode = QDesignerSettings(m_core).uiMode(); diff --git a/src/designer/src/designer/qdesigner_workbench.h b/src/designer/src/designer/qdesigner_workbench.h index 7f41180..cd5581d 100644 --- a/src/designer/src/designer/qdesigner_workbench.h +++ b/src/designer/src/designer/qdesigner_workbench.h @@ -116,6 +116,7 @@ public: bool handleClose(); bool readInBackup(); void updateBackup(QDesignerFormWindowInterface* fwi); + void applyUiSettings(); signals: void modeChanged(UIMode mode); @@ -140,6 +141,7 @@ private slots: void minimizationStateChanged(QDesignerFormWindowInterface *formWindow, bool minimized); void restoreUISettings(); + void notifyUISettingsChanged(); void slotFileDropped(const QString &f); private: @@ -205,6 +207,7 @@ private: enum State { StateInitializing, StateUp, StateClosing }; State m_state; + bool m_uiSettingsChanged; // UI mode changed in preference dialog, trigger delayed slot. }; QT_END_NAMESPACE -- 2.7.4