mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:10:04 +00:00
Cleanup use of custom provider definitions, use common map_provider.hpp
This commit is contained in:
parent
6f40c75a33
commit
c77c899040
3 changed files with 48 additions and 38 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
#include <scwx/qt/manager/settings_manager.hpp>
|
#include <scwx/qt/manager/settings_manager.hpp>
|
||||||
|
#include <scwx/qt/map/map_provider.hpp>
|
||||||
#include <scwx/qt/util/json.hpp>
|
#include <scwx/qt/util/json.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
|
@ -148,28 +150,30 @@ static void ValidateSettings()
|
||||||
auto& generalSettings = general_settings();
|
auto& generalSettings = general_settings();
|
||||||
|
|
||||||
// Validate map provider
|
// Validate map provider
|
||||||
std::string mapProvider = generalSettings.map_provider().GetValue();
|
std::string mapProviderName = generalSettings.map_provider().GetValue();
|
||||||
std::string mapboxApiKey = generalSettings.mapbox_api_key().GetValue();
|
std::string mapboxApiKey = generalSettings.mapbox_api_key().GetValue();
|
||||||
std::string maptilerApiKey = generalSettings.maptiler_api_key().GetValue();
|
std::string maptilerApiKey = generalSettings.maptiler_api_key().GetValue();
|
||||||
|
|
||||||
if (mapProvider == "maptiler" && //
|
map::MapProvider mapProvider = map::GetMapProvider(mapProviderName);
|
||||||
mapboxApiKey.size() > 1 && //
|
std::string mapApiKey = map::GetMapProviderApiKey(mapProvider);
|
||||||
maptilerApiKey == "?")
|
|
||||||
|
if (mapApiKey == "?")
|
||||||
{
|
{
|
||||||
logger_->info("Setting Map Provider to Mapbox based on API key settings");
|
for (map::MapProvider newProvider : map::MapProviderIterator())
|
||||||
|
{
|
||||||
|
if (mapProvider != newProvider &&
|
||||||
|
map::GetMapProviderApiKey(newProvider).size() > 1)
|
||||||
|
{
|
||||||
|
logger_->info(
|
||||||
|
"Setting Map Provider to {} based on API key settings",
|
||||||
|
map::GetMapProviderName(newProvider));
|
||||||
|
|
||||||
generalSettings.map_provider().SetValue("mapbox");
|
std::string newProviderName {GetMapProviderName(newProvider)};
|
||||||
settingsChanged = true;
|
boost::to_lower(newProviderName);
|
||||||
}
|
generalSettings.map_provider().SetValue(newProviderName);
|
||||||
else if (mapProvider == "mapbox" && //
|
settingsChanged = true;
|
||||||
maptilerApiKey.size() > 1 && //
|
}
|
||||||
mapboxApiKey == "?")
|
}
|
||||||
{
|
|
||||||
logger_->info(
|
|
||||||
"Setting Map Provider to MapTiler based on API key settings");
|
|
||||||
|
|
||||||
generalSettings.map_provider().SetValue("maptiler");
|
|
||||||
settingsChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settingsChanged)
|
if (settingsChanged)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
#include <scwx/qt/settings/general_settings.hpp>
|
#include <scwx/qt/settings/general_settings.hpp>
|
||||||
#include <scwx/qt/settings/settings_container.hpp>
|
#include <scwx/qt/settings/settings_container.hpp>
|
||||||
|
#include <scwx/qt/map/map_provider.hpp>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace qt
|
namespace qt
|
||||||
|
|
@ -12,9 +15,6 @@ namespace settings
|
||||||
|
|
||||||
static const std::string logPrefix_ = "scwx::qt::settings::general_settings";
|
static const std::string logPrefix_ = "scwx::qt::settings::general_settings";
|
||||||
|
|
||||||
static const std::array<std::string, 2> kMapProviderValues_ {"mapbox",
|
|
||||||
"maptiler"};
|
|
||||||
|
|
||||||
class GeneralSettingsImpl
|
class GeneralSettingsImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -41,9 +41,15 @@ public:
|
||||||
mapProvider_.SetValidator(
|
mapProvider_.SetValidator(
|
||||||
[](const std::string& value)
|
[](const std::string& value)
|
||||||
{
|
{
|
||||||
return std::find(kMapProviderValues_.cbegin(),
|
return std::find_if(map::MapProviderIterator().begin(),
|
||||||
kMapProviderValues_.cend(),
|
map::MapProviderIterator().end(),
|
||||||
value) != kMapProviderValues_.cend();
|
[&value](map::MapProvider mapProvider)
|
||||||
|
{
|
||||||
|
std::string mapProviderName =
|
||||||
|
map::GetMapProviderName(mapProvider);
|
||||||
|
boost::to_lower(mapProviderName);
|
||||||
|
return value == mapProviderName;
|
||||||
|
}) != map::MapProviderIterator().end();
|
||||||
});
|
});
|
||||||
mapboxApiKey_.SetValidator([](const std::string& value)
|
mapboxApiKey_.SetValidator([](const std::string& value)
|
||||||
{ return !value.empty(); });
|
{ return !value.empty(); });
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <scwx/common/color_table.hpp>
|
#include <scwx/common/color_table.hpp>
|
||||||
#include <scwx/qt/config/radar_site.hpp>
|
#include <scwx/qt/config/radar_site.hpp>
|
||||||
#include <scwx/qt/manager/settings_manager.hpp>
|
#include <scwx/qt/manager/settings_manager.hpp>
|
||||||
|
#include <scwx/qt/map/map_provider.hpp>
|
||||||
#include <scwx/qt/settings/settings_interface.hpp>
|
#include <scwx/qt/settings/settings_interface.hpp>
|
||||||
#include <scwx/qt/ui/radar_site_dialog.hpp>
|
#include <scwx/qt/ui/radar_site_dialog.hpp>
|
||||||
#include <scwx/qt/util/color.hpp>
|
#include <scwx/qt/util/color.hpp>
|
||||||
|
|
@ -36,8 +37,6 @@ struct ColorTableConversions
|
||||||
float scale {1.0f};
|
float scale {1.0f};
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::array<std::string, 2> kMapProviders_ {"Mapbox", "MapTiler"};
|
|
||||||
|
|
||||||
static const std::array<std::pair<std::string, std::string>, 15>
|
static const std::array<std::pair<std::string, std::string>, 15>
|
||||||
kColorTableTypes_ {std::pair {"BR", "BR"},
|
kColorTableTypes_ {std::pair {"BR", "BR"},
|
||||||
std::pair {"BV", "BV"},
|
std::pair {"BV", "BV"},
|
||||||
|
|
@ -320,29 +319,30 @@ void SettingsDialogImpl::SetupGeneralTab()
|
||||||
gridHeight_.SetEditWidget(self_->ui->gridHeightSpinBox);
|
gridHeight_.SetEditWidget(self_->ui->gridHeightSpinBox);
|
||||||
gridHeight_.SetResetButton(self_->ui->resetGridHeightButton);
|
gridHeight_.SetResetButton(self_->ui->resetGridHeightButton);
|
||||||
|
|
||||||
for (const auto& mapProvider : kMapProviders_)
|
for (const auto& mapProvider : map::MapProviderIterator())
|
||||||
{
|
{
|
||||||
self_->ui->mapProviderComboBox->addItem(
|
self_->ui->mapProviderComboBox->addItem(
|
||||||
QString::fromStdString(mapProvider));
|
QString::fromStdString(map::GetMapProviderName(mapProvider)));
|
||||||
}
|
}
|
||||||
|
|
||||||
mapProvider_.SetSettingsVariable(generalSettings.map_provider());
|
mapProvider_.SetSettingsVariable(generalSettings.map_provider());
|
||||||
mapProvider_.SetMapFromValueFunction(
|
mapProvider_.SetMapFromValueFunction(
|
||||||
[](const std::string& text) -> std::string
|
[](const std::string& text) -> std::string
|
||||||
{
|
{
|
||||||
auto it = std::find_if(kMapProviders_.cbegin(),
|
auto it = std::find_if(
|
||||||
kMapProviders_.cend(),
|
map::MapProviderIterator().begin(),
|
||||||
[&text](const std::string& mapProvider)
|
map::MapProviderIterator().end(),
|
||||||
{ return boost::iequals(text, mapProvider); });
|
[&text](map::MapProvider mapProvider)
|
||||||
|
{ return boost::iequals(text, GetMapProviderName(mapProvider)); });
|
||||||
|
|
||||||
if (it == kMapProviders_.cend())
|
if (it != map::MapProviderIterator().end())
|
||||||
{
|
{
|
||||||
// Map provider label not found, return unknown
|
// Return map provider label
|
||||||
return "?";
|
return GetMapProviderName(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return map provider label
|
// Map provider label not found, return unknown
|
||||||
return *it;
|
return "?";
|
||||||
});
|
});
|
||||||
mapProvider_.SetMapToValueFunction(
|
mapProvider_.SetMapToValueFunction(
|
||||||
[](std::string text) -> std::string
|
[](std::string text) -> std::string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue