From 67706dc186d640c0858fd89f4d195fc49d7008c5 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 13 Oct 2024 09:51:16 -0400 Subject: [PATCH 1/4] trim whitespace from placefile URL's --- scwx-qt/source/scwx/qt/util/network.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/util/network.cpp b/scwx-qt/source/scwx/qt/util/network.cpp index 2e8d442f..429fac95 100644 --- a/scwx-qt/source/scwx/qt/util/network.cpp +++ b/scwx-qt/source/scwx/qt/util/network.cpp @@ -17,7 +17,8 @@ std::string NormalizeUrl(const std::string& urlString) std::string normalizedUrl; // Normalize URL string - QUrl url = QUrl::fromUserInput(QString::fromStdString(urlString)); + QString trimmedUrlString = QString::fromStdString(urlString).trimmed(); + QUrl url = QUrl::fromUserInput(trimmedUrlString); if (url.isLocalFile()) { normalizedUrl = QDir::toNativeSeparators(url.toLocalFile()).toStdString(); From 25fb9bdae077e733d5b1b77ec6194a52ee273fc7 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 13 Oct 2024 09:59:24 -0400 Subject: [PATCH 2/4] Add whitespace trimming to some settings --- .../source/scwx/qt/settings/settings_interface.cpp | 13 ++++++++++++- .../source/scwx/qt/settings/settings_interface.hpp | 9 +++++++++ scwx-qt/source/scwx/qt/ui/settings_dialog.cpp | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/settings/settings_interface.cpp b/scwx-qt/source/scwx/qt/settings/settings_interface.cpp index 61a793e8..4d491563 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_interface.cpp +++ b/scwx-qt/source/scwx/qt/settings/settings_interface.cpp @@ -56,6 +56,8 @@ class SettingsInterface::Impl double unitScale_ {1}; std::optional unitAbbreviation_ {}; bool unitEnabled_ {false}; + + bool trimmingEnabled_ {false}; }; template @@ -191,8 +193,11 @@ void SettingsInterface::SetEditWidget(QWidget* widget) p->context_.get(), [this](const QString& text) { + QString trimmedText = + p->trimmingEnabled_ ? text.trimmed() : text; + // Map to value if required - std::string value {text.toStdString()}; + std::string value {trimmedText.toStdString()}; if (p->mapToValue_ != nullptr) { value = p->mapToValue_(value); @@ -488,6 +493,12 @@ void SettingsInterface::SetUnit(const double& scale, p->UpdateUnitLabel(); } +template +void SettingsInterface::EnableTrimming(bool trimmingEnabled) +{ + p->trimmingEnabled_ = trimmingEnabled; +} + template template void SettingsInterface::Impl::SetWidgetText(U* widget, const T& currentValue) diff --git a/scwx-qt/source/scwx/qt/settings/settings_interface.hpp b/scwx-qt/source/scwx/qt/settings/settings_interface.hpp index 2092b1b4..84812f4f 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_interface.hpp +++ b/scwx-qt/source/scwx/qt/settings/settings_interface.hpp @@ -126,6 +126,15 @@ class SettingsInterface : public SettingsInterfaceBase */ void SetUnit(const double& scale, const std::string& abbreviation); + /** + * Enables or disables whitespace trimming of text input. + * Removes whitespace ('\t', '\n', '\v', '\f', '\r', and ' ') at the + * beginning and end of the string from a QLineEdit. + * + * @param trimmingEnabled If trimming should be enabled. + */ + void EnableTrimming(bool trimmingEnabled = true); + private: class Impl; std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index c35607a9..74831a47 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -603,14 +603,17 @@ void SettingsDialogImpl::SetupGeneralTab() mapboxApiKey_.SetSettingsVariable(generalSettings.mapbox_api_key()); mapboxApiKey_.SetEditWidget(self_->ui->mapboxApiKeyLineEdit); mapboxApiKey_.SetResetButton(self_->ui->resetMapboxApiKeyButton); + mapboxApiKey_.EnableTrimming(); mapTilerApiKey_.SetSettingsVariable(generalSettings.maptiler_api_key()); mapTilerApiKey_.SetEditWidget(self_->ui->mapTilerApiKeyLineEdit); mapTilerApiKey_.SetResetButton(self_->ui->resetMapTilerApiKeyButton); + mapTilerApiKey_.EnableTrimming(); customStyleUrl_.SetSettingsVariable(generalSettings.custom_style_url()); customStyleUrl_.SetEditWidget(self_->ui->customMapUrlLineEdit); customStyleUrl_.SetResetButton(self_->ui->resetCustomMapUrlButton); + customStyleUrl_.EnableTrimming(); customStyleDrawLayer_.SetSettingsVariable( generalSettings.custom_style_draw_layer()); @@ -676,6 +679,7 @@ void SettingsDialogImpl::SetupGeneralTab() warningsProvider_.SetSettingsVariable(generalSettings.warnings_provider()); warningsProvider_.SetEditWidget(self_->ui->warningsProviderLineEdit); warningsProvider_.SetResetButton(self_->ui->resetWarningsProviderButton); + warningsProvider_.EnableTrimming(); antiAliasingEnabled_.SetSettingsVariable( generalSettings.anti_aliasing_enabled()); From bc3b1ad3d250b190d56b119d4114121a2e62fc83 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 13 Oct 2024 10:00:37 -0400 Subject: [PATCH 3/4] fix some spelling mistakes in comments --- scwx-qt/source/scwx/qt/settings/settings_interface.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scwx-qt/source/scwx/qt/settings/settings_interface.hpp b/scwx-qt/source/scwx/qt/settings/settings_interface.hpp index 84812f4f..a0005098 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_interface.hpp +++ b/scwx-qt/source/scwx/qt/settings/settings_interface.hpp @@ -121,8 +121,8 @@ class SettingsInterface : public SettingsInterfaceBase /** * Sets the unit to be used by this setting. * - * @param scale The radio of the current unit to the base unit - * @param abbreviation The abreviation to be displayed + * @param scale The ratio of the current unit to the base unit + * @param abbreviation The abbreviation to be displayed */ void SetUnit(const double& scale, const std::string& abbreviation); From bf3454d9a49029952d4c022e89caa13be02bedc0 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 13 Oct 2024 10:07:58 -0400 Subject: [PATCH 4/4] Add whitespace trimming to more settings --- scwx-qt/source/scwx/qt/ui/settings_dialog.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index 74831a47..d4f4f096 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -675,6 +675,7 @@ void SettingsDialogImpl::SetupGeneralTab() nmeaSource_.SetSettingsVariable(generalSettings.nmea_source()); nmeaSource_.SetEditWidget(self_->ui->nmeaSourceLineEdit); nmeaSource_.SetResetButton(self_->ui->resetNmeaSourceButton); + nmeaSource_.EnableTrimming(); warningsProvider_.SetSettingsVariable(generalSettings.warnings_provider()); warningsProvider_.SetEditWidget(self_->ui->warningsProviderLineEdit); @@ -754,6 +755,7 @@ void SettingsDialogImpl::SetupPalettesColorTablesTab() colorTable.SetSettingsVariable(colorTableVariable); colorTable.SetEditWidget(lineEdit); colorTable.SetResetButton(resetButton); + colorTable.EnableTrimming(); colorTableVariable.RegisterValueStagedCallback( [colorTableType, imageLabel](const std::string& value) @@ -877,6 +879,7 @@ void SettingsDialogImpl::SetupAudioTab() alertAudioSoundFile_.SetSettingsVariable(audioSettings.alert_sound_file()); alertAudioSoundFile_.SetEditWidget(self_->ui->alertAudioSoundLineEdit); alertAudioSoundFile_.SetResetButton(self_->ui->resetAlertAudioSoundButton); + alertAudioSoundFile_.EnableTrimming(); QObject::connect( self_->ui->alertAudioSoundSelectButton, @@ -1089,6 +1092,7 @@ void SettingsDialogImpl::SetupAudioTab() alertAudioCounty_.SetSettingsVariable(audioSettings.alert_county()); alertAudioCounty_.SetEditWidget(self_->ui->alertAudioCountyLineEdit); alertAudioCounty_.SetResetButton(self_->ui->resetAlertAudioCountyButton); + alertAudioCounty_.EnableTrimming(); QObject::connect(self_->ui->alertAudioWFOSelectButton, &QAbstractButton::clicked, @@ -1121,6 +1125,7 @@ void SettingsDialogImpl::SetupAudioTab() alertAudioWFO_.SetSettingsVariable(audioSettings.alert_wfo()); alertAudioWFO_.SetEditWidget(self_->ui->alertAudioWFOLineEdit); alertAudioWFO_.SetResetButton(self_->ui->resetAlertAudioWFOButton); + alertAudioWFO_.EnableTrimming(); } void SettingsDialogImpl::SetupTextTab()