diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-04-23 11:22:00 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-04-23 11:22:00 +0200 |
commit | 79381ca10d9944b12b785c67121f688360b467f3 (patch) | |
tree | 8835822c5e6fd0faee02265721b6dacbc95b03a0 | |
parent | c197615bd99ec76ebb3ca9aff959826b4e7ff43b (diff) | |
parent | 0c6b4dd4ad66d86d5a8dba998679ea53a563b685 (diff) |
Merge 5.15 into 5.15.0
Change-Id: Ib5251a8cb59693f076da7f75b86bfb6767bdf958
-rw-r--r-- | examples/network/securesocketclient/sslclient.cpp | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 16 | ||||
-rw-r--r-- | src/corelib/text/qlocale.cpp | 9 | ||||
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 35 | ||||
-rw-r--r-- | src/corelib/time/qdatetimeparser.cpp | 74 | ||||
-rw-r--r-- | src/corelib/time/qdatetimeparser_p.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoabackingstore.mm | 6 | ||||
-rw-r--r-- | src/widgets/widgets/qdatetimeedit.cpp | 7 | ||||
-rw-r--r-- | src/widgets/widgets/qdatetimeedit_p.h | 6 | ||||
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 5 |
10 files changed, 108 insertions, 55 deletions
diff --git a/examples/network/securesocketclient/sslclient.cpp b/examples/network/securesocketclient/sslclient.cpp index d6c52a1c66..949edd39c7 100644 --- a/examples/network/securesocketclient/sslclient.cpp +++ b/examples/network/securesocketclient/sslclient.cpp @@ -63,6 +63,7 @@ SslClient::SslClient(QWidget *parent) SslClient::~SslClient() { + delete socket; delete form; } diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 23e4e1163c..3765e19184 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4614,6 +4614,14 @@ QDebug operator<<(QDebug dbg, const QObject *o) \c{staticMetaObject} is of type QMetaObject and provides access to the enums declared with Q_ENUM_NS/Q_FLAG_NS. + For example: + + \code + namespace test { + Q_NAMESPACE + ... + \endcode + \sa Q_NAMESPACE_EXPORT */ @@ -4630,6 +4638,14 @@ QDebug operator<<(QDebug dbg, const QObject *o) is declared with the supplied \a EXPORT_MACRO qualifier. This is useful if the object needs to be exported from a dynamic library. + For example: + + \code + namespace test { + Q_NAMESPACE_EXPORT(EXPORT_MACRO) + ... + \endcode + \sa Q_NAMESPACE, {Creating Shared Libraries} */ diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 6e33e27276..60bfac62ab 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2559,19 +2559,18 @@ QDateTime QLocale::toDateTime(const QString &string, const QString &format) cons QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCalendar cal) const { #if QT_CONFIG(datetimeparser) - QTime time; - QDate date; + QDateTime datetime; QDateTimeParser dt(QMetaType::QDateTime, QDateTimeParser::FromString, cal); dt.setDefaultLocale(*this); - if (dt.parseFormat(format) && dt.fromString(string, &date, &time)) - return QDateTime(date, time); + if (dt.parseFormat(format) && dt.fromString(string, &datetime)) + return datetime; #else Q_UNUSED(string); Q_UNUSED(format); Q_UNUSED(cal); #endif - return QDateTime(QDate(), QTime(-1, -1, -1)); + return QDateTime(); } #endif // datestring diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 9d95f6eb1c..8553f79d90 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -1762,9 +1762,9 @@ QT_WARNING_POP be given in the user's local language. It is only possible to use the English names if the user's language is English. - All other input characters will be treated as text. Any sequence - of characters that are enclosed in single quotes will also be - treated as text and will not be used as an expression. For example: + All other input characters will be treated as text. Any non-empty sequence + of characters enclosed in single quotes will also be treated (stripped of + the quotes) as text and not be interpreted as expressions. For example: \snippet code/src_corelib_tools_qdatetime.cpp 1 @@ -2132,11 +2132,11 @@ QT_WARNING_POP \row \li t \li The timezone (for example "CEST") \endtable - Any sequence of characters enclosed in single quotes will be included - verbatim in the output string (stripped of the quotes), even if it contains - formatting characters. Two consecutive single quotes ("''") are replaced by - a single quote in the output. All other characters in the format string are - included verbatim in the output string. + Any non-empty sequence of characters enclosed in single quotes will be + included verbatim in the output string (stripped of the quotes), even if it + contains formatting characters. Two consecutive single quotes ("''") are + replaced by a single quote in the output. All other characters in the format + string are included verbatim in the output string. Formats without separators (e.g. "ddMM") are supported but must be used with care, as the resulting strings aren't always reliably readable (e.g. if "dM" @@ -2536,9 +2536,9 @@ QT_WARNING_POP \row \li t \li the timezone (for example "CEST") \endtable - All other input characters will be treated as text. Any sequence - of characters that are enclosed in single quotes will also be - treated as text and not be used as an expression. + All other input characters will be treated as text. Any non-empty sequence + of characters enclosed in single quotes will also be treated (stripped of + the quotes) as text and not be interpreted as expressions. \snippet code/src_corelib_tools_qdatetime.cpp 6 @@ -5480,9 +5480,9 @@ QT_WARNING_POP See QDate::fromString() and QTime::fromString() for the expressions recognized in the format string to represent parts of the date and time. - All other input characters will be treated as text. Any sequence of - characters that are enclosed in single quotes will also be treated as text - and not be used as an expression. + All other input characters will be treated as text. Any non-empty sequence + of characters enclosed in single quotes will also be treated (stripped of + the quotes) as text and not be interpreted as expressions. \snippet code/src_corelib_tools_qdatetime.cpp 12 @@ -5537,13 +5537,12 @@ QT_WARNING_POP QDateTime QDateTime::fromString(const QString &string, const QString &format, QCalendar cal) { #if QT_CONFIG(datetimeparser) - QTime time; - QDate date; + QDateTime datetime; QDateTimeParser dt(QMetaType::QDateTime, QDateTimeParser::FromString, cal); // dt.setDefaultLocale(QLocale::c()); ### Qt 6 - if (dt.parseFormat(format) && dt.fromString(string, &date, &time)) - return QDateTime(date, time); + if (dt.parseFormat(format) && dt.fromString(string, &datetime)) + return datetime; #else Q_UNUSED(string); Q_UNUSED(format); diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 2a19611493..3374b28b69 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -1207,12 +1207,16 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, Q_ASSERT(!zoneName.isEmpty()); // sect.used > 0 const QByteArray latinZone(zoneName == QLatin1String("Z") ? QByteArray("UTC") : zoneName.toLatin1()); - timeZone = QTimeZone(latinZone); - tspec = timeZone.isValid() - ? (QTimeZone::isTimeZoneIdAvailable(latinZone) - ? Qt::TimeZone - : Qt::OffsetFromUTC) - : (Q_ASSERT(startsWithLocalTimeZone(zoneName)), Qt::LocalTime); + if (latinZone.startsWith("UTC") && + (latinZone.size() == 3 || latinZone.at(3) == '+' || latinZone.at(3) == '-' )) { + timeZone = QTimeZone(sect.value); + tspec = sect.value ? Qt::OffsetFromUTC : Qt::UTC; + } else { + timeZone = QTimeZone(latinZone); + tspec = timeZone.isValid() + ? Qt::TimeZone + : (Q_ASSERT(startsWithLocalTimeZone(zoneName)), Qt::LocalTime); + } #else tspec = Qt::LocalTime; #endif @@ -1537,12 +1541,10 @@ QDateTimeParser::parse(QString input, int position, const QDateTime &defaultValu } } text = scan.input = input; - // Set spec *after* all checking, so validity is a property of the string: - scan.value = scan.value.toTimeSpec(spec); /* - However, even with a valid string we might have ended up with an invalid datetime: - the non-existent hour during dst changes, for instance. + We might have ended up with an invalid datetime: the non-existent hour + during dst changes, for instance. */ if (!scan.value.isValid() && scan.state == Acceptable) scan.state = Intermediate; @@ -2018,13 +2020,12 @@ QString QDateTimeParser::stateName(State s) const #if QT_CONFIG(datestring) bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) const { - QDateTime val(QDate(1900, 1, 1).startOfDay()); - const StateNode tmp = parse(t, -1, val, false); - if (tmp.state != Acceptable || tmp.conflicts) { + QDateTime datetime; + if (!fromString(t, &datetime)) return false; - } + if (time) { - const QTime t = tmp.value.time(); + const QTime t = datetime.time(); if (!t.isValid()) { return false; } @@ -2032,7 +2033,7 @@ bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) con } if (date) { - const QDate d = tmp.value.date(); + const QDate d = datetime.date(); if (!d.isValid()) { return false; } @@ -2040,26 +2041,43 @@ bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) con } return true; } + +bool QDateTimeParser::fromString(const QString &t, QDateTime* datetime) const +{ + QDateTime val(QDate(1900, 1, 1).startOfDay()); + const StateNode tmp = parse(t, -1, val, false); + if (tmp.state != Acceptable || tmp.conflicts) + return false; + if (datetime) { + if (!tmp.value.isValid()) + return false; + *datetime = tmp.value; + } + + return true; +} #endif // datestring QDateTime QDateTimeParser::getMinimum() const { - // Cache the most common case - if (spec == Qt::LocalTime) { - static const QDateTime localTimeMin(QDATETIMEEDIT_DATE_MIN.startOfDay(Qt::LocalTime)); - return localTimeMin; - } - return QDateTime(QDATETIMEEDIT_DATE_MIN.startOfDay(spec)); + // NB: QDateTimeParser always uses Qt::LocalTime time spec by default. If + // any subclass needs a changing time spec, it must override this + // method. At the time of writing, this is done by QDateTimeEditPrivate. + + // Cache the only case + static const QDateTime localTimeMin(QDATETIMEEDIT_DATE_MIN.startOfDay(Qt::LocalTime)); + return localTimeMin; } QDateTime QDateTimeParser::getMaximum() const { - // Cache the most common case - if (spec == Qt::LocalTime) { - static const QDateTime localTimeMax(QDATETIMEEDIT_DATE_MAX.endOfDay(Qt::LocalTime)); - return localTimeMax; - } - return QDateTime(QDATETIMEEDIT_DATE_MAX.endOfDay(spec)); + // NB: QDateTimeParser always uses Qt::LocalTime time spec by default. If + // any subclass needs a changing time spec, it must override this + // method. At the time of writing, this is done by QDateTimeEditPrivate. + + // Cache the only case + static const QDateTime localTimeMax(QDATETIMEEDIT_DATE_MAX.endOfDay(Qt::LocalTime)); + return localTimeMax; } QString QDateTimeParser::getAmPmText(AmPm ap, Case cs) const diff --git a/src/corelib/time/qdatetimeparser_p.h b/src/corelib/time/qdatetimeparser_p.h index 5c612ef6a4..f2795c31f0 100644 --- a/src/corelib/time/qdatetimeparser_p.h +++ b/src/corelib/time/qdatetimeparser_p.h @@ -85,7 +85,7 @@ public: }; QDateTimeParser(QMetaType::Type t, Context ctx, const QCalendar &cal = QCalendar()) : currentSectionIndex(-1), cachedDay(-1), parserType(t), - fixday(false), spec(Qt::LocalTime), context(ctx), calendar(cal) + fixday(false), context(ctx), calendar(cal) { defaultLocale = QLocale::system(); first.type = FirstSection; @@ -181,6 +181,7 @@ public: #if QT_CONFIG(datestring) StateNode parse(QString input, int position, const QDateTime &defaultValue, bool fixup) const; bool fromString(const QString &text, QDate *date, QTime *time) const; + bool fromString(const QString &text, QDateTime* datetime) const; #endif bool parseFormat(const QString &format); @@ -297,7 +298,6 @@ protected: // for the benefit of QDateTimeEditPrivate QLocale defaultLocale; QMetaType::Type parserType; bool fixday; - Qt::TimeSpec spec; // spec if used by QDateTimeEdit Context context; QCalendar calendar; }; diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 3b9df8da3a..ba5d42e706 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -537,8 +537,10 @@ void QCALayerBackingStore::flush(QWindow *flushedWindow, const QRegion ®ion, flushedView.layer.contentsScale = m_buffers.back()->devicePixelRatio(); } + const bool isSingleBuffered = window()->format().swapBehavior() == QSurfaceFormat::SingleBuffer; + id backBufferSurface = (__bridge id)m_buffers.back()->surface(); - if (flushedView.layer.contents == backBufferSurface) { + if (!isSingleBuffered && flushedView.layer.contents == backBufferSurface) { // We've managed to paint to the back buffer again before Core Animation had time // to flush the transaction and persist the layer changes to the window server, or // we've been asked to flush without painting anything. The layer already knows about @@ -555,7 +557,7 @@ void QCALayerBackingStore::flush(QWindow *flushedWindow, const QRegion ®ion, // with other pending view and layer updates. flushedView.window.viewsNeedDisplay = YES; - if (window()->format().swapBehavior() == QSurfaceFormat::SingleBuffer) { + if (isSingleBuffered) { // The private API [CALayer reloadValueForKeyPath:@"contents"] would be preferable, // but barring any side effects or performance issues we opt for the hammer for now. flushedView.layer.contents = nil; diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index d145985c1d..deb4dc36ba 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -1976,7 +1976,14 @@ QDateTime QDateTimeEditPrivate::validateAndInterpret(QString &input, int &positi return minimum.toDateTime(); } } + StateNode tmp = parse(input, position, value.toDateTime(), fixup); + // Impose this widget's spec: + tmp.value = tmp.value.toTimeSpec(spec); + // ... but that might turn a valid datetime into an invalid one: + if (!tmp.value.isValid() && tmp.state == Acceptable) + tmp.state = Intermediate; + input = tmp.input; position += tmp.padded; state = QValidator::State(int(tmp.state)); diff --git a/src/widgets/widgets/qdatetimeedit_p.h b/src/widgets/widgets/qdatetimeedit_p.h index 323246a87b..7df2b59710 100644 --- a/src/widgets/widgets/qdatetimeedit_p.h +++ b/src/widgets/widgets/qdatetimeedit_p.h @@ -98,12 +98,16 @@ public: { if (keyboardTracking) return minimum.toDateTime(); + if (spec != Qt::LocalTime) + return QDateTime(QDATETIMEEDIT_DATE_MIN.startOfDay(spec)); return QDateTimeParser::getMinimum(); } QDateTime getMaximum() const override { if (keyboardTracking) return maximum.toDateTime(); + if (spec != Qt::LocalTime) + return QDateTime(QDATETIMEEDIT_DATE_MIN.startOfDay(spec)); return QDateTimeParser::getMaximum(); } QLocale locale() const override { return q_func()->locale(); } @@ -148,6 +152,8 @@ public: #ifdef QT_KEYPAD_NAVIGATION bool focusOnButton; #endif + + Qt::TimeSpec spec = Qt::LocalTime; }; diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 26ad91271d..08196d8377 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2554,6 +2554,11 @@ void tst_QDateTime::fromStringStringFormat() QDateTime dt = QDateTime::fromString(string, format); + if (expected.isValid()) { + QCOMPARE(dt.timeSpec(), expected.timeSpec()); + if (expected.timeSpec() == Qt::TimeZone) + QCOMPARE(dt.timeZone(), expected.timeZone()); + } QCOMPARE(dt, expected); } |