mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:00:05 +00:00
Settings variable minimum/maximum, additional tests
This commit is contained in:
parent
db665ed9ec
commit
08b1d6e152
3 changed files with 67 additions and 11 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#define SETTINGS_VARIABLE_IMPLEMENTATION
|
||||
|
||||
#include <scwx/qt/settings/settings_variable.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
|
|
@ -8,11 +10,6 @@ namespace qt
|
|||
namespace settings
|
||||
{
|
||||
|
||||
template class SettingsVariable<bool>;
|
||||
template class SettingsVariable<int64_t>;
|
||||
template class SettingsVariable<std::string>;
|
||||
template class SettingsVariable<std::vector<int64_t>>;
|
||||
|
||||
static const std::string logPrefix_ = "scwx::qt::settings::settings_variable";
|
||||
|
||||
template<class T>
|
||||
|
|
@ -84,6 +81,14 @@ bool SettingsVariable<T>::SetValueOrDefault(const T& value)
|
|||
p->value_ = value;
|
||||
validated = true;
|
||||
}
|
||||
else if (p->minimum_.has_value() && value < p->minimum_)
|
||||
{
|
||||
p->value_ = *p->minimum_;
|
||||
}
|
||||
else if (p->maximum_.has_value() && value > p->maximum_)
|
||||
{
|
||||
p->value_ = *p->maximum_;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->value_ = p->default_;
|
||||
|
|
@ -92,6 +97,12 @@ bool SettingsVariable<T>::SetValueOrDefault(const T& value)
|
|||
return validated;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void SettingsVariable<T>::SetValueToDefault()
|
||||
{
|
||||
p->value_ = p->default_;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool SettingsVariable<T>::StageValue(const T& value)
|
||||
{
|
||||
|
|
@ -111,7 +122,7 @@ void SettingsVariable<T>::Commit()
|
|||
{
|
||||
if (p->staged_.has_value())
|
||||
{
|
||||
p->value_ = std::move(p->staged_.value());
|
||||
p->value_ = std::move(*p->staged_);
|
||||
p->staged_.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public:
|
|||
T GetValue() const;
|
||||
bool SetValue(const T& value);
|
||||
bool SetValueOrDefault(const T& value);
|
||||
void SetValueToDefault();
|
||||
|
||||
bool StageValue(const T& value);
|
||||
void Commit();
|
||||
|
|
@ -45,11 +46,11 @@ private:
|
|||
std::unique_ptr<Impl> p;
|
||||
};
|
||||
|
||||
// Instantiated templates:
|
||||
// template class SettingsVariable<bool>;
|
||||
// template class SettingsVariable<int64_t>;
|
||||
// template class SettingsVariable<std::string>;
|
||||
// template class SettingsVariable<std::vector<int64_t>>;
|
||||
#ifdef SETTINGS_VARIABLE_IMPLEMENTATION
|
||||
template class SettingsVariable<bool>;
|
||||
template class SettingsVariable<int64_t>;
|
||||
template class SettingsVariable<std::string>;
|
||||
#endif
|
||||
|
||||
} // namespace settings
|
||||
} // namespace qt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue