Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions scwx-qt/source/scwx/qt/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QTranslator>
#include <QPalette>
#include <QStyle>
#include <QSysInfo>

#define QT6CT_LIBRARY
#include <qt6ct-common/qt6ct.h>
Expand Down Expand Up @@ -65,6 +66,7 @@ int main(int argc, char* argv[])
logManager.Initialize();

QCoreApplication::setApplicationName("Supercell Wx");
const std::string osName = QSysInfo::prettyProductName().toStdString();

logManager.InitializeLogFile();

Expand All @@ -74,13 +76,14 @@ int main(int argc, char* argv[])
scwx::qt::main::kCommitString_);
logger_->info("Qt version {}",
QLibraryInfo::version().toString().toStdString());
logger_->info("Running on {}", osName);

InitializeOpenGL();

QApplication a(argc, argv);

scwx::network::cpr::SetUserAgent(
fmt::format("SupercellWx/{}", scwx::qt::main::kVersionString_));
scwx::network::cpr::SetUserAgent(fmt::format(
"SupercellWx/{} ({})", scwx::qt::main::kVersionString_, osName));

// Enable internationalization support
QTranslator translator;
Expand Down
139 changes: 69 additions & 70 deletions scwx-qt/source/scwx/qt/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QScreen>
#include <QSignalBlocker>
#include <QSplitter>
#include <QStandardPaths>
#include <QTimer>
Expand Down Expand Up @@ -93,16 +94,9 @@ class MainWindowImpl : public QObject
updateManager_ {manager::UpdateManager::Instance()},
maps_ {}
{
mapProvider_ = map::GetMapProvider(
settings::GeneralSettings::Instance().map_provider().GetValue());
const map::MapProviderInfo& mapProviderInfo =
map::GetMapProviderInfo(mapProvider_);

std::string appDataPath {
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
.toStdString()};
std::string cacheDbPath {appDataPath + "/" +
mapProviderInfo.cacheDbName_};

if (!std::filesystem::exists(appDataPath))
{
Expand All @@ -114,35 +108,25 @@ class MainWindowImpl : public QObject
}
}

std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider_);

if (mapProvider_ == map::MapProvider::Mapbox)
{
settings_.setProviderTemplate(mapProviderInfo.providerTemplate_);
settings_.setApiKey(QString {mapProviderApiKey.c_str()});
}
settings_.setCacheDatabasePath(QString {cacheDbPath.c_str()});
settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
mapProvider_ = map::GetMapProvider(
settings::GeneralSettings::Instance().map_provider().GetValue());
map::ConfigureMapSettings(mapProvider_, settings_);

if (settings::GeneralSettings::Instance().track_location().GetValue())
{
positionManager_->TrackLocation(true);
}
}

~MainWindowImpl()
{
homeRadarConnection_.disconnect();
clockFormatConnection_.disconnect();
defaultTimeZoneConnection_.disconnect();

auto& generalSettings = settings::GeneralSettings::Instance();

auto& customStyleUrl = generalSettings.custom_style_url();
auto& customStyleDrawLayer = generalSettings.custom_style_draw_layer();

customStyleUrl.UnregisterValueChangedCallback(
customStyleUrlChangedCallbackUuid_);
customStyleDrawLayer.UnregisterValueChangedCallback(
customStyleDrawLayerChangedCallbackUuid_);
for (auto& connection : connections_)
{
connection.disconnect();
}

clockTimer_.stop();
threadPool_.join();
Expand Down Expand Up @@ -214,9 +198,9 @@ class MainWindowImpl : public QObject

QTimer clockTimer_ {};

bool customStyleAvailable_ {false};
boost::uuids::uuid customStyleDrawLayerChangedCallbackUuid_ {};
boost::uuids::uuid customStyleUrlChangedCallbackUuid_ {};
bool customStyleAvailable_ {false};

std::vector<boost::signals2::scoped_connection> connections_ {};

#ifdef Q_OS_WIN
QRect priorFullScreenGeometry_ {};
Expand Down Expand Up @@ -907,29 +891,38 @@ void MainWindowImpl::ConfigureMapStyles()

for (std::size_t i = 0; i < maps_.size(); i++)
{
std::string styleName = mapSettings.map_style(i).GetValue();

if ((customStyleAvailable_ && styleName == "Custom") ||
styleName == "None" ||
std::ranges::find_if(mapProviderInfo.mapStyles_,
[&](const auto& mapStyle)
{ return mapStyle.name_ == styleName; }) !=
mapProviderInfo.mapStyles_.cend())
const std::string configuredStyleName =
mapSettings.map_style(i).GetValue();
std::string styleName = configuredStyleName;

if (!((customStyleAvailable_ && styleName == "Custom") ||
styleName == "None" ||
std::ranges::find_if(mapProviderInfo.mapStyles_,
[&](const auto& mapStyle)
{ return mapStyle.name_ == styleName; }) !=
mapProviderInfo.mapStyles_.cend()))
{
// Initialize map style from settings
maps_.at(i)->SetInitialMapStyle(styleName);
styleName = !mapProviderInfo.mapStyles_.empty() ?
mapProviderInfo.mapStyles_.at(0).name_ :
"None";
}

// Update the active map's style
if (maps_[i] == activeMap_)
{
UpdateMapStyle(styleName);
}
const std::string currentStyleName = maps_.at(i)->GetMapStyle();
if (currentStyleName != "?")
{
styleName = currentStyleName;
}

maps_.at(i)->SetInitialMapStyle(styleName);

if (maps_[i] == activeMap_)
{
UpdateMapStyle(styleName);
}
else if (!mapProviderInfo.mapStyles_.empty())

if (configuredStyleName != styleName)
{
// Stage first valid map style from map provider
mapSettings.map_style(i).StageValue(
mapProviderInfo.mapStyles_.at(0).name_);
mapSettings.map_style(i).StageValue(styleName);
}
}
}
Expand Down Expand Up @@ -1398,14 +1391,11 @@ void MainWindowImpl::ConnectOtherSignals()
auto& generalSettings = settings::GeneralSettings::Instance();
homeRadarConnection_ =
generalSettings.default_radar_site().changed_signal().connect(
[this]()
[this](const auto& event)
{
const std::shared_ptr<config::RadarSite> radarSite =
activeMap_->GetRadarSite();
const std::string homeRadarSite =
settings::GeneralSettings::Instance()
.default_radar_site()
.GetValue();
const std::string& homeRadarSite = event.newValue_;
if (radarSite == nullptr)
{
mainWindow_->ui->saveRadarProductsButton->setVisible(false);
Expand All @@ -1419,21 +1409,36 @@ void MainWindowImpl::ConnectOtherSignals()

clockFormatConnection_ =
generalSettings.clock_format().changed_signal().connect(
[]()
[](const auto& event)
{
auto& generalSettings = settings::GeneralSettings::Instance();
util::time::set_default_clock_format(
util::GetClockFormat(generalSettings.clock_format().GetValue()));
util::GetClockFormat(event.newValue_));
});
defaultTimeZoneConnection_ =
generalSettings.default_time_zone().changed_signal().connect(
[this]()
[this](auto&&...)
{
const auto defaultTimeZone = activeMap_->GetDefaultTimeZone();
util::time::set_current_time_zone(defaultTimeZone);
animationDockWidget_->UpdateTimeZone(defaultTimeZone);
});

connections_.emplace_back(
generalSettings.custom_style_url().changed_signal().connect(
[this](auto&&...) { PopulateCustomMapStyle(); }));
connections_.emplace_back(
generalSettings.custom_style_draw_layer().changed_signal().connect(
[this](auto&&...) { PopulateCustomMapStyle(); }));

connections_.emplace_back(
generalSettings.map_provider().changed_signal().connect(
[this](const auto& event)
{
mapProvider_ = map::GetMapProvider(event.newValue_);
PopulateMapStyles();
ConfigureMapStyles();
}));

// Ensure default clock format is initialized
util::time::set_default_clock_format(
util::GetClockFormat(generalSettings.clock_format().GetValue()));
Expand Down Expand Up @@ -1552,6 +1557,10 @@ void MainWindowImpl::PopulateCustomMapStyle()

void MainWindowImpl::PopulateMapStyles()
{
const QSignalBlocker blocker(mainWindow_->ui->mapStyleComboBox);

mainWindow_->ui->mapStyleComboBox->clear();

const auto& mapProviderInfo = map::GetMapProviderInfo(mapProvider_);
for (const auto& mapStyle : mapProviderInfo.mapStyles_)
{
Expand All @@ -1562,19 +1571,8 @@ void MainWindowImpl::PopulateMapStyles()
const std::string kNone = "None";
mainWindow_->ui->mapStyleComboBox->addItem(QString::fromStdString(kNone));

auto& generalSettings = settings::GeneralSettings::Instance();

auto& customStyleUrl = generalSettings.custom_style_url();
auto& customStyleDrawLayer = generalSettings.custom_style_draw_layer();

customStyleUrlChangedCallbackUuid_ =
customStyleUrl.RegisterValueChangedCallback(
[this]([[maybe_unused]] const std::string& value)
{ PopulateCustomMapStyle(); });
customStyleDrawLayerChangedCallbackUuid_ =
customStyleDrawLayer.RegisterValueChangedCallback(
[this]([[maybe_unused]] const std::string& value)
{ PopulateCustomMapStyle(); });
// The combobox was cleared above, so force re-evaluation of custom style.
customStyleAvailable_ = false;

PopulateCustomMapStyle();
}
Expand Down Expand Up @@ -1660,6 +1658,7 @@ void MainWindowImpl::UpdateMapStyle(const std::string& styleName)
QString::fromStdString(styleName));
if (index != -1)
{
const QSignalBlocker blocker(mainWindow_->ui->mapStyleComboBox);
mainWindow_->ui->mapStyleComboBox->setCurrentIndex(index);

// Update settings for active map
Expand Down
8 changes: 6 additions & 2 deletions scwx-qt/source/scwx/qt/manager/placefile_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,15 @@ void PlacefileManager::Impl::PlacefileRecord::Update()
}
else if (response.status_code == 0 && enabled_)
{
logger_->error("Error loading placefile: {}", response.error.message);
logger_->error("Error loading placefile: {} ({})",
decodedUrl,
response.error.message);
}
else if (enabled_)
{
logger_->error("Error loading placefile: {}", response.status_line);
logger_->error("Error loading placefile: {} ({})",
decodedUrl,
response.status_line);
}
else
{
Expand Down
33 changes: 33 additions & 0 deletions scwx-qt/source/scwx/qt/map/map_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <unordered_map>

#include <boost/algorithm/string.hpp>
#include <QStandardPaths>

namespace scwx::qt::map
{
Expand Down Expand Up @@ -185,6 +186,38 @@ bool MapStyle::IsValid() const
return !url_.empty() && !drawBelow_.empty();
}

void ConfigureMapSettings(MapProvider mapProvider,
QMapLibre::Settings& settings)
{
static constexpr std::size_t kMaxCacheSize =
20ull * 1024ull * 1024ull; // 20 MB

const auto& mapProviderInfo = GetMapProviderInfo(mapProvider);

const std::string appDataPath {
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
.toStdString()};
const std::string cacheDbPath {appDataPath + "/" +
mapProviderInfo.cacheDbName_};

const std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider);

if (mapProvider == map::MapProvider::Mapbox)
{
settings.setProviderTemplate(mapProviderInfo.providerTemplate_);
settings.setApiKey(QString {mapProviderApiKey.c_str()});
}
else
{
settings.setProviderTemplate(
QMapLibre::Settings::ProviderTemplate::NoProvider);
settings.setApiKey({});
}

settings.setCacheDatabasePath(QString {cacheDbPath.c_str()});
settings.setCacheDatabaseMaximumSize(kMaxCacheSize);
}

MapProvider GetMapProvider(const std::string& name)
{
auto result =
Expand Down
2 changes: 2 additions & 0 deletions scwx-qt/source/scwx/qt/map/map_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct MapProviderInfo
std::vector<MapStyle> mapStyles_ {};
};

void ConfigureMapSettings(MapProvider mapProvider,
QMapLibre::Settings& settings);
MapProvider GetMapProvider(const std::string& name);
std::string GetMapProviderName(MapProvider mapProvider);
std::string GetMapProviderApiKey(MapProvider mapProvider);
Expand Down
Loading
Loading