mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:50:05 +00:00 
			
		
		
		
	Inheriting MapSettings and PaletteSettings from SettingsCategory, updating SettingsManager initialization
This commit is contained in:
		
							parent
							
								
									c93e776137
								
							
						
					
					
						commit
						891b6c839f
					
				
					 14 changed files with 231 additions and 269 deletions
				
			
		|  | @ -1,7 +1,4 @@ | |||
| #include <scwx/qt/settings/general_settings.hpp> | ||||
| #include <scwx/qt/util/json.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <scwx/qt/settings/settings_container.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
|  | @ -12,7 +9,6 @@ namespace settings | |||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::settings::general_settings"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class GeneralSettingsImpl | ||||
| { | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| #include <scwx/qt/settings/map_settings.hpp> | ||||
| #include <scwx/qt/config/radar_site.hpp> | ||||
| #include <scwx/qt/settings/settings_variable.hpp> | ||||
| #include <scwx/qt/util/json.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
|  | @ -16,11 +17,16 @@ namespace settings | |||
| static const std::string logPrefix_ = "scwx::qt::settings::map_settings"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| static constexpr size_t  kCount_            = 4u; | ||||
| static const std::string kDefaultRadarSite_ = "KLSX"; | ||||
| static constexpr std::size_t kCount_            = 4u; | ||||
| static const std::string     kDefaultRadarSite_ = "KLSX"; | ||||
| 
 | ||||
| static const common::RadarProductGroup kDefaultRadarProductGroup_ = | ||||
| static const std::string kRadarSiteName_ {"radar_site"}; | ||||
| static const std::string kRadarProductGroupName_ {"radar_product_group"}; | ||||
| static const std::string kRadarProductName_ {"radar_product"}; | ||||
| 
 | ||||
| static constexpr common::RadarProductGroup kDefaultRadarProductGroup_ = | ||||
|    common::RadarProductGroup::Level3; | ||||
| static const std::string kDefaultRadarProductGroupString_ = "L3"; | ||||
| static const std::array<std::string, kCount_> kDefaultRadarProduct_ { | ||||
|    "N0B", "N0G", "N0C", "N0X"}; | ||||
| 
 | ||||
|  | @ -29,180 +35,182 @@ class MapSettingsImpl | |||
| public: | ||||
|    struct MapData | ||||
|    { | ||||
|       std::string               radarSite_; | ||||
|       common::RadarProductGroup radarProductGroup_; | ||||
|       std::string               radarProduct_; | ||||
|       SettingsVariable<std::string> radarSite_ {kRadarSiteName_}; | ||||
|       SettingsVariable<std::string> radarProductGroup_ { | ||||
|          kRadarProductGroupName_}; | ||||
|       SettingsVariable<std::string> radarProduct_ {kRadarProductName_}; | ||||
|    }; | ||||
| 
 | ||||
|    explicit MapSettingsImpl() { SetDefaults(); } | ||||
| 
 | ||||
|    ~MapSettingsImpl() {} | ||||
| 
 | ||||
|    void SetDefaults(size_t i) | ||||
|    explicit MapSettingsImpl() | ||||
|    { | ||||
|       map_[i].radarSite_         = kDefaultRadarSite_; | ||||
|       map_[i].radarProductGroup_ = kDefaultRadarProductGroup_; | ||||
|       map_[i].radarProduct_      = kDefaultRadarProduct_[i]; | ||||
|    } | ||||
| 
 | ||||
|    void SetDefaults() | ||||
|    { | ||||
|       for (size_t i = 0; i < kCount_; i++) | ||||
|       for (std::size_t i = 0; i < kCount_; i++) | ||||
|       { | ||||
|          SetDefaults(i); | ||||
|          map_[i].radarSite_.SetDefault(kDefaultRadarSite_); | ||||
|          map_[i].radarProductGroup_.SetDefault( | ||||
|             kDefaultRadarProductGroupString_); | ||||
|          map_[i].radarProduct_.SetDefault(kDefaultRadarProduct_[i]); | ||||
| 
 | ||||
|          map_[i].radarSite_.SetValidator( | ||||
|             [](const std::string& value) | ||||
|             { | ||||
|                // Radar site must exist
 | ||||
|                return config::RadarSite::Get(value) != nullptr; | ||||
|             }); | ||||
| 
 | ||||
|          map_[i].radarProductGroup_.SetValidator( | ||||
|             [](const std::string& value) | ||||
|             { | ||||
|                // Radar product group must be valid
 | ||||
|                common::RadarProductGroup radarProductGroup = | ||||
|                   common::GetRadarProductGroup(value); | ||||
|                return radarProductGroup != common::RadarProductGroup::Unknown; | ||||
|             }); | ||||
| 
 | ||||
|          map_[i].radarProduct_.SetValidator( | ||||
|             [this, i](const std::string& value) | ||||
|             { | ||||
|                common::RadarProductGroup radarProductGroup = | ||||
|                   common::GetRadarProductGroup( | ||||
|                      map_[i].radarProductGroup_.GetValue()); | ||||
| 
 | ||||
|                if (radarProductGroup == common::RadarProductGroup::Level2) | ||||
|                { | ||||
|                   // Radar product must be valid
 | ||||
|                   return common::GetLevel2Product(value) != | ||||
|                          common::Level2Product::Unknown; | ||||
|                } | ||||
|                else | ||||
|                { | ||||
|                   // TODO: Validate level 3 product
 | ||||
|                   return true; | ||||
|                } | ||||
|             }); | ||||
| 
 | ||||
|          variables_.insert(variables_.cend(), | ||||
|                            {&map_[i].radarSite_, | ||||
|                             &map_[i].radarProductGroup_, | ||||
|                             &map_[i].radarProduct_}); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::array<MapData, kCount_> map_; | ||||
|    ~MapSettingsImpl() {} | ||||
| 
 | ||||
|    void SetDefaults(std::size_t i) | ||||
|    { | ||||
|       map_[i].radarSite_.SetValueToDefault(); | ||||
|       map_[i].radarProductGroup_.SetValueToDefault(); | ||||
|       map_[i].radarProduct_.SetValueToDefault(); | ||||
|    } | ||||
| 
 | ||||
|    std::array<MapData, kCount_>       map_ {}; | ||||
|    std::vector<SettingsVariableBase*> variables_ {}; | ||||
| }; | ||||
| 
 | ||||
| MapSettings::MapSettings() : p(std::make_unique<MapSettingsImpl>()) {} | ||||
| MapSettings::MapSettings() : | ||||
|     SettingsCategory("maps"), p(std::make_unique<MapSettingsImpl>()) | ||||
| { | ||||
|    RegisterVariables(p->variables_); | ||||
|    SetDefaults(); | ||||
| 
 | ||||
|    p->variables_.clear(); | ||||
| } | ||||
| MapSettings::~MapSettings() = default; | ||||
| 
 | ||||
| MapSettings::MapSettings(MapSettings&&) noexcept            = default; | ||||
| MapSettings& MapSettings::operator=(MapSettings&&) noexcept = default; | ||||
| 
 | ||||
| size_t MapSettings::count() const | ||||
| std::size_t MapSettings::count() const | ||||
| { | ||||
|    return kCount_; | ||||
| } | ||||
| 
 | ||||
| std::string MapSettings::radar_site(size_t i) const | ||||
| std::string MapSettings::radar_site(std::size_t i) const | ||||
| { | ||||
|    return p->map_[i].radarSite_; | ||||
|    return p->map_[i].radarSite_.GetValue(); | ||||
| } | ||||
| 
 | ||||
| common::RadarProductGroup MapSettings::radar_product_group(size_t i) const | ||||
| common::RadarProductGroup MapSettings::radar_product_group(std::size_t i) const | ||||
| { | ||||
|    return p->map_[i].radarProductGroup_; | ||||
|    return common::GetRadarProductGroup( | ||||
|       p->map_[i].radarProductGroup_.GetValue()); | ||||
| } | ||||
| 
 | ||||
| std::string MapSettings::radar_product(size_t i) const | ||||
| std::string MapSettings::radar_product(std::size_t i) const | ||||
| { | ||||
|    return p->map_[i].radarProduct_; | ||||
|    return p->map_[i].radarProduct_.GetValue(); | ||||
| } | ||||
| 
 | ||||
| boost::json::value MapSettings::ToJson() const | ||||
| bool MapSettings::ReadJson(const boost::json::object& json) | ||||
| { | ||||
|    boost::json::value json; | ||||
|    bool validated = true; | ||||
| 
 | ||||
|    json = boost::json::value_from(p->map_); | ||||
|    const boost::json::value* value = json.if_contains(name()); | ||||
| 
 | ||||
|    return json; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<MapSettings> MapSettings::Create() | ||||
| { | ||||
|    std::shared_ptr<MapSettings> generalSettings = | ||||
|       std::make_shared<MapSettings>(); | ||||
| 
 | ||||
|    generalSettings->p->SetDefaults(); | ||||
| 
 | ||||
|    return generalSettings; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<MapSettings> MapSettings::Load(const boost::json::value* json, | ||||
|                                                bool& jsonDirty) | ||||
| { | ||||
|    std::shared_ptr<MapSettings> mapSettings = std::make_shared<MapSettings>(); | ||||
| 
 | ||||
|    if (json != nullptr && json->is_array()) | ||||
|    if (value != nullptr && value->is_array()) | ||||
|    { | ||||
|       const boost::json::array& mapArray = json->as_array(); | ||||
|       const boost::json::array& mapArray = value->as_array(); | ||||
| 
 | ||||
|       for (size_t i = 0; i < kCount_; ++i) | ||||
|       for (std::size_t i = 0; i < kCount_; ++i) | ||||
|       { | ||||
|          if (i < mapArray.size() && mapArray.at(i).is_object()) | ||||
|          { | ||||
|             const boost::json::object& mapRecord = mapArray.at(i).as_object(); | ||||
|             MapSettingsImpl::MapData&  mapRecordSettings = | ||||
|                mapSettings->p->map_[i]; | ||||
| 
 | ||||
|             std::string radarProductGroup; | ||||
|             MapSettingsImpl::MapData&  mapRecordSettings = p->map_[i]; | ||||
| 
 | ||||
|             // Load JSON Elements
 | ||||
|             jsonDirty |= | ||||
|                !util::json::FromJsonString(mapRecord, | ||||
|                                            "radar_site", | ||||
|                                            mapRecordSettings.radarSite_, | ||||
|                                            kDefaultRadarSite_); | ||||
|             jsonDirty |= !util::json::FromJsonString(mapRecord, | ||||
|                                                      "radar_product_group", | ||||
|                                                      radarProductGroup, | ||||
|                                                      kDefaultRadarSite_); | ||||
|             jsonDirty |= | ||||
|                !util::json::FromJsonString(mapRecord, | ||||
|                                            "radar_product", | ||||
|                                            mapRecordSettings.radarProduct_, | ||||
|                                            kDefaultRadarProduct_[i]); | ||||
|             validated &= mapRecordSettings.radarSite_.ReadValue(mapRecord); | ||||
|             validated &= | ||||
|                mapRecordSettings.radarProductGroup_.ReadValue(mapRecord); | ||||
| 
 | ||||
|             // Validate Radar Site
 | ||||
|             if (config::RadarSite::Get(mapRecordSettings.radarSite_) == nullptr) | ||||
|             bool productValidated = | ||||
|                mapRecordSettings.radarProduct_.ReadValue(mapRecord); | ||||
|             if (!productValidated) | ||||
|             { | ||||
|                mapRecordSettings.radarSite_ = kDefaultRadarSite_; | ||||
|                jsonDirty                    = true; | ||||
|                // Product was set to default, reset group to default to match
 | ||||
|                mapRecordSettings.radarProductGroup_.SetValueToDefault(); | ||||
|                validated = false; | ||||
|             } | ||||
| 
 | ||||
|             // Validate Radar Product Group
 | ||||
|             mapRecordSettings.radarProductGroup_ = | ||||
|                common::GetRadarProductGroup(radarProductGroup); | ||||
|             if (mapRecordSettings.radarProductGroup_ == | ||||
|                 common::RadarProductGroup::Unknown) | ||||
|             { | ||||
|                mapRecordSettings.radarProductGroup_ = | ||||
|                   kDefaultRadarProductGroup_; | ||||
|                jsonDirty = true; | ||||
|             } | ||||
| 
 | ||||
|             // Validate Radar Product
 | ||||
|             if (mapRecordSettings.radarProductGroup_ == | ||||
|                    common::RadarProductGroup::Level2 && | ||||
|                 common::GetLevel2Product(mapRecordSettings.radarProduct_) == | ||||
|                    common::Level2Product::Unknown) | ||||
|             { | ||||
|                mapRecordSettings.radarProductGroup_ = | ||||
|                   kDefaultRadarProductGroup_; | ||||
|                mapRecordSettings.radarProduct_ = kDefaultRadarProduct_[i]; | ||||
|                jsonDirty                       = true; | ||||
|             } | ||||
| 
 | ||||
|             // TODO: Validate level 3 product
 | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             logger_->warn( | ||||
|                "Too few array entries, resetting record {} to defaults", i + 1); | ||||
|             jsonDirty = true; | ||||
|             mapSettings->p->SetDefaults(i); | ||||
|             validated = false; | ||||
|             p->SetDefaults(i); | ||||
|          } | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       if (json == nullptr) | ||||
|       if (value == nullptr) | ||||
|       { | ||||
|          logger_->warn("Key is not present, resetting to defaults"); | ||||
|       } | ||||
|       else if (!json->is_array()) | ||||
|       else if (!value->is_array()) | ||||
|       { | ||||
|          logger_->warn("Invalid json, resetting to defaults"); | ||||
|       } | ||||
| 
 | ||||
|       mapSettings->p->SetDefaults(); | ||||
|       jsonDirty = true; | ||||
|       SetDefaults(); | ||||
|       validated = false; | ||||
|    } | ||||
| 
 | ||||
|    return mapSettings; | ||||
|    return validated; | ||||
| } | ||||
| 
 | ||||
| void MapSettings::WriteJson(boost::json::object& json) const | ||||
| { | ||||
|    boost::json::value object = boost::json::value_from(p->map_); | ||||
|    json.insert_or_assign(name(), object); | ||||
| } | ||||
| 
 | ||||
| void tag_invoke(boost::json::value_from_tag, | ||||
|                 boost::json::value&             jv, | ||||
|                 const MapSettingsImpl::MapData& data) | ||||
| { | ||||
|    jv = {{"radar_site", data.radarSite_}, | ||||
|          {"radar_product_group", | ||||
|           common::GetRadarProductGroupName(data.radarProductGroup_)}, | ||||
|          {"radar_product", data.radarProduct_}}; | ||||
|    jv = {{kRadarSiteName_, data.radarSite_.GetValue()}, | ||||
|          {kRadarProductGroupName_, data.radarProductGroup_.GetValue()}, | ||||
|          {kRadarProductName_, data.radarProduct_.GetValue()}}; | ||||
| } | ||||
| 
 | ||||
| bool operator==(const MapSettings& lhs, const MapSettings& rhs) | ||||
|  |  | |||
|  | @ -1,12 +1,11 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/common/products.hpp> | ||||
| #include <scwx/qt/settings/settings_category.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| #include <string> | ||||
| 
 | ||||
| #include <boost/json.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
|  | @ -16,28 +15,39 @@ namespace settings | |||
| 
 | ||||
| class MapSettingsImpl; | ||||
| 
 | ||||
| class MapSettings | ||||
| class MapSettings : public SettingsCategory | ||||
| { | ||||
| public: | ||||
|    explicit MapSettings(); | ||||
|    ~MapSettings(); | ||||
| 
 | ||||
|    MapSettings(const MapSettings&) = delete; | ||||
|    MapSettings(const MapSettings&)            = delete; | ||||
|    MapSettings& operator=(const MapSettings&) = delete; | ||||
| 
 | ||||
|    MapSettings(MapSettings&&) noexcept; | ||||
|    MapSettings& operator=(MapSettings&&) noexcept; | ||||
| 
 | ||||
|    size_t                    count() const; | ||||
|    std::string               radar_site(size_t i) const; | ||||
|    common::RadarProductGroup radar_product_group(size_t i) const; | ||||
|    std::string               radar_product(size_t i) const; | ||||
|    std::size_t               count() const; | ||||
|    std::string               radar_site(std::size_t i) const; | ||||
|    common::RadarProductGroup radar_product_group(std::size_t i) const; | ||||
|    std::string               radar_product(std::size_t i) const; | ||||
| 
 | ||||
|    boost::json::value ToJson() const; | ||||
|    /**
 | ||||
|     * Reads the variables from the JSON object. | ||||
|     * | ||||
|     * @param json JSON object to read | ||||
|     * | ||||
|     * @return true if the values read are valid, false if any values were | ||||
|     * modified. | ||||
|     */ | ||||
|    bool ReadJson(const boost::json::object& json) override; | ||||
| 
 | ||||
|    static std::shared_ptr<MapSettings> Create(); | ||||
|    static std::shared_ptr<MapSettings> Load(const boost::json::value* json, | ||||
|                                             bool& jsonDirty); | ||||
|    /**
 | ||||
|     * Writes the variables to the JSON object. | ||||
|     * | ||||
|     * @param json JSON object to write | ||||
|     */ | ||||
|    void WriteJson(boost::json::object& json) const override; | ||||
| 
 | ||||
|    friend bool operator==(const MapSettings& lhs, const MapSettings& rhs); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,5 @@ | |||
| #include <scwx/qt/settings/palette_settings.hpp> | ||||
| #include <scwx/qt/util/json.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/qt/settings/settings_variable.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -10,7 +9,6 @@ namespace settings | |||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::settings::palette_settings"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| static const std::vector<std::string> paletteNames_ = { | ||||
|    // Level 2 / Common Products
 | ||||
|  | @ -33,29 +31,43 @@ static const std::vector<std::string> paletteNames_ = { | |||
|    "VIL", | ||||
|    "???"}; | ||||
| 
 | ||||
| static const std::string DEFAULT_KEY     = "Default"; | ||||
| static const std::string DEFAULT_PALETTE = ""; | ||||
| static const std::string kDefaultKey     = "???"; | ||||
| static const std::string kDefaultPalette = ""; | ||||
| 
 | ||||
| class PaletteSettingsImpl | ||||
| { | ||||
| public: | ||||
|    explicit PaletteSettingsImpl() {} | ||||
| 
 | ||||
|    ~PaletteSettingsImpl() {} | ||||
| 
 | ||||
|    void SetDefaults() | ||||
|    explicit PaletteSettingsImpl() | ||||
|    { | ||||
|       std::for_each(paletteNames_.cbegin(), | ||||
|                     paletteNames_.cend(), | ||||
|                     [&](const std::string& name) | ||||
|                     { palette_[name] = DEFAULT_PALETTE; }); | ||||
|                     { | ||||
|                        auto result = palette_.emplace( | ||||
|                           name, SettingsVariable<std::string> {name}); | ||||
| 
 | ||||
|                        SettingsVariable<std::string>& settingsVariable = | ||||
|                           result.first->second; | ||||
| 
 | ||||
|                        settingsVariable.SetDefault(kDefaultPalette); | ||||
| 
 | ||||
|                        variables_.push_back(&settingsVariable); | ||||
|                     }); | ||||
|    } | ||||
| 
 | ||||
|    std::unordered_map<std::string, std::string> palette_; | ||||
|    ~PaletteSettingsImpl() {} | ||||
| 
 | ||||
|    std::unordered_map<std::string, SettingsVariable<std::string>> palette_; | ||||
|    std::vector<SettingsVariableBase*>                             variables_; | ||||
| }; | ||||
| 
 | ||||
| PaletteSettings::PaletteSettings() : p(std::make_unique<PaletteSettingsImpl>()) | ||||
| PaletteSettings::PaletteSettings() : | ||||
|     SettingsCategory("palette"), p(std::make_unique<PaletteSettingsImpl>()) | ||||
| { | ||||
|    RegisterVariables(p->variables_); | ||||
|    SetDefaults(); | ||||
| 
 | ||||
|    p->variables_.clear(); | ||||
| } | ||||
| PaletteSettings::~PaletteSettings() = default; | ||||
| 
 | ||||
|  | @ -63,80 +75,21 @@ PaletteSettings::PaletteSettings(PaletteSettings&&) noexcept = default; | |||
| PaletteSettings& | ||||
| PaletteSettings::operator=(PaletteSettings&&) noexcept = default; | ||||
| 
 | ||||
| const std::string& PaletteSettings::palette(const std::string& name) const | ||||
| std::string PaletteSettings::palette(const std::string& name) const | ||||
| { | ||||
|    auto palette = p->palette_.find(name); | ||||
| 
 | ||||
|    if (palette == p->palette_.cend()) | ||||
|    { | ||||
|       palette = p->palette_.find("Default"); | ||||
|       palette = p->palette_.find(kDefaultKey); | ||||
|    } | ||||
| 
 | ||||
|    if (palette == p->palette_.cend()) | ||||
|    { | ||||
|       return DEFAULT_PALETTE; | ||||
|       return kDefaultPalette; | ||||
|    } | ||||
| 
 | ||||
|    return palette->second; | ||||
| } | ||||
| 
 | ||||
| boost::json::value PaletteSettings::ToJson() const | ||||
| { | ||||
|    boost::json::object json; | ||||
| 
 | ||||
|    std::for_each(paletteNames_.cbegin(), | ||||
|                  paletteNames_.cend(), | ||||
|                  [&](const std::string& name) | ||||
|                  { json[name] = p->palette_[name]; }); | ||||
| 
 | ||||
|    return json; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<PaletteSettings> PaletteSettings::Create() | ||||
| { | ||||
|    std::shared_ptr<PaletteSettings> generalSettings = | ||||
|       std::make_shared<PaletteSettings>(); | ||||
| 
 | ||||
|    generalSettings->p->SetDefaults(); | ||||
| 
 | ||||
|    return generalSettings; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<PaletteSettings> | ||||
| PaletteSettings::Load(const boost::json::value* json, bool& jsonDirty) | ||||
| { | ||||
|    std::shared_ptr<PaletteSettings> generalSettings = | ||||
|       std::make_shared<PaletteSettings>(); | ||||
| 
 | ||||
|    if (json != nullptr && json->is_object()) | ||||
|    { | ||||
|       std::for_each(paletteNames_.cbegin(), | ||||
|                     paletteNames_.cend(), | ||||
|                     [&](const std::string& name) | ||||
|                     { | ||||
|                        jsonDirty |= !util::json::FromJsonString( | ||||
|                           json->as_object(), | ||||
|                           name, | ||||
|                           generalSettings->p->palette_[name], | ||||
|                           DEFAULT_PALETTE); | ||||
|                     }); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       if (json == nullptr) | ||||
|       { | ||||
|          logger_->warn("Key is not present, resetting to defaults"); | ||||
|       } | ||||
|       else if (!json->is_object()) | ||||
|       { | ||||
|          logger_->warn("Invalid json, resetting to defaults"); | ||||
|       } | ||||
| 
 | ||||
|       generalSettings->p->SetDefaults(); | ||||
|       jsonDirty = true; | ||||
|    } | ||||
| 
 | ||||
|    return generalSettings; | ||||
|    return palette->second.GetValue(); | ||||
| } | ||||
| 
 | ||||
| bool operator==(const PaletteSettings& lhs, const PaletteSettings& rhs) | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/settings/settings_category.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| #include <string> | ||||
| 
 | ||||
| #include <boost/json.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
|  | @ -14,25 +14,19 @@ namespace settings | |||
| 
 | ||||
| class PaletteSettingsImpl; | ||||
| 
 | ||||
| class PaletteSettings | ||||
| class PaletteSettings : public SettingsCategory | ||||
| { | ||||
| public: | ||||
|    explicit PaletteSettings(); | ||||
|    ~PaletteSettings(); | ||||
| 
 | ||||
|    PaletteSettings(const PaletteSettings&) = delete; | ||||
|    PaletteSettings(const PaletteSettings&)            = delete; | ||||
|    PaletteSettings& operator=(const PaletteSettings&) = delete; | ||||
| 
 | ||||
|    PaletteSettings(PaletteSettings&&) noexcept; | ||||
|    PaletteSettings& operator=(PaletteSettings&&) noexcept; | ||||
| 
 | ||||
|    const std::string& palette(const std::string& name) const; | ||||
| 
 | ||||
|    boost::json::value ToJson() const; | ||||
| 
 | ||||
|    static std::shared_ptr<PaletteSettings> Create(); | ||||
|    static std::shared_ptr<PaletteSettings> Load(const boost::json::value* json, | ||||
|                                                 bool& jsonDirty); | ||||
|    std::string palette(const std::string& name) const; | ||||
| 
 | ||||
|    friend bool operator==(const PaletteSettings& lhs, | ||||
|                           const PaletteSettings& rhs); | ||||
|  |  | |||
|  | @ -34,6 +34,11 @@ SettingsCategory::SettingsCategory(SettingsCategory&&) noexcept = default; | |||
| SettingsCategory& | ||||
| SettingsCategory::operator=(SettingsCategory&&) noexcept = default; | ||||
| 
 | ||||
| std::string SettingsCategory::name() const | ||||
| { | ||||
|    return p->name_; | ||||
| } | ||||
| 
 | ||||
| void SettingsCategory::SetDefaults() | ||||
| { | ||||
|    for (auto& variable : p->variables_) | ||||
|  | @ -95,6 +100,13 @@ void SettingsCategory::RegisterVariables( | |||
|    p->variables_.insert(p->variables_.end(), variables); | ||||
| } | ||||
| 
 | ||||
| void SettingsCategory::RegisterVariables( | ||||
|    std::vector<SettingsVariableBase*> variables) | ||||
| { | ||||
|    p->variables_.insert( | ||||
|       p->variables_.end(), variables.cbegin(), variables.cend()); | ||||
| } | ||||
| 
 | ||||
| } // namespace settings
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -26,10 +26,12 @@ public: | |||
|    SettingsCategory(SettingsCategory&&) noexcept; | ||||
|    SettingsCategory& operator=(SettingsCategory&&) noexcept; | ||||
| 
 | ||||
|    std::string name() const; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Set all variables to their defaults. | ||||
|     */ | ||||
|    virtual void SetDefaults(); | ||||
|    void SetDefaults(); | ||||
| 
 | ||||
|    /**
 | ||||
|     * Reads the variables from the JSON object. | ||||
|  | @ -51,6 +53,7 @@ public: | |||
| protected: | ||||
|    void | ||||
|    RegisterVariables(std::initializer_list<SettingsVariableBase*> variables); | ||||
|    void RegisterVariables(std::vector<SettingsVariableBase*> variables); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat