From c61cedcc5475a77fb94ed12788f61039835f8079 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 3 Jan 2020 23:06:45 +0100 Subject: GCC: revoke constexpr before 5.0 It's causing build failures on GCC 4.9 due to our code hitting https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57694 (at least since de82d239f814cf2a717bea0defeee3732384e271). Task-number: QTBUG-80997 Change-Id: I80a9d1fcbf26d8c0bf514ddc7bdb86eb7173360f Reviewed-by: Ville Voutilainen --- src/corelib/global/qcompilerdetection.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 0091cfcb60..1ea4e7d287 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -883,7 +883,6 @@ # define Q_COMPILER_DEFAULT_MEMBERS # define Q_COMPILER_DELETE_MEMBERS /* C++11 features supported in GCC 4.6: */ -# define Q_COMPILER_CONSTEXPR # define Q_COMPILER_NULLPTR # define Q_COMPILER_UNRESTRICTED_UNIONS # define Q_COMPILER_RANGE_FOR @@ -914,7 +913,11 @@ # define Q_COMPILER_REF_QUALIFIERS # endif # endif - /* C++11 features are complete as of GCC 4.8.1 */ +# if Q_CC_GNU >= 500 + /* GCC 4.6 introduces constexpr, but it's bugged (at least) in the whole + * 4.x series, see e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57694 */ +# define Q_COMPILER_CONSTEXPR +# endif # endif # if __cplusplus > 201103L # if Q_CC_GNU >= 409 -- cgit v1.2.3 From 64359ad710756e7cca5ca553521b2aada18fb0fe Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 7 Jan 2020 16:25:37 -0800 Subject: ucstrncmp: Fix UBSan report of array overflowing The expression "a + offset + N" will eventually calculate an address past the end of a, since we are comparing to end. That's undefined behavior. Instead, calculate end - a and compare that to offset + N. This commit subtracts "a" from both sides of the inequalities and swaps the two sides to make them obey Qt coding style. Testing with GCC 9 (which is the only one I care about) shows the compiler generates the same code. Fixes: QTBUG-81218 Change-Id: Id84da383373844f3a4b0fffd15e7c1ab904daccd Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/text/qstring.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 4d83f19db7..b929786255 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -915,7 +915,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, size_t l) }; // we're going to read a[0..15] and b[0..15] (32 bytes) - for ( ; a + offset + 16 <= end; offset += 16) { + for ( ; end - a >= offset + 16; offset += 16) { #ifdef __AVX2__ __m256i a_data = _mm256_loadu_si256(reinterpret_cast(a + offset)); __m256i b_data = _mm256_loadu_si256(reinterpret_cast(b + offset)); @@ -939,7 +939,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, size_t l) } // we're going to read a[0..7] and b[0..7] (16 bytes) - if (a + offset + 8 <= end) { + if (end - a >= offset + 8) { __m128i a_data = _mm_loadu_si128(reinterpret_cast(a + offset)); __m128i b_data = _mm_loadu_si128(reinterpret_cast(b + offset)); if (isDifferent(a_data, b_data)) @@ -949,7 +949,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, size_t l) } // we're going to read a[0..3] and b[0..3] (8 bytes) - if (a + offset + 4 <= end) { + if (end - a >= offset + 4) { __m128i a_data = _mm_loadl_epi64(reinterpret_cast(a + offset)); __m128i b_data = _mm_loadl_epi64(reinterpret_cast(b + offset)); if (isDifferent(a_data, b_data)) @@ -970,7 +970,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, size_t l) if (l >= 8) { const QChar *end = a + l; const uint16x8_t mask = { 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 }; - while (a + 7 < end) { + while (end - a > 7) { uint16x8_t da = vld1q_u16(reinterpret_cast(a)); uint16x8_t db = vld1q_u16(reinterpret_cast(b)); -- cgit v1.2.3 From 445c1a873fcdc58a7880394b8d7473b7eff43d99 Mon Sep 17 00:00:00 2001 From: Inho Lee Date: Tue, 7 Jan 2020 15:06:37 +0100 Subject: Resolve a build error for ICC 19 This argument name makes an error with "line 302:Type t = Undefined;" Change-Id: I5488ff02ab7c9f9391c17361da5e2aac2727a6a0 Reviewed-by: Thiago Macieira --- src/corelib/serialization/qcborvalue.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index 914103b0a5..dcbe7efc26 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -320,9 +320,9 @@ private: return Type(quint8(st) | SimpleType); } - Q_DECL_CONSTEXPR static bool isTag_helper(Type t) + Q_DECL_CONSTEXPR static bool isTag_helper(Type tt) { - return t == Tag || t >= 0x10000; + return tt == Tag || tt >= 0x10000; } }; Q_DECLARE_SHARED(QCborValue) -- cgit v1.2.3 From 1edf8bc46542ad302085b9e957c8c3c31c7db9da Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 4 Jan 2020 16:03:35 +0100 Subject: QObject: Replace more 0 and NULL with nullptr ... in docs, comments, and warnings. Also adopt some occurrences around there and in the snippets. Change-Id: Icc0aa0868cadd8ec2270dda794bf83cd7ab84160 Reviewed-by: Christian Ehrlicher --- .../snippets/code/src_corelib_kernel_qobject.cpp | 16 ++--- src/corelib/kernel/qobject.cpp | 76 +++++++++++----------- 2 files changed, 46 insertions(+), 46 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp index 1966f8195a..43bcc22720 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -71,7 +71,7 @@ QTimer *timer = qobject_cast(obj); // timer == (QObject *)obj QAbstractButton *button = qobject_cast(obj); -// button == 0 +// button == nullptr //! [3] @@ -144,7 +144,7 @@ class MyObject : public QObject Q_OBJECT public: - MyObject(QObject *parent = 0); + MyObject(QObject *parent = nullptr); protected: void timerEvent(QTimerEvent *event) override; @@ -322,7 +322,7 @@ QObject::connect: Cannot queue arguments of type 'MyType' //! [26] -disconnect(myObject, 0, 0, 0); +disconnect(myObject, nullptr, nullptr, nullptr); //! [26] @@ -332,7 +332,7 @@ myObject->disconnect(); //! [28] -disconnect(myObject, SIGNAL(mySignal()), 0, 0); +disconnect(myObject, SIGNAL(mySignal()), nullptr, nullptr); //! [28] @@ -342,7 +342,7 @@ myObject->disconnect(SIGNAL(mySignal())); //! [30] -disconnect(myObject, 0, myReceiver, 0); +disconnect(myObject, nullptr, myReceiver, nullptr); //! [30] @@ -391,7 +391,7 @@ class MyClass : public QObject Q_OBJECT public: - MyClass(QObject *parent = 0); + MyClass(QObject *parent = nullptr); ~MyClass(); enum Priority { High, Low, VeryHigh, VeryLow }; @@ -467,7 +467,7 @@ QObject::connect(socket, &QTcpSocket::connected, [=] () { //! [46] //! [47] -disconnect(myObject, &MyObject::mySignal(), 0, 0); +disconnect(myObject, &MyObject::mySignal(), nullptr, nullptr); //! [47] //! [48] @@ -505,7 +505,7 @@ class MyClass : public QWidget Q_OBJECT public: - MyClass(QWidget *parent = 0); + MyClass(QWidget *parent = nullptr); ~MyClass(); bool event(QEvent* ev) override diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index cc50d9ccc7..e2e133ac28 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1185,8 +1185,8 @@ QObjectPrivate::Connection::~Connection() \relates QObject Returns the given \a object cast to type T if the object is of type - T (or of a subclass); otherwise returns 0. If \a object is 0 then - it will also return 0. + T (or of a subclass); otherwise returns \nullptr. If \a object is + \nullptr then it will also return \nullptr. The class T must inherit (directly or indirectly) QObject and be declared with the \l Q_OBJECT macro. @@ -1538,7 +1538,7 @@ QThread *QObject::thread() const the thread affinity is changed. You can handle this event to perform any special processing. Note that any new events that are posted to this object will be handled in the \a targetThread, - provided it is non-null: when it is \nullptr, no event processing + provided it is not \nullptr: when it is \nullptr, no event processing for this object or its children can happen, as they are no longer associated with any thread. @@ -2335,7 +2335,7 @@ void QObject::deleteLater() If the same \a sourceText is used in different roles within the same context, an additional identifying string may be passed in - \a disambiguation (0 by default). In Qt 4.4 and earlier, this was + \a disambiguation (\nullptr by default). In Qt 4.4 and earlier, this was the preferred way to pass comments to translators. Example: @@ -2521,7 +2521,7 @@ QObject *QObject::sender() const For signals with default parameters, this function will always return the index with all parameters, regardless of which was used with - connect(). For example, the signal \c {destroyed(QObject *obj = 0)} + connect(). For example, the signal \c {destroyed(QObject *obj = \nullptr)} will have two different indexes (with and without the parameter), but this function will always return the index with a parameter. This does not apply when overloading signals with different parameters. @@ -2662,7 +2662,7 @@ bool QObject::isSignalConnected(const QMetaMethod &signal) const member in the specified class. \list - \li If member.mobj is 0 then both signalIndex and methodIndex are set to -1. + \li If member.mobj is \nullptr then both signalIndex and methodIndex are set to -1. \li If specified member is not a member of obj instance class (or one of its parent classes) then both signalIndex and methodIndex are set to -1. @@ -2799,12 +2799,12 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign const QObject *receiver, const char *method, Qt::ConnectionType type) { - if (sender == 0 || receiver == 0 || signal == 0 || method == 0) { + if (sender == nullptr || receiver == nullptr || signal == nullptr || method == nullptr) { qWarning("QObject::connect: Cannot connect %s::%s to %s::%s", - sender ? sender->metaObject()->className() : "(null)", - (signal && *signal) ? signal+1 : "(null)", - receiver ? receiver->metaObject()->className() : "(null)", - (method && *method) ? method+1 : "(null)"); + sender ? sender->metaObject()->className() : "(nullptr)", + (signal && *signal) ? signal+1 : "(nullptr)", + receiver ? receiver->metaObject()->className() : "(nullptr)", + (method && *method) ? method+1 : "(nullptr)"); return QMetaObject::Connection(0); } QByteArray tmp_signal_name; @@ -2937,14 +2937,14 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) { - if (sender == 0 - || receiver == 0 + if (sender == nullptr + || receiver == nullptr || signal.methodType() != QMetaMethod::Signal || method.methodType() == QMetaMethod::Constructor) { qWarning("QObject::connect: Cannot connect %s::%s to %s::%s", - sender ? sender->metaObject()->className() : "(null)", + sender ? sender->metaObject()->className() : "(nullptr)", signal.methodSignature().constData(), - receiver ? receiver->metaObject()->className() : "(null)", + receiver ? receiver->metaObject()->className() : "(nullptr)", method.methodSignature().constData() ); return QMetaObject::Connection(0); } @@ -3046,20 +3046,20 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho \endlist - 0 may be used as a wildcard, meaning "any signal", "any receiving + \nullptr may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively. The \a sender may never be \nullptr. (You cannot disconnect signals from more than one object in a single call.) - If \a signal is 0, it disconnects \a receiver and \a method from + If \a signal is \nullptr, it disconnects \a receiver and \a method from any signal. If not, only the specified signal is disconnected. - If \a receiver is 0, it disconnects anything connected to \a + If \a receiver is \nullptr, it disconnects anything connected to \a signal. If not, slots in objects other than \a receiver are not disconnected. - If \a method is 0, it disconnects anything that is connected to \a + If \a method is \nullptr, it disconnects anything that is connected to \a receiver. If not, only slots named \a method will be disconnected, and all other slots are left alone. The \a method must be \nullptr if \a receiver is left out, so you cannot disconnect a @@ -3070,8 +3070,8 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho bool QObject::disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method) { - if (sender == 0 || (receiver == 0 && method != 0)) { - qWarning("QObject::disconnect: Unexpected null parameter"); + if (sender == nullptr || (receiver == nullptr && method != nullptr)) { + qWarning("QObject::disconnect: Unexpected nullptr parameter"); return false; } @@ -3197,16 +3197,16 @@ bool QObject::disconnect(const QObject *sender, const char *signal, \endlist QMetaMethod() may be used as wildcard in the meaning "any signal" or "any slot in receiving object". - In the same way 0 can be used for \a receiver in the meaning "any receiving object". In this case - method should also be QMetaMethod(). \a sender parameter should be never 0. + In the same way \nullptr can be used for \a receiver in the meaning "any receiving object". + In this case method should also be QMetaMethod(). \a sender parameter should be never \nullptr. \sa disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method) */ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) { - if (sender == 0 || (receiver == 0 && method.mobj != 0)) { - qWarning("QObject::disconnect: Unexpected null parameter"); + if (sender == nullptr || (receiver == nullptr && method.mobj != nullptr)) { + qWarning("QObject::disconnect: Unexpected nullptr parameter"); return false; } if (signal.mobj) { @@ -3240,7 +3240,7 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal, QMetaObjectPrivate::memberIndexes(sender, signal, &signal_index, &dummy); QMetaObjectPrivate::memberIndexes(receiver, method, &dummy, &method_index); } - // If we are here sender is not null. If signal is not null while signal_index + // If we are here sender is not nullptr. If signal is not nullptr while signal_index // is -1 then this signal is not a member of sender. if (signal.mobj && signal_index == -1) { qWarning("QObject::disconect: signal %s not found on class %s", @@ -3329,7 +3329,7 @@ void QObject::connectNotify(const QMetaMethod &signal) \a signal with a specific signal. If all signals were disconnected from this object (e.g., the - signal argument to disconnect() was 0), disconnectNotify() + signal argument to disconnect() was \nullptr), disconnectNotify() is only called once, and the \a signal will be an invalid QMetaMethod (QMetaMethod::isValid() returns \c false). @@ -4929,7 +4929,7 @@ void qDeleteInEventHandler(QObject *o) \a sender is the sender object \a signal is a pointer to a pointer to a member signal of the sender - \a receiver is the receiver object, may not be null, will be equal to sender when + \a receiver is the receiver object, may not be \nullptr, will be equal to sender when connecting to a static function or a functor \a slot a pointer only used when using Qt::UniqueConnection \a type the Qt::ConnctionType passed as argument to connect @@ -4937,7 +4937,7 @@ void qDeleteInEventHandler(QObject *o) to be used with queued connection must stay valid at least for the whole time of the connection, this function do not take ownership. typically static data. - If null, then the types will be computed when the signal is emit in a queued + If \nullptr, then the types will be computed when the signal is emit in a queued connection from the types from the signature. \a senderMetaObject is the metaobject used to lookup the signal, the signal must be in this metaobject @@ -4948,7 +4948,7 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa const int *types, const QMetaObject *senderMetaObject) { if (!signal) { - qWarning("QObject::connect: invalid null parameter"); + qWarning("QObject::connect: invalid nullptr parameter"); if (slotObj) slotObj->destroyIfLastRef(); return QMetaObject::Connection(); @@ -4988,7 +4988,7 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s : "Unknown"; const char *receiverString = receiver ? receiver->metaObject()->className() : "Unknown"; - qWarning("QObject::connect(%s, %s): invalid null parameter", senderString, receiverString); + qWarning("QObject::connect(%s, %s): invalid nullptr parameter", senderString, receiverString); if (slotObj) slotObj->destroyIfLastRef(); return QMetaObject::Connection(); @@ -5121,20 +5121,20 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) \endlist - 0 may be used as a wildcard, meaning "any signal", "any receiving + \nullptr may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively. The \a sender may never be \nullptr. (You cannot disconnect signals from more than one object in a single call.) - If \a signal is 0, it disconnects \a receiver and \a method from + If \a signal is \nullptr, it disconnects \a receiver and \a method from any signal. If not, only the specified signal is disconnected. - If \a receiver is 0, it disconnects anything connected to \a + If \a receiver is \nullptr, it disconnects anything connected to \a signal. If not, slots in objects other than \a receiver are not disconnected. - If \a method is 0, it disconnects anything that is connected to \a + If \a method is \nullptr, it disconnects anything that is connected to \a receiver. If not, only slots named \a method will be disconnected, and all other slots are left alone. The \a method must be \nullptr if \a receiver is left out, so you cannot disconnect a @@ -5150,8 +5150,8 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) bool QObject::disconnectImpl(const QObject *sender, void **signal, const QObject *receiver, void **slot, const QMetaObject *senderMetaObject) { - if (sender == 0 || (receiver == 0 && slot != 0)) { - qWarning("QObject::disconnect: Unexpected null parameter"); + if (sender == nullptr || (receiver == nullptr && slot != nullptr)) { + qWarning("QObject::disconnect: Unexpected nullptr parameter"); return false; } @@ -5182,7 +5182,7 @@ bool QObject::disconnectImpl(const QObject *sender, void **signal, const QObject QMetaObject::Connection QObjectPrivate::connect(const QObject *sender, int signal_index, QtPrivate::QSlotObjectBase *slotObj, Qt::ConnectionType type) { if (!sender) { - qWarning("QObject::connect: invalid null parameter"); + qWarning("QObject::connect: invalid nullptr parameter"); if (slotObj) slotObj->destroyIfLastRef(); return QMetaObject::Connection(); -- cgit v1.2.3 From 6f1ae59ee6b82123f073fc8fd0ed6d010818041e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 6 Jan 2020 13:25:30 +0100 Subject: Change getMacLocaleName() to return a QString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Returning a QByteArray required doing a toUtf8() to a QString on one of its paths, which was promptly undone by its caller using fromUTf8(), since a QString was needed anyway. Drive-by - remove spurious default for parameter in method definition. Change-Id: I45f553d74cd0ba9dab25c439ba8291c00b7ceb5b Reviewed-by: Tor Arne Vestbø Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale_mac.mm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index 9719278426..31ede1352b 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -67,16 +67,16 @@ static QByteArray envVarLocale() return lang; } -static QByteArray getMacLocaleName() +static QString getMacLocaleName() { - QByteArray result = envVarLocale(); + QString result = QString::fromLocal8Bit(envVarLocale()); QString lang, script, cntry; if (result.isEmpty() - || (result != "C" && !qt_splitLocaleName(QString::fromLocal8Bit(result), lang, script, cntry))) { + || (result != QLatin1String("C") && !qt_splitLocaleName(result, lang, script, cntry))) { QCFType l = CFLocaleCopyCurrent(); CFStringRef locale = CFLocaleGetIdentifier(l); - result = QString::fromCFString(locale).toUtf8(); + result = QString::fromCFString(locale); } return result; } @@ -402,10 +402,10 @@ static QVariant macQuoteString(QSystemLocale::QueryType type, const QStringRef & QLocale QSystemLocale::fallbackUiLocale() const { - return QLocale(QString::fromUtf8(getMacLocaleName().constData())); + return QLocale(getMacLocaleName()); } -QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const +QVariant QSystemLocale::query(QueryType type, QVariant in) const { QMacAutoReleasePool pool; switch(type) { -- cgit v1.2.3 From f91af791cc3be1dfb9645ed4ebba10a7d9f74134 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 7 Jan 2020 15:06:54 +0100 Subject: Add advance warning of change of return types coming in Qt6 The QLocale methods that report the fragments used in making up numbers all return QChar. A note dating from before Qt5 times warned that we need to change these to return QString (since we might need a surrogate pair to represent the relevant characters). Give advance warning in the documentation that this shall happen at Qt 6. [ChangeLog][QtCore][QLocale] decimalPoint(), groupSeparator(), percent(), zeroDigit(), negativeSign(), positiveSign() and exponential() still return QChar but shall be changed to return QString in Qt 6. Callers are encouraged to switch to QString early, exploiting the QString(QChar) constructor. Task-number: QTBUG-81053 Change-Id: Ia802c7665676ecf13669c6a6f173f2e70eac578e Reviewed-by: Paul Wicking --- src/corelib/text/qlocale.cpp | 30 +++++++++++++++++++++++++++++- src/corelib/text/qlocale.h | 6 +++--- 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 425cb87d31..dd3263e5aa 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -2525,6 +2525,10 @@ QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCal \since 4.1 Returns the decimal point character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::decimalPoint() const { @@ -2535,6 +2539,10 @@ QChar QLocale::decimalPoint() const \since 4.1 Returns the group separator character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::groupSeparator() const { @@ -2545,6 +2553,10 @@ QChar QLocale::groupSeparator() const \since 4.1 Returns the percent character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::percent() const { @@ -2555,6 +2567,10 @@ QChar QLocale::percent() const \since 4.1 Returns the zero digit character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::zeroDigit() const { @@ -2565,6 +2581,10 @@ QChar QLocale::zeroDigit() const \since 4.1 Returns the negative sign character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::negativeSign() const { @@ -2575,6 +2595,10 @@ QChar QLocale::negativeSign() const \since 4.5 Returns the positive sign character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::positiveSign() const { @@ -2585,6 +2609,10 @@ QChar QLocale::positiveSign() const \since 4.1 Returns the exponential character of this locale. + + \note This function shall change to return a QString instead of QChar in + Qt6. Callers are encouraged to exploit the QString(QChar) constructor to + convert early in preparation for this. */ QChar QLocale::exponential() const { diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index 8b73eb5493..513e0f097b 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -1044,8 +1044,8 @@ public: QDateTime toDateTime(const QString &string, const QString &format, QCalendar cal) const; #endif - // ### Qt 5: We need to return QString from these function since - // unicode data contains several characters for these fields. + // ### Qt 6: We need to return QString from these function since + // UTF-16 may need surrogate pairs to represent these fields. QChar decimalPoint() const; QChar groupSeparator() const; QChar percent() const; -- cgit v1.2.3 From 0f80452b924230013d713c2bc6681efc0e654a1b Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 8 Jan 2020 12:00:09 +0100 Subject: Improve QLocale method documentation Add missing \sa lines, clarify what the exponential character is and mention that C is an exception to the "no number options set". Change-Id: I13ca483a07738908640408e0ca512de31586cec9 Reviewed-by: Paul Wicking Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index dd3263e5aa..e3e0ebdcbd 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -1048,6 +1048,8 @@ uint qHash(const QLocale &key, uint seed) noexcept Sets the \a options related to number conversions for this QLocale instance. + + \sa numberOptions() */ void QLocale::setNumberOptions(NumberOptions options) { @@ -1060,7 +1062,10 @@ void QLocale::setNumberOptions(NumberOptions options) Returns the options related to number conversions for this QLocale instance. - By default, no options are set for the standard locales. + By default, no options are set for the standard locales, except + for the "C" locale, which has OmitGroupSeparator set by default. + + \sa setNumberOptions(), toString(), groupSeparator() */ QLocale::NumberOptions QLocale::numberOptions() const { @@ -1962,7 +1967,7 @@ double QLocale::toDouble(QStringView s, bool *ok) const /*! Returns a localized string representation of \a i. - \sa toLongLong() + \sa toLongLong(), numberOptions(), zeroDigit(), positiveSign() */ QString QLocale::toString(qlonglong i) const @@ -1978,7 +1983,7 @@ QString QLocale::toString(qlonglong i) const /*! \overload - \sa toULongLong() + \sa toULongLong(), numberOptions(), zeroDigit(), positiveSign() */ QString QLocale::toString(qulonglong i) const @@ -2529,6 +2534,8 @@ QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCal \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa groupSeparator(), toString() */ QChar QLocale::decimalPoint() const { @@ -2543,6 +2550,8 @@ QChar QLocale::decimalPoint() const \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa decimalPoint(), toString() */ QChar QLocale::groupSeparator() const { @@ -2557,6 +2566,8 @@ QChar QLocale::groupSeparator() const \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa toString() */ QChar QLocale::percent() const { @@ -2571,6 +2582,8 @@ QChar QLocale::percent() const \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa toString() */ QChar QLocale::zeroDigit() const { @@ -2585,6 +2598,8 @@ QChar QLocale::zeroDigit() const \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa positiveSign(), toString() */ QChar QLocale::negativeSign() const { @@ -2599,6 +2614,8 @@ QChar QLocale::negativeSign() const \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa negativeSign(), toString() */ QChar QLocale::positiveSign() const { @@ -2608,11 +2625,14 @@ QChar QLocale::positiveSign() const /*! \since 4.1 - Returns the exponential character of this locale. + Returns the exponential character of this locale, used to separate exponent + from mantissa in some floating-point numeric representations. \note This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this. + + \sa toString(double, char, int) */ QChar QLocale::exponential() const { @@ -2637,7 +2657,7 @@ static char qToLower(char c) \a f and \a prec have the same meaning as in QString::number(double, char, int). - \sa toDouble() + \sa toDouble(), numberOptions(), exponential(), decimalPoint(), zeroDigit(), positiveSign(), percent() */ QString QLocale::toString(double i, char f, int prec) const -- cgit v1.2.3 From 11c5c078c7743050a115a4dcc31f52caaa378e35 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 6 Jan 2020 12:11:28 +0100 Subject: Eliminate QLocale's default_number_options global static It had create()'s default number options when passed to create, so wasn't useful then; and otherwise shadowed the value held by the cached private for the default locale. Noticed in the course of adding an analogous global for the system locale. Drive-by - eliminated a redundant language != C check. Change-Id: I5601dc09188804c11dede5be460bfdd12b8152ce Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index e3e0ebdcbd..e3530eeee1 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -651,7 +651,6 @@ int qt_repeatCount(QStringView s) } static const QLocaleData *default_data = nullptr; -static QLocale::NumberOptions default_number_options = QLocale::DefaultNumberOptions; static const QLocaleData *const c_data = locale_data; static QLocalePrivate *c_private() @@ -834,7 +833,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l) static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1; Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, defaultLocalePrivate, - (QLocalePrivate::create(defaultData(), default_number_options))) + (QLocalePrivate::create(defaultData()))) Q_GLOBAL_STATIC_WITH_ARGS(QExplicitlySharedDataPointer, systemLocalePrivate, (QLocalePrivate::create(systemData()))) @@ -862,8 +861,9 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions; // If not found, should default to system - if (data->m_language_id == QLocale::C && language != QLocale::C) { - numberOptions = default_number_options; + if (data->m_language_id == QLocale::C) { + if (defaultLocalePrivate.exists()) + numberOptions = defaultLocalePrivate->data()->m_numberOptions; data = defaultData(); } return QLocalePrivate::create(data, offset, numberOptions); @@ -1175,12 +1175,9 @@ QString QLocale::createSeparatedList(const QStringList &list) const void QLocale::setDefault(const QLocale &locale) { default_data = locale.d->m_data; - default_number_options = locale.numberOptions(); - if (defaultLocalePrivate.exists()) { - // update the cached private + if (defaultLocalePrivate.exists()) // update the cached private *defaultLocalePrivate = locale.d; - } } /*! -- cgit v1.2.3 From efff8ff57a70f6de9a70e2bfda625bef86a9d6b6 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 15 Dec 2019 13:17:39 +0100 Subject: QFileSystemWatcher/win: watch also for attribute changes of directories The windows filesystemwatcher did not watch for attribute changes for directories (e.g. hidden flag) so it was not in sync with other backends. Fix it by adding FILE_NOTIFY_CHANGE_ATTRIBUTES to the watch flags when watching a directory. [ChangeLog][QtCore][QFileSystemWatcher] Fixed a bug that caused QFSW not to watch for attribute changes on Windows. Now it will correctly report when files and directories become hidden or unhidden, for example. Fixes: QTBUG-80545 Change-Id: I31767a0da899963e3940b4f5b36d1d581e6aa57c Reviewed-by: Thiago Macieira Reviewed-by: Friedemann Kleint --- src/corelib/io/qfilesystemwatcher_win.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/corelib') diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 5f91ce5e3d..3b67dd61c7 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -403,6 +403,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath(); const uint flags = isDir ? (FILE_NOTIFY_CHANGE_DIR_NAME + | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_FILE_NAME) : (FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME -- cgit v1.2.3 From 577d698b8e72bc0969ae7545a1a56d3a3d08bdda Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 16 Dec 2019 20:09:25 +0100 Subject: QString::isLower/isUpper: redo the implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use QStringIterator rather than indexed loops. This fixes handling of non-BMP code points (which may be lower or uppercase, see the test). Change also the semantics of the functions, adopting Unicode §3.13 definitions: a string is lowercase/uppercase if it's equal to its own toLower/toUpper folding. As a side effect, empty strings are now correctly reported to be lowercase AND uppercase. [ChangeLog][Important Behavior Changes] The semantics of QString::isLower() and QString::isUpper() have been changed to match the Unicode specification. Now lowercase (resp. uppercase) strings are allowed to contain any character; a string is considered lowercase (resp. uppercase) if it's equal to its own toLower() (resp. toUpper()) folding. Previously, a non-letter character would make the string not lowercase nor uppercase, and the mere presence of an uppercase (resp. lowercase) letter would make isLower() (resp. isUpper()) return false, even if the letter wouldn't change under case folding. As a consequence, now empty strings are lowercase and uppercase. [ChangeLog][QtCore][QString] Fixed a number of bugs of QString::isLower() and QString::isUpper(). Empty strings are now correctly reported to be lowercase (resp. uppercase), and strings containing code points outside the BMP are now correctly handled. Note that the behavior of these functions has also been changed. Change-Id: Iba1398279a072399a9f21295fe75f6e414f3f813 Reviewed-by: Thiago Macieira --- src/corelib/text/qstring.cpp | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index b929786255..fa8b5cf3f8 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -5109,21 +5109,25 @@ bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const } /*! - Returns \c true if the string only contains uppercase letters, - otherwise returns \c false. + Returns \c true if the string is uppercase, that is, it's identical + to its toUpper() folding. + + Note that this does \e not mean that the string does not contain + lowercase letters (some lowercase letters do not have a uppercase + folding; they are left unchanged by toUpper()). + For more information, refer to the Unicode standard, section 3.13. + \since 5.12 - \sa QChar::isUpper(), isLower() + \sa QChar::toUpper(), isLower() */ bool QString::isUpper() const { - if (isEmpty()) - return false; + QStringIterator it(*this); - const QChar *d = data(); - - for (int i = 0, max = size(); i < max; ++i) { - if (!d[i].isUpper()) + while (it.hasNext()) { + uint uc = it.nextUnchecked(); + if (qGetProp(uc)->cases[QUnicodeTables::UpperCase].diff) return false; } @@ -5131,21 +5135,25 @@ bool QString::isUpper() const } /*! - Returns \c true if the string only contains lowercase letters, - otherwise returns \c false. + Returns \c true if the string is lowercase, that is, it's identical + to its toLower() folding. + + Note that this does \e not mean that the string does not contain + uppercase letters (some uppercase letters do not have a lowercase + folding; they are left unchanged by toLower()). + For more information, refer to the Unicode standard, section 3.13. + \since 5.12 - \sa QChar::isLower(), isUpper() + \sa QChar::toLower(), isUpper() */ bool QString::isLower() const { - if (isEmpty()) - return false; + QStringIterator it(*this); - const QChar *d = data(); - - for (int i = 0, max = size(); i < max; ++i) { - if (!d[i].isLower()) + while (it.hasNext()) { + uint uc = it.nextUnchecked(); + if (qGetProp(uc)->cases[QUnicodeTables::LowerCase].diff) return false; } -- cgit v1.2.3 From 2f536411d8d6918a8fed53198190d60fe188b0a4 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 6 Jan 2020 11:51:07 +0100 Subject: QRegularExpression: minor doc fixes Amends d24a1d4323e73400ef4ecca99e03ff0f41c60389 Change-Id: I108f85b174e21ef71bf269fb9f6725972e76f107 Reviewed-by: David Faure --- src/corelib/text/qregularexpression.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 8627cbba4f..67be67c243 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -463,10 +463,10 @@ QT_BEGIN_NAMESPACE \c{\xHHHH} with more than 2 digits. A pattern like \c{\x2022} neeeds to be ported to \c{\x{2022}}, or it will match a space (\c{0x20}) followed by the string \c{"22"}. In general, it is highly recommended to always use - curly braces with the \c{\\x} escape, no matter the amount of digits + curly braces with the \c{\x} escape, no matter the amount of digits specified. - \li A 0-to-n quantification like \c{{,n}} needs to be ported to c{{0,n}} to + \li A 0-to-n quantification like \c{{,n}} needs to be ported to \c{{0,n}} to preserve semantics. Otherwise, a pattern such as \c{\d{,3}} would actually match a digit followed by the exact string \c{"{,3}"}. -- cgit v1.2.3 From 3d1e257770e8c79c7cd9a08f9caf1bd8395cb10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 31 Oct 2019 09:33:40 +0100 Subject: Wasm: Support event loop wakeup from secondary threads Minimal fix for the missing wakeup issue, in leu of a new event loop implementation. So far, emscripten_async_run_in_main_runtime_thread_ looks to be our option for scheduling calls on the main thread. This function is available on emsdk 1.38.22 and higher. Requires making from QEventDispatcherUNIX::wakeUp() non-final. The future event dispatcher implementation will not inherit QEventDispatcherUNIX, so this is a temporary change. Fixes: QTBUG-75793 Task-number: QTBUG-76007 Change-Id: Ie6f6ee6f7674206fc0673a4fe866ac614432ab65 Reviewed-by: Lorn Potter --- src/corelib/kernel/qeventdispatcher_unix_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h index f37edfc967..581df9242c 100644 --- a/src/corelib/kernel/qeventdispatcher_unix_p.h +++ b/src/corelib/kernel/qeventdispatcher_unix_p.h @@ -118,7 +118,7 @@ public: int remainingTime(int timerId) final; - void wakeUp() final; + void wakeUp() override; void interrupt() final; void flush() override; -- cgit v1.2.3 From f936ca4f86e359cb919be9d21ad239618a878559 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 12 Jan 2020 11:32:06 -0800 Subject: qglobal.h: remove non-ASCII quotes from comment Because MSVC warns. Added by me on commit. c496fee2a5b65fd1b0672923293db058486e350e Fixes: QTBUG-81310 Change-Id: I596aec77785a4e4e84d5fffd15e93a8e367e035e Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Edward Welbourne --- src/corelib/global/qglobal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index e636a7cf8f..fe8e8e8bc8 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -945,7 +945,7 @@ QT_WARNING_POP #endif QT_WARNING_PUSH -// warning: noexcept-expression evaluates to ‘false’ because of a call to ‘void swap(..., ...)' +// warning: noexcept-expression evaluates to 'false' because of a call to 'void swap(..., ...)' QT_WARNING_DISABLE_GCC("-Wnoexcept") namespace QtPrivate -- cgit v1.2.3 From 04f6073da2eb9af1d0728aa688c906b682a44801 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 9 Jan 2020 10:35:12 +0100 Subject: ICC compile-fix for __builtin_add_overflow()'s parameter type Based on Glen Johnson's patch, but rearranged to avoid repetition. Fixes: QTBUG-81248 Change-Id: I9c23ab233ebd5514bc05fd155999597ada7295ef Reviewed-by: Thiago Macieira --- src/corelib/global/qnumeric_p.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index fdfcbda6ca..7418579fe0 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -249,7 +249,8 @@ QT_WARNING_POP // size_t. Implementations for 8- and 16-bit types will work but may not be as // efficient. Implementations for 64-bit may be missing on 32-bit platforms. -#if (defined(Q_CC_GNU) && (Q_CC_GNU >= 500) || (defined(Q_CC_INTEL) && !defined(Q_OS_WIN))) || __has_builtin(__builtin_add_overflow) +#if ((defined(Q_CC_INTEL) ? (Q_CC_INTEL >= 1800 && !defined(Q_OS_WIN)) : defined(Q_CC_GNU)) \ + && Q_CC_GNU >= 500) || __has_builtin(__builtin_add_overflow) // GCC 5, ICC 18, and Clang 3.8 have builtins to detect overflows template inline -- cgit v1.2.3 From 9233ffa2d10094faeea05b48c9779ad73942e6a1 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Mon, 13 Jan 2020 11:48:21 +0100 Subject: Doc: Don't document QTextStreamManipulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-81002 Change-Id: Ic7d0516a25a8a6e63e1a305ca87498948d41013c Reviewed-by: Topi Reiniö --- src/corelib/doc/src/dontdocument.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/src/dontdocument.qdoc b/src/corelib/doc/src/dontdocument.qdoc index 19ca7db299..ff0aa98709 100644 --- a/src/corelib/doc/src/dontdocument.qdoc +++ b/src/corelib/doc/src/dontdocument.qdoc @@ -37,5 +37,5 @@ QCborValueRef qfloat16 QDeferredDeleteEvent QSpecialInteger QLittleEndianStorageType QBigEndianStorageType QFactoryInterface QFutureWatcherBase QJsonValuePtr QJsonValueRefPtr QLinkedListNode QAbstractConcatenable QStringBuilderCommon - QTextCodec::ConverterState QThreadStorageData) + QTextCodec::ConverterState QThreadStorageData QTextStreamManipulator) */ -- cgit v1.2.3 From 7b3d0abfa25676c34808e714d4f0cccc6b6bb885 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 3 Dec 2019 15:48:21 +0100 Subject: Do fewer calendrical calculations in QDateTimeParser::setDigit() It was calling a QDate's year(), month() and day() methods, each of which repeats most of the same calendrical calculations; and the same results can be obtained from the calendar's partsFromDate() all in one go. This also reduces the number of local variables needed. Change-Id: I8f84e66a5f677f55cb2113c56ebbdf7c2517e828 Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetimeparser.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 61214b0c7e..2636928e69 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -137,13 +137,12 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const #endif return false; } - const SectionNode &node = sectionNodes.at(index); - const QDate date = v.date(); + QCalendar::YearMonthDay date = calendar.partsFromDate(v.date()); + if (!date.isValid()) + return false; + const QTime time = v.time(); - int year = date.year(calendar); - int month = date.month(calendar); - int day = date.day(calendar); int hour = time.hour(); int minute = time.minute(); int second = time.second(); @@ -152,14 +151,15 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const // Only offset from UTC is amenable to setting an int value: int offset = tspec == Qt::OffsetFromUTC ? v.offsetFromUtc() : 0; + const SectionNode &node = sectionNodes.at(index); switch (node.type) { case Hour24Section: case Hour12Section: hour = newVal; break; case MinuteSection: minute = newVal; break; case SecondSection: second = newVal; break; case MSecSection: msec = newVal; break; case YearSection2Digits: - case YearSection: year = newVal; break; - case MonthSection: month = newVal; break; + case YearSection: date.year = newVal; break; + case MonthSection: date.month = newVal; break; case DaySection: case DayOfWeekSectionShort: case DayOfWeekSectionLong: @@ -169,7 +169,7 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const // to 31 for february should return true return false; } - day = newVal; + date.day = newVal; break; case TimeZoneSection: if (newVal < absoluteMin(index) || newVal > absoluteMax(index)) @@ -185,15 +185,14 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const } if (!(node.type & DaySectionMask)) { - if (day < cachedDay) - day = cachedDay; - const int max = calendar.daysInMonth(month, year); - if (day > max) { - day = max; - } + if (date.day < cachedDay) + date.day = cachedDay; + const int max = calendar.daysInMonth(date.month, date.year); + if (date.day > max) + date.day = max; } - const QDate newDate(year, month, day, calendar); + const QDate newDate = calendar.dateFromParts(date); const QTime newTime(hour, minute, second, msec); if (!newDate.isValid() || !newTime.isValid()) return false; -- cgit v1.2.3 From 7a59d6f138ff8799170cc03d709525ab965d703a Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Wed, 8 Jan 2020 14:46:12 +0100 Subject: Doc: Correct non-link related qdoc compilation errors Task-number: QTBUG-79824 Change-Id: I94dc566c9fb11bc8c598c0d5c043b6f388ebdc80 Reviewed-by: Paul Wicking --- src/corelib/io/qprocess.cpp | 4 +++- src/corelib/itemmodels/qstringlistmodel.cpp | 5 +++++ src/corelib/tools/qline.cpp | 2 +- src/corelib/tools/qscopeguard.qdoc | 8 ++++---- src/corelib/tools/qsharedpointer.cpp | 2 ++ 5 files changed, 15 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 3a77242d7c..49e0847d44 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1004,7 +1004,7 @@ QT_WARNING_POP /*! \internal - Returns true if we emitted readyRead(). + Returns \c true if we emitted readyRead(). */ bool QProcessPrivate::tryReadFromChannel(Channel *channel) { @@ -2187,6 +2187,8 @@ bool QProcess::startDetached(qint64 *pid) This method is an alias for start(), and exists only to fully implement the interface defined by QIODevice. + Returns \c true if the program has been started. + \sa start(), setProgram(), setArguments() */ bool QProcess::open(OpenMode mode) diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index a248cdcd38..4c7616a126 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -212,6 +212,7 @@ Qt::ItemFlags QStringListModel::flags(const QModelIndex &index) const \a index in the model, to the provided \a value. The dataChanged() signal is emitted if the item is changed. + Returns \c true after emitting the dataChanged() signal. \sa Qt::ItemDataRole, data() */ @@ -249,6 +250,8 @@ bool QStringListModel::clearItemData(const QModelIndex &index) specified, indicating that the rows are inserted in the top level of the model. + Returns \c true if the insertion was successful. + \sa QAbstractItemModel::insertRows() */ @@ -275,6 +278,8 @@ bool QStringListModel::insertRows(int row, int count, const QModelIndex &parent) specified, indicating that the rows are removed in the top level of the model. + Returns \c true if the row removal was successful. + \sa QAbstractItemModel::removeRows() */ diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index 3afd23d76b..dde66ed093 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -374,7 +374,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) */ /*! - \enum QLineF::IntersectionType + \enum QLineF::IntersectType Describes the intersection between two lines. diff --git a/src/corelib/tools/qscopeguard.qdoc b/src/corelib/tools/qscopeguard.qdoc index 5a9b7fd210..6b3c942e84 100644 --- a/src/corelib/tools/qscopeguard.qdoc +++ b/src/corelib/tools/qscopeguard.qdoc @@ -51,10 +51,10 @@ QT_BEGIN_NAMESPACE of the scope. \ingroup misc - QScopeGuard is a class which sole purpose is to run a function \e F in - its destructor. This is useful for guaranteeing your cleanup code is - executed, whether the function is exited normally, exited early by a return - statement, or exited by an exception. + QScopeGuard is a class of which the sole purpose is to run the function + \a f in its destructor. This is useful for guaranteeing + your cleanup code is executed, whether the function is exited normally, + exited early by a return statement, or exited by an exception. If \e F is a lambda then you cannot instantiate the template directly, therefore the qScopeGuard() helper is provided and QScopeGuard is made a diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index f185d2f23f..0576fb2bd0 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1285,6 +1285,8 @@ \relates QSharedPointer \since 5.14 + Returns a shared pointer to the pointer held by \a src. + Same as qSharedPointerObjectCast(). This function is provided for STL compatibility. */ -- cgit v1.2.3