mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 23:50:05 +00:00 
			
		
		
		
	Save loop delay, speed, and time to settings on shutdown
This commit is contained in:
		
							parent
							
								
									8f0afbcd1c
								
							
						
					
					
						commit
						e8e3032dcd
					
				
					 11 changed files with 138 additions and 19 deletions
				
			
		|  | @ -82,6 +82,7 @@ int main(int argc, char* argv[]) | ||||||
| 
 | 
 | ||||||
|    // Shutdown application
 |    // Shutdown application
 | ||||||
|    scwx::qt::manager::ResourceManager::Shutdown(); |    scwx::qt::manager::ResourceManager::Shutdown(); | ||||||
|  |    scwx::qt::manager::SettingsManager::Shutdown(); | ||||||
| 
 | 
 | ||||||
|    // Shutdown AWS SDK
 |    // Shutdown AWS SDK
 | ||||||
|    Aws::ShutdownAPI(awsSdkOptions); |    Aws::ShutdownAPI(awsSdkOptions); | ||||||
|  |  | ||||||
|  | @ -90,6 +90,18 @@ void SaveSettings() | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Shutdown() | ||||||
|  | { | ||||||
|  |    bool dataChanged = false; | ||||||
|  | 
 | ||||||
|  |    dataChanged |= general_settings().Shutdown(); | ||||||
|  | 
 | ||||||
|  |    if (dataChanged) | ||||||
|  |    { | ||||||
|  |       SaveSettings(); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| settings::GeneralSettings& general_settings() | settings::GeneralSettings& general_settings() | ||||||
| { | { | ||||||
|    static settings::GeneralSettings generalSettings_; |    static settings::GeneralSettings generalSettings_; | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ namespace SettingsManager | ||||||
| void Initialize(); | void Initialize(); | ||||||
| void ReadSettings(const std::string& settingsPath); | void ReadSettings(const std::string& settingsPath); | ||||||
| void SaveSettings(); | void SaveSettings(); | ||||||
|  | void Shutdown(); | ||||||
| 
 | 
 | ||||||
| settings::GeneralSettings& general_settings(); | settings::GeneralSettings& general_settings(); | ||||||
| settings::MapSettings&     map_settings(); | settings::MapSettings&     map_settings(); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| #include <scwx/qt/manager/timeline_manager.hpp> | #include <scwx/qt/manager/timeline_manager.hpp> | ||||||
| #include <scwx/qt/manager/radar_product_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/logger.hpp> | ||||||
| #include <scwx/util/map.hpp> | #include <scwx/util/map.hpp> | ||||||
| #include <scwx/util/threads.hpp> | #include <scwx/util/threads.hpp> | ||||||
|  | @ -33,7 +34,15 @@ static constexpr std::chrono::seconds kRadarSweepMonitorTimeout_ {5}; | ||||||
| class TimelineManager::Impl | class TimelineManager::Impl | ||||||
| { | { | ||||||
| public: | 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() |    ~Impl() | ||||||
|    { |    { | ||||||
|  | @ -72,9 +81,9 @@ public: | ||||||
|    std::chrono::system_clock::time_point adjustedTime_ {}; |    std::chrono::system_clock::time_point adjustedTime_ {}; | ||||||
|    std::chrono::system_clock::time_point selectedTime_ {}; |    std::chrono::system_clock::time_point selectedTime_ {}; | ||||||
|    types::MapTime                        viewType_ {types::MapTime::Live}; |    types::MapTime                        viewType_ {types::MapTime::Live}; | ||||||
|    std::chrono::minutes                  loopTime_ {30}; |    std::chrono::minutes                  loopTime_; | ||||||
|    double                                loopSpeed_ {5.0}; |    double                                loopSpeed_; | ||||||
|    std::chrono::milliseconds             loopDelay_ {2500}; |    std::chrono::milliseconds             loopDelay_; | ||||||
| 
 | 
 | ||||||
|    bool                    radarSweepMonitorActive_ {false}; |    bool                    radarSweepMonitorActive_ {false}; | ||||||
|    std::mutex              radarSweepMonitorMutex_ {}; |    std::mutex              radarSweepMonitorMutex_ {}; | ||||||
|  |  | ||||||
|  | @ -33,6 +33,9 @@ public: | ||||||
|       defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); |       defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); | ||||||
|       defaultRadarSite_.SetDefault("KLSX"); |       defaultRadarSite_.SetDefault("KLSX"); | ||||||
|       fontSizes_.SetDefault({16}); |       fontSizes_.SetDefault({16}); | ||||||
|  |       loopDelay_.SetDefault(2500); | ||||||
|  |       loopSpeed_.SetDefault(5.0); | ||||||
|  |       loopTime_.SetDefault(30); | ||||||
|       gridWidth_.SetDefault(1); |       gridWidth_.SetDefault(1); | ||||||
|       gridHeight_.SetDefault(1); |       gridHeight_.SetDefault(1); | ||||||
|       mapProvider_.SetDefault(defaultMapProviderValue); |       mapProvider_.SetDefault(defaultMapProviderValue); | ||||||
|  | @ -48,6 +51,12 @@ public: | ||||||
|       gridWidth_.SetMaximum(2); |       gridWidth_.SetMaximum(2); | ||||||
|       gridHeight_.SetMinimum(1); |       gridHeight_.SetMinimum(1); | ||||||
|       gridHeight_.SetMaximum(2); |       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( |       defaultAlertAction_.SetValidator( | ||||||
|          [](const std::string& value) |          [](const std::string& value) | ||||||
|  | @ -101,6 +110,9 @@ public: | ||||||
|    SettingsContainer<std::vector<std::int64_t>> fontSizes_ {"font_sizes"}; |    SettingsContainer<std::vector<std::int64_t>> fontSizes_ {"font_sizes"}; | ||||||
|    SettingsVariable<std::int64_t>               gridWidth_ {"grid_width"}; |    SettingsVariable<std::int64_t>               gridWidth_ {"grid_width"}; | ||||||
|    SettingsVariable<std::int64_t>               gridHeight_ {"grid_height"}; |    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>                mapProvider_ {"map_provider"}; | ||||||
|    SettingsVariable<std::string> mapboxApiKey_ {"mapbox_api_key"}; |    SettingsVariable<std::string> mapboxApiKey_ {"mapbox_api_key"}; | ||||||
|    SettingsVariable<std::string> maptilerApiKey_ {"maptiler_api_key"}; |    SettingsVariable<std::string> maptilerApiKey_ {"maptiler_api_key"}; | ||||||
|  | @ -116,6 +128,9 @@ GeneralSettings::GeneralSettings() : | ||||||
|                       &p->fontSizes_, |                       &p->fontSizes_, | ||||||
|                       &p->gridWidth_, |                       &p->gridWidth_, | ||||||
|                       &p->gridHeight_, |                       &p->gridHeight_, | ||||||
|  |                       &p->loopDelay_, | ||||||
|  |                       &p->loopSpeed_, | ||||||
|  |                       &p->loopTime_, | ||||||
|                       &p->mapProvider_, |                       &p->mapProvider_, | ||||||
|                       &p->mapboxApiKey_, |                       &p->mapboxApiKey_, | ||||||
|                       &p->maptilerApiKey_, |                       &p->maptilerApiKey_, | ||||||
|  | @ -159,6 +174,21 @@ SettingsVariable<std::int64_t>& GeneralSettings::grid_width() const | ||||||
|    return p->gridWidth_; |    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 | SettingsVariable<std::string>& GeneralSettings::map_provider() const | ||||||
| { | { | ||||||
|    return p->mapProvider_; |    return p->mapProvider_; | ||||||
|  | @ -179,6 +209,18 @@ SettingsVariable<bool>& GeneralSettings::update_notifications_enabled() const | ||||||
|    return p->updateNotificationsEnabled_; |    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) | bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) | ||||||
| { | { | ||||||
|    return (lhs.p->debugEnabled_ == rhs.p->debugEnabled_ && |    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->fontSizes_ == rhs.p->fontSizes_ && | ||||||
|            lhs.p->gridWidth_ == rhs.p->gridWidth_ && |            lhs.p->gridWidth_ == rhs.p->gridWidth_ && | ||||||
|            lhs.p->gridHeight_ == rhs.p->gridHeight_ && |            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->mapProvider_ == rhs.p->mapProvider_ && | ||||||
|            lhs.p->mapboxApiKey_ == rhs.p->mapboxApiKey_ && |            lhs.p->mapboxApiKey_ == rhs.p->mapboxApiKey_ && | ||||||
|            lhs.p->maptilerApiKey_ == rhs.p->maptilerApiKey_ && |            lhs.p->maptilerApiKey_ == rhs.p->maptilerApiKey_ && | ||||||
|  |  | ||||||
|  | @ -33,6 +33,9 @@ public: | ||||||
|    SettingsContainer<std::vector<std::int64_t>>& font_sizes() const; |    SettingsContainer<std::vector<std::int64_t>>& font_sizes() const; | ||||||
|    SettingsVariable<std::int64_t>&               grid_height() const; |    SettingsVariable<std::int64_t>&               grid_height() const; | ||||||
|    SettingsVariable<std::int64_t>&               grid_width() 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>&                map_provider() const; | ||||||
|    SettingsVariable<std::string>&                mapbox_api_key() const; |    SettingsVariable<std::string>&                mapbox_api_key() const; | ||||||
|    SettingsVariable<std::string>&                maptiler_api_key() const; |    SettingsVariable<std::string>&                maptiler_api_key() const; | ||||||
|  | @ -41,6 +44,8 @@ public: | ||||||
|    friend bool operator==(const GeneralSettings& lhs, |    friend bool operator==(const GeneralSettings& lhs, | ||||||
|                           const GeneralSettings& rhs); |                           const GeneralSettings& rhs); | ||||||
| 
 | 
 | ||||||
|  |    bool Shutdown(); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    std::unique_ptr<GeneralSettingsImpl> p; |    std::unique_ptr<GeneralSettingsImpl> p; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -51,7 +51,8 @@ SettingsVariable<T>::operator=(SettingsVariable&&) noexcept = default; | ||||||
| template<class T> | template<class T> | ||||||
| inline auto FormatParameter(const T& value) | 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; |       return value; | ||||||
|    } |    } | ||||||
|  |  | ||||||
|  | @ -208,6 +208,7 @@ private: | ||||||
| 
 | 
 | ||||||
| #ifdef SETTINGS_VARIABLE_IMPLEMENTATION | #ifdef SETTINGS_VARIABLE_IMPLEMENTATION | ||||||
| template class SettingsVariable<bool>; | template class SettingsVariable<bool>; | ||||||
|  | template class SettingsVariable<double>; | ||||||
| template class SettingsVariable<std::int64_t>; | template class SettingsVariable<std::int64_t>; | ||||||
| template class SettingsVariable<std::string>; | template class SettingsVariable<std::string>; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| #include "animation_dock_widget.hpp" | #include "animation_dock_widget.hpp" | ||||||
| #include "ui_animation_dock_widget.h" | #include "ui_animation_dock_widget.h" | ||||||
| 
 | 
 | ||||||
|  | #include <scwx/qt/manager/settings_manager.hpp> | ||||||
| #include <scwx/qt/util/time.hpp> | #include <scwx/qt/util/time.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | @ -86,9 +87,11 @@ AnimationDockWidget::AnimationDockWidget(QWidget* parent) : | ||||||
|    maxDateTimer->start(15000); |    maxDateTimer->start(15000); | ||||||
| 
 | 
 | ||||||
|    // Set loop defaults
 |    // Set loop defaults
 | ||||||
|    ui->loopTimeSpinBox->setValue(30); |    auto& generalSettings = manager::SettingsManager::general_settings(); | ||||||
|    ui->loopSpeedSpinBox->setValue(5.0); |    ui->loopTimeSpinBox->setValue(generalSettings.loop_time().GetValue()); | ||||||
|    ui->loopDelaySpinBox->setValue(2.5); |    ui->loopSpeedSpinBox->setValue(generalSettings.loop_speed().GetValue()); | ||||||
|  |    ui->loopDelaySpinBox->setValue(generalSettings.loop_delay().GetValue() * | ||||||
|  |                                   0.001); | ||||||
| 
 | 
 | ||||||
|    // Connect widget signals
 |    // Connect widget signals
 | ||||||
|    p->ConnectSignals(); |    p->ConnectSignals(); | ||||||
|  | @ -152,22 +155,33 @@ void AnimationDockWidgetImpl::ConnectSignals() | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|    // Loop controls
 |    // Loop controls
 | ||||||
|    QObject::connect(self_->ui->loopTimeSpinBox, |    QObject::connect( | ||||||
|                     &QSpinBox::valueChanged, |       self_->ui->loopTimeSpinBox, | ||||||
|                     self_, |       &QSpinBox::valueChanged, | ||||||
|                     [this](int i) { |       self_, | ||||||
|                        Q_EMIT self_->LoopTimeChanged(std::chrono::minutes(i)); |       [this](int i) | ||||||
|                     }); |       { | ||||||
|    QObject::connect(self_->ui->loopSpeedSpinBox, |          manager::SettingsManager::general_settings().loop_time().StageValue(i); | ||||||
|                     &QDoubleSpinBox::valueChanged, |          Q_EMIT self_->LoopTimeChanged(std::chrono::minutes(i)); | ||||||
|                     self_, |       }); | ||||||
|                     [this](double d) { Q_EMIT self_->LoopSpeedChanged(d); }); |    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( |    QObject::connect( | ||||||
|       self_->ui->loopDelaySpinBox, |       self_->ui->loopDelaySpinBox, | ||||||
|       &QDoubleSpinBox::valueChanged, |       &QDoubleSpinBox::valueChanged, | ||||||
|       self_, |       self_, | ||||||
|       [this](double d) |       [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( |          Q_EMIT self_->LoopDelayChanged(std::chrono::milliseconds( | ||||||
|             static_cast<typename std::chrono::milliseconds::rep>(d * 1000.0))); |             static_cast<typename std::chrono::milliseconds::rep>(d * 1000.0))); | ||||||
|       }); |       }); | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| Subproject commit 93eb0d154ce70675812c5569a51c4fdadedbc24d | Subproject commit 98ee58919fc2d616519e514f70308658c5a737e5 | ||||||
|  | @ -23,6 +23,36 @@ TEST(SettingsVariableTest, Boolean) | ||||||
|    EXPECT_EQ(boolVariable.GetValue(), false); |    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) | TEST(SettingsVariableTest, Integer) | ||||||
| { | { | ||||||
|    SettingsVariable<int64_t> intVariable {"int64_t"}; |    SettingsVariable<int64_t> intVariable {"int64_t"}; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat