1080 QValidator::State &state)
const
1082 if (cachedText == input && !input.isEmpty()) {
1083 state = cachedState;
1084 qCDebug(lcWidgetSpinBox) <<
"cachedText was '" << cachedText <<
"' state was" << state
1085 <<
"and value was" << cachedValue;
1089 const int max = maximum.toInt();
1090 const int min = minimum.toInt();
1092 QString copy = stripped(input, &pos);
1093 qCDebug(lcWidgetSpinBox) <<
"input" << input <<
"copy" << copy;
1094 state = QValidator::Acceptable;
1097 if (max != min && (copy.isEmpty()
1098 || (min < 0 && copy ==
"-"_L1)
1099 || (max >= 0 && copy ==
"+"_L1))) {
1100 state = QValidator::Intermediate;
1101 qCDebug(lcWidgetSpinBox) <<
"num is set to" << num;
1102 }
else if (copy.startsWith(u'-') && min >= 0) {
1103 state = QValidator::Invalid;
1109 num = locale.toInt(copy, &ok);
1110 if (!ok && (max >= 1000 || min <= -1000)) {
1111 const QString sep(locale.groupSeparator());
1112 const QString doubleSep = sep + sep;
1113 if (copy.contains(sep) && !copy.contains(doubleSep)) {
1114 QString copy2 = copy;
1116 num = locale.toInt(copy2, &ok);
1120 qCDebug(lcWidgetSpinBox) <<
"num is set to" << num;
1122 state = QValidator::Invalid;
1123 }
else if (num >= min && num <= max) {
1124 state = QValidator::Acceptable;
1125 }
else if (max == min) {
1126 state = QValidator::Invalid;
1128 if ((num >= 0 && num > max) || (num < 0 && num < min))
1129 state = QValidator::Invalid;
1131 state = QValidator::Intermediate;
1133 qCDebug(lcWidgetSpinBox) <<
"state is set to" << state;
1135 if (state != QValidator::Acceptable)
1136 num = max > 0 ? min : max;
1137 input = prefix + copy + suffix;
1139 cachedState = state;
1140 cachedValue = QVariant((
int)num);
1142 qCDebug(lcWidgetSpinBox) <<
"cachedText is set to '" << cachedText <<
"' state is set to"
1143 << state <<
"and value is set to" << cachedValue;
1231 QValidator::State &state)
const
1233 if (cachedText == input && !input.isEmpty()) {
1234 state = cachedState;
1235 qCDebug(lcWidgetDblSpinBox) <<
"cachedText was '" << cachedText <<
"' state was" << state
1236 <<
"and value was" << cachedValue;
1239 const double max = maximum.toDouble();
1240 const double min = minimum.toDouble();
1242 QString copy = stripped(input, &pos);
1243 qCDebug(lcWidgetDblSpinBox) <<
"input" << input <<
"copy" << copy;
1244 int len = copy.size();
1246 const bool plus = max >= 0;
1247 const bool minus = min <= 0;
1249 const QString group(locale.groupSeparator());
1250 const uint groupUcs = (group.isEmpty() ? 0 :
1251 (group.size() > 1 && group.at(0).isHighSurrogate()
1252 ? QChar::surrogateToUcs4(group.at(0), group.at(1))
1253 : group.at(0).unicode()));
1256 state = max != min ? QValidator::Intermediate : QValidator::Invalid;
1259 if (copy.at(0) == locale.decimalPoint()
1260 || (plus && copy.at(0) == u'+')
1261 || (minus && copy.at(0) == u'-')) {
1262 state = QValidator::Intermediate;
1267 if (copy.at(1) == locale.decimalPoint()
1268 && ((plus && copy.at(0) == u'+') || (minus && copy.at(0) == u'-'))) {
1269 state = QValidator::Intermediate;
1276 if (groupUcs && copy.startsWith(group)) {
1277 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1278 state = QValidator::Invalid;
1280 }
else if (len > 1) {
1281 const int dec = copy.indexOf(locale.decimalPoint());
1283 if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) {
1284 copy.remove(dec + 1, 1);
1287 if (copy.size() - dec >
decimals + 1) {
1288 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1289 state = QValidator::Invalid;
1292 for (
int i = dec + 1; i < copy.size(); ++i) {
1293 if (copy.at(i).isSpace()
1294 || (groupUcs && QStringView{copy}.sliced(i).startsWith(group))) {
1295 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1296 state = QValidator::Invalid;
1301 const QChar last = copy.back();
1302 const bool groupEnd = groupUcs && copy.endsWith(group);
1303 const QStringView head(copy.constData(), groupEnd ? len - group.size() : len - 1);
1304 const QChar secondLast = head.back();
1305 if ((groupEnd || last.isSpace())
1306 && ((groupUcs && head.endsWith(group)) || secondLast.isSpace())) {
1307 state = QValidator::Invalid;
1308 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1310 }
else if (last.isSpace() && (!QChar::isSpace(groupUcs) || secondLast.isSpace())) {
1311 state = QValidator::Invalid;
1312 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1320 num = locale.toDouble(copy, &ok);
1321 qCDebug(lcWidgetDblSpinBox) << locale << copy << num << ok;
1324 if (QChar::isPrint(groupUcs)) {
1325 if (max < 1000 && min > -1000 && groupUcs && copy.contains(group)) {
1326 state = QValidator::Invalid;
1327 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1331 const int len = copy.size();
1332 for (
int i = 0; i < len - 1;) {
1333 if (groupUcs && QStringView{copy}.sliced(i).startsWith(group)) {
1334 if (QStringView(copy).mid(i + group.size()).startsWith(group)) {
1335 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1336 state = QValidator::Invalid;
1345 QString copy2 = copy;
1347 copy2.remove(group);
1348 num = locale.toDouble(copy2, &ok);
1349 qCDebug(lcWidgetDblSpinBox) << group << num << copy2 << ok;
1352 state = QValidator::Invalid;
1353 qCDebug(lcWidgetDblSpinBox) <<
"state is set to Invalid";
1360 state = QValidator::Invalid;
1361 }
else if (num >= min && num <= max) {
1362 state = QValidator::Acceptable;
1363 }
else if (max == min) {
1364 state = QValidator::Invalid;
1366 if ((num >= 0 && num > max) || (num < 0 && num < min))
1367 state = QValidator::Invalid;
1369 state = QValidator::Intermediate;
1371 qCDebug(lcWidgetDblSpinBox) <<
"state is set to" << state;
1375 if (state != QValidator::Acceptable) {
1376 num = max > 0 ? min : max;
1379 input = prefix + copy + suffix;
1381 cachedState = state;
1382 cachedValue = QVariant(num);
1383 return QVariant(num);