Be more robust wrt restoring settings.

Make sure that we give the QMainWindow always a valid layout before
restoring settings, so if something goes wrong with that, we don't end
up with a broken layout.
This commit is contained in:
con
2009-08-11 11:58:19 +02:00
parent 5435b09622
commit 0624fb5608
2 changed files with 16 additions and 4 deletions

View File

@@ -80,7 +80,8 @@ SharedSubWindow::~SharedSubWindow()
QHash<QString, QVariant> EditorWidget::m_globalState = QHash<QString, QVariant>();
EditorWidget::EditorWidget(QWidget *formWindow)
: m_mainWindow(new Core::Utils::FancyMainWindow)
: m_mainWindow(new Core::Utils::FancyMainWindow),
m_initialized(false)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
@@ -125,7 +126,6 @@ void EditorWidget::setDefaultLayout()
}
m_mainWindow->setTrackingEnabled(true);
m_globalState = m_mainWindow->saveSettings();
}
void EditorWidget::activate()
@@ -133,10 +133,21 @@ void EditorWidget::activate()
for (int i=0; i < DesignerSubWindowCount; i++)
m_designerSubWindows[i]->activate();
if (!m_initialized) {
// set a default layout, so if something goes wrong with
// restoring the settings below, there is a fallback
// (otherwise we end up with a broken mainwindow layout)
// we can't do it in the constructor, because the sub windows
// don't have their widgets yet there
setDefaultLayout();
m_initialized = true;
}
if (!m_globalState.isEmpty())
m_mainWindow->restoreSettings(m_globalState);
else
setDefaultLayout();
else {
m_globalState = m_mainWindow->saveSettings();
}
}
void EditorWidget::hideEvent(QHideEvent *)

View File

@@ -93,6 +93,7 @@ private:
SharedSubWindow* m_designerSubWindows[Designer::Constants::DesignerSubWindowCount];
QDockWidget *m_designerDockWidgets[Designer::Constants::DesignerSubWindowCount];
Core::Utils::FancyMainWindow *m_mainWindow;
bool m_initialized;
static QHash<QString, QVariant> m_globalState;
};