11#ifdef QSPINBOX_QSBDEBUG
12#define QSBDEBUG qDebug
24 QSBDEBUG(
"%lld %lld %lld", num, min, max);
26 if (num >= min && num <= max) {
35 int digits[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
41 for (
int i = 0;
tmp > 0; ++i) {
42 digits[numDigits++] = int(
tmp) % 10;
49 for (number = max; number >= min; --number) {
51 for (
int i = 0;
tmp > 0;) {
52 if (digits[i] == (
tmp % 10)) {
53 if (++i == numDigits) {
62 if (failures++ == 500000) {
76 QDoubleSpinBox::setDecimals(1000);
79 double doubleMax = std::numeric_limits<double>::max();
80 setRange(-doubleMax, doubleMax);
82 v =
new QDoubleValidator(
this);
84 v->setNotation(QDoubleValidator::ScientificNotation);
85 this->lineEdit()->setValidator(
v);
89 const QString str = (parent ? parent->locale() : QLocale()).toString(4567.1);
90 if (str.size() == 6) {
93 }
else if (str.size() == 7) {
116 setValue(
value() / this->singleStep());
118 setValue(
value() - this->singleStep());
124 setValue(
value() * this->singleStep());
126 setValue(
value() + this->singleStep());
138 if (qAbs(
value) >= 1000.0) {
146 int pos = this->lineEdit()->cursorPosition();
147 QValidator::State state = QValidator::Acceptable;
159 return locale().toDouble(strDbl);
164 QValidator::State state;
175 QSBDEBUG() <<
"input is" << str << minimum() << maximum();
178 for (
int i = 0; i <
decimals(); ++i)
181 const QLatin1Char dot(
'.');
187 const QString minstr = QString::number(minimum(),
'f', QDoubleSpinBox::decimals());
188 qint64 min_left = minstr.left(minstr.indexOf(dot)).toLongLong();
189 qint64 min_right = minstr.mid(minstr.indexOf(dot) + 1).toLongLong();
191 const QString maxstr = QString::number(maximum(),
'f', QDoubleSpinBox::decimals());
192 qint64 max_left = maxstr.left(maxstr.indexOf(dot)).toLongLong();
193 qint64 max_right = maxstr.mid(maxstr.indexOf(dot) + 1).toLongLong();
198 const int dotindex = str.indexOf(
delimiter);
199 const bool negative = maximum() < 0;
204 if (dotindex == -1) {
205 left = str.toLongLong();
209 else if (dotindex == 0 || (dotindex == 1 && str.at(0) == QLatin1Char(
'+'))) {
212 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns false";
216 right = str.mid(dotindex + 1).toLongLong();
219 else if (dotindex == 1 && str.at(0) == QLatin1Char(
'-')) {
222 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns false";
226 right = str.mid(dotindex + 1).toLongLong();
228 left = str.left(dotindex).toLongLong();
229 if (dotindex == str.size() - 1) {
232 right = str.mid(dotindex + 1).toLongLong();
236 if ((
left >= 0 && max_left < 0 && !str.startsWith(QLatin1Char(
'-')))
238 || (left < 0 && min_left >= 0)) {
243 qint64 match = min_left;
245 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns false";
249 QSBDEBUG(
"match %lld min_left %lld max_left %lld", match, min_left, max_left);
251 if (min_left == max_left) {
254 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns" << ret;
256 }
else if (qAbs(max_left - min_left) == 1) {
259 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns" << ret;
263 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns" << ret;
267 if (match != min_left) {
268 min_right = negative ? dec : 0;
270 if (match != max_left) {
271 max_right = negative ? 0 : dec;
273 qint64 tmpl = negative ? max_right : min_right;
274 qint64 tmpr = negative ? min_right : max_right;
276 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns" << ret;
279 QSBDEBUG() << __FILE__ << __LINE__ <<
"returns true";
295 static QString cachedText;
296 static QValidator::State cachedState;
297 static QVariant cachedValue;
299 if (cachedText == input && !input.isEmpty()) {
302 <<
"'" << cachedText <<
"'"
303 <<
"state was " << state <<
" and value was " << cachedValue;
306 const double max = maximum();
307 const double min = minimum();
310 QString copy =
stripped(input, &pos);
311 QSBDEBUG() <<
"input" << input <<
"copy" << copy;
313 int len = copy.size();
315 const bool plus = max >= 0;
316 const bool minus = min <= 0;
323 state = QValidator::Intermediate;
325 state = QValidator::Invalid;
330 if (copy.at(0) ==
delimiter || (plus && copy.at(0) == QLatin1Char(
'+')) ||
331 (minus && copy.at(0) == QLatin1Char(
'-'))) {
332 state = QValidator::Intermediate;
339 ((plus && copy.at(0) == QLatin1Char(
'+')) || (minus && copy.at(0) == QLatin1Char(
'-')))) {
340 state = QValidator::Intermediate;
350 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
351 state = QValidator::Invalid;
360 if (dec + 1 < copy.size() && copy.at(dec + 1) ==
delimiter && pos == dec + 1) {
365 if (copy.size() - dec > QDoubleSpinBox::decimals() + 1) {
366 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
367 state = QValidator::Invalid;
371 for (
int i = dec + 1; i < copy.size(); ++i) {
372 if (copy.at(i).isSpace() || copy.at(i) ==
thousand) {
373 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
374 state = QValidator::Invalid;
380 const QChar &last = copy.at(len - 1);
381 const QChar &secondLast = copy.at(len - 2);
383 if ((last ==
thousand || last.isSpace()) && (secondLast ==
thousand || secondLast.isSpace())) {
384 state = QValidator::Invalid;
385 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
389 else if (last.isSpace() && (!
thousand.isSpace() || secondLast.isSpace())) {
390 state = QValidator::Invalid;
391 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
400 bool notAcceptable =
false;
403 QLocale loc(locale());
404 num = loc.toDouble(copy, &ok);
405 QSBDEBUG() << __FILE__ << __LINE__ << loc << copy << num << ok;
413 if (max < 1000 && min > -1000 && copy.contains(
thousand)) {
414 state = QValidator::Invalid;
415 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
420 const int copyLen = copy.size();
421 for (
int i = 0; i < copyLen - 1; ++i) {
423 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
424 state = QValidator::Invalid;
430 const int s = copy.size();
432 pos = qMax(0, pos - (s - copy.size()));
434 num = loc.toDouble(copy, &ok);
439 state = QValidator::Invalid;
440 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
443 notAcceptable =
true;
449 state = QValidator::Invalid;
450 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
453 else if (num >= min && num <= max) {
455 state = QValidator::Intermediate;
457 state = QValidator::Acceptable;
459 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to "
460 << (state == QValidator::Intermediate ?
"Intermediate" :
"Acceptable");
463 else if (max == min) {
464 state = QValidator::Invalid;
465 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
468 if ((num >= 0 && num > max) || (num < 0 && num < min)) {
469 state = QValidator::Invalid;
470 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to Invalid";
474 state = QValidator::Intermediate;
476 state = QValidator::Invalid;
478 QSBDEBUG() << __FILE__ << __LINE__ <<
"state is set to "
479 << (state == QValidator::Intermediate ?
"Intermediate" :
"Acceptable");
486 if (state != QValidator::Acceptable) {
487 num = max > 0 ? min : max;
491 cachedText = prefix() + copy + suffix();
493 cachedValue = QVariant(num);
495 return QVariant(num);
505 QString prefixtext = prefix();
506 QString suffixtext = suffix();
508 if (specialValueText().size() == 0 || text != specialValueText()) {
510 int size = text.size();
511 bool changed =
false;
512 if (prefixtext.size() && text.startsWith(prefixtext)) {
513 from += prefixtext.size();
517 if (suffixtext.size() && text.endsWith(suffixtext)) {
518 size -= suffixtext.size();
522 text = text.mid(from, size);
525 const int s = text.size();
526 text = text.trimmed();
528 (*pos) -= (s - text.size());
double value
The value of the point.
void setDecimals(int value)
QString stripped(const QString &t, int *pos) const
bool isIntermediateValue(const QString &str) const
double valueFromText(const QString &text) const override
void initLocalValues(QWidget *parent)
QString textFromValue(double value) const override
text to be displayed in spinbox
void valueChangedFromArrows()
QScienceSpinBox(QWidget *parent=nullptr)
void setLogSteps(bool logSteps)
QValidator::State validate(QString &text, int &pos) const override
bool m_logSteps
Will step in a log way (multiplicatively)
double round(double value) const
Round.
void stepBy(int steps) override
void fixup(QString &input) const override
QVariant validateAndInterpret(QString &input, int &pos, QValidator::State &state) const
bool isIntermediateValueHelper(qint64 num, qint64 min, qint64 max, qint64 *match=nullptr)
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...