Tidy implementation and use of QDateTimeParser::setDigit()
The implementation did a validity check on data it then gave to constructors that repeat the validity checks; so do the construction first and use the cheaper instance isValid() methods instead. Fixed local callers (but not QDateTimeEditPrivate::stepBy, the only other caller) to actually attend to the return value; if the attempt to set a field fails, it probably means the min is too low, or max too high; and comparing the modified date-time against global min and max makes no sense if it hasn't been revised anyway. Change-Id: If4505c43c92e247445dcd10ac436b775c3ead4da Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
4cb46e27fd
commit
748d87f28f
|
|
@ -179,11 +179,14 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const
|
|||
day = max;
|
||||
}
|
||||
}
|
||||
if (QDate::isValid(year, month, day) && QTime::isValid(hour, minute, second, msec)) {
|
||||
v = QDateTime(QDate(year, month, day), QTime(hour, minute, second, msec), spec);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
const QDate newDate(year, month, day);
|
||||
const QTime newTime(hour, minute, second, msec);
|
||||
if (!newDate.isValid() || !newTime.isValid())
|
||||
return false;
|
||||
|
||||
v = QDateTime(newDate, newTime, spec);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1765,16 +1768,13 @@ bool QDateTimeParser::skipToNextSection(int index, const QDateTime ¤t, con
|
|||
|
||||
QDateTime tmp = current;
|
||||
int min = absoluteMin(index);
|
||||
setDigit(tmp, index, min);
|
||||
if (tmp < minimum) {
|
||||
if (!setDigit(tmp, index, min) || tmp < minimum)
|
||||
min = getDigit(minimum, index);
|
||||
}
|
||||
|
||||
int max = absoluteMax(index, current);
|
||||
setDigit(tmp, index, max);
|
||||
if (tmp > maximum) {
|
||||
if (!setDigit(tmp, index, max) || tmp > maximum)
|
||||
max = getDigit(maximum, index);
|
||||
}
|
||||
|
||||
int pos = cursorPosition() - node.pos;
|
||||
if (pos < 0 || pos >= text.size())
|
||||
pos = -1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue