46 setContentsMargins(0, 0, 0, 0);
49 value_.setSuffix(QString::fromUtf8(suffix));
51 connect(&
list_, SIGNAL(currentIndexChanged(
int)),
53 connect(&
value_, SIGNAL(editingFinished()),
80 value_.setSingleStep(step);
91 for (
size_t i = 0; i < count; i++) {
92 char *
const s = sr_si_string_u64(vals[i],
suffix_);
93 list_.addItem(QString::fromUtf8(s),
94 qVariantFromValue(vals[i]));
107 const unsigned int FineScales[] = {1, 2, 5};
108 uint64_t
value, decade;
110 vector<uint64_t> values;
113 for (decade = 1; decade * 10 <= min; decade *= 10);
116 for (fine = 0; fine <
countof(FineScales); fine++)
117 if (FineScales[fine] * decade >= min)
120 assert(fine <
countof(FineScales));
123 if (min != FineScales[fine] * decade)
124 values.push_back(min);
126 while ((value = FineScales[fine] * decade) < max) {
127 values.push_back(value);
128 if (++fine >=
countof(FineScales))
129 fine = 0, decade *= 10;
133 values.push_back(max);
136 uint64_t *
const values_array =
new uint64_t[values.size()];
137 copy(values.begin(), values.end(), values_array);
139 delete[] values_array;
149 return (uint64_t)
value_.value();
153 const int index =
list_.currentIndex();
154 return (index >= 0) ?
list_.itemData(
155 index).value<uint64_t>() : 0;
169 int best_match =
list_.count() - 1;
170 int64_t best_variance = INT64_MAX;
172 for (
int i = 0; i <
list_.count(); i++) {
173 const int64_t this_variance = abs(
174 (int64_t)value -
list_.itemData(i).value<int64_t>());
175 if (this_variance < best_variance) {
176 best_variance = this_variance;
181 list_.setCurrentIndex(best_match);