mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:10:04 +00:00
Add whitespace trimming to some settings
This commit is contained in:
parent
67706dc186
commit
25fb9bdae0
3 changed files with 25 additions and 1 deletions
|
|
@ -56,6 +56,8 @@ public:
|
||||||
double unitScale_ {1};
|
double unitScale_ {1};
|
||||||
std::optional<std::string> unitAbbreviation_ {};
|
std::optional<std::string> unitAbbreviation_ {};
|
||||||
bool unitEnabled_ {false};
|
bool unitEnabled_ {false};
|
||||||
|
|
||||||
|
bool trimmingEnabled_ {false};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
@ -191,8 +193,11 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget)
|
||||||
p->context_.get(),
|
p->context_.get(),
|
||||||
[this](const QString& text)
|
[this](const QString& text)
|
||||||
{
|
{
|
||||||
|
QString trimmedText =
|
||||||
|
p->trimmingEnabled_ ? text.trimmed() : text;
|
||||||
|
|
||||||
// Map to value if required
|
// Map to value if required
|
||||||
std::string value {text.toStdString()};
|
std::string value {trimmedText.toStdString()};
|
||||||
if (p->mapToValue_ != nullptr)
|
if (p->mapToValue_ != nullptr)
|
||||||
{
|
{
|
||||||
value = p->mapToValue_(value);
|
value = p->mapToValue_(value);
|
||||||
|
|
@ -488,6 +493,12 @@ void SettingsInterface<T>::SetUnit(const double& scale,
|
||||||
p->UpdateUnitLabel();
|
p->UpdateUnitLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void SettingsInterface<T>::EnableTrimming(bool trimmingEnabled)
|
||||||
|
{
|
||||||
|
p->trimmingEnabled_ = trimmingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<class U>
|
template<class U>
|
||||||
void SettingsInterface<T>::Impl::SetWidgetText(U* widget, const T& currentValue)
|
void SettingsInterface<T>::Impl::SetWidgetText(U* widget, const T& currentValue)
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,15 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetUnit(const double& scale, const std::string& abbreviation);
|
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:
|
private:
|
||||||
class Impl;
|
class Impl;
|
||||||
std::unique_ptr<Impl> p;
|
std::unique_ptr<Impl> p;
|
||||||
|
|
|
||||||
|
|
@ -603,14 +603,17 @@ void SettingsDialogImpl::SetupGeneralTab()
|
||||||
mapboxApiKey_.SetSettingsVariable(generalSettings.mapbox_api_key());
|
mapboxApiKey_.SetSettingsVariable(generalSettings.mapbox_api_key());
|
||||||
mapboxApiKey_.SetEditWidget(self_->ui->mapboxApiKeyLineEdit);
|
mapboxApiKey_.SetEditWidget(self_->ui->mapboxApiKeyLineEdit);
|
||||||
mapboxApiKey_.SetResetButton(self_->ui->resetMapboxApiKeyButton);
|
mapboxApiKey_.SetResetButton(self_->ui->resetMapboxApiKeyButton);
|
||||||
|
mapboxApiKey_.EnableTrimming();
|
||||||
|
|
||||||
mapTilerApiKey_.SetSettingsVariable(generalSettings.maptiler_api_key());
|
mapTilerApiKey_.SetSettingsVariable(generalSettings.maptiler_api_key());
|
||||||
mapTilerApiKey_.SetEditWidget(self_->ui->mapTilerApiKeyLineEdit);
|
mapTilerApiKey_.SetEditWidget(self_->ui->mapTilerApiKeyLineEdit);
|
||||||
mapTilerApiKey_.SetResetButton(self_->ui->resetMapTilerApiKeyButton);
|
mapTilerApiKey_.SetResetButton(self_->ui->resetMapTilerApiKeyButton);
|
||||||
|
mapTilerApiKey_.EnableTrimming();
|
||||||
|
|
||||||
customStyleUrl_.SetSettingsVariable(generalSettings.custom_style_url());
|
customStyleUrl_.SetSettingsVariable(generalSettings.custom_style_url());
|
||||||
customStyleUrl_.SetEditWidget(self_->ui->customMapUrlLineEdit);
|
customStyleUrl_.SetEditWidget(self_->ui->customMapUrlLineEdit);
|
||||||
customStyleUrl_.SetResetButton(self_->ui->resetCustomMapUrlButton);
|
customStyleUrl_.SetResetButton(self_->ui->resetCustomMapUrlButton);
|
||||||
|
customStyleUrl_.EnableTrimming();
|
||||||
|
|
||||||
customStyleDrawLayer_.SetSettingsVariable(
|
customStyleDrawLayer_.SetSettingsVariable(
|
||||||
generalSettings.custom_style_draw_layer());
|
generalSettings.custom_style_draw_layer());
|
||||||
|
|
@ -676,6 +679,7 @@ void SettingsDialogImpl::SetupGeneralTab()
|
||||||
warningsProvider_.SetSettingsVariable(generalSettings.warnings_provider());
|
warningsProvider_.SetSettingsVariable(generalSettings.warnings_provider());
|
||||||
warningsProvider_.SetEditWidget(self_->ui->warningsProviderLineEdit);
|
warningsProvider_.SetEditWidget(self_->ui->warningsProviderLineEdit);
|
||||||
warningsProvider_.SetResetButton(self_->ui->resetWarningsProviderButton);
|
warningsProvider_.SetResetButton(self_->ui->resetWarningsProviderButton);
|
||||||
|
warningsProvider_.EnableTrimming();
|
||||||
|
|
||||||
antiAliasingEnabled_.SetSettingsVariable(
|
antiAliasingEnabled_.SetSettingsVariable(
|
||||||
generalSettings.anti_aliasing_enabled());
|
generalSettings.anti_aliasing_enabled());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue