summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-07-29 14:09:04 (GMT)
committerFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-07-29 14:09:04 (GMT)
commit96c8fdd87878da258286e053edf1046750485821 (patch)
treec63a6083df1c5e832f2762ffdf94a93de3cc0aa4 /src
parent11468d1086315c2d4f77f3747488e423d499bf56 (diff)
downloadQt-96c8fdd87878da258286e053edf1046750485821.zip
Qt-96c8fdd87878da258286e053edf1046750485821.tar.gz
Qt-96c8fdd87878da258286e053edf1046750485821.tar.bz2
Setting a timeSpec on QDateTimeEdit breaks the edit when only time is shown
Because of the time zone change we get an "overflow" in the min and max time. For example min 00:00:00 becomes 01:00:00 and max 23:59:59 becomes 00:59:59 which is an invalid time span and the displayed time gets fixed to the newly set min/max value. Autotest included. Task-number: QTBUG-12384 Reviewed-by: Gabriel
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/qdatetimeedit.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/widgets/qdatetimeedit.cpp b/src/gui/widgets/qdatetimeedit.cpp
index 50fa9c9..e272ce4 100644
--- a/src/gui/widgets/qdatetimeedit.cpp
+++ b/src/gui/widgets/qdatetimeedit.cpp
@@ -889,7 +889,13 @@ void QDateTimeEdit::setDisplayFormat(const QString &format)
const bool dateShown = (d->sections & DateSections_Mask);
Q_ASSERT(dateShown || timeShown);
if (timeShown && !dateShown) {
+ QTime time = d->value.toTime();
setDateRange(d->value.toDate(), d->value.toDate());
+ if (d->minimum.toTime() >= d->maximum.toTime()) {
+ setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX);
+ // if the time range became invalid during the adjustment, the time would have been reset
+ setTime(time);
+ }
} else if (dateShown && !timeShown) {
setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX);
d->value = QDateTime(d->value.toDate(), QTime(), d->spec);
@@ -1667,6 +1673,15 @@ void QDateTimeEditPrivate::updateTimeSpec()
minimum = minimum.toDateTime().toTimeSpec(spec);
maximum = maximum.toDateTime().toTimeSpec(spec);
value = value.toDateTime().toTimeSpec(spec);
+
+ // time zone changes can lead to 00:00:00 becomes 01:00:00 and 23:59:59 becomes 00:59:59 (invalid range)
+ const bool dateShown = (sections & QDateTimeEdit::DateSections_Mask);
+ if (!dateShown) {
+ if (minimum.toTime() >= maximum.toTime()){
+ minimum = QDateTime(value.toDate(), QDATETIMEEDIT_TIME_MIN, spec);
+ maximum = QDateTime(value.toDate(), QDATETIMEEDIT_TIME_MAX, spec);
+ }
+ }
}
void QDateTimeEditPrivate::updateEdit()