From 748d87f28f87fd12b5a1e156025a92c32b73ae8e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 16 May 2017 16:32:25 +0200 Subject: 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 --- src/corelib/tools/qdatetimeparser.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index d46d9942d3..45eb207d1f 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -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; -- cgit v1.2.3