diff --git a/src/blackgui/components/settingssimulatorcomponent.cpp b/src/blackgui/components/settingssimulatorcomponent.cpp index 7bc85548e..6088ef9f8 100644 --- a/src/blackgui/components/settingssimulatorcomponent.cpp +++ b/src/blackgui/components/settingssimulatorcomponent.cpp @@ -78,7 +78,7 @@ namespace BlackGui connect(ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedDistance, Qt::QueuedConnection); connect(ui->pb_ApplyComSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyComSync, Qt::QueuedConnection); connect(ui->pb_ApplyCGSource, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyCGSource, Qt::QueuedConnection); - connect(ui->pb_ApplyRecordOwnAircraftGnd, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyRecordGnd, Qt::QueuedConnection); + connect(ui->pb_ApplyRecordOwnAircraftGnd, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyRecordGnd, Qt::QueuedConnection); connect(ui->pb_ClearRestrictedRendering, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::clearRestricedRendering); connect(ui->pb_DisableRendering, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyDisableRendering); @@ -338,8 +338,17 @@ namespace BlackGui bool ok = false; CSimulatorSettings settings = this->getSimulatorSettings(ok); if (!ok) { return; } - CLength radius; - radius.parseFromString(ui->le_RecordOwnGndPositionsRadius->text()); + + // get value, automatically add default unit if unit is missing + CLength radius = CLength::null(); + QString radiusString = ui->le_RecordOwnGndPositionsRadius->text().trimmed(); + if (!radiusString.isEmpty()) + { + if (!CMeasurementUnit::endWithValidUnitSymbol(radiusString)) { radiusString += "m"; } + radius.parseFromString(radiusString); + } + ui->le_RecordOwnGndPositionsRadius->setText(radius.valueRoundedWithUnit(1)); + const bool c1 = settings.setRecordOwnAircraftGnd(ui->cb_RecordOwnGndPositions->isChecked()); const bool c2 = settings.setRecordedGndRadius(radius); if (!c1 && !c2) { return; } diff --git a/src/blackmisc/pq/measurementunit.h b/src/blackmisc/pq/measurementunit.h index 6acfaba41..8a7bec489 100644 --- a/src/blackmisc/pq/measurementunit.h +++ b/src/blackmisc/pq/measurementunit.h @@ -471,6 +471,36 @@ namespace BlackMisc return false; } + /*! + * Contains valid unit symbol? + * \param candidate to be tested + * \param caseSensitivity check case sensitiv? + */ + template static bool containsValidUnitSymbol(const QString &candidate, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) + { + if (candidate.isEmpty()) return false; + for (const auto &unit : U::allUnits()) + { + if (candidate.contains(unit.getSymbol(), caseSensitivity)) { return true; } + } + return false; + } + + /*! + * Ends with valid unit symbol? + * \param candidate to be tested + * \param caseSensitivity check case sensitiv? + */ + template static bool endWithValidUnitSymbol(const QString &candidate, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) + { + if (candidate.isEmpty()) return false; + for (const auto &unit : U::allUnits()) + { + if (candidate.endsWith(unit.getSymbol(), caseSensitivity)) { return true; } + } + return false; + } + //! Dimensionless unit static CMeasurementUnit None() {