diff --git a/scwx-qt/source/scwx/qt/settings/settings_interface.cpp b/scwx-qt/source/scwx/qt/settings/settings_interface.cpp index 3c2c4962..2cd1a298 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_interface.cpp +++ b/scwx-qt/source/scwx/qt/settings/settings_interface.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -41,8 +43,8 @@ public: QWidget* editWidget_ {nullptr}; QAbstractButton* resetButton_ {nullptr}; - std::function mapFromValue_ {nullptr}; - std::function mapToValue_ {nullptr}; + std::function mapFromValue_ {nullptr}; + std::function mapToValue_ {nullptr}; }; template @@ -99,6 +101,52 @@ void SettingsInterface::SetEditWidget(QWidget* widget) // TODO: Display invalid status }); } + else if constexpr (std::is_same_v>) + { + // If the line is edited (not programatically changed), stage the new + // value + QObject::connect( + lineEdit, + &QLineEdit::textEdited, + p->context_.get(), + [this](const QString& text) + { + // Map to value if required + T value {}; + if (p->mapToValue_ != nullptr) + { + // User-defined map to value + value = p->mapToValue_(text.toStdString()); + } + else + { + // Tokenize string to parse each element + const std::string str {text.toStdString()}; + boost::tokenizer tokens(str); + for (auto it = tokens.begin(); it != tokens.end(); ++it) + { + try + { + // Good value + value.push_back( + static_cast(std::stoll(*it))); + } + catch (const std::exception&) + { + // Error value + value.push_back( + std::numeric_limits::min()); + } + } + } + + // Attempt to stage the value + p->stagedValid_ = p->variable_->StageValue(value); + p->UpdateResetButton(); + + // TODO: Display invalid status + }); + } } else if (QCheckBox* checkBox = dynamic_cast(widget)) { @@ -228,14 +276,14 @@ void SettingsInterface::SetResetButton(QAbstractButton* button) template void SettingsInterface::SetMapFromValueFunction( - std::function function) + std::function function) { p->mapFromValue_ = function; } template void SettingsInterface::SetMapToValueFunction( - std::function function) + std::function function) { p->mapToValue_ = function; } @@ -266,6 +314,19 @@ void SettingsInterface::Impl::UpdateEditWidget() lineEdit->setText(QString::fromStdString(currentValue)); } } + else if constexpr (std::is_same_v>) + { + if (mapFromValue_ != nullptr) + { + lineEdit->setText( + QString::fromStdString(mapFromValue_(currentValue))); + } + else + { + lineEdit->setText(QString::fromStdString( + fmt::format("{}", fmt::join(currentValue, ", ")))); + } + } } else if (QCheckBox* checkBox = dynamic_cast(editWidget_)) { diff --git a/scwx-qt/source/scwx/qt/settings/settings_interface.hpp b/scwx-qt/source/scwx/qt/settings/settings_interface.hpp index c47fbe9b..4c9eec92 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_interface.hpp +++ b/scwx-qt/source/scwx/qt/settings/settings_interface.hpp @@ -60,7 +60,7 @@ public: * * @param function Map from settings value function */ - void SetMapFromValueFunction(std::function function); + void SetMapFromValueFunction(std::function function); /** * If the edit widget displays a different value than what is stored in the @@ -69,7 +69,7 @@ public: * * @param function Map to settings value function */ - void SetMapToValueFunction(std::function function); + void SetMapToValueFunction(std::function function); private: class Impl; diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index 0761bddc..6aa8963d 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -55,11 +55,12 @@ public: SettingsDialog* self_; - settings::SettingsInterface defaultRadarSite_ {}; - settings::SettingsInterface gridWidth_ {}; - settings::SettingsInterface gridHeight_ {}; - settings::SettingsInterface mapboxApiKey_ {}; - settings::SettingsInterface debugEnabled_ {}; + settings::SettingsInterface defaultRadarSite_ {}; + settings::SettingsInterface> fontSizes_ {}; + settings::SettingsInterface gridWidth_ {}; + settings::SettingsInterface gridHeight_ {}; + settings::SettingsInterface mapboxApiKey_ {}; + settings::SettingsInterface debugEnabled_ {}; std::unordered_map> colorTables_ {}; @@ -150,6 +151,10 @@ void SettingsDialogImpl::SetupGeneralTab() defaultRadarSite_.SetEditWidget(self_->ui->radarSiteComboBox); defaultRadarSite_.SetResetButton(self_->ui->resetRadarSiteButton); + fontSizes_.SetSettingsVariable(generalSettings.font_sizes()); + fontSizes_.SetEditWidget(self_->ui->fontSizesLineEdit); + fontSizes_.SetResetButton(self_->ui->resetFontSizesButton); + gridWidth_.SetSettingsVariable(generalSettings.grid_width()); gridWidth_.SetEditWidget(self_->ui->gridWidthSpinBox); gridWidth_.SetResetButton(self_->ui->resetGridWidthButton); diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui index c314ca26..0c72ab61 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui @@ -116,17 +116,17 @@ - + Grid Height - + - + ... @@ -137,10 +137,7 @@ - - - - + ... @@ -151,7 +148,7 @@ - + ... @@ -162,13 +159,13 @@ - + - + - + ... @@ -179,20 +176,44 @@ - + Mapbox API Key + + + + + + Font Sizes + + + + Grid Width + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + +