1079 QValidator::State &state)
const
1081 if (cachedText == input && !input.isEmpty()) {
1082 state = cachedState;
1083 qCDebug(lcWidgetSpinBox) <<
"cachedText was '" << cachedText <<
"' state was" << state
1084 <<
"and value was" << cachedValue;
1088 const int max = maximum.toInt();
1089 const int min = minimum.toInt();
1091 QString copy = stripped(input, &pos);
1092 qCDebug(lcWidgetSpinBox) <<
"input" << input <<
"copy" << copy;
1093 state = QValidator::Acceptable;
1096 if (max != min && (copy.isEmpty()
1097 || (min < 0 && copy ==
"-"_L1)
1098 || (max >= 0 && copy ==
"+"_L1))) {
1099 state = QValidator::Intermediate;
1100 qCDebug(lcWidgetSpinBox) <<
"num is set to" << num;
1101 }
else if (copy.startsWith(u'-') && min >= 0) {
1102 state = QValidator::Invalid;
1108 num = locale.toInt(copy, &ok);
1109 if (!ok && (max >= 1000 || min <= -1000)) {
1110 const QString sep(locale.groupSeparator());
1111 const QString doubleSep = sep + sep;
1112 if (copy.contains(sep) && !copy.contains(doubleSep)) {
1113 QString copy2 = copy;
1115 num = locale.toInt(copy2, &ok);
1119 qCDebug(lcWidgetSpinBox) <<
"num is set to" << num;
1121 state = QValidator::Invalid;
1122 }
else if (num >= min && num <= max) {
1123 state = QValidator::Acceptable;
1124 }
else if (max == min) {
1125 state = QValidator::Invalid;
1127 if ((num >= 0 && num > max) || (num < 0 && num < min))
1128 state = QValidator::Invalid;
1130 state = QValidator::Intermediate;
1132 qCDebug(lcWidgetSpinBox) <<
"state is set to" << state;
1134 if (state != QValidator::Acceptable)
1135 num = max > 0 ? min : max;
1136 input = prefix + copy + suffix;
1138 cachedState = state;
1139 cachedValue = QVariant((
int)num);
1141 qCDebug(lcWidgetSpinBox) <<
"cachedText is set to '" << cachedText <<
"' state is set to"
1142 << state <<
"and value is set to" << cachedValue;
1230 QValidator::State &state)
const
1232 if (cachedText == input && !input.isEmpty()) {
1233 state = cachedState;
1234 qCDebug(lcWidgetDblSpinBox) <<
"cachedText was '" << cachedText <<
"' state was" << state
1235 <<
"and value was" << cachedValue;
1238 const double max = maximum.toDouble();
1239 const double min = minimum.toDouble();
1241 QString copy = stripped(input, &pos);
1242 qCDebug(lcWidgetDblSpinBox) <<
"input" << input <<
"copy" << copy;
1243 int len = copy.size();
1245 const bool plus = max >= 0;
1246 const bool minus = min <= 0;
1248 const QString group(locale.groupSeparator());
1249 const uint groupUcs = (group.isEmpty() ? 0 :
1250 (group.size() > 1 && group.at(0).isHighSurrogate()
1251 ? QChar::surrogateToUcs4(group.at(0), group.at(1))
1252 : group.at(0).unicode()));
1255 state = max != min ? QValidator::Intermediate : QValidator::Invalid;
1258 if (copy.at(0) == locale.decimalPoint()
1259 || (plus && copy.at(0) == u'+')
1260 || (minus && copy.at(0) == u'-')) {
1261 state = QValidator::Intermediate;
1266 if (copy.at(1) == locale.decimalPoint()
1267 && ((plus && copy.at(0) == u'+') || (minus && copy.at(0) == u'-'))) {
1268 state = QValidator::Intermediate;
1275 if (groupUcs && copy.startsWith(group)) {
1276 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1277 state = QValidator::Invalid;
1279 }
else if (len > 1) {
1280 const int dec = copy.indexOf(locale.decimalPoint());
1282 if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) {
1283 copy.remove(dec + 1, 1);
1286 if (copy.size() - dec >
decimals + 1) {
1287 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1288 state = QValidator::Invalid;
1291 for (
int i = dec + 1; i < copy.size(); ++i) {
1292 if (copy.at(i).isSpace()
1293 || (groupUcs && QStringView{copy}.sliced(i).startsWith(group))) {
1294 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1295 state = QValidator::Invalid;
1300 const QChar last = copy.back();
1301 const bool groupEnd = groupUcs && copy.endsWith(group);
1302 const QStringView head(copy.constData(), groupEnd ? len - group.size() : len - 1);
1303 const QChar secondLast = head.back();
1304 if ((groupEnd || last.isSpace())
1305 && ((groupUcs && head.endsWith(group)) || secondLast.isSpace())) {
1306 state = QValidator::Invalid;
1307 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1309 }
else if (last.isSpace() && (!QChar::isSpace(groupUcs) || secondLast.isSpace())) {
1310 state = QValidator::Invalid;
1311 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1319 num = locale.toDouble(copy, &ok);
1320 qCDebug(lcWidgetDblSpinBox) << locale << copy << num << ok;
1323 if (QChar::isPrint(groupUcs)) {
1324 if (max < 1000 && min > -1000 && groupUcs && copy.contains(group)) {
1325 state = QValidator::Invalid;
1326 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1330 const int len = copy.size();
1331 for (
int i = 0; i < len - 1;) {
1332 if (groupUcs && QStringView{copy}.sliced(i).startsWith(group)) {
1333 if (QStringView(copy).mid(i + group.size()).startsWith(group)) {
1334 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1335 state = QValidator::Invalid;
1344 QString copy2 = copy;
1346 copy2.remove(group);
1347 num = locale.toDouble(copy2, &ok);
1348 qCDebug(lcWidgetDblSpinBox) << group << num << copy2 << ok;
1351 state = QValidator::Invalid;
1352 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1359 state = QValidator::Invalid;
1360 }
else if (num >= min && num <= max) {
1361 state = QValidator::Acceptable;
1362 }
else if (max == min) {
1363 state = QValidator::Invalid;
1365 if ((num >= 0 && num > max) || (num < 0 && num < min))
1366 state = QValidator::Invalid;
1368 state = QValidator::Intermediate;
1370 qCDebug(lcWidgetDblSpinBox) <<
"state is set to" << state;
1374 if (state != QValidator::Acceptable) {
1375 num = max > 0 ? min : max;
1378 input = prefix + copy + suffix;
1380 cachedState = state;
1381 cachedValue = QVariant(num);
1382 return QVariant(num);