1081 QValidator::State &state)
const
1083 if (cachedText == input && !input.isEmpty()) {
1084 state = cachedState;
1085 qCDebug(lcWidgetSpinBox) <<
"cachedText was '" << cachedText <<
"' state was" << state
1086 <<
"and value was" << cachedValue;
1090 const int max = maximum.toInt();
1091 const int min = minimum.toInt();
1093 QString copy = stripped(input, &pos);
1094 qCDebug(lcWidgetSpinBox) <<
"input" << input <<
"copy" << copy;
1095 state = QValidator::Acceptable;
1098 if (max != min && (copy.isEmpty()
1099 || (min < 0 && copy ==
"-"_L1)
1100 || (max >= 0 && copy ==
"+"_L1))) {
1101 state = QValidator::Intermediate;
1102 qCDebug(lcWidgetSpinBox) <<
"num is set to" << num;
1103 }
else if (copy.startsWith(u'-') && min >= 0) {
1104 state = QValidator::Invalid;
1110 num = locale.toInt(copy, &ok);
1111 if (!ok && (max >= 1000 || min <= -1000)) {
1112 const QString sep(locale.groupSeparator());
1113 const QString doubleSep = sep + sep;
1114 if (copy.contains(sep) && !copy.contains(doubleSep)) {
1115 QString copy2 = copy;
1117 num = locale.toInt(copy2, &ok);
1121 qCDebug(lcWidgetSpinBox) <<
"num is set to" << num;
1123 state = QValidator::Invalid;
1124 }
else if (num >= min && num <= max) {
1125 state = QValidator::Acceptable;
1126 }
else if (max == min) {
1127 state = QValidator::Invalid;
1129 if ((num >= 0 && num > max) || (num < 0 && num < min))
1130 state = QValidator::Invalid;
1132 state = QValidator::Intermediate;
1134 qCDebug(lcWidgetSpinBox) <<
"state is set to" << state;
1136 if (state != QValidator::Acceptable)
1137 num = max > 0 ? min : max;
1138 input = prefix + copy + suffix;
1140 cachedState = state;
1141 cachedValue = QVariant((
int)num);
1143 qCDebug(lcWidgetSpinBox) <<
"cachedText is set to '" << cachedText <<
"' state is set to"
1144 << state <<
"and value is set to" << cachedValue;
1232 QValidator::State &state)
const
1234 if (cachedText == input && !input.isEmpty()) {
1235 state = cachedState;
1236 qCDebug(lcWidgetDblSpinBox) <<
"cachedText was '" << cachedText <<
"' state was" << state
1237 <<
"and value was" << cachedValue;
1240 const double max = maximum.toDouble();
1241 const double min = minimum.toDouble();
1243 QString copy = stripped(input, &pos);
1244 qCDebug(lcWidgetDblSpinBox) <<
"input" << input <<
"copy" << copy;
1245 int len = copy.size();
1247 const bool plus = max >= 0;
1248 const bool minus = min <= 0;
1250 const QString group(locale.groupSeparator());
1251 const char32_t groupUcs = [&] {
1252 QStringIterator it(group);
1255 return it.nextOrRawCodeUnit();
1259 state = max != min ? QValidator::Intermediate : QValidator::Invalid;
1262 if (copy.at(0) == locale.decimalPoint()
1263 || (plus && copy.at(0) == u'+')
1264 || (minus && copy.at(0) == u'-')) {
1265 state = QValidator::Intermediate;
1270 if (copy.at(1) == locale.decimalPoint()
1271 && ((plus && copy.at(0) == u'+') || (minus && copy.at(0) == u'-'))) {
1272 state = QValidator::Intermediate;
1279 if (groupUcs && copy.startsWith(group)) {
1280 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1281 state = QValidator::Invalid;
1283 }
else if (len > 1) {
1284 const int dec = copy.indexOf(locale.decimalPoint());
1286 if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) {
1287 copy.remove(dec + 1, 1);
1290 if (copy.size() - dec >
decimals + 1) {
1291 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1292 state = QValidator::Invalid;
1295 for (
int i = dec + 1; i < copy.size(); ++i) {
1296 if (copy.at(i).isSpace()
1297 || (groupUcs && QStringView{copy}.sliced(i).startsWith(group))) {
1298 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1299 state = QValidator::Invalid;
1304 const QChar last = copy.back();
1305 const bool groupEnd = groupUcs && copy.endsWith(group);
1306 const QStringView head(copy.constData(), groupEnd ? len - group.size() : len - 1);
1307 const QChar secondLast = head.back();
1308 if ((groupEnd || last.isSpace())
1309 && ((groupUcs && head.endsWith(group)) || secondLast.isSpace())) {
1310 state = QValidator::Invalid;
1311 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1313 }
else if (last.isSpace() && (!QChar::isSpace(groupUcs) || secondLast.isSpace())) {
1314 state = QValidator::Invalid;
1315 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1323 num = locale.toDouble(copy, &ok);
1324 qCDebug(lcWidgetDblSpinBox) << locale << copy << num << ok;
1327 if (QChar::isPrint(groupUcs)) {
1328 if (max < 1000 && min > -1000 && groupUcs && copy.contains(group)) {
1329 state = QValidator::Invalid;
1330 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1334 const int len = copy.size();
1335 for (
int i = 0; i < len - 1;) {
1336 if (groupUcs && QStringView{copy}.sliced(i).startsWith(group)) {
1337 if (QStringView(copy).mid(i + group.size()).startsWith(group)) {
1338 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1339 state = QValidator::Invalid;
1348 QString copy2 = copy;
1350 copy2.remove(group);
1351 num = locale.toDouble(copy2, &ok);
1352 qCDebug(lcWidgetDblSpinBox) << group << num << copy2 << ok;
1355 state = QValidator::Invalid;
1356 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1363 state = QValidator::Invalid;
1364 }
else if (num >= min && num <= max) {
1365 state = QValidator::Acceptable;
1366 }
else if (max == min) {
1367 state = QValidator::Invalid;
1369 if ((num >= 0 && num > max) || (num < 0 && num < min))
1370 state = QValidator::Invalid;
1372 state = QValidator::Intermediate;
1374 qCDebug(lcWidgetDblSpinBox) <<
"state is set to" << state;
1378 if (state != QValidator::Acceptable) {
1379 num = max > 0 ? min : max;
1382 input = prefix + copy + suffix;
1384 cachedState = state;
1385 cachedValue = QVariant(num);
1386 return QVariant(num);