File: HintedSpinBox.cpp

package info (click to toggle)
wsjtx-improved 3.0.0%2B250924%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 86,260 kB
  • sloc: cpp: 105,882; f90: 60,117; python: 27,241; ansic: 13,372; fortran: 2,382; makefile: 197; sh: 135
file content (55 lines) | stat: -rwxr-xr-x 1,463 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#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
    }
}