Shortened decimal check code in QuantitySpinBox
This commit is contained in:
parent
001ebc0b70
commit
7535d7a1d1
|
@ -140,36 +140,19 @@ public:
|
|||
goto end;
|
||||
}
|
||||
else if (len > 1) {
|
||||
int dec = copy.indexOf(locale.decimalPoint());
|
||||
if (dec != -1) {
|
||||
// fix two directly consecutive decimal points immediately
|
||||
if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) {
|
||||
copy.remove(dec + 1, 1);
|
||||
}
|
||||
else {
|
||||
// search for a second decimal point
|
||||
int dec2 = copy.indexOf(locale.decimalPoint(), dec + 1);
|
||||
while (dec2 != -1) {
|
||||
// if the string between the two decimal points builds one number then
|
||||
// the input is invalid
|
||||
bool digits = true;
|
||||
for (int i = dec + 1; i < dec2; i++) {
|
||||
QChar c = copy.at(i);
|
||||
if (!(c.isDigit() || c == locale.groupSeparator())) {
|
||||
digits = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (digits) {
|
||||
// trying to add a second decimal point inside the same number is not allowed
|
||||
state = QValidator::Invalid;
|
||||
goto end;
|
||||
}
|
||||
|
||||
dec = dec2;
|
||||
dec2 = copy.indexOf(locale.decimalPoint(), dec + 1);
|
||||
bool decOccurred = false;
|
||||
for (int i = 0; i<copy.size(); i++) {
|
||||
if (copy.at(i) == locale.decimalPoint()) {
|
||||
// Disallow multiple decimal points within the same numeric substring
|
||||
if (decOccurred) {
|
||||
state = QValidator::Invalid;
|
||||
goto end;
|
||||
}
|
||||
decOccurred = true;
|
||||
}
|
||||
// Reset decOcurred if non-numeric character found
|
||||
else if (!(copy.at(i) == locale.groupSeparator() || copy.at(i).isDigit())) {
|
||||
decOccurred = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user