diff --git a/scwx-qt/source/scwx/qt/settings/settings_variable.cpp b/scwx-qt/source/scwx/qt/settings/settings_variable.cpp index b09be78b..74e611c2 100644 --- a/scwx-qt/source/scwx/qt/settings/settings_variable.cpp +++ b/scwx-qt/source/scwx/qt/settings/settings_variable.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace scwx @@ -278,6 +279,45 @@ void SettingsVariable::SetEditWidget(QWidget* widget) }); } } + else if (QSpinBox* spinBox = dynamic_cast(widget)) + { + if constexpr (std::is_integral_v) + { + if (p->minimum_.has_value()) + { + spinBox->setMinimum(static_cast(*p->minimum_)); + } + if (p->maximum_.has_value()) + { + spinBox->setMaximum(static_cast(*p->maximum_)); + } + + // If the spin box is edited, stage a changed value + QObject::connect(spinBox, + &QSpinBox::valueChanged, + p->context_.get(), + [this](int i) + { + // If there is a value staged, and the new value is + // the same as the current value, reset the staged + // value + if (p->staged_.has_value() && + static_cast(i) == p->value_) + { + Reset(); + } + // If there is no staged value, or if the new value + // is different than what is staged, attempt to + // stage the value + else if (!p->staged_.has_value() || + static_cast(i) != *p->staged_) + { + StageValue(static_cast(i)); + } + // Otherwise, don't process an unchanged value + }); + } + } p->UpdateEditWidget(); } @@ -326,6 +366,13 @@ void SettingsVariable::Impl::UpdateEditWidget() lineEdit->setText(QString::fromStdString(value)); } } + else if (QSpinBox* spinBox = dynamic_cast(editWidget_)) + { + if constexpr (std::is_integral_v) + { + spinBox->setValue(static_cast(value)); + } + } } template