Merge pull request #268 from AdenKoperczak/save_ui_state

Save UI State
This commit is contained in:
Dan Paulat 2024-09-17 21:51:24 -05:00 committed by GitHub
commit 475460ff84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 57 additions and 6 deletions

View file

@ -279,7 +279,6 @@ MainWindow::MainWindow(QWidget* parent) :
// Configure Alert Dock // Configure Alert Dock
p->alertDockWidget_ = new ui::AlertDockWidget(this); p->alertDockWidget_ = new ui::AlertDockWidget(this);
p->alertDockWidget_->setVisible(false);
addDockWidget(Qt::BottomDockWidgetArea, p->alertDockWidget_); addDockWidget(Qt::BottomDockWidgetArea, p->alertDockWidget_);
// GPS Info Dialog // GPS Info Dialog
@ -444,9 +443,38 @@ void MainWindow::keyReleaseEvent(QKeyEvent* ev)
void MainWindow::showEvent(QShowEvent* event) void MainWindow::showEvent(QShowEvent* event)
{ {
QMainWindow::showEvent(event); QMainWindow::showEvent(event);
auto& uiSettings = settings::UiSettings::Instance();
// 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); 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() void MainWindow::on_actionOpenNexrad_triggered()
{ {

View file

@ -29,6 +29,7 @@ public:
void keyPressEvent(QKeyEvent* ev) override final; void keyPressEvent(QKeyEvent* ev) override final;
void keyReleaseEvent(QKeyEvent* ev) override final; void keyReleaseEvent(QKeyEvent* ev) override final;
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
void closeEvent(QCloseEvent *event) override;
signals: signals:
void ActiveMapMoved(double latitude, double longitude); void ActiveMapMoved(double latitude, double longitude);

View file

@ -91,7 +91,7 @@ public:
* @return true if the staged value was committed, false if no staged value * @return true if the staged value was committed, false if no staged value
* is present. * is present.
*/ */
bool Commit(); bool Commit() override;
/** /**
* Clears the staged value of the settings variable. * Clears the staged value of the settings variable.

View file

@ -19,6 +19,8 @@ public:
level3ProductsExpanded_.SetDefault(true); level3ProductsExpanded_.SetDefault(true);
mapSettingsExpanded_.SetDefault(true); mapSettingsExpanded_.SetDefault(true);
timelineExpanded_.SetDefault(true); timelineExpanded_.SetDefault(true);
mainUIState_.SetDefault("");
mainUIGeometry_.SetDefault("");
} }
~UiSettingsImpl() {} ~UiSettingsImpl() {}
@ -28,6 +30,8 @@ public:
SettingsVariable<bool> level3ProductsExpanded_ {"level3_products_expanded"}; SettingsVariable<bool> level3ProductsExpanded_ {"level3_products_expanded"};
SettingsVariable<bool> mapSettingsExpanded_ {"map_settings_expanded"}; SettingsVariable<bool> mapSettingsExpanded_ {"map_settings_expanded"};
SettingsVariable<bool> timelineExpanded_ {"timeline_expanded"}; SettingsVariable<bool> timelineExpanded_ {"timeline_expanded"};
SettingsVariable<std::string> mainUIState_ {"main_ui_state"};
SettingsVariable<std::string> mainUIGeometry_ {"main_ui_geometry"};
}; };
UiSettings::UiSettings() : UiSettings::UiSettings() :
@ -37,7 +41,9 @@ UiSettings::UiSettings() :
&p->level2SettingsExpanded_, &p->level2SettingsExpanded_,
&p->level3ProductsExpanded_, &p->level3ProductsExpanded_,
&p->mapSettingsExpanded_, &p->mapSettingsExpanded_,
&p->timelineExpanded_}); &p->timelineExpanded_,
&p->mainUIState_,
&p->mainUIGeometry_});
SetDefaults(); SetDefaults();
} }
UiSettings::~UiSettings() = default; UiSettings::~UiSettings() = default;
@ -70,6 +76,16 @@ SettingsVariable<bool>& UiSettings::timeline_expanded() const
return p->timelineExpanded_; return p->timelineExpanded_;
} }
SettingsVariable<std::string>& UiSettings::main_ui_state() const
{
return p->mainUIState_;
}
SettingsVariable<std::string>& UiSettings::main_ui_geometry() const
{
return p->mainUIGeometry_;
}
bool UiSettings::Shutdown() bool UiSettings::Shutdown()
{ {
bool dataChanged = false; bool dataChanged = false;
@ -80,6 +96,8 @@ bool UiSettings::Shutdown()
dataChanged |= p->level3ProductsExpanded_.Commit(); dataChanged |= p->level3ProductsExpanded_.Commit();
dataChanged |= p->mapSettingsExpanded_.Commit(); dataChanged |= p->mapSettingsExpanded_.Commit();
dataChanged |= p->timelineExpanded_.Commit(); dataChanged |= p->timelineExpanded_.Commit();
dataChanged |= p->mainUIState_.Commit();
dataChanged |= p->mainUIGeometry_.Commit();
return dataChanged; return dataChanged;
} }
@ -96,7 +114,9 @@ bool operator==(const UiSettings& lhs, const UiSettings& rhs)
lhs.p->level2SettingsExpanded_ == rhs.p->level2SettingsExpanded_ && lhs.p->level2SettingsExpanded_ == rhs.p->level2SettingsExpanded_ &&
lhs.p->level3ProductsExpanded_ == rhs.p->level3ProductsExpanded_ && lhs.p->level3ProductsExpanded_ == rhs.p->level3ProductsExpanded_ &&
lhs.p->mapSettingsExpanded_ == rhs.p->mapSettingsExpanded_ && 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 } // namespace settings

View file

@ -32,6 +32,8 @@ public:
SettingsVariable<bool>& level3_products_expanded() const; SettingsVariable<bool>& level3_products_expanded() const;
SettingsVariable<bool>& map_settings_expanded() const; SettingsVariable<bool>& map_settings_expanded() const;
SettingsVariable<bool>& timeline_expanded() const; SettingsVariable<bool>& timeline_expanded() const;
SettingsVariable<std::string>& main_ui_state() const;
SettingsVariable<std::string>& main_ui_geometry() const;
bool Shutdown(); bool Shutdown();

@ -1 +1 @@
Subproject commit 5a91ded677d4032b0de9370ed767a16708c0ecff Subproject commit 20a1ca1752499222d33869e37148321936ca6354