mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:30:05 +00:00
Load color tables from settings
This commit is contained in:
parent
bcae7d9825
commit
b241703b40
16 changed files with 324 additions and 17 deletions
|
|
@ -12,7 +12,7 @@ namespace settings
|
|||
|
||||
static const std::string logPrefix_ = "[scwx::qt::settings::general_settings] ";
|
||||
|
||||
static const std::string& DEFAULT_DEFAULT_RADAR_SITE = "KLSX";
|
||||
static const std::string DEFAULT_DEFAULT_RADAR_SITE = "KLSX";
|
||||
|
||||
class GeneralSettingsImpl
|
||||
{
|
||||
|
|
@ -35,12 +35,12 @@ GeneralSettings::GeneralSettings(GeneralSettings&&) noexcept = default;
|
|||
GeneralSettings&
|
||||
GeneralSettings::operator=(GeneralSettings&&) noexcept = default;
|
||||
|
||||
const std::string& GeneralSettings::default_radar_site()
|
||||
const std::string& GeneralSettings::default_radar_site() const
|
||||
{
|
||||
return p->defaultRadarSite_;
|
||||
}
|
||||
|
||||
boost::json::value GeneralSettings::ToJson()
|
||||
boost::json::value GeneralSettings::ToJson() const
|
||||
{
|
||||
boost::json::object json;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ public:
|
|||
GeneralSettings(GeneralSettings&&) noexcept;
|
||||
GeneralSettings& operator=(GeneralSettings&&) noexcept;
|
||||
|
||||
const std::string& default_radar_site();
|
||||
const std::string& default_radar_site() const;
|
||||
|
||||
boost::json::value ToJson();
|
||||
boost::json::value ToJson() const;
|
||||
|
||||
static std::shared_ptr<GeneralSettings> Create();
|
||||
static std::shared_ptr<GeneralSettings> Load(const boost::json::value* json,
|
||||
|
|
|
|||
132
scwx-qt/source/scwx/qt/settings/palette_settings.cpp
Normal file
132
scwx-qt/source/scwx/qt/settings/palette_settings.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
#include <scwx/qt/settings/palette_settings.hpp>
|
||||
#include <scwx/qt/util/json.hpp>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "[scwx::qt::settings::palette_settings] ";
|
||||
|
||||
static const std::vector<std::string> paletteNames_ = {
|
||||
"BR", "BV", "SW", "ZDR", "PHI", "CC", "???"};
|
||||
|
||||
static const std::string DEFAULT_KEY = "Default";
|
||||
static const std::string DEFAULT_PALETTE = "";
|
||||
|
||||
class PaletteSettingsImpl
|
||||
{
|
||||
public:
|
||||
explicit PaletteSettingsImpl() {}
|
||||
|
||||
~PaletteSettingsImpl() {}
|
||||
|
||||
void SetDefaults()
|
||||
{
|
||||
std::for_each(
|
||||
paletteNames_.cbegin(),
|
||||
paletteNames_.cend(),
|
||||
[&](const std::string& name) { palette_[name] = DEFAULT_PALETTE; });
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::string> palette_;
|
||||
};
|
||||
|
||||
PaletteSettings::PaletteSettings() : p(std::make_unique<PaletteSettingsImpl>())
|
||||
{
|
||||
}
|
||||
PaletteSettings::~PaletteSettings() = default;
|
||||
|
||||
PaletteSettings::PaletteSettings(PaletteSettings&&) noexcept = default;
|
||||
PaletteSettings&
|
||||
PaletteSettings::operator=(PaletteSettings&&) noexcept = default;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
if (palette == p->palette_.cend())
|
||||
{
|
||||
return DEFAULT_PALETTE;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Key is not present, resetting to defaults";
|
||||
}
|
||||
else if (!json->is_object())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Invalid json, resetting to defaults";
|
||||
}
|
||||
|
||||
generalSettings->p->SetDefaults();
|
||||
jsonDirty = true;
|
||||
}
|
||||
|
||||
return generalSettings;
|
||||
}
|
||||
|
||||
bool operator==(const PaletteSettings& lhs, const PaletteSettings& rhs)
|
||||
{
|
||||
return lhs.p->palette_ == rhs.p->palette_;
|
||||
}
|
||||
|
||||
} // namespace settings
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
46
scwx-qt/source/scwx/qt/settings/palette_settings.hpp
Normal file
46
scwx-qt/source/scwx/qt/settings/palette_settings.hpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
|
||||
class PaletteSettingsImpl;
|
||||
|
||||
class PaletteSettings
|
||||
{
|
||||
public:
|
||||
explicit PaletteSettings();
|
||||
~PaletteSettings();
|
||||
|
||||
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);
|
||||
|
||||
friend bool operator==(const PaletteSettings& lhs,
|
||||
const PaletteSettings& rhs);
|
||||
|
||||
private:
|
||||
std::unique_ptr<PaletteSettingsImpl> p;
|
||||
};
|
||||
|
||||
} // namespace settings
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue