diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 4046e3bd..d511241a 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -279,7 +279,6 @@ MainWindow::MainWindow(QWidget* parent) : // Configure Alert Dock p->alertDockWidget_ = new ui::AlertDockWidget(this); - p->alertDockWidget_->setVisible(false); addDockWidget(Qt::BottomDockWidgetArea, p->alertDockWidget_); // GPS Info Dialog @@ -444,8 +443,37 @@ void MainWindow::keyReleaseEvent(QKeyEvent* ev) void MainWindow::showEvent(QShowEvent* event) { QMainWindow::showEvent(event); + auto& uiSettings = settings::UiSettings::Instance(); - resizeDocks({ui->radarToolboxDock}, {194}, Qt::Horizontal); + // restore the geometry state + std::string uiGeometry = uiSettings.main_ui_geometry().GetValue(); + restoreGeometry( + QByteArray::fromBase64(QByteArray::fromStdString(uiGeometry))); + + // restore the UI state + std::string uiState = uiSettings.main_ui_state().GetValue(); + + bool restored = + restoreState(QByteArray::fromBase64(QByteArray::fromStdString(uiState))); + if (!restored) + { + resizeDocks({ui->radarToolboxDock}, {194}, Qt::Horizontal); + } +} + +void MainWindow::closeEvent(QCloseEvent* event) +{ + auto& uiSettings = settings::UiSettings::Instance(); + + // save the UI geometry + QByteArray uiGeometry = saveGeometry().toBase64(); + uiSettings.main_ui_geometry().StageValue(uiGeometry.data()); + + // save the UI state + QByteArray uiState = saveState().toBase64(); + uiSettings.main_ui_state().StageValue(uiState.data()); + + QMainWindow::closeEvent(event); } void MainWindow::on_actionOpenNexrad_triggered() diff --git a/scwx-qt/source/scwx/qt/main/main_window.hpp b/scwx-qt/source/scwx/qt/main/main_window.hpp index 33043308..c6ea3a5f 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.hpp +++ b/scwx-qt/source/scwx/qt/main/main_window.hpp @@ -29,6 +29,7 @@ public: void keyPressEvent(QKeyEvent* ev) override final; void keyReleaseEvent(QKeyEvent* ev) override final; void showEvent(QShowEvent* event) override; + void closeEvent(QCloseEvent *event) override; signals: void ActiveMapMoved(double latitude, double longitude); diff --git a/scwx-qt/source/scwx/qt/settings/settings_variable.hpp b/scwx-qt/source/scwx/qt/settings/settings_variable.hpp index 581ebcbe..4141f96b 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_variable.hpp +++ b/scwx-qt/source/scwx/qt/settings/settings_variable.hpp @@ -91,7 +91,7 @@ public: * @return true if the staged value was committed, false if no staged value * is present. */ - bool Commit(); + bool Commit() override; /** * Clears the staged value of the settings variable. diff --git a/scwx-qt/source/scwx/qt/settings/ui_settings.cpp b/scwx-qt/source/scwx/qt/settings/ui_settings.cpp index dc131d96..eca2c8e1 100644 --- a/scwx-qt/source/scwx/qt/settings/ui_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/ui_settings.cpp @@ -19,6 +19,8 @@ public: level3ProductsExpanded_.SetDefault(true); mapSettingsExpanded_.SetDefault(true); timelineExpanded_.SetDefault(true); + mainUIState_.SetDefault(""); + mainUIGeometry_.SetDefault(""); } ~UiSettingsImpl() {} @@ -28,6 +30,8 @@ public: SettingsVariable level3ProductsExpanded_ {"level3_products_expanded"}; SettingsVariable mapSettingsExpanded_ {"map_settings_expanded"}; SettingsVariable timelineExpanded_ {"timeline_expanded"}; + SettingsVariable mainUIState_ {"main_ui_state"}; + SettingsVariable mainUIGeometry_ {"main_ui_geometry"}; }; UiSettings::UiSettings() : @@ -37,7 +41,9 @@ UiSettings::UiSettings() : &p->level2SettingsExpanded_, &p->level3ProductsExpanded_, &p->mapSettingsExpanded_, - &p->timelineExpanded_}); + &p->timelineExpanded_, + &p->mainUIState_, + &p->mainUIGeometry_}); SetDefaults(); } UiSettings::~UiSettings() = default; @@ -70,6 +76,16 @@ SettingsVariable& UiSettings::timeline_expanded() const return p->timelineExpanded_; } +SettingsVariable& UiSettings::main_ui_state() const +{ + return p->mainUIState_; +} + +SettingsVariable& UiSettings::main_ui_geometry() const +{ + return p->mainUIGeometry_; +} + bool UiSettings::Shutdown() { bool dataChanged = false; @@ -80,6 +96,8 @@ bool UiSettings::Shutdown() dataChanged |= p->level3ProductsExpanded_.Commit(); dataChanged |= p->mapSettingsExpanded_.Commit(); dataChanged |= p->timelineExpanded_.Commit(); + dataChanged |= p->mainUIState_.Commit(); + dataChanged |= p->mainUIGeometry_.Commit(); return dataChanged; } @@ -96,7 +114,9 @@ bool operator==(const UiSettings& lhs, const UiSettings& rhs) lhs.p->level2SettingsExpanded_ == rhs.p->level2SettingsExpanded_ && lhs.p->level3ProductsExpanded_ == rhs.p->level3ProductsExpanded_ && lhs.p->mapSettingsExpanded_ == rhs.p->mapSettingsExpanded_ && - lhs.p->timelineExpanded_ == rhs.p->timelineExpanded_); + lhs.p->timelineExpanded_ == rhs.p->timelineExpanded_ && + lhs.p->mainUIState_ == rhs.p->mainUIState_ && + lhs.p->mainUIGeometry_ == rhs.p->mainUIGeometry_); } } // namespace settings diff --git a/scwx-qt/source/scwx/qt/settings/ui_settings.hpp b/scwx-qt/source/scwx/qt/settings/ui_settings.hpp index e3045bcb..0a9f95ef 100644 --- a/scwx-qt/source/scwx/qt/settings/ui_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/ui_settings.hpp @@ -32,6 +32,8 @@ public: SettingsVariable& level3_products_expanded() const; SettingsVariable& map_settings_expanded() const; SettingsVariable& timeline_expanded() const; + SettingsVariable& main_ui_state() const; + SettingsVariable& main_ui_geometry() const; bool Shutdown(); diff --git a/test/data b/test/data index 5a91ded6..20a1ca17 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 5a91ded677d4032b0de9370ed767a16708c0ecff +Subproject commit 20a1ca1752499222d33869e37148321936ca6354