Save loop delay, speed, and time to settings on shutdown

This commit is contained in:
Dan Paulat 2023-06-14 22:56:26 -05:00
parent 8f0afbcd1c
commit e8e3032dcd
11 changed files with 138 additions and 19 deletions

View file

@ -82,6 +82,7 @@ int main(int argc, char* argv[])
// Shutdown application
scwx::qt::manager::ResourceManager::Shutdown();
scwx::qt::manager::SettingsManager::Shutdown();
// Shutdown AWS SDK
Aws::ShutdownAPI(awsSdkOptions);

View file

@ -90,6 +90,18 @@ void SaveSettings()
}
}
void Shutdown()
{
bool dataChanged = false;
dataChanged |= general_settings().Shutdown();
if (dataChanged)
{
SaveSettings();
}
}
settings::GeneralSettings& general_settings()
{
static settings::GeneralSettings generalSettings_;

View file

@ -16,6 +16,7 @@ namespace SettingsManager
void Initialize();
void ReadSettings(const std::string& settingsPath);
void SaveSettings();
void Shutdown();
settings::GeneralSettings& general_settings();
settings::MapSettings& map_settings();

View file

@ -1,5 +1,6 @@
#include <scwx/qt/manager/timeline_manager.hpp>
#include <scwx/qt/manager/radar_product_manager.hpp>
#include <scwx/qt/manager/settings_manager.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/map.hpp>
#include <scwx/util/threads.hpp>
@ -33,7 +34,15 @@ static constexpr std::chrono::seconds kRadarSweepMonitorTimeout_ {5};
class TimelineManager::Impl
{
public:
explicit Impl(TimelineManager* self) : self_ {self} {}
explicit Impl(TimelineManager* self) : self_ {self}
{
auto& generalSettings = SettingsManager::general_settings();
loopDelay_ =
std::chrono::milliseconds(generalSettings.loop_delay().GetValue());
loopSpeed_ = generalSettings.loop_speed().GetValue();
loopTime_ = std::chrono::minutes(generalSettings.loop_time().GetValue());
}
~Impl()
{
@ -72,9 +81,9 @@ public:
std::chrono::system_clock::time_point adjustedTime_ {};
std::chrono::system_clock::time_point selectedTime_ {};
types::MapTime viewType_ {types::MapTime::Live};
std::chrono::minutes loopTime_ {30};
double loopSpeed_ {5.0};
std::chrono::milliseconds loopDelay_ {2500};
std::chrono::minutes loopTime_;
double loopSpeed_;
std::chrono::milliseconds loopDelay_;
bool radarSweepMonitorActive_ {false};
std::mutex radarSweepMonitorMutex_ {};

View file

@ -33,6 +33,9 @@ public:
defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue);
defaultRadarSite_.SetDefault("KLSX");
fontSizes_.SetDefault({16});
loopDelay_.SetDefault(2500);
loopSpeed_.SetDefault(5.0);
loopTime_.SetDefault(30);
gridWidth_.SetDefault(1);
gridHeight_.SetDefault(1);
mapProvider_.SetDefault(defaultMapProviderValue);
@ -48,6 +51,12 @@ public:
gridWidth_.SetMaximum(2);
gridHeight_.SetMinimum(1);
gridHeight_.SetMaximum(2);
loopDelay_.SetMinimum(0);
loopDelay_.SetMaximum(15000);
loopSpeed_.SetMinimum(1.0);
loopSpeed_.SetMaximum(99.99);
loopTime_.SetMinimum(1);
loopTime_.SetMaximum(1440);
defaultAlertAction_.SetValidator(
[](const std::string& value)
@ -101,6 +110,9 @@ public:
SettingsContainer<std::vector<std::int64_t>> fontSizes_ {"font_sizes"};
SettingsVariable<std::int64_t> gridWidth_ {"grid_width"};
SettingsVariable<std::int64_t> gridHeight_ {"grid_height"};
SettingsVariable<std::int64_t> loopDelay_ {"loop_delay"};
SettingsVariable<double> loopSpeed_ {"loop_speed"};
SettingsVariable<std::int64_t> loopTime_ {"loop_time"};
SettingsVariable<std::string> mapProvider_ {"map_provider"};
SettingsVariable<std::string> mapboxApiKey_ {"mapbox_api_key"};
SettingsVariable<std::string> maptilerApiKey_ {"maptiler_api_key"};
@ -116,6 +128,9 @@ GeneralSettings::GeneralSettings() :
&p->fontSizes_,
&p->gridWidth_,
&p->gridHeight_,
&p->loopDelay_,
&p->loopSpeed_,
&p->loopTime_,
&p->mapProvider_,
&p->mapboxApiKey_,
&p->maptilerApiKey_,
@ -159,6 +174,21 @@ SettingsVariable<std::int64_t>& GeneralSettings::grid_width() const
return p->gridWidth_;
}
SettingsVariable<std::int64_t>& GeneralSettings::loop_delay() const
{
return p->loopDelay_;
}
SettingsVariable<double>& GeneralSettings::loop_speed() const
{
return p->loopSpeed_;
}
SettingsVariable<std::int64_t>& GeneralSettings::loop_time() const
{
return p->loopTime_;
}
SettingsVariable<std::string>& GeneralSettings::map_provider() const
{
return p->mapProvider_;
@ -179,6 +209,18 @@ SettingsVariable<bool>& GeneralSettings::update_notifications_enabled() const
return p->updateNotificationsEnabled_;
}
bool GeneralSettings::Shutdown()
{
bool dataChanged = false;
// Commit settings that are managed separate from the settings dialog
dataChanged |= p->loopDelay_.Commit();
dataChanged |= p->loopSpeed_.Commit();
dataChanged |= p->loopTime_.Commit();
return dataChanged;
}
bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs)
{
return (lhs.p->debugEnabled_ == rhs.p->debugEnabled_ &&
@ -187,6 +229,9 @@ bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs)
lhs.p->fontSizes_ == rhs.p->fontSizes_ &&
lhs.p->gridWidth_ == rhs.p->gridWidth_ &&
lhs.p->gridHeight_ == rhs.p->gridHeight_ &&
lhs.p->loopDelay_ == rhs.p->loopDelay_ &&
lhs.p->loopSpeed_ == rhs.p->loopSpeed_ &&
lhs.p->loopTime_ == rhs.p->loopTime_ &&
lhs.p->mapProvider_ == rhs.p->mapProvider_ &&
lhs.p->mapboxApiKey_ == rhs.p->mapboxApiKey_ &&
lhs.p->maptilerApiKey_ == rhs.p->maptilerApiKey_ &&

View file

@ -33,6 +33,9 @@ public:
SettingsContainer<std::vector<std::int64_t>>& font_sizes() const;
SettingsVariable<std::int64_t>& grid_height() const;
SettingsVariable<std::int64_t>& grid_width() const;
SettingsVariable<std::int64_t>& loop_delay() const;
SettingsVariable<double>& loop_speed() const;
SettingsVariable<std::int64_t>& loop_time() const;
SettingsVariable<std::string>& map_provider() const;
SettingsVariable<std::string>& mapbox_api_key() const;
SettingsVariable<std::string>& maptiler_api_key() const;
@ -41,6 +44,8 @@ public:
friend bool operator==(const GeneralSettings& lhs,
const GeneralSettings& rhs);
bool Shutdown();
private:
std::unique_ptr<GeneralSettingsImpl> p;
};

View file

@ -51,7 +51,8 @@ SettingsVariable<T>::operator=(SettingsVariable&&) noexcept = default;
template<class T>
inline auto FormatParameter(const T& value)
{
if constexpr (std::is_integral_v<T> || std::is_same_v<T, std::string>)
if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T> ||
std::is_same_v<T, std::string>)
{
return value;
}

View file

@ -208,6 +208,7 @@ private:
#ifdef SETTINGS_VARIABLE_IMPLEMENTATION
template class SettingsVariable<bool>;
template class SettingsVariable<double>;
template class SettingsVariable<std::int64_t>;
template class SettingsVariable<std::string>;

View file

@ -1,6 +1,7 @@
#include "animation_dock_widget.hpp"
#include "ui_animation_dock_widget.h"
#include <scwx/qt/manager/settings_manager.hpp>
#include <scwx/qt/util/time.hpp>
#include <scwx/util/logger.hpp>
@ -86,9 +87,11 @@ AnimationDockWidget::AnimationDockWidget(QWidget* parent) :
maxDateTimer->start(15000);
// Set loop defaults
ui->loopTimeSpinBox->setValue(30);
ui->loopSpeedSpinBox->setValue(5.0);
ui->loopDelaySpinBox->setValue(2.5);
auto& generalSettings = manager::SettingsManager::general_settings();
ui->loopTimeSpinBox->setValue(generalSettings.loop_time().GetValue());
ui->loopSpeedSpinBox->setValue(generalSettings.loop_speed().GetValue());
ui->loopDelaySpinBox->setValue(generalSettings.loop_delay().GetValue() *
0.001);
// Connect widget signals
p->ConnectSignals();
@ -152,22 +155,33 @@ void AnimationDockWidgetImpl::ConnectSignals()
});
// Loop controls
QObject::connect(self_->ui->loopTimeSpinBox,
&QSpinBox::valueChanged,
self_,
[this](int i) {
Q_EMIT self_->LoopTimeChanged(std::chrono::minutes(i));
});
QObject::connect(self_->ui->loopSpeedSpinBox,
&QDoubleSpinBox::valueChanged,
self_,
[this](double d) { Q_EMIT self_->LoopSpeedChanged(d); });
QObject::connect(
self_->ui->loopTimeSpinBox,
&QSpinBox::valueChanged,
self_,
[this](int i)
{
manager::SettingsManager::general_settings().loop_time().StageValue(i);
Q_EMIT self_->LoopTimeChanged(std::chrono::minutes(i));
});
QObject::connect(
self_->ui->loopSpeedSpinBox,
&QDoubleSpinBox::valueChanged,
self_,
[this](double d)
{
manager::SettingsManager::general_settings().loop_speed().StageValue(
d);
Q_EMIT self_->LoopSpeedChanged(d);
});
QObject::connect(
self_->ui->loopDelaySpinBox,
&QDoubleSpinBox::valueChanged,
self_,
[this](double d)
{
manager::SettingsManager::general_settings().loop_delay().StageValue(
static_cast<std::int64_t>(d * 1000.0));
Q_EMIT self_->LoopDelayChanged(std::chrono::milliseconds(
static_cast<typename std::chrono::milliseconds::rep>(d * 1000.0)));
});

@ -1 +1 @@
Subproject commit 93eb0d154ce70675812c5569a51c4fdadedbc24d
Subproject commit 98ee58919fc2d616519e514f70308658c5a737e5

View file

@ -23,6 +23,36 @@ TEST(SettingsVariableTest, Boolean)
EXPECT_EQ(boolVariable.GetValue(), false);
}
TEST(SettingsVariableTest, Double)
{
SettingsVariable<double> doubleVariable {"double"};
doubleVariable.SetDefault(4.2);
doubleVariable.SetMinimum(1.0);
doubleVariable.SetMaximum(9.9);
doubleVariable.SetValue(5.0);
EXPECT_EQ(doubleVariable.name(), "double");
EXPECT_EQ(doubleVariable.GetValue(), 5.0);
EXPECT_EQ(doubleVariable.SetValue(0), false);
EXPECT_EQ(doubleVariable.GetValue(), 5.0);
EXPECT_EQ(doubleVariable.SetValueOrDefault(0.0), false); // < Minimum
EXPECT_EQ(doubleVariable.GetValue(), 1.0);
EXPECT_EQ(doubleVariable.SetValueOrDefault(10.0), false); // > Maximum
EXPECT_EQ(doubleVariable.GetValue(), 9.9);
doubleVariable.SetValueToDefault();
EXPECT_EQ(doubleVariable.GetValue(), 4.2);
EXPECT_EQ(doubleVariable.SetValue(4.3), true);
EXPECT_EQ(doubleVariable.GetValue(), 4.3);
EXPECT_EQ(doubleVariable.SetValueOrDefault(5.7), true);
EXPECT_EQ(doubleVariable.GetValue(), 5.7);
EXPECT_EQ(doubleVariable.StageValue(0.0), false);
EXPECT_EQ(doubleVariable.StageValue(5.0), true);
EXPECT_EQ(doubleVariable.GetValue(), 5.7);
doubleVariable.Commit();
EXPECT_EQ(doubleVariable.GetValue(), 5.0);
}
TEST(SettingsVariableTest, Integer)
{
SettingsVariable<int64_t> intVariable {"int64_t"};