diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-05-16 16:32:25 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-06-13 11:27:49 +0000 |
commit | 748d87f28f87fd12b5a1e156025a92c32b73ae8e (patch) | |
tree | 2204fa96d8700c42d54ba22a013e7a66c05d07c9 /src | |
parent | 4cb46e27fdf30d6db9f7720fd23f7e983c38edaa (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qdatetimeparser.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
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; |