mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-23 20:58:55 -05:00
947b429723
This change incorporates a reorganization of the GUI code with widgets, validators, models, and item delegates being moved to sub-directories. Relax the requirements of the ForeignKeyDelegate and related CandidateKeyFilter classes to allow them to work with constant model pointers for both referenced and referencing models.
56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#include "HintedSpinBox.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
auto HintedSpinBox::values (values_type values, bool set_min_max) -> values_type
|
|
{
|
|
// replace any prior values
|
|
std::swap (values, values_);
|
|
|
|
// sort values and make unique
|
|
std::sort (values_.begin (), values_.end ());
|
|
auto last = std::unique (values_.begin (), values_.end ());
|
|
values_.erase (last, values_.end ());
|
|
if (set_min_max)
|
|
{
|
|
setMinimum (values_.front ());
|
|
setMaximum (values_.back ());
|
|
}
|
|
return values; // return old values
|
|
}
|
|
|
|
void HintedSpinBox::stepBy (int steps)
|
|
{
|
|
if (values_.size ())
|
|
{
|
|
if (steps > 0)
|
|
{
|
|
auto p = std::upper_bound (values_.begin (), values_.end (), value ());
|
|
if (p != values_.end () && *p <= maximum ())
|
|
{
|
|
setValue (*p);
|
|
}
|
|
else if (wrapping ())
|
|
{
|
|
setValue (values_.front ());
|
|
}
|
|
}
|
|
else if (steps < 0)
|
|
{
|
|
auto p = std::lower_bound (values_.begin (), values_.end (), value ());
|
|
if (p != values_.begin () && *(p - 1) >= minimum ())
|
|
{
|
|
setValue (*(p - 1));
|
|
}
|
|
else if (wrapping ())
|
|
{
|
|
setValue (values_.back ());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QSpinBox::stepBy (steps); // no values so revert to QSpinBox behaviour
|
|
}
|
|
}
|