Skip to content
Snippets Groups Projects
Commit 0624fb56 authored by con's avatar con
Browse files

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.
parent 5435b096
No related branches found
No related tags found
No related merge requests found
...@@ -80,7 +80,8 @@ SharedSubWindow::~SharedSubWindow() ...@@ -80,7 +80,8 @@ SharedSubWindow::~SharedSubWindow()
QHash<QString, QVariant> EditorWidget::m_globalState = QHash<QString, QVariant>(); QHash<QString, QVariant> EditorWidget::m_globalState = QHash<QString, QVariant>();
EditorWidget::EditorWidget(QWidget *formWindow) EditorWidget::EditorWidget(QWidget *formWindow)
: m_mainWindow(new Core::Utils::FancyMainWindow) : m_mainWindow(new Core::Utils::FancyMainWindow),
m_initialized(false)
{ {
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0); layout->setMargin(0);
...@@ -125,7 +126,6 @@ void EditorWidget::setDefaultLayout() ...@@ -125,7 +126,6 @@ void EditorWidget::setDefaultLayout()
} }
m_mainWindow->setTrackingEnabled(true); m_mainWindow->setTrackingEnabled(true);
m_globalState = m_mainWindow->saveSettings();
} }
void EditorWidget::activate() void EditorWidget::activate()
...@@ -133,10 +133,21 @@ void EditorWidget::activate() ...@@ -133,10 +133,21 @@ void EditorWidget::activate()
for (int i=0; i < DesignerSubWindowCount; i++) for (int i=0; i < DesignerSubWindowCount; i++)
m_designerSubWindows[i]->activate(); 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()) if (!m_globalState.isEmpty())
m_mainWindow->restoreSettings(m_globalState); m_mainWindow->restoreSettings(m_globalState);
else else {
setDefaultLayout(); m_globalState = m_mainWindow->saveSettings();
}
} }
void EditorWidget::hideEvent(QHideEvent *) void EditorWidget::hideEvent(QHideEvent *)
......
...@@ -93,6 +93,7 @@ private: ...@@ -93,6 +93,7 @@ private:
SharedSubWindow* m_designerSubWindows[Designer::Constants::DesignerSubWindowCount]; SharedSubWindow* m_designerSubWindows[Designer::Constants::DesignerSubWindowCount];
QDockWidget *m_designerDockWidgets[Designer::Constants::DesignerSubWindowCount]; QDockWidget *m_designerDockWidgets[Designer::Constants::DesignerSubWindowCount];
Core::Utils::FancyMainWindow *m_mainWindow; Core::Utils::FancyMainWindow *m_mainWindow;
bool m_initialized;
static QHash<QString, QVariant> m_globalState; static QHash<QString, QVariant> m_globalState;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment