diff options
| author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 21:00:55 +0100 |
|---|---|---|
| committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 21:00:55 +0100 |
| commit | dcd5cb973622d059818dba1a2c7b9a7b7601a14c (patch) | |
| tree | fbda1c8c6d36cae42b084f7298cf5b1904e21e9f /src/corelib | |
| parent | f299b565b5904e39a47b6133643448e46810f0ed (diff) | |
| parent | ff68e5d667cc62141f177d01f747a62c95f08d3e (diff) | |
| download | qtbase-dcd5cb973622d059818dba1a2c7b9a7b7601a14c.tar.gz | |
Merge remote-tracking branch 'gerrit/dev' into HEAD
Diffstat (limited to 'src/corelib')
70 files changed, 955 insertions, 426 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 662774b484..8c189e9288 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -242,6 +242,7 @@ QUnifiedTimer *QUnifiedTimer::instance(bool create) inst = unifiedTimer() ? unifiedTimer()->localData() : 0; } #else + Q_UNUSED(create); static QUnifiedTimer unifiedTimer; inst = &unifiedTimer; #endif @@ -576,6 +577,7 @@ QAnimationTimer *QAnimationTimer::instance(bool create) inst = animationTimer() ? animationTimer()->localData() : 0; } #else + Q_UNUSED(create); static QAnimationTimer animationTimer; inst = &animationTimer; #endif diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 6e5b08c295..9fd845bb93 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -269,10 +269,8 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState, QPropertyAnimation *animToStop = 0; { -#ifndef QT_NO_THREAD static QBasicMutex mutex; QMutexLocker locker(&mutex); -#endif typedef QPair<QObject *, QByteArray> QPropertyAnimationPair; typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash; static QPropertyAnimationHash hash; diff --git a/src/corelib/configure.json b/src/corelib/configure.json index f84a13fa50..60248e9cd2 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -305,6 +305,7 @@ "label": "Mimetype handling", "purpose": "Provides MIME type handling.", "section": "Utilities", + "condition": "features.textcodec", "output": [ "publicFeature", "feature" ] }, "system-pcre2": { diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 5871026f95..41ee5a9cef 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -380,14 +380,14 @@ void Widget::fillFunction() void Widget::fromRawDataFunction() { //! [22] - QRegExp pattern; + QRegularExpression pattern("\u00A4"); static const QChar unicode[] = { 0x005A, 0x007F, 0x00A4, 0x0060, 0x1009, 0x0020, 0x0020}; int size = sizeof(unicode) / sizeof(QChar); QString str = QString::fromRawData(unicode, size); - if (str.contains(QRegExp(pattern))) { + if (str.contains(pattern) { // ... //! [22] //! [23] } diff --git a/src/corelib/doc/snippets/qstringlist/main.cpp b/src/corelib/doc/snippets/qstringlist/main.cpp index 7e7d55ca30..4d9c015747 100644 --- a/src/corelib/doc/snippets/qstringlist/main.cpp +++ b/src/corelib/doc/snippets/qstringlist/main.cpp @@ -97,7 +97,7 @@ Widget::Widget(QWidget *parent) //! [6] //! [7] - QStringList monospacedFonts = fonts.filter(QRegExp("Courier|Fixed")); + QStringList monospacedFonts = fonts.filter(QRegularExpression("Courier|Fixed")); //! [7] //! [8] diff --git a/src/corelib/doc/src/filestorage.qdoc b/src/corelib/doc/src/filestorage.qdoc index c6a4a85646..e291ba1375 100644 --- a/src/corelib/doc/src/filestorage.qdoc +++ b/src/corelib/doc/src/filestorage.qdoc @@ -75,7 +75,7 @@ by a Sun SPARC running Solaris. You can also use a data stream to read/write raw unencoded binary data. For more details on the datatypes that QDataStream can serialize, see -{Serializing Qt Data Types}. +\l{Serializing Qt Data Types}. The QTextStream class provides a convenient interface for reading and writing text. QTextStream can operate on a QIODevice, a QByteArray or diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index d23706e631..9ae1e3a4ae 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -11,6 +11,8 @@ HEADERS += \ global/qendian.h \ global/qnumeric_p.h \ global/qnumeric.h \ + global/qfloat16_p.h \ + global/qfloat16.h \ global/qglobalstatic.h \ global/qlibraryinfo.h \ global/qlogging.h \ @@ -29,6 +31,7 @@ SOURCES += \ global/qlibraryinfo.cpp \ global/qmalloc.cpp \ global/qnumeric.cpp \ + global/qfloat16.cpp \ global/qoperatingsystemversion.cpp \ global/qlogging.cpp \ global/qhooks.cpp @@ -76,3 +79,14 @@ gcc:ltcg { } else { SOURCES += $$VERSIONTAGGING_SOURCES } + +QMAKE_QFLOAT16_TABLES_GENERATE = global/qfloat16.h + +qtPrepareTool(QMAKE_QFLOAT16_TABLES, qfloat16-tables) + +qfloat16_tables.commands = $$QMAKE_QFLOAT16_TABLES ${QMAKE_FILE_OUT} +qfloat16_tables.output = global/qfloat16tables.cpp +qfloat16_tables.depends = $$QMAKE_QFLOAT16_TABLES +qfloat16_tables.input = QMAKE_QFLOAT16_TABLES_GENERATE +qfloat16_tables.variable_out = SOURCES +QMAKE_EXTRA_COMPILERS += qfloat16_tables diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 723611e1d8..a9922bb31d 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -996,11 +996,20 @@ #ifdef __cplusplus # include <utility> # if defined(Q_OS_QNX) -// QNX: test if we are using libcpp (Dinkumware-based). -// Older versions (QNX 650) do not support C++11 features +// By default, QNX 7.0 uses libc++ (from LLVM) and +// QNX 6.X uses Dinkumware's libcpp. In all versions, +// it is also possible to use GNU libstdc++. + +// For Dinkumware, some features must be disabled +// (mostly because of library problems). +// Dinkumware is assumed when __GLIBCXX__ (GNU libstdc++) +// and _LIBCPP_VERSION (LLVM libc++) are both absent. +# if !defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) + +// Older versions of libcpp (QNX 650) do not support C++11 features // _HAS_* macros are set to 1 by toolchains that actually include // Dinkum C++11 libcpp. -# if !defined(__GLIBCXX__) + # if !defined(_HAS_CPP0X) || !_HAS_CPP0X // Disable C++11 features that depend on library support # undef Q_COMPILER_INITIALIZER_LISTS @@ -1017,7 +1026,7 @@ // Disable constexpr support on QNX even if the compiler supports it # undef Q_COMPILER_CONSTEXPR # endif // !_HAS_CONSTEXPR -# endif // !__GLIBCXX__ +# endif // !__GLIBCXX__ && !_LIBCPP_VERSION # endif // Q_OS_QNX # if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC) && defined(__GNUC_LIBSTD__) \ && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402) diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index d0e45478cc..d7849d4699 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -83,11 +83,14 @@ #define QT_NO_TRANSLATION #define QT_FEATURE_translation -1 #define QT_NO_GEOM_VARIANT +#define QT_FEATURE_sharedmemory -1 +#define QT_FEATURE_systemsemaphore -1 -#if defined(QT_BUILD_QMAKE) || defined(QT_BUILD_CONFIGURE) +#ifdef QT_BUILD_QMAKE #define QT_FEATURE_commandlineparser -1 #define QT_NO_COMPRESS #define QT_JSON_READONLY +#define QT_NO_STANDARDPATHS #define QT_NO_TEXTCODEC #define QT_FEATURE_textcodec -1 #else @@ -97,8 +100,4 @@ #define QT_FEATURE_textcodec 1 #endif -#if defined(QT_BUILD_QMAKE) -#define QT_NO_STANDARDPATHS -#endif - #endif // QT_BOOTSTRAPPED diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 89a0ae9083..93dbedc930 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -46,8 +46,6 @@ #include <initializer_list> #endif -#include <type_traits> - QT_BEGIN_NAMESPACE class QFlag diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp new file mode 100644 index 0000000000..5264b56104 --- /dev/null +++ b/src/corelib/global/qfloat16.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2016 by Southwest Research Institute (R) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qfloat16_p.h" + +QT_BEGIN_NAMESPACE + +/*! \headerfile <QFloat16> + + This header file provides support for half-precision (16-bit) floating + point data with the class \c qfloat16. It is fully compliant with IEEE + 754 as a storage type. This implies that any arithmetic operation on a + \c qfloat16 instance results in the value first being converted to a + \c float. This conversion to and from \c float is performed by hardware + when possible, but on processors that do not natively support half-precision, + the conversion is performed through a sequence of lookup table operations. + + \c qfloat16 should be treated as if it were a POD (plain old data) type. + Consequently, none of the supported operations need any elaboration beyond + stating that it supports all arithmetic operators incident to floating point + types. + + \since 5.9 +*/ + +Q_STATIC_ASSERT_X(sizeof(float) == sizeof(quint32), + "qfloat16 assumes that floats are 32 bits wide"); +Q_STATIC_ASSERT_X(std::numeric_limits<float>::is_iec559, + "Only works with IEEE 754 floating point"); + +/*! + Returns true if the \c qfloat16 \a {f} is equivalent to infinity. + \relates <QFloat16> + + \sa qIsInf +*/ +Q_REQUIRED_RESULT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW { return qt_is_inf(f); } + +/*! + Returns true if the \c qfloat16 \a {f} is not a number (NaN). + \relates <QFloat16> + + \sa qIsNaN +*/ +Q_REQUIRED_RESULT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW { return qt_is_nan(f); } + +/*! + Returns true if the \c qfloat16 \a {f} is a finite number. + \relates <QFloat16> + + \sa qIsFinite +*/ +Q_REQUIRED_RESULT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW { return qt_is_finite(f); } + +/*! \fn int qRound(qfloat16 value) + \relates <QFloat16> + + Rounds \a value to the nearest integer. + + \sa qRound +*/ + +/*! \fn qint64 qRound64(qfloat16 value) + \relates <QFloat16> + + Rounds \a value to the nearest 64-bit integer. + + \sa qRound64 +*/ + +/*! \fn bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) + \relates <QFloat16> + + Compares the floating point value \a p1 and \a p2 and + returns \c true if they are considered equal, otherwise \c false. + + The two numbers are compared in a relative way, where the + exactness is stronger the smaller the numbers are. + */ + +QT_END_NAMESPACE diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h new file mode 100644 index 0000000000..5059108fb8 --- /dev/null +++ b/src/corelib/global/qfloat16.h @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2016 by Southwest Research Institute (R) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFLOAT16_H +#define QFLOAT16_H + +#include <QtCore/qglobal.h> +#include <QtCore/qmetatype.h> +#include <string.h> + +QT_BEGIN_NAMESPACE + +#if 0 +#pragma qt_class(QFloat16) +#endif + +class qfloat16 +{ +public: +#ifndef Q_QDOC + Q_DECL_CONSTEXPR inline qfloat16() Q_DECL_NOTHROW : b16(0) { } + inline qfloat16(float f) Q_DECL_NOTHROW; + inline operator float() const Q_DECL_NOTHROW; + inline operator double() const Q_DECL_NOTHROW; + inline operator long double() const Q_DECL_NOTHROW; +#endif + +private: + quint16 b16; + + Q_CORE_EXPORT static const quint32 mantissatable[]; + Q_CORE_EXPORT static const quint32 exponenttable[]; + Q_CORE_EXPORT static const quint32 offsettable[]; + Q_CORE_EXPORT static const quint32 basetable[]; + Q_CORE_EXPORT static const quint32 shifttable[]; + + friend bool qIsNull(qfloat16 f) Q_DECL_NOTHROW; + friend qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW; +}; + +Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE); + +Q_CORE_EXPORT Q_REQUIRED_RESULT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h +Q_CORE_EXPORT Q_REQUIRED_RESULT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h +Q_CORE_EXPORT Q_REQUIRED_RESULT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h + +// The remainder of these utility functions complement qglobal.h +inline Q_REQUIRED_RESULT int qRound(qfloat16 d) Q_DECL_NOTHROW +{ return qRound(static_cast<float>(d)); } + +inline Q_REQUIRED_RESULT qint64 qRound64(qfloat16 d) Q_DECL_NOTHROW +{ return qRound64(static_cast<float>(d)); } + +inline Q_REQUIRED_RESULT bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) Q_DECL_NOTHROW +{ + float f1 = static_cast<float>(p1); + float f2 = static_cast<float>(p2); + // The significand precision for IEEE754 half precision is + // 11 bits (10 explicitly stored), or approximately 3 decimal + // digits. In selecting the fuzzy comparison factor of 102.5f + // (that is, (2^10+1)/10) below, we effectively select a + // window of about 1 (least significant) decimal digit about + // which the two operands can vary and still return true. + return (qAbs(f1 - f2) * 102.5f <= qMin(qAbs(f1), qAbs(f2))); +} + +inline Q_REQUIRED_RESULT bool qIsNull(qfloat16 f) Q_DECL_NOTHROW +{ + return (f.b16 & static_cast<quint16>(0x7fff)) == 0; +} + +inline int qIntCast(qfloat16 f) Q_DECL_NOTHROW +{ return int(static_cast<float>(f)); } + +inline qfloat16::qfloat16(float f) Q_DECL_NOTHROW +{ + quint32 u; + memcpy(&u, &f, sizeof(quint32)); + b16 = basetable[(u >> 23) & 0x1ff] + + ((u & 0x007fffff) >> shifttable[(u >> 23) & 0x1ff]); +} + +inline qfloat16::operator float() const Q_DECL_NOTHROW +{ + quint32 u = mantissatable[offsettable[b16 >> 10] + (b16 & 0x3ff)] + + exponenttable[b16 >> 10]; + float f; + memcpy(&f, &u, sizeof(quint32)); + return f; +} + +inline qfloat16::operator double() const Q_DECL_NOTHROW +{ + return static_cast<double>(float(*this)); +} + +inline qfloat16::operator long double() const Q_DECL_NOTHROW +{ + return static_cast<long double>(float(*this)); +} + +inline qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW +{ + qfloat16 f; + f.b16 = a.b16 ^ quint16(0x8000); + return f; +} + +inline qfloat16 operator+(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) + static_cast<float>(b)); } +inline qfloat16 operator-(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) - static_cast<float>(b)); } +inline qfloat16 operator*(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) * static_cast<float>(b)); } +inline qfloat16 operator/(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) / static_cast<float>(b)); } + +#define QF16_MAKE_ARITH_OP_FP(FP, OP) \ + inline FP operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast<FP>(lhs) OP rhs; } \ + inline FP operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<FP>(rhs); } +#define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP) \ + inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) Q_DECL_NOTHROW { lhs = qfloat16(static_cast<FP>(lhs) OP rhs); return lhs; } +#define QF16_MAKE_ARITH_OP(FP) \ + QF16_MAKE_ARITH_OP_FP(FP, +) \ + QF16_MAKE_ARITH_OP_FP(FP, -) \ + QF16_MAKE_ARITH_OP_FP(FP, *) \ + QF16_MAKE_ARITH_OP_FP(FP, /) \ + QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \ + QF16_MAKE_ARITH_OP_EQ_FP(FP, -=, -) \ + QF16_MAKE_ARITH_OP_EQ_FP(FP, *=, *) \ + QF16_MAKE_ARITH_OP_EQ_FP(FP, /=, /) +QF16_MAKE_ARITH_OP(long double) +QF16_MAKE_ARITH_OP(double) +QF16_MAKE_ARITH_OP(float) +#undef QF16_MAKE_ARITH_OP +#undef QF16_MAKE_ARITH_OP_FP + +#define QF16_MAKE_ARITH_OP_INT(OP) \ + inline double operator OP(qfloat16 lhs, int rhs) Q_DECL_NOTHROW { return static_cast<double>(lhs) OP rhs; } \ + inline double operator OP(int lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<double>(rhs); } +QF16_MAKE_ARITH_OP_INT(+) +QF16_MAKE_ARITH_OP_INT(-) +QF16_MAKE_ARITH_OP_INT(*) +QF16_MAKE_ARITH_OP_INT(/) +#undef QF16_MAKE_ARITH_OP_INT + +inline bool operator>(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) > static_cast<float>(b); } +inline bool operator<(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) < static_cast<float>(b); } +inline bool operator>=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) >= static_cast<float>(b); } +inline bool operator<=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) <= static_cast<float>(b); } +inline bool operator==(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) == static_cast<float>(b); } +inline bool operator!=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) != static_cast<float>(b); } + +#define QF16_MAKE_BOOL_OP_FP(FP, OP) \ + inline bool operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast<FP>(lhs) OP rhs; } \ + inline bool operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<FP>(rhs); } +#define QF16_MAKE_BOOL_OP(FP) \ + QF16_MAKE_BOOL_OP_FP(FP, <) \ + QF16_MAKE_BOOL_OP_FP(FP, >) \ + QF16_MAKE_BOOL_OP_FP(FP, >=) \ + QF16_MAKE_BOOL_OP_FP(FP, <=) \ + QF16_MAKE_BOOL_OP_FP(FP, ==) \ + QF16_MAKE_BOOL_OP_FP(FP, !=) +QF16_MAKE_BOOL_OP(long double) +QF16_MAKE_BOOL_OP(double) +QF16_MAKE_BOOL_OP(float) +#undef QF16_MAKE_BOOL_OP +#undef QF16_MAKE_BOOL_OP_FP + +#define QF16_MAKE_BOOL_OP_INT(OP) \ + inline bool operator OP(qfloat16 a, int b) Q_DECL_NOTHROW { return static_cast<float>(a) OP b; } \ + inline bool operator OP(int a, qfloat16 b) Q_DECL_NOTHROW { return a OP static_cast<float>(b); } +QF16_MAKE_BOOL_OP_INT(>) +QF16_MAKE_BOOL_OP_INT(<) +QF16_MAKE_BOOL_OP_INT(>=) +QF16_MAKE_BOOL_OP_INT(<=) +QF16_MAKE_BOOL_OP_INT(==) +QF16_MAKE_BOOL_OP_INT(!=) +#undef QF16_MAKE_BOOL_OP_INT + +/*! + \internal +*/ +inline Q_REQUIRED_RESULT bool qFuzzyIsNull(qfloat16 f) Q_DECL_NOTHROW +{ + return qAbs(static_cast<float>(f)) <= 0.001f; +} + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(qfloat16) + +#endif // QFLOAT16_H diff --git a/src/corelib/global/qfloat16_p.h b/src/corelib/global/qfloat16_p.h new file mode 100644 index 0000000000..ae52e64435 --- /dev/null +++ b/src/corelib/global/qfloat16_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 by Southwest Research Institute (R) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFLOAT16_P_H +#define QFLOAT16_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qfloat16.h> +#include <QtCore/qsysinfo.h> + +QT_BEGIN_NAMESPACE + +static inline bool qt_is_inf(qfloat16 d) Q_DECL_NOTHROW +{ + bool is_inf; + uchar *ch = (uchar *)&d; + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) + is_inf = (ch[0] & 0x7c) == 0x7c; + else + is_inf = (ch[1] & 0x7c) == 0x7c; + return is_inf; +} + +static inline bool qt_is_nan(qfloat16 d) Q_DECL_NOTHROW +{ + bool is_nan; + uchar *ch = (uchar *)&d; + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) + is_nan = (ch[0] & 0x7c) == 0x7c && (ch[0] & 0x02) != 0; + else + is_nan = (ch[1] & 0x7c) == 0x7c && (ch[1] & 0x02) != 0; + return is_nan; +} + +static inline bool qt_is_finite(qfloat16 d) Q_DECL_NOTHROW +{ + bool is_finite; + uchar *ch = (uchar *)&d; + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) + is_finite = (ch[0] & 0x7c) != 0x7c; + else + is_finite = (ch[1] & 0x7c) != 0x7c; + return is_finite; +} + + +QT_END_NAMESPACE + +#endif // QFLOAT16_P_H diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index b34e8ec659..010f2c18c4 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1516,6 +1516,13 @@ bool qSharedBuild() Q_DECL_NOTHROW */ /*! + \macro Q_CC_CLANG + \relates <QtGlobal> + + Defined if the application is compiled using Clang. +*/ + +/*! \macro Q_CC_BOR \relates <QtGlobal> diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index a020be7fb2..9ac29acd16 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -44,7 +44,6 @@ #ifdef __cplusplus # include <type_traits> # include <cstddef> -# include <type_traits> # include <utility> #endif @@ -83,7 +82,7 @@ 1: The feature is available */ #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1) -#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not vailable.") +#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.") #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) # define QT_NO_UNSHARABLE_CONTAINERS diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 87ee75fa45..03ee0730db 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -41,18 +41,15 @@ #include "qdir.h" #include "qstringlist.h" #include "qfile.h" -#include "qtemporaryfile.h" #include "qsettings.h" #include "qlibraryinfo.h" #include "qscopedpointer.h" #ifdef QT_BUILD_QMAKE QT_BEGIN_NAMESPACE -extern QString qmake_absoluteLocation(); extern QString qmake_libraryInfoFile(); QT_END_NAMESPACE #else -# include "qconfig.cpp" # include "qcoreapplication.h" #endif @@ -60,6 +57,10 @@ QT_END_NAMESPACE # include "private/qcore_mac_p.h" #endif +#ifndef QT_BUILD_QMAKE_BOOTSTRAP +# include "qconfig.cpp" +#endif + #include "archdetect.cpp" QT_BEGIN_NAMESPACE @@ -72,16 +73,9 @@ struct QLibrarySettings { QLibrarySettings(); void load(); -#ifdef QT_BUILD_QMAKE - void loadBuiltinValues(QSettings *config); -#endif QScopedPointer<QSettings> settings; #ifdef QT_BUILD_QMAKE - QString builtinValues[QLibraryInfo::LastHostPath + 1]; -# ifndef Q_OS_WIN - QString builtinSettingsPath; -# endif bool haveDevicePaths; bool haveEffectiveSourcePaths; bool haveEffectivePaths; @@ -113,25 +107,6 @@ public: ? ls->haveDevicePaths : ls->havePaths) : false; } - static bool sysrootify() - { - // This is actually bogus, as it does not consider post-configure settings. - QLibrarySettings *ls = qt_library_settings(); - return ls ? (!ls->builtinValues[QLibraryInfo::SysrootPath].isEmpty() - && ls->builtinValues[QLibraryInfo::ExtPrefixPath].isEmpty()) : false; - } - static QString builtinValue(int loc) - { - QLibrarySettings *ls = qt_library_settings(); - return ls ? ls->builtinValues[loc] : QString(); - } -# ifndef Q_OS_WIN - static QString builtinSettingsPath() - { - QLibrarySettings *ls = qt_library_settings(); - return ls ? ls->builtinSettingsPath : QString(); - } -# endif #endif static QSettings *configuration() { @@ -155,20 +130,6 @@ QLibrarySettings::QLibrarySettings() load(); } -#ifdef QT_BUILD_QMAKE -static QByteArray qtconfSeparator() -{ -# ifdef Q_OS_WIN - QByteArray header = QByteArrayLiteral("\r\n===========================================================\r\n"); -# else - QByteArray header = QByteArrayLiteral("\n===========================================================\n"); -# endif - QByteArray content = QByteArrayLiteral("==================== qt.conf beginning ===================="); - // Assemble from pieces to avoid that the string appears in a raw executable - return header + content + header; -} -#endif - void QLibrarySettings::load() { // If we get any settings here, those won't change when the application shows up. @@ -206,27 +167,6 @@ void QLibrarySettings::load() havePaths = false; #endif } - -#ifdef QT_BUILD_QMAKE - // Try to use an embedded qt.conf appended to the QMake executable. - QFile qmakeFile(qmake_absoluteLocation()); - if (!qmakeFile.open(QIODevice::ReadOnly)) - return; - qmakeFile.seek(qmakeFile.size() - 10000); - QByteArray tail = qmakeFile.read(10000); - QByteArray separator = qtconfSeparator(); - int qtconfOffset = tail.lastIndexOf(separator); - if (qtconfOffset < 0) - return; - tail.remove(0, qtconfOffset + separator.size()); - // If QSettings had a c'tor taking a QIODevice, we'd pass a QBuffer ... - QTemporaryFile tmpFile; - tmpFile.open(); - tmpFile.write(tail); - tmpFile.close(); - QSettings builtinSettings(tmpFile.fileName(), QSettings::IniFormat); - loadBuiltinValues(&builtinSettings); -#endif } QSettings *QLibraryInfoPrivate::findConfiguration() @@ -483,29 +423,17 @@ static const struct { { "Tests", "tests" }, #ifdef QT_BUILD_QMAKE { "Sysroot", "" }, + { "SysrootifyPrefix", "" }, { "HostBinaries", "bin" }, { "HostLibraries", "lib" }, { "HostData", "." }, { "TargetSpec", "" }, { "HostSpec", "" }, - { "ExtPrefix", "" }, { "HostPrefix", "" }, #endif }; #ifdef QT_BUILD_QMAKE -void QLibrarySettings::loadBuiltinValues(QSettings *config) -{ - config->beginGroup(QLatin1String("Paths")); - for (int i = 0; i <= QLibraryInfo::LastHostPath; i++) - builtinValues[i] = config->value(QLatin1String(qtConfEntries[i].key), - QLatin1String(qtConfEntries[i].value)).toString(); -# ifndef Q_OS_WIN - builtinSettingsPath = config->value(QLatin1String("Settings")).toString(); -# endif - config->endGroup(); -} - void QLibraryInfo::reload() { QLibraryInfoPrivate::reload(); @@ -522,13 +450,17 @@ QLibraryInfo::location(LibraryLocation loc) QString ret = rawLocation(loc, FinalPaths); // Automatically prepend the sysroot to target paths - if ((loc < SysrootPath || loc > LastHostPath) && QLibraryInfoPrivate::sysrootify()) { + if (loc < SysrootPath || loc > LastHostPath) { QString sysroot = rawLocation(SysrootPath, FinalPaths); - if (!sysroot.isEmpty() && ret.length() > 2 && ret.at(1) == QLatin1Char(':') - && (ret.at(2) == QLatin1Char('/') || ret.at(2) == QLatin1Char('\\'))) - ret.replace(0, 2, sysroot); // Strip out the drive on Windows targets - else - ret.prepend(sysroot); + if (!sysroot.isEmpty() + && QVariant::fromValue(rawLocation(SysrootifyPrefixPath, FinalPaths)).toBool()) { + if (ret.length() > 2 && ret.at(1) == QLatin1Char(':') + && (ret.at(2) == QLatin1Char('/') || ret.at(2) == QLatin1Char('\\'))) { + ret.replace(0, 2, sysroot); // Strip out the drive on Windows targets + } else { + ret.prepend(sysroot); + } + } } return ret; @@ -591,21 +523,31 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) if (loc == HostPrefixPath) ret = config->value(QLatin1String(qtConfEntries[PrefixPath].key), QLatin1String(qtConfEntries[PrefixPath].value)).toString(); - else if (loc == TargetSpecPath || loc == HostSpecPath) + else if (loc == TargetSpecPath || loc == HostSpecPath || loc == SysrootifyPrefixPath) fromConf = false; // The last case here is SysrootPath, which can be legitimately empty. // All other keys have non-empty fallbacks to start with. } #endif - // expand environment variables in the form $(ENVVAR) - int rep; - QRegExp reg_var(QLatin1String("\\$\\(.*\\)")); - reg_var.setMinimal(true); - while((rep = reg_var.indexIn(ret)) != -1) { - ret.replace(rep, reg_var.matchedLength(), - QString::fromLocal8Bit(qgetenv(ret.midRef(rep + 2, - reg_var.matchedLength() - 3).toLatin1().constData()).constData())); + int startIndex = 0; + forever { + startIndex = ret.indexOf(QLatin1Char('$'), startIndex); + if (startIndex < 0) + break; + if (ret.length() < startIndex + 3) + break; + if (ret.at(startIndex + 1) != QLatin1Char('(')) { + startIndex++; + continue; + } + int endIndex = ret.indexOf(QLatin1Char(')'), startIndex + 2); + if (endIndex < 0) + break; + QStringRef envVarName = ret.midRef(startIndex + 2, endIndex - startIndex - 2); + QString value = QString::fromLocal8Bit(qgetenv(envVarName.toLocal8Bit().constData())); + ret.replace(startIndex, endIndex - startIndex + 1, value); + startIndex += value.length(); } config->endGroup(); @@ -615,38 +557,36 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) } #endif // QT_NO_SETTINGS +#ifndef QT_BUILD_QMAKE_BOOTSTRAP if (!fromConf) { -#ifdef QT_BUILD_QMAKE - if ((unsigned)loc <= (unsigned)LastHostPath) { - if (loc == PrefixPath && group != DevicePaths) - ret = QLibraryInfoPrivate::builtinValue(ExtPrefixPath); - else - ret = QLibraryInfoPrivate::builtinValue(loc); -# ifndef Q_OS_WIN // On Windows we use the registry - } else if (loc == SettingsPath) { - ret = QLibraryInfoPrivate::builtinSettingsPath(); -# endif - } -#else // QT_BUILD_QMAKE const char * volatile path = 0; if (loc == PrefixPath) { - path = QT_CONFIGURE_PREFIX_PATH; + path = +# ifdef QT_BUILD_QMAKE + (group != DevicePaths) ? + QT_CONFIGURE_EXT_PREFIX_PATH : +# endif + QT_CONFIGURE_PREFIX_PATH; } else if (unsigned(loc) <= sizeof(qt_configure_str_offsets)/sizeof(qt_configure_str_offsets[0])) { path = qt_configure_strs + qt_configure_str_offsets[loc - 1]; #ifndef Q_OS_WIN // On Windows we use the registry } else if (loc == SettingsPath) { path = QT_CONFIGURE_SETTINGS_PATH; #endif +# ifdef QT_BUILD_QMAKE + } else if (loc == HostPrefixPath) { + path = QT_CONFIGURE_HOST_PREFIX_PATH; +# endif } if (path) ret = QString::fromLocal8Bit(path); -#endif } +#endif #ifdef QT_BUILD_QMAKE - // The specs need to be returned verbatim. - if (loc == TargetSpecPath || loc == HostSpecPath) + // These values aren't actually paths and thus need to be returned verbatim. + if (loc == TargetSpecPath || loc == HostSpecPath || loc == SysrootifyPrefixPath) return ret; #endif diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 9d794ce1da..809813d99d 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -91,12 +91,12 @@ public: #ifdef QT_BUILD_QMAKE // These are not subject to binary compatibility constraints SysrootPath, + SysrootifyPrefixPath, HostBinariesPath, HostLibrariesPath, HostDataPath, TargetSpecPath, HostSpecPath, - ExtPrefixPath, HostPrefixPath, LastHostPath = HostPrefixPath, #endif diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index dfecc3e2d3..af485a1832 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -123,16 +123,14 @@ \value AA_PluginApplication Indicates that Qt is used to author a plugin. Depending on the operating system, it suppresses specific initializations that do not necessarily make sense in the plugin case. - For example on OS X, this includes avoiding loading our nib for the main menu and not taking possession of the native menu bar. Setting this attribute to true will also set the AA_DontUseNativeMenuBar attribute to true. It also disables native event filters. - This attribute has been added in Qt 5.7. It must be set before \l {QGuiApplication}{Q(Gui)Application} is constructed. - \value AA_MacPluginApplication This attribute has been deprecated. + \value AA_MacPluginApplication This attribute has been deprecated. Use AA_PluginApplication instead. \value AA_DontUseNativeMenuBar All menubars created while this attribute is @@ -166,7 +164,6 @@ \value AA_UseHighDpiPixmaps Make QIcon::pixmap() generate high-dpi pixmaps that can be larger than the requested size. Such pixmaps will have \l {QPixmap::devicePixelRatio}{devicePixelRatio()} set to a value higher than 1. - After setting this attribute, application code that uses pixmap sizes in layout geometry calculations should typically divide by \l {QPixmap::devicePixelRatio}{devicePixelRatio()} to get device-independent layout geometry. @@ -2660,7 +2657,7 @@ \value FontRole The font used for items rendered with the default delegate. (QFont) \value TextAlignmentRole The alignment of the text for items rendered with the - default delegate. (Qt::AlignmentFlag) + default delegate. (Qt::Alignment) \value BackgroundRole The background brush used for items rendered with the default delegate. (QBrush) \value BackgroundColorRole This role is obsolete. Use BackgroundRole instead. diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 01b8772ee1..62add95533 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -174,7 +174,7 @@ static inline bool qt_is_finite(float f) // Unsigned overflow math // namespace { -template <typename T> inline typename QtPrivate::QEnableIf<std::is_unsigned<T>::value, bool>::Type +template <typename T> inline typename std::enable_if<std::is_unsigned<T>::value, bool>::type add_overflow(T v1, T v2, T *r) { // unsigned additions are well-defined @@ -182,7 +182,7 @@ add_overflow(T v1, T v2, T *r) return v1 > T(v1 + v2); } -template <typename T> inline typename QtPrivate::QEnableIf<std::is_unsigned<T>::value, bool>::Type +template <typename T> inline typename std::enable_if<std::is_unsigned<T>::value, bool>::type mul_overflow(T v1, T v2, T *r) { // use the next biggest type diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index 9fb3473ed3..ed11e013f2 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -234,9 +234,6 @@ # if defined(_MIPS_ARCH_MIPS2) || (defined(__mips) && __mips - 0 >= 2) # define Q_PROCESSOR_MIPS_II # endif -# if defined(_MIPS_ARCH_MIPS32) || defined(__mips32) -# define Q_PROCESSOR_MIPS_32 -# endif # if defined(_MIPS_ARCH_MIPS3) || (defined(__mips) && __mips - 0 >= 3) # define Q_PROCESSOR_MIPS_III # endif @@ -246,6 +243,9 @@ # if defined(_MIPS_ARCH_MIPS5) || (defined(__mips) && __mips - 0 >= 5) # define Q_PROCESSOR_MIPS_V # endif +# if defined(_MIPS_ARCH_MIPS32) || defined(__mips32) || (defined(__mips) && __mips - 0 >= 32) +# define Q_PROCESSOR_MIPS_32 +# endif # if defined(_MIPS_ARCH_MIPS64) || defined(__mips64) # define Q_PROCESSOR_MIPS_64 # define Q_PROCESSOR_WORDSIZE 8 diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 8aa5cb4fb4..53f6b3fff6 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -124,7 +124,7 @@ struct QTypeInfoQuery : public QTypeInfo<T> // if QTypeInfo<T>::isRelocatable exists, use it template <typename T> -struct QTypeInfoQuery<T, typename QtPrivate::QEnableIf<QTypeInfo<T>::isRelocatable || true>::Type> : public QTypeInfo<T> +struct QTypeInfoQuery<T, typename std::enable_if<QTypeInfo<T>::isRelocatable || true>::type> : public QTypeInfo<T> {}; /*! diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 2730fd7f11..2369fe4726 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -42,6 +42,7 @@ #if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) #include "qbuffer.h" +#include "qfloat16.h" #include "qstring.h" #include <stdio.h> #include <ctype.h> @@ -448,6 +449,9 @@ QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const The default is DoublePrecision. + Note that this property does not affect the serialization or deserialization of \c qfloat16 + instances. + \warning This property must be set to the same value on the object that writes and the object that reads the data stream. @@ -973,6 +977,20 @@ QDataStream &QDataStream::operator>>(double &f) /*! \overload + \since 5.9 + + Reads a floating point number from the stream into \a f, + using the standard IEEE 754 format. Returns a reference to the + stream. +*/ +QDataStream &QDataStream::operator>>(qfloat16 &f) +{ + return *this >> reinterpret_cast<qint16&>(f); +} + + +/*! + \overload Reads the '\\0'-terminated string \a s from the stream and returns a reference to the stream. @@ -1260,6 +1278,19 @@ QDataStream &QDataStream::operator<<(double f) /*! + \fn QDataStream &QDataStream::operator<<(qfloat16 f) + \overload + \since 5.9 + + Writes a floating point number, \a f, to the stream using + the standard IEEE 754 format. Returns a reference to the stream. +*/ +QDataStream &QDataStream::operator<<(qfloat16 f) +{ + return *this << reinterpret_cast<qint16&>(f); +} + +/*! \overload Writes the '\\0'-terminated string \a s to the stream and returns a @@ -1282,7 +1313,6 @@ QDataStream &QDataStream::operator<<(const char *s) return *this; } - /*! Writes the length specifier \a len and the buffer \a s to the stream and returns a reference to the stream. diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h index 994ed88791..ecd55f71ae 100644 --- a/src/corelib/io/qdatastream.h +++ b/src/corelib/io/qdatastream.h @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE - +class qfloat16; class QByteArray; class QIODevice; @@ -154,6 +154,7 @@ public: QDataStream &operator>>(quint64 &i); QDataStream &operator>>(bool &i); + QDataStream &operator>>(qfloat16 &f); QDataStream &operator>>(float &f); QDataStream &operator>>(double &f); QDataStream &operator>>(char *&str); @@ -167,6 +168,7 @@ public: QDataStream &operator<<(qint64 i); QDataStream &operator<<(quint64 i); QDataStream &operator<<(bool i); + QDataStream &operator<<(qfloat16 f); QDataStream &operator<<(float f); QDataStream &operator<<(double f); QDataStream &operator<<(const char *str); diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index abc2abeaec..61059dd694 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -365,7 +365,7 @@ Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, int value, const QMetaO Q_CORE_EXPORT QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value, const QMetaObject *meta, const char *name); template<typename T> -typename QtPrivate::QEnableIf<QtPrivate::IsQEnumHelper<T>::Value, QDebug>::Type +typename std::enable_if<QtPrivate::IsQEnumHelper<T>::Value, QDebug>::type operator<<(QDebug dbg, T value) { const QMetaObject *obj = qt_getEnumMetaObject(value); @@ -374,9 +374,9 @@ operator<<(QDebug dbg, T value) } template <class T> -inline typename QtPrivate::QEnableIf< +inline typename std::enable_if< QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<QFlags<T> >::Value, - QDebug>::Type + QDebug>::type qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) { const QMetaObject *obj = qt_getEnumMetaObject(T()); @@ -385,9 +385,9 @@ qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) } template <class T> -inline typename QtPrivate::QEnableIf< +inline typename std::enable_if< !QtPrivate::IsQEnumHelper<T>::Value && !QtPrivate::IsQEnumHelper<QFlags<T> >::Value, - QDebug>::Type + QDebug>::type qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) #else // !QT_NO_QOBJECT && !Q_QDOC template <class T> @@ -402,7 +402,7 @@ template<typename T> inline QDebug operator<<(QDebug debug, const QFlags<T> &flags) { // We have to use an indirection otherwise specialisation of some other overload of the - // operator<< the compiler would try to instantiate QFlags<T> for the QEnableIf + // operator<< the compiler would try to instantiate QFlags<T> for the std::enable_if return qt_QMetaEnum_flagDebugOperator_helper(debug, flags); } diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index b2e3df79b8..ca5af924e9 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -629,7 +629,7 @@ QString QFSFileEngine::fileName(FileName file) const bool QFSFileEngine::isRelativePath() const { Q_D(const QFSFileEngine); - return d->fileEntry.filePath().length() ? d->fileEntry.filePath()[0] != QLatin1Char('/') : true; + return d->fileEntry.filePath().length() ? d->fileEntry.filePath().at(0) != QLatin1Char('/') : true; } uint QFSFileEngine::ownerId(FileOwner own) const diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp index ae3a7c6abc..cb1ff93ad3 100644 --- a/src/corelib/io/qlockfile.cpp +++ b/src/corelib/io/qlockfile.cpp @@ -84,6 +84,9 @@ QT_BEGIN_NAMESPACE For the use case of protecting a resource over a long time, you should therefore call setStaleLockTime(0), and when tryLock() returns LockFailedError, inform the user that the document is locked, possibly using getLockInfo() for more details. + + \note On Windows, this class has problems detecting a stale lock if the + machine's hostname contains characters outside the US-ASCII character set. */ /*! diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index 82beb15912..3a80014c00 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -81,15 +81,6 @@ QT_BEGIN_NAMESPACE -static QByteArray localHostName() // from QHostInfo::localHostName(), modified to return a QByteArray -{ - QByteArray hostName(512, Qt::Uninitialized); - if (gethostname(hostName.data(), hostName.size()) == -1) - return QByteArray(); - hostName.truncate(strlen(hostName.data())); - return hostName; -} - // ### merge into qt_safe_write? static qint64 qt_write_loop(int fd, const char *data, qint64 len) { @@ -185,7 +176,7 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() // Use operator% from the fast builder to avoid multiple memory allocations. QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) % '\n' % QCoreApplication::applicationName().toUtf8() % '\n' - % localHostName() % '\n'; + % QSysInfo::machineHostName().toUtf8() % '\n'; const QByteArray lockFileName = QFile::encodeName(fileName); const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0666); @@ -242,7 +233,7 @@ bool QLockFilePrivate::isApparentlyStale() const qint64 pid; QString hostname, appname; if (getLockInfo(&pid, &hostname, &appname)) { - if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) { + if (hostname.isEmpty() || hostname == QSysInfo::machineHostName()) { if (::kill(pid, 0) == -1 && errno == ESRCH) return true; // PID doesn't exist anymore const QString processName = processNameByPid(pid); diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index f2c2ba4476..c27484acbe 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -513,6 +513,9 @@ void QProcessPrivate::Channel::clear() You can also call error() to find the type of error that occurred last, and state() to find the current process state. + \note QProcess is not supported on VxWorks, iOS, tvOS, watchOS, + or the Universal Windows Platform. + \section1 Communicating via Channels Processes have two predefined output channels: The standard diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 1a69891d3b..16dab38a60 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1494,7 +1494,7 @@ void QConfFileSettingsPrivate::syncConfFile(QConfFile *confFile) ensureAllSectionsParsed(confFile); ParsedSettingsMap mergedKeys = confFile->mergedKeyMap(); -#ifndef QT_BOOTSTRAPPED +#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(temporaryfile) QSaveFile sf(confFile->name); #else QFile sf(confFile->name); @@ -1522,7 +1522,7 @@ void QConfFileSettingsPrivate::syncConfFile(QConfFile *confFile) ok = writeFunc(sf, tempOriginalKeys); } -#ifndef QT_BOOTSTRAPPED +#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(temporaryfile) if (ok) ok = sf.commit(); #endif diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index c224b032aa..a6372b75f6 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -240,7 +240,7 @@ Only valid if RemovePath is not set. \value PreferLocalFile If the URL is a local file according to isLocalFile() and contains no query or fragment, a local file path is returned. - \value StripTrailingSlash The trailing slash is removed if one is present. + \value StripTrailingSlash The trailing slash is removed from the path, if one is present. \value NormalizePathSegments Modifies the path to remove redundant directory separators, and to resolve "."s and ".."s (as far as possible). diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp index e537793146..7c306799d0 100644 --- a/src/corelib/itemmodels/qidentityproxymodel.cpp +++ b/src/corelib/itemmodels/qidentityproxymodel.cpp @@ -496,15 +496,6 @@ void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPe { Q_Q(QIdentityProxyModel); - const auto proxyPersistentIndexes = q->persistentIndexList(); - for (const QPersistentModelIndex &proxyPersistentIndex : proxyPersistentIndexes) { - proxyIndexes << proxyPersistentIndex; - Q_ASSERT(proxyPersistentIndex.isValid()); - const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); - Q_ASSERT(srcPersistentIndex.isValid()); - layoutChangePersistentIndexes << srcPersistentIndex; - } - QList<QPersistentModelIndex> parents; parents.reserve(sourceParents.size()); for (const QPersistentModelIndex &parent : sourceParents) { @@ -518,6 +509,15 @@ void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPe } q->layoutAboutToBeChanged(parents, hint); + + const auto proxyPersistentIndexes = q->persistentIndexList(); + for (const QPersistentModelIndex &proxyPersistentIndex : proxyPersistentIndexes) { + proxyIndexes << proxyPersistentIndex; + Q_ASSERT(proxyPersistentIndex.isValid()); + const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); + Q_ASSERT(srcPersistentIndex.isValid()); + layoutChangePersistentIndexes << srcPersistentIndex; + } } void QIdentityProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint) diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 92c459a243..2421610bce 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -228,6 +228,24 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags) // dummy implentation of qHash() necessary for instantiating QList<QItemSelectionRange>::toSet() with MSVC inline uint qHash(const QItemSelectionRange &) { return 0; } +#ifdef Q_CC_MSVC + +/* + ### Qt 6: + ### This needs to be removed for next releases of Qt. It is a workaround for vc++ because + ### Qt exports QItemSelection that inherits QList<QItemSelectionRange>. +*/ + +# ifndef Q_TEMPLATE_EXTERN +# if defined(QT_BUILD_CORE_LIB) +# define Q_TEMPLATE_EXTERN +# else +# define Q_TEMPLATE_EXTERN extern +# endif +# endif +Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QList<QItemSelectionRange>; +#endif // Q_CC_MSVC + class Q_CORE_EXPORT QItemSelection : public QList<QItemSelectionRange> { public: diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index b0ddfa879d..226a2401e1 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -171,6 +171,7 @@ public: QRowsRemoval itemsBeingRemoved; QModelIndexPairList saved_persistent_indexes; + QList<QPersistentModelIndex> saved_layoutChange_parents; QHash<QModelIndex, Mapping *>::const_iterator create_mapping( const QModelIndex &source_parent) const; @@ -1331,23 +1332,23 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<Q Q_UNUSED(hint); // We can't forward Hint because we might filter additional rows or columns saved_persistent_indexes.clear(); - QList<QPersistentModelIndex> parents; + saved_layoutChange_parents.clear(); for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { - parents << QPersistentModelIndex(); + saved_layoutChange_parents << QPersistentModelIndex(); continue; } const QModelIndex mappedParent = q->mapFromSource(parent); // Might be filtered out. if (mappedParent.isValid()) - parents << mappedParent; + saved_layoutChange_parents << mappedParent; } // All parents filtered out. - if (!sourceParents.isEmpty() && parents.isEmpty()) + if (!sourceParents.isEmpty() && saved_layoutChange_parents.isEmpty()) return; - emit q->layoutAboutToBeChanged(parents); + emit q->layoutAboutToBeChanged(saved_layoutChange_parents); if (persistent.indexes.isEmpty()) return; @@ -1359,6 +1360,9 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersisten Q_Q(QSortFilterProxyModel); Q_UNUSED(hint); // We can't forward Hint because we might filter additional rows or columns + if (!sourceParents.isEmpty() && saved_layoutChange_parents.isEmpty()) + return; + // Optimize: We only actually have to clear the mapping related to the contents of // sourceParents, not everything. qDeleteAll(source_index_mapping); @@ -1373,21 +1377,8 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersisten source_index_mapping.clear(); } - QList<QPersistentModelIndex> parents; - for (const QPersistentModelIndex &parent : sourceParents) { - if (!parent.isValid()) { - parents << QPersistentModelIndex(); - continue; - } - const QModelIndex mappedParent = q->mapFromSource(parent); - if (mappedParent.isValid()) - parents << mappedParent; - } - - if (!sourceParents.isEmpty() && parents.isEmpty()) - return; - - emit q->layoutChanged(parents); + emit q->layoutChanged(saved_layoutChange_parents); + saved_layoutChange_parents.clear(); } void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeInserted( @@ -1427,49 +1418,27 @@ void QSortFilterProxyModelPrivate::_q_sourceRowsRemoved( void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeMoved( const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) { - Q_Q(QSortFilterProxyModel); // Because rows which are contiguous in the source model might not be contiguous // in the proxy due to sorting, the best thing we can do here is be specific about what // parents are having their children changed. // Optimize: Emit move signals if the proxy is not sorted. Will need to account for rows // being filtered out though. - saved_persistent_indexes.clear(); - QList<QPersistentModelIndex> parents; - parents << q->mapFromSource(sourceParent); + parents << sourceParent; if (sourceParent != destParent) - parents << q->mapFromSource(destParent); - emit q->layoutAboutToBeChanged(parents); - if (persistent.indexes.isEmpty()) - return; - saved_persistent_indexes = store_persistent_indexes(); + parents << destParent; + _q_sourceLayoutAboutToBeChanged(parents, QAbstractItemModel::NoLayoutChangeHint); } void QSortFilterProxyModelPrivate::_q_sourceRowsMoved( const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) { - Q_Q(QSortFilterProxyModel); - - // Optimize: We only need to clear and update the persistent indexes which are children of - // sourceParent or destParent - qDeleteAll(source_index_mapping); - source_index_mapping.clear(); - - update_persistent_indexes(saved_persistent_indexes); - saved_persistent_indexes.clear(); - - if (dynamic_sortfilter && update_source_sort_column()) { - //update_source_sort_column might have created wrong mapping so we have to clear it again - qDeleteAll(source_index_mapping); - source_index_mapping.clear(); - } - QList<QPersistentModelIndex> parents; - parents << q->mapFromSource(sourceParent); + parents << sourceParent; if (sourceParent != destParent) - parents << q->mapFromSource(destParent); - emit q->layoutChanged(parents); + parents << destParent; + _q_sourceLayoutChanged(parents, QAbstractItemModel::NoLayoutChangeHint); } void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeInserted( @@ -1531,42 +1500,21 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeMoved( const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) { - Q_Q(QSortFilterProxyModel); - - saved_persistent_indexes.clear(); - QList<QPersistentModelIndex> parents; - parents << q->mapFromSource(sourceParent); + parents << sourceParent; if (sourceParent != destParent) - parents << q->mapFromSource(destParent); - emit q->layoutAboutToBeChanged(parents); - - if (persistent.indexes.isEmpty()) - return; - saved_persistent_indexes = store_persistent_indexes(); + parents << destParent; + _q_sourceLayoutAboutToBeChanged(parents, QAbstractItemModel::NoLayoutChangeHint); } void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) { - Q_Q(QSortFilterProxyModel); - - qDeleteAll(source_index_mapping); - source_index_mapping.clear(); - - update_persistent_indexes(saved_persistent_indexes); - saved_persistent_indexes.clear(); - - if (dynamic_sortfilter && update_source_sort_column()) { - qDeleteAll(source_index_mapping); - source_index_mapping.clear(); - } - QList<QPersistentModelIndex> parents; - parents << q->mapFromSource(sourceParent); + parents << sourceParent; if (sourceParent != destParent) - parents << q->mapFromSource(destParent); - emit q->layoutChanged(parents); + parents << destParent; + _q_sourceLayoutChanged(parents, QAbstractItemModel::NoLayoutChangeHint); } /*! diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index b5756af994..80058d9115 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -370,7 +370,7 @@ union qt_semun { }; #ifndef QT_POSIX_IPC -#ifndef QT_NO_SHAREDMEMORY +#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore) #ifndef Q_OS_ANDROID static inline key_t qt_safe_ftok(const QByteArray &filename, int proj_id) { @@ -379,7 +379,7 @@ static inline key_t qt_safe_ftok(const QByteArray &filename, int proj_id) return ::ftok(filename.constData(), qHash(filename, proj_id)); } #endif // !Q_OS_ANDROID -#endif // !QT_NO_SHAREDMEMORY +#endif // QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore) #endif // !QT_POSIX_IPC QT_END_NAMESPACE diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 75ac104155..79146dac34 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -97,9 +97,7 @@ QEventDispatcherWin32Private::QEventDispatcherWin32Private() : threadId(GetCurrentThreadId()), interrupt(false), closingDown(false), internalHwnd(0), getMessageHook(0), serialNumber(0), lastSerialNumber(0), sendPostedEventsWindowsTimerId(0), wakeUps(0) -#ifndef Q_OS_WINCE , activateNotifiersPosted(false) -#endif { } @@ -180,11 +178,9 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA QSockNot *sn = dict ? dict->value(wp) : 0; if (sn) { -#ifndef Q_OS_WINCE d->doWsaAsyncSelect(sn->fd, 0); d->active_fd[sn->fd].selected = false; d->postActivateSocketNotifiers(); -#endif if (type < 3) { QEvent event(QEvent::SockAct); QCoreApplication::sendEvent(sn->obj, &event); @@ -195,7 +191,6 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA } } return 0; -#ifndef Q_OS_WINCE } else if (message == WM_QT_ACTIVATENOTIFIERS) { Q_ASSERT(d != 0); @@ -210,7 +205,6 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA } d->activateNotifiersPosted = false; return 0; -#endif // !Q_OS_WINCE } else if (message == WM_QT_SENDPOSTEDEVENTS // we also use a Windows timer to send posted events when the message queue is full || (message == WM_TIMER @@ -445,13 +439,11 @@ void QEventDispatcherWin32Private::doWsaAsyncSelect(int socket, long event) WSAAsyncSelect(socket, internalHwnd, event ? int(WM_QT_SOCKETNOTIFIER) : 0, event); } -#ifndef Q_OS_WINCE void QEventDispatcherWin32Private::postActivateSocketNotifiers() { if (!activateNotifiersPosted) activateNotifiersPosted = PostMessage(internalHwnd, WM_QT_ACTIVATENOTIFIERS, 0, 0); } -#endif // !Q_OS_WINCE void QEventDispatcherWin32::createInternalHwnd() { @@ -705,22 +697,16 @@ void QEventDispatcherWin32::registerSocketNotifier(QSocketNotifier *notifier) QSFDict::iterator it = d->active_fd.find(sockfd); if (it != d->active_fd.end()) { QSockFd &sd = it.value(); -#ifndef Q_OS_WINCE if (sd.selected) { d->doWsaAsyncSelect(sockfd, 0); sd.selected = false; } -#endif // !Q_OS_WINCE sd.event |= event; } else { d->active_fd.insert(sockfd, QSockFd(event)); } -#ifndef Q_OS_WINCE d->postActivateSocketNotifiers(); -#else - d->doWsaAsyncSelect(sockfd, event); -#endif } void QEventDispatcherWin32::unregisterSocketNotifier(QSocketNotifier *notifier) @@ -749,7 +735,6 @@ void QEventDispatcherWin32::doUnregisterSocketNotifier(QSocketNotifier *notifier QSFDict::iterator it = d->active_fd.find(sockfd); if (it != d->active_fd.end()) { QSockFd &sd = it.value(); -#ifndef Q_OS_WINCE if (sd.selected) d->doWsaAsyncSelect(sockfd, 0); const long event[3] = { FD_READ | FD_CLOSE | FD_ACCEPT, FD_WRITE | FD_CONNECT, FD_OOB }; @@ -760,13 +745,6 @@ void QEventDispatcherWin32::doUnregisterSocketNotifier(QSocketNotifier *notifier sd.selected = false; d->postActivateSocketNotifiers(); } -#else - const long event[3] = { FD_READ | FD_CLOSE | FD_ACCEPT, FD_WRITE | FD_CONNECT, FD_OOB }; - sd.event ^= event[type]; - d->doWsaAsyncSelect(sockfd, sd.event); - if (sd.event == 0) - d->active_fd.erase(it); -#endif // !Q_OS_WINCE } QSNDict *sn_vec[3] = { &d->sn_read, &d->sn_write, &d->sn_except }; diff --git a/src/corelib/kernel/qeventdispatcher_win_p.h b/src/corelib/kernel/qeventdispatcher_win_p.h index 227fcf89ff..423dc5b169 100644 --- a/src/corelib/kernel/qeventdispatcher_win_p.h +++ b/src/corelib/kernel/qeventdispatcher_win_p.h @@ -187,10 +187,8 @@ public: QSNDict sn_write; QSNDict sn_except; QSFDict active_fd; -#ifndef Q_OS_WINCE bool activateNotifiersPosted; void postActivateSocketNotifiers(); -#endif void doWsaAsyncSelect(int socket, long event); QList<QWinEventNotifier *> winEventNotifierList; diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index fb86d0222e..5623b085b8 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -207,8 +207,6 @@ struct DefinedTypesFilter { \enum QMetaType::Type These are the built-in types supported by QMetaType: - Read doc on QChar - Read doc on \l QChar \value Void \c void \value Bool \c bool diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 7b0a9f986b..3674ebc1a1 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -1413,17 +1413,17 @@ namespace QtPrivate static inline const QMetaObject *value() { return Q_NULLPTR; } }; template<typename T> - struct MetaObjectForType<T*, typename QEnableIf<IsPointerToTypeDerivedFromQObject<T*>::Value>::Type> + struct MetaObjectForType<T*, typename std::enable_if<IsPointerToTypeDerivedFromQObject<T*>::Value>::type> { static inline const QMetaObject *value() { return &T::staticMetaObject; } }; template<typename T> - struct MetaObjectForType<T, typename QEnableIf<IsGadgetHelper<T>::Value>::Type> + struct MetaObjectForType<T, typename std::enable_if<IsGadgetHelper<T>::Value>::type> { static inline const QMetaObject *value() { return &T::staticMetaObject; } }; template<typename T> - struct MetaObjectForType<T, typename QEnableIf<IsQEnumHelper<T>::Value>::Type > + struct MetaObjectForType<T, typename std::enable_if<IsQEnumHelper<T>::Value>::type > { static inline const QMetaObject *value() { return qt_getEnumMetaObject(T()); } }; @@ -2009,7 +2009,7 @@ struct SharedPointerMetaTypeIdHelper<SMART_POINTER<T>, true> \ }; \ template<typename T> \ struct MetaTypeSmartPointerHelper<SMART_POINTER<T> , \ - typename QEnableIf<IsPointerToTypeDerivedFromQObject<T*>::Value >::Type> \ + typename std::enable_if<IsPointerToTypeDerivedFromQObject<T*>::Value>::type> \ { \ static bool registerConverter(int id) \ { \ diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 5e6c44fb13..8088b18ef4 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2636,6 +2636,9 @@ static inline void check_and_warn_compat(const QMetaObject *sender, const QMetaM (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return an invalid QMetaObject::Connection. + \note Qt::UniqueConnections do not work for lambdas, non-member functions + and functors; they only apply to connecting to member functions. + The optional \a type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery @@ -4705,7 +4708,10 @@ void qDeleteInEventHandler(QObject *o) Creates a connection of a given \a type from \a signal in \a sender object to \a functor to be placed in a specific event - loop of \a context, and returns a handle to the connection + loop of \a context, and returns a handle to the connection. + + \note Qt::UniqueConnections do not work for lambdas, non-member functions + and functors; they only apply to connecting to member functions. The signal must be a function declared as a signal in the header. The slot function can be any function or functor that can be connected diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index d42eb2a13d..6941c55896 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -261,7 +261,7 @@ public: //connect to a function pointer (not a member) template <typename Func1, typename Func2> - static inline typename QtPrivate::QEnableIf<int(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0, QMetaObject::Connection>::Type + static inline typename std::enable_if<int(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0, QMetaObject::Connection>::type connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot) { return connect(sender, signal, sender, slot, Qt::DirectConnection); @@ -269,8 +269,8 @@ public: //connect to a function pointer (not a member) template <typename Func1, typename Func2> - static inline typename QtPrivate::QEnableIf<int(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0 && - !QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction, QMetaObject::Connection>::Type + static inline typename std::enable_if<int(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0 && + !QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction, QMetaObject::Connection>::type connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type = Qt::AutoConnection) { @@ -301,7 +301,7 @@ public: //connect to a functor template <typename Func1, typename Func2> - static inline typename QtPrivate::QEnableIf<QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1, QMetaObject::Connection>::Type + static inline typename std::enable_if<QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1, QMetaObject::Connection>::type connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot) { return connect(sender, signal, sender, slot, Qt::DirectConnection); @@ -309,7 +309,7 @@ public: //connect to a functor, with a "context" object defining in which event loop is going to be executed template <typename Func1, typename Func2> - static inline typename QtPrivate::QEnableIf<QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1, QMetaObject::Connection>::Type + static inline typename std::enable_if<QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1, QMetaObject::Connection>::type connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type = Qt::AutoConnection) { diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index 79c9c8303e..bd08ca1763 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -50,8 +50,6 @@ #pragma qt_sync_stop_processing #endif -#include <type_traits> - QT_BEGIN_NAMESPACE @@ -149,6 +147,20 @@ namespace QtPrivate { (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]); } }; +#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510 + template <int... II, typename... SignalArgs, typename R, typename... SlotArgs, typename SlotRet, class Obj> + struct FunctorCall<IndexesList<II...>, List<SignalArgs...>, R, SlotRet (Obj::*)(SlotArgs...) noexcept> { + static void call(SlotRet (Obj::*f)(SlotArgs...) noexcept, Obj *o, void **arg) { + (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]); + } + }; + template <int... II, typename... SignalArgs, typename R, typename... SlotArgs, typename SlotRet, class Obj> + struct FunctorCall<IndexesList<II...>, List<SignalArgs...>, R, SlotRet (Obj::*)(SlotArgs...) const noexcept> { + static void call(SlotRet (Obj::*f)(SlotArgs...) const noexcept, Obj *o, void **arg) { + (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]); + } + }; +#endif template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...)> { @@ -187,6 +199,47 @@ namespace QtPrivate { } }; +#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510 + template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...) noexcept> + { + typedef Obj Object; + typedef List<Args...> Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Args...) noexcept; + template <class Base> struct ChangeClass { typedef Ret (Base:: *Type)(Args...) noexcept; }; + enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = true}; + template <typename SignalArgs, typename R> + static void call(Function f, Obj *o, void **arg) { + FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, o, arg); + } + }; + template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...) const noexcept> + { + typedef Obj Object; + typedef List<Args...> Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Args...) const noexcept; + template <class Base> struct ChangeClass { typedef Ret (Base:: *Type)(Args...) const noexcept; }; + enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = true}; + template <typename SignalArgs, typename R> + static void call(Function f, Obj *o, void **arg) { + FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, o, arg); + } + }; + + template<typename Ret, typename... Args> struct FunctionPointer<Ret (*) (Args...) noexcept> + { + typedef List<Args...> Arguments; + typedef Ret ReturnType; + typedef Ret (*Function) (Args...) noexcept; + enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = false}; + template <typename SignalArgs, typename R> + static void call(Function f, void *, void **arg) { + FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, arg); + } + }; +#endif + template<typename Function, int N> struct Functor { template <typename SignalArgs, typename R> diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h index 51f729cf23..95fe0d1083 100644 --- a/src/corelib/kernel/qsharedmemory_p.h +++ b/src/corelib/kernel/qsharedmemory_p.h @@ -53,6 +53,8 @@ #include "qsharedmemory.h" +#include <QtCore/qstring.h> + #ifdef QT_NO_SHAREDMEMORY # ifndef QT_NO_SYSTEMSEMAPHORE namespace QSharedMemoryPrivate diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h index 96c7efd8f5..d3b1fd6a18 100644 --- a/src/corelib/kernel/qtimer.h +++ b/src/corelib/kernel/qtimer.h @@ -118,30 +118,30 @@ public: } // singleShot to a functor or function pointer (without context) template <typename Duration, typename Func1> - static inline typename QtPrivate::QEnableIf<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && - !std::is_same<const char*, Func1>::value, void>::Type + static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && + !std::is_same<const char*, Func1>::value, void>::type singleShot(Duration interval, Func1 slot) { singleShot(interval, defaultTypeFor(interval), nullptr, slot); } template <typename Duration, typename Func1> - static inline typename QtPrivate::QEnableIf<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && - !std::is_same<const char*, Func1>::value, void>::Type + static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && + !std::is_same<const char*, Func1>::value, void>::type singleShot(Duration interval, Qt::TimerType timerType, Func1 slot) { singleShot(interval, timerType, nullptr, slot); } // singleShot to a functor or function pointer (with context) template <typename Duration, typename Func1> - static inline typename QtPrivate::QEnableIf<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && - !std::is_same<const char*, Func1>::value, void>::Type + static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && + !std::is_same<const char*, Func1>::value, void>::type singleShot(Duration interval, QObject *context, Func1 slot) { singleShot(interval, defaultTypeFor(interval), context, slot); } template <typename Duration, typename Func1> - static inline typename QtPrivate::QEnableIf<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && - !std::is_same<const char*, Func1>::value, void>::Type + static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && + !std::is_same<const char*, Func1>::value, void>::type singleShot(Duration interval, Qt::TimerType timerType, QObject *context, Func1 slot) { //compilation error if the slot has arguments. diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 4a4d5b9294..8a4ad8bbf3 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1186,7 +1186,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names \snippet code/src_corelib_kernel_qvariant.cpp 1 QVariant can be extended to support other types than those - mentioned in the \l Type enum. See the \l QMetaType documentation + mentioned in the \l Type enum. See \l{Creating Custom Qt Types}{Creating Custom Qt Types} for details. \section1 A Note on GUI Types diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index bf88def438..487949431c 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -177,6 +177,26 @@ inline void v_clear(QVariant::Private *d, T* = 0) } +template <typename T> +struct PrimitiveIsNull +{ +public: + static bool isNull(const QVariant::Private *d) + { + return d->is_null; + } +}; + +template <> +struct PrimitiveIsNull<std::nullptr_t> +{ +public: + static bool isNull(const QVariant::Private *) + { + return true; + } +}; + template<class Filter> class QVariantComparator { template<typename T, bool IsAcceptedType = Filter::template Acceptor<T>::IsAccepted> @@ -268,7 +288,7 @@ class QVariantIsNull { static bool isNull(const QVariant::Private *d) { - return d->is_null; + return PrimitiveIsNull<T>::isNull(d); } }; diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp index 448e6117b1..fda9f01643 100644 --- a/src/corelib/mimetypes/qmimedatabase.cpp +++ b/src/corelib/mimetypes/qmimedatabase.cpp @@ -108,12 +108,12 @@ QMimeType QMimeDatabasePrivate::mimeTypeForName(const QString &nameOrAlias) return provider()->mimeTypeForName(provider()->resolveAlias(nameOrAlias)); } -QStringList QMimeDatabasePrivate::mimeTypeForFileName(const QString &fileName, QString *foundSuffix) +QStringList QMimeDatabasePrivate::mimeTypeForFileName(const QString &fileName) { if (fileName.endsWith(QLatin1Char('/'))) return QStringList() << QLatin1String("inode/directory"); - QStringList matchingMimeTypes = provider()->findByFileName(QFileInfo(fileName).fileName(), foundSuffix); + QStringList matchingMimeTypes = provider()->findByFileName(QFileInfo(fileName).fileName()).m_matchingMimeTypes; matchingMimeTypes.sort(); // make it deterministic return matchingMimeTypes; } @@ -168,13 +168,17 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa *accuracyPtr = 0; // Pass 1) Try to match on the file name - QStringList candidatesByName = mimeTypeForFileName(fileName); - if (candidatesByName.count() == 1) { + QMimeGlobMatchResult candidatesByName; + if (fileName.endsWith(QLatin1Char('/'))) + candidatesByName.addMatch(QLatin1String("inode/directory"), 100, QString()); + else + candidatesByName = provider()->findByFileName(QFileInfo(fileName).fileName()); + if (candidatesByName.m_allMatchingMimeTypes.count() == 1) { *accuracyPtr = 100; - const QMimeType mime = mimeTypeForName(candidatesByName.at(0)); + const QMimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0)); if (mime.isValid()) return mime; - candidatesByName.clear(); + candidatesByName = {}; } // Extension is unknown, or matches multiple mimetypes. @@ -193,7 +197,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa // "for glob_match in glob_matches:" // "if glob_match is subclass or equal to sniffed_type, use glob_match" const QString sniffedMime = candidateByData.name(); - for (const QString &m : qAsConst(candidatesByName)) { + for (const QString &m : qAsConst(candidatesByName.m_matchingMimeTypes)) { if (inherits(m, sniffedMime)) { // We have magic + pattern pointing to this, so it's a pretty good match *accuracyPtr = 100; @@ -205,9 +209,10 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa } } - if (candidatesByName.count() > 1) { + if (candidatesByName.m_allMatchingMimeTypes.count() > 1) { + candidatesByName.m_matchingMimeTypes.sort(); // make it deterministic *accuracyPtr = 20; - const QMimeType mime = mimeTypeForName(candidatesByName.at(0)); + const QMimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0)); if (mime.isValid()) return mime; } @@ -455,9 +460,7 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co QString QMimeDatabase::suffixForFileName(const QString &fileName) const { QMutexLocker locker(&d->mutex); - QString foundSuffix; - d->mimeTypeForFileName(fileName, &foundSuffix); - return foundSuffix; + return d->provider()->findByFileName(QFileInfo(fileName).fileName()).m_foundSuffix; } /*! diff --git a/src/corelib/mimetypes/qmimedatabase_p.h b/src/corelib/mimetypes/qmimedatabase_p.h index 4ff5110a5b..3f63f5f103 100644 --- a/src/corelib/mimetypes/qmimedatabase_p.h +++ b/src/corelib/mimetypes/qmimedatabase_p.h @@ -90,7 +90,7 @@ public: QMimeType mimeTypeForName(const QString &nameOrAlias); QMimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device, int *priorityPtr); QMimeType findByData(const QByteArray &data, int *priorityPtr); - QStringList mimeTypeForFileName(const QString &fileName, QString *foundSuffix = 0); + QStringList mimeTypeForFileName(const QString &fileName); mutable QMimeProviderBase *m_provider; const QString m_defaultMimeType; diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp index 568f9bf4de..a4d2b046fa 100644 --- a/src/corelib/mimetypes/qmimeglobpattern.cpp +++ b/src/corelib/mimetypes/qmimeglobpattern.cpp @@ -58,9 +58,13 @@ QT_BEGIN_NAMESPACE void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern) { + if (m_allMatchingMimeTypes.contains(mimeType)) + return; // Is this a lower-weight pattern than the last match? Skip this match then. - if (weight < m_weight) + if (weight < m_weight) { + m_allMatchingMimeTypes.append(mimeType); return; + } bool replace = weight > m_weight; if (!replace) { // Compare the length of the match @@ -79,6 +83,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q } if (!m_matchingMimeTypes.contains(mimeType)) { m_matchingMimeTypes.append(mimeType); + m_allMatchingMimeTypes.append(mimeType); if (pattern.startsWith(QLatin1String("*."))) m_foundSuffix = pattern.mid(2); } @@ -201,35 +206,32 @@ void QMimeGlobPatternList::match(QMimeGlobMatchResult &result, } } -QStringList QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QString *foundSuffix) const +QMimeGlobMatchResult QMimeAllGlobPatterns::matchingGlobs(const QString &fileName) const { // First try the high weight matches (>50), if any. QMimeGlobMatchResult result; m_highWeightGlobs.match(result, fileName); - if (result.m_matchingMimeTypes.isEmpty()) { - - // Now use the "fast patterns" dict, for simple *.foo patterns with weight 50 - // (which is most of them, so this optimization is definitely worth it) - const int lastDot = fileName.lastIndexOf(QLatin1Char('.')); - if (lastDot != -1) { // if no '.', skip the extension lookup - const int ext_len = fileName.length() - lastDot - 1; - const QString simpleExtension = fileName.right(ext_len).toLower(); - // (toLower because fast patterns are always case-insensitive and saved as lowercase) - - const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension); - const QString simplePattern = QLatin1String("*.") + simpleExtension; - for (const QString &mime : matchingMimeTypes) - result.addMatch(mime, 50, simplePattern); - // Can't return yet; *.tar.bz2 has to win over *.bz2, so we need the low-weight mimetypes anyway, - // at least those with weight 50. - } - // Finally, try the low weight matches (<=50) - m_lowWeightGlobs.match(result, fileName); + // Now use the "fast patterns" dict, for simple *.foo patterns with weight 50 + // (which is most of them, so this optimization is definitely worth it) + const int lastDot = fileName.lastIndexOf(QLatin1Char('.')); + if (lastDot != -1) { // if no '.', skip the extension lookup + const int ext_len = fileName.length() - lastDot - 1; + const QString simpleExtension = fileName.right(ext_len).toLower(); + // (toLower because fast patterns are always case-insensitive and saved as lowercase) + + const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension); + const QString simplePattern = QLatin1String("*.") + simpleExtension; + for (const QString &mime : matchingMimeTypes) + result.addMatch(mime, 50, simplePattern); + // Can't return yet; *.tar.bz2 has to win over *.bz2, so we need the low-weight mimetypes anyway, + // at least those with weight 50. } - if (foundSuffix) - *foundSuffix = result.m_foundSuffix; - return result.m_matchingMimeTypes; + + // Finally, try the low weight matches (<=50) + m_lowWeightGlobs.match(result, fileName); + + return result; } void QMimeAllGlobPatterns::clear() diff --git a/src/corelib/mimetypes/qmimeglobpattern_p.h b/src/corelib/mimetypes/qmimeglobpattern_p.h index 3e4fdb50f6..c8b70464fd 100644 --- a/src/corelib/mimetypes/qmimeglobpattern_p.h +++ b/src/corelib/mimetypes/qmimeglobpattern_p.h @@ -68,7 +68,8 @@ struct QMimeGlobMatchResult void addMatch(const QString &mimeType, int weight, const QString &pattern); - QStringList m_matchingMimeTypes; + QStringList m_matchingMimeTypes; // only those with highest weight + QStringList m_allMatchingMimeTypes; int m_weight; int m_matchingPatternLength; QString m_foundSuffix; @@ -153,7 +154,7 @@ public: void addGlob(const QMimeGlobPattern &glob); void removeMimeType(const QString &mimeType); - QStringList matchingGlobs(const QString &fileName, QString *foundSuffix) const; + QMimeGlobMatchResult matchingGlobs(const QString &fileName) const; void clear(); PatternsMap m_fastPatterns; // example: "doc" -> "application/msword", "text/plain" diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp index 7e07f8acb9..5bbf1bba9d 100644 --- a/src/corelib/mimetypes/qmimemagicrule.cpp +++ b/src/corelib/mimetypes/qmimemagicrule.cpp @@ -161,7 +161,7 @@ bool QMimeMagicRule::matchNumber(const QByteArray &data) const //qDebug() << "mask" << QString::number(m_numberMask, 16); const char *p = data.constData() + m_startPos; - const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1); + const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos); for ( ; p <= e; ++p) { if ((qFromUnaligned<T>(p) & mask) == (value & mask)) return true; @@ -299,20 +299,30 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, } break; case Big16: - case Host16: case Little16: if (m_number <= quint16(-1)) { m_number = m_type == Little16 ? qFromLittleEndian<quint16>(m_number) : qFromBigEndian<quint16>(m_number); + if (m_numberMask != 0) + m_numberMask = m_type == Little16 ? qFromLittleEndian<quint16>(m_numberMask) : qFromBigEndian<quint16>(m_numberMask); + } + Q_FALLTHROUGH(); + case Host16: + if (m_number <= quint16(-1)) { if (m_numberMask == 0) m_numberMask = quint16(-1); m_matchFunction = &QMimeMagicRule::matchNumber<quint16>; } break; case Big32: - case Host32: case Little32: if (m_number <= quint32(-1)) { m_number = m_type == Little32 ? qFromLittleEndian<quint32>(m_number) : qFromBigEndian<quint32>(m_number); + if (m_numberMask != 0) + m_numberMask = m_type == Little32 ? qFromLittleEndian<quint32>(m_numberMask) : qFromBigEndian<quint32>(m_numberMask); + } + Q_FALLTHROUGH(); + case Host32: + if (m_number <= quint32(-1)) { if (m_numberMask == 0) m_numberMask = quint32(-1); m_matchFunction = &QMimeMagicRule::matchNumber<quint32>; diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 65b011b439..959421bf52 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -287,13 +287,13 @@ QMimeType QMimeBinaryProvider::mimeTypeForName(const QString &name) return mimeTypeForNameUnchecked(name); } -QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString *foundSuffix) +QMimeGlobMatchResult QMimeBinaryProvider::findByFileName(const QString &fileName) { checkCache(); + QMimeGlobMatchResult result; if (fileName.isEmpty()) - return QStringList(); + return result; const QString lowerFileName = fileName.toLower(); - QMimeGlobMatchResult result; // TODO this parses in the order (local, global). Check that it handles "NOGLOBS" correctly. for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) { matchGlobList(result, cacheFile, cacheFile->getUint32(PosLiteralListOffset), fileName); @@ -305,9 +305,7 @@ QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString if (result.m_matchingMimeTypes.isEmpty()) matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true); } - if (foundSuffix) - *foundSuffix = result.m_foundSuffix; - return result.m_matchingMimeTypes; + return result; } void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName) @@ -728,12 +726,11 @@ QMimeType QMimeXMLProvider::mimeTypeForName(const QString &name) return m_nameMimeTypeMap.value(name); } -QStringList QMimeXMLProvider::findByFileName(const QString &fileName, QString *foundSuffix) +QMimeGlobMatchResult QMimeXMLProvider::findByFileName(const QString &fileName) { ensureLoaded(); - const QStringList matchingMimeTypes = m_mimeTypeGlobs.matchingGlobs(fileName, foundSuffix); - return matchingMimeTypes; + return m_mimeTypeGlobs.matchingGlobs(fileName); } QMimeType QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr) diff --git a/src/corelib/mimetypes/qmimeprovider_p.h b/src/corelib/mimetypes/qmimeprovider_p.h index e6fc47bf80..f410e62267 100644 --- a/src/corelib/mimetypes/qmimeprovider_p.h +++ b/src/corelib/mimetypes/qmimeprovider_p.h @@ -56,6 +56,7 @@ #ifndef QT_NO_MIMETYPE +#include "qmimeglobpattern_p.h" #include <QtCore/qdatetime.h> #include <QtCore/qset.h> #include <QtCore/qelapsedtimer.h> @@ -72,7 +73,7 @@ public: virtual bool isValid() = 0; virtual QMimeType mimeTypeForName(const QString &name) = 0; - virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix) = 0; + virtual QMimeGlobMatchResult findByFileName(const QString &fileName) = 0; virtual QStringList parents(const QString &mime) = 0; virtual QString resolveAlias(const QString &name) = 0; virtual QStringList listAliases(const QString &name) = 0; @@ -99,7 +100,7 @@ public: virtual bool isValid() Q_DECL_OVERRIDE; virtual QMimeType mimeTypeForName(const QString &name) Q_DECL_OVERRIDE; - virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix) Q_DECL_OVERRIDE; + virtual QMimeGlobMatchResult findByFileName(const QString &fileName) Q_DECL_OVERRIDE; virtual QStringList parents(const QString &mime) Q_DECL_OVERRIDE; virtual QString resolveAlias(const QString &name) Q_DECL_OVERRIDE; virtual QStringList listAliases(const QString &name) Q_DECL_OVERRIDE; @@ -142,7 +143,7 @@ public: virtual bool isValid() Q_DECL_OVERRIDE; virtual QMimeType mimeTypeForName(const QString &name) Q_DECL_OVERRIDE; - virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix) Q_DECL_OVERRIDE; + virtual QMimeGlobMatchResult findByFileName(const QString &fileName) Q_DECL_OVERRIDE; virtual QStringList parents(const QString &mime) Q_DECL_OVERRIDE; virtual QString resolveAlias(const QString &name) Q_DECL_OVERRIDE; virtual QStringList listAliases(const QString &name) Q_DECL_OVERRIDE; diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index c09dc6c22b..b8e18cc9a8 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -282,6 +282,7 @@ QObject *QFactoryLoader::instance(int index) const return 0; #ifndef QT_NO_LIBRARY + QMutexLocker lock(&d->mutex); if (index < d->libraryList.size()) { QLibraryPrivate *library = d->libraryList.at(index); if (library->instance || library->loadPlugin()) { @@ -297,6 +298,7 @@ QObject *QFactoryLoader::instance(int index) const return 0; } index -= d->libraryList.size(); + lock.unlock(); #endif QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins(); diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 433f595611..d7cdec9aac 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -2024,7 +2024,9 @@ void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) if (QThread::currentThread() == q->thread()) { _q_process(); break; - } // fallthrough -- processing must be done in the machine thread + } + // processing must be done in the machine thread, so: + Q_FALLTHROUGH(); case QueuedProcessing: processingScheduled = true; QMetaObject::invokeMethod(q, "_q_process", Qt::QueuedConnection); diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 9418813afd..c28b162305 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -79,7 +79,7 @@ class QFinalState; class QHistoryState; class QState; -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) class QAbstractAnimation; #endif @@ -123,7 +123,7 @@ public: // private slots void _q_start(); void _q_process(); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) void _q_animationFinished(); #endif void _q_startDelayedEventTimer(int id, int delay); @@ -152,7 +152,7 @@ public: const QList<QAbstractState*> &statesToEnter_sorted, const QSet<QAbstractState*> &statesForDefaultEntry, QHash<QAbstractState *, QVector<QPropertyAssignment> > &propertyAssignmentsForState -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) , const QList<QAbstractAnimation*> &selectedAnimations #endif ); @@ -264,7 +264,7 @@ public: QSet<QAbstractState *> pendingErrorStates; QSet<QAbstractState *> pendingErrorStatesForDefaultEntry; -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) bool animated; struct InitializeAnimationResult { @@ -326,7 +326,9 @@ public: static const Handler *handler; }; +#if QT_CONFIG(animation) Q_DECLARE_SHARED(QStateMachinePrivate::InitializeAnimationResult) +#endif Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler(); diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index bbfc11f6c0..f9eacbf6f0 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -176,6 +176,9 @@ public: } #endif inline QAtomicPointer(const QAtomicPointer<T> &other) Q_DECL_NOTHROW +#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS + : QBasicAtomicPointer<T>() +#endif { this->storeRelease(other.loadAcquire()); } diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h index 06bb4bc8f1..5c4c02a2ec 100644 --- a/src/corelib/thread/qgenericatomic.h +++ b/src/corelib/thread/qgenericatomic.h @@ -283,7 +283,7 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndRelaxed(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndAndRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { // implement fetchAndAnd on top of testAndSet T tmp = BaseClass::load(_q_value); @@ -294,7 +294,7 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndAcquire(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndAndAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { T tmp = BaseClass::fetchAndAndRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -302,21 +302,21 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndRelease(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndAndRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndAndRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndOrdered(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndAndOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndAndRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrRelaxed(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndOrRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { // implement fetchAndOr on top of testAndSet T tmp = BaseClass::load(_q_value); @@ -327,7 +327,7 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrAcquire(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndOrAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { T tmp = BaseClass::fetchAndOrRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -335,21 +335,21 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrRelease(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndOrRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndOrRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrOrdered(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndOrOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndOrRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorRelaxed(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndXorRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { // implement fetchAndXor on top of testAndSet T tmp = BaseClass::load(_q_value); @@ -360,7 +360,7 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorAcquire(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndXorAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { T tmp = BaseClass::fetchAndXorRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -368,14 +368,14 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorRelease(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndXorRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndXorRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorOrdered(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW + T fetchAndXorOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndXorRelaxed(_q_value, operand); diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index 410f642ca7..45786537e2 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -140,10 +140,10 @@ public: static QThread* currentThread(); protected: - QThread(QThreadPrivate &dd, QObject *parent = 0); + QThread(QThreadPrivate &dd, QObject *parent = nullptr); private: - explicit QThread(QObject *parent = 0); + explicit QThread(QObject *parent = nullptr); static QThread *instance; friend class QCoreApplication; diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index ba5f2dca95..c60742631b 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -211,25 +211,25 @@ static void clear_thread_data() } template <typename T> -static typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, Qt::HANDLE>::Type to_HANDLE(T id) +static typename std::enable_if<QTypeInfo<T>::isIntegral, Qt::HANDLE>::type to_HANDLE(T id) { return reinterpret_cast<Qt::HANDLE>(static_cast<intptr_t>(id)); } template <typename T> -static typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type from_HANDLE(Qt::HANDLE id) +static typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type from_HANDLE(Qt::HANDLE id) { return static_cast<T>(reinterpret_cast<intptr_t>(id)); } template <typename T> -static typename QtPrivate::QEnableIf<QTypeInfo<T>::isPointer, Qt::HANDLE>::Type to_HANDLE(T id) +static typename std::enable_if<QTypeInfo<T>::isPointer, Qt::HANDLE>::type to_HANDLE(T id) { return id; } template <typename T> -static typename QtPrivate::QEnableIf<QTypeInfo<T>::isPointer, T>::Type from_HANDLE(Qt::HANDLE id) +static typename std::enable_if<QTypeInfo<T>::isPointer, T>::type from_HANDLE(Qt::HANDLE id) { return static_cast<T>(id); } diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 6bb8280ca8..47a19dd75d 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -411,18 +411,18 @@ struct QArrayOpsSelector template <class T> struct QArrayOpsSelector<T, - typename QEnableIf< + typename std::enable_if< !QTypeInfo<T>::isComplex && !QTypeInfo<T>::isStatic - >::Type> + >::type> { typedef QPodArrayOps<T> Type; }; template <class T> struct QArrayOpsSelector<T, - typename QEnableIf< + typename std::enable_if< QTypeInfo<T>::isComplex && !QTypeInfo<T>::isStatic - >::Type> + >::type> { typedef QMovableArrayOps<T> Type; }; diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 621c877174..65016933a0 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -1139,6 +1139,7 @@ end: } break; } } + Q_FALLTHROUGH(); case MonthSection: if (sn.count >= 3) { const int currentMonth = newCurrentValue.date().month(); @@ -1216,15 +1217,15 @@ end: } else { if (context == FromString) { // optimization - Q_ASSERT(getMaximum().date().toJulianDay() == 4642999); + Q_ASSERT(maximum.date().toJulianDay() == 4642999); if (newCurrentValue.date().toJulianDay() > 4642999) state = Invalid; } else { - if (newCurrentValue > getMaximum()) + if (newCurrentValue > maximum) state = Invalid; } - QDTPDEBUG << "not checking intermediate because newCurrentValue is" << newCurrentValue << getMinimum() << getMaximum(); + QDTPDEBUG << "not checking intermediate because newCurrentValue is" << newCurrentValue << minimum << maximum; } } StateNode node; @@ -1607,13 +1608,13 @@ bool QDateTimeParser::potentialValue(const QStringRef &str, int min, int max, in bool QDateTimeParser::skipToNextSection(int index, const QDateTime ¤t, const QStringRef &text) const { - Q_ASSERT(current >= getMinimum() && current <= getMaximum()); - const SectionNode &node = sectionNode(index); Q_ASSERT(text.size() < sectionMaxSize(index)); const QDateTime maximum = getMaximum(); const QDateTime minimum = getMinimum(); + Q_ASSERT(current >= minimum && current <= maximum); + QDateTime tmp = current; int min = absoluteMin(index); setDigit(tmp, index, min); @@ -1713,11 +1714,21 @@ bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) con QDateTime QDateTimeParser::getMinimum() const { + // Cache the most common case + if (spec == Qt::LocalTime) { + static const QDateTime localTimeMin(QDATETIMEEDIT_DATE_MIN, QDATETIMEEDIT_TIME_MIN, Qt::LocalTime); + return localTimeMin; + } return QDateTime(QDATETIMEEDIT_DATE_MIN, QDATETIMEEDIT_TIME_MIN, spec); } QDateTime QDateTimeParser::getMaximum() const { + // Cache the most common case + if (spec == Qt::LocalTime) { + static const QDateTime localTimeMax(QDATETIMEEDIT_DATE_MAX, QDATETIMEEDIT_TIME_MAX, Qt::LocalTime); + return localTimeMax; + } return QDateTime(QDATETIMEEDIT_DATE_MAX, QDATETIMEEDIT_TIME_MAX, spec); } diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index abec9ebb79..9270539f4f 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -199,14 +199,14 @@ static uint crc32(...) } #endif -static inline uint hash(const uchar *p, int len, uint seed) Q_DECL_NOTHROW +static inline uint hash(const uchar *p, size_t len, uint seed) Q_DECL_NOTHROW { uint h = seed; if (hasFastCrc32()) - return crc32(p, size_t(len), h); + return crc32(p, len, h); - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) h = 31 * h + p[i]; return h; @@ -217,14 +217,14 @@ uint qHashBits(const void *p, size_t len, uint seed) Q_DECL_NOTHROW return hash(static_cast<const uchar*>(p), int(len), seed); } -static inline uint hash(const QChar *p, int len, uint seed) Q_DECL_NOTHROW +static inline uint hash(const QChar *p, size_t len, uint seed) Q_DECL_NOTHROW { uint h = seed; if (hasFastCrc32()) - return crc32(p, size_t(len), h); + return crc32(p, len, h); - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) h = 31 * h + p[i].unicode(); return h; @@ -232,23 +232,24 @@ static inline uint hash(const QChar *p, int len, uint seed) Q_DECL_NOTHROW uint qHash(const QByteArray &key, uint seed) Q_DECL_NOTHROW { - return hash(reinterpret_cast<const uchar *>(key.constData()), key.size(), seed); + return hash(reinterpret_cast<const uchar *>(key.constData()), size_t(key.size()), seed); } uint qHash(const QString &key, uint seed) Q_DECL_NOTHROW { - return hash(key.unicode(), key.size(), seed); + return hash(key.unicode(), size_t(key.size()), seed); } uint qHash(const QStringRef &key, uint seed) Q_DECL_NOTHROW { - return hash(key.unicode(), key.size(), seed); + return hash(key.unicode(), size_t(key.size()), seed); } uint qHash(const QBitArray &bitArray, uint seed) Q_DECL_NOTHROW { int m = bitArray.d.size() - 1; - uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), qMax(0, m), seed); + uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), + size_t(qMax(0, m)), seed); // deal with the last 0 to 7 bits manually, because we can't trust that // the padding is initialized to 0 in bitArray.d @@ -260,7 +261,7 @@ uint qHash(const QBitArray &bitArray, uint seed) Q_DECL_NOTHROW uint qHash(QLatin1String key, uint seed) Q_DECL_NOTHROW { - return hash(reinterpret_cast<const uchar *>(key.data()), key.size(), seed); + return hash(reinterpret_cast<const uchar *>(key.data()), size_t(key.size()), seed); } /*! diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 77f7ba963b..cdda5292e7 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -334,33 +334,17 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const return localeId.withLikelySubtagsRemoved().name(separator); } -const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country) +static const QLocaleData *findLocaleDataById(const QLocaleId &localeId) { - QLocaleId localeId = QLocaleId::fromIds(language, script, country); - localeId = localeId.withLikelySubtagsAdded(); - - uint idx = locale_index[localeId.language_id]; + const uint idx = locale_index[localeId.language_id]; const QLocaleData *data = locale_data + idx; - if (idx == 0) // default language has no associated country + if (idx == 0) // default language has no associated script or country return data; Q_ASSERT(data->m_language_id == localeId.language_id); - if (localeId.script_id != QLocale::AnyScript && localeId.country_id != QLocale::AnyCountry) { - // both script and country are explicitly specified - do { - if (data->m_script_id == localeId.script_id && data->m_country_id == localeId.country_id) - return data; - ++data; - } while (data->m_language_id == localeId.language_id); - - // no match; try again with default script - localeId.script_id = QLocale::AnyScript; - data = locale_data + idx; - } - if (localeId.script_id == QLocale::AnyScript && localeId.country_id == QLocale::AnyCountry) return data; @@ -369,15 +353,72 @@ const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLoca if (data->m_country_id == localeId.country_id) return data; ++data; - } while (data->m_language_id == localeId.language_id); + } while (data->m_language_id && data->m_language_id == localeId.language_id); } else if (localeId.country_id == QLocale::AnyCountry) { do { if (data->m_script_id == localeId.script_id) return data; ++data; - } while (data->m_language_id == localeId.language_id); + } while (data->m_language_id && data->m_language_id == localeId.language_id); + } else { + do { + if (data->m_script_id == localeId.script_id && data->m_country_id == localeId.country_id) + return data; + ++data; + } while (data->m_language_id && data->m_language_id == localeId.language_id); + } + + return 0; +} + +const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country) +{ + QLocaleId localeId = QLocaleId::fromIds(language, script, country); + localeId = localeId.withLikelySubtagsAdded(); + + const uint idx = locale_index[localeId.language_id]; + + // Try a straight match + if (const QLocaleData *const data = findLocaleDataById(localeId)) + return data; + QList<QLocaleId> tried; + tried.push_back(localeId); + + // No match; try again with likely country + localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry); + localeId = localeId.withLikelySubtagsAdded(); + if (!tried.contains(localeId)) { + if (const QLocaleData *const data = findLocaleDataById(localeId)) + return data; + tried.push_back(localeId); } + // No match; try again with any country + localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry); + if (!tried.contains(localeId)) { + if (const QLocaleData *const data = findLocaleDataById(localeId)) + return data; + tried.push_back(localeId); + } + + // No match; try again with likely script + localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country); + localeId = localeId.withLikelySubtagsAdded(); + if (!tried.contains(localeId)) { + if (const QLocaleData *const data = findLocaleDataById(localeId)) + return data; + tried.push_back(localeId); + } + + // No match; try again with any script + localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country); + if (!tried.contains(localeId)) { + if (const QLocaleData *const data = findLocaleDataById(localeId)) + return data; + tried.push_back(localeId); + } + + // No match; return data at original index return locale_data + idx; } @@ -1305,8 +1346,8 @@ float QLocale::toFloat(const QString &s, bool *ok) const If \a ok is not 0, reports failure by setting *ok to false and success by setting *ok to true. - Unlike QString::toDouble(), this function does not fall back to - the "C" locale if the string cannot be interpreted in this + Unlike QString::toDouble(), this function does not use + the 'C' locale if the string cannot be interpreted in this locale. \snippet code/src_corelib_tools_qlocale.cpp 3 diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index b5f97b5fe8..d1abb8b565 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -691,7 +691,7 @@ QString QSystemLocalePrivate::winToQtFormat(const QString &sys_fmt) if (text == QLatin1String("'")) result += QLatin1String("''"); else - result += QString(QLatin1Char('\'') + text + QLatin1Char('\'')); + result += QLatin1Char('\'') + text + QLatin1Char('\''); continue; } diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 3f4f034b4e..e6da2820f8 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -99,10 +99,10 @@ struct Q_CORE_EXPORT QMapNodeBase void setParent(QMapNodeBase *pp) { p = (p & Mask) | quintptr(pp); } template <typename T> - static typename QtPrivate::QEnableIf<QTypeInfo<T>::isComplex>::Type + static typename std::enable_if<QTypeInfo<T>::isComplex>::type callDestructorIfNecessary(T &t) Q_DECL_NOTHROW { Q_UNUSED(t); t.~T(); } // Q_UNUSED: silence MSVC unused 't' warning template <typename T> - static typename QtPrivate::QEnableIf<!QTypeInfo<T>::isComplex>::Type + static typename std::enable_if<!QTypeInfo<T>::isComplex>::type callDestructorIfNecessary(T &) Q_DECL_NOTHROW {} }; diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 5738413bfb..0d42c8a212 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -974,13 +974,13 @@ qobject_cast(const QWeakPointer<T> &src) } template<typename T> -QWeakPointer<typename QtPrivate::QEnableIf<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, T>::Type> +QWeakPointer<typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, T>::type> qWeakPointerFromVariant(const QVariant &variant) { return QWeakPointer<T>(qobject_cast<T*>(QtSharedPointer::weakPointerFromVariant_internal(variant).data())); } template<typename T> -QSharedPointer<typename QtPrivate::QEnableIf<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, T>::Type> +QSharedPointer<typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, T>::type> qSharedPointerFromVariant(const QVariant &variant) { return qSharedPointerObjectCast<T>(QtSharedPointer::sharedPointerFromVariant_internal(variant)); diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a727f5168c..66ce29c859 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -496,7 +496,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int 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 + 8 < end) { + while (a + 7 < end) { uint16x8_t da = vld1q_u16(reinterpret_cast<const uint16_t *>(a)); uint16x8_t db = vld1q_u16(reinterpret_cast<const uint16_t *>(b)); @@ -8159,7 +8159,7 @@ bool QString::isRightToLeft() const to create a deep copy of the data, ensuring that the raw data isn't modified. - Here's an example of how we can use a QRegExp on raw data in + Here's an example of how we can use a QRegularExpression on raw data in memory without requiring to copy the data into a QString: \snippet qstring/main.cpp 22 diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index a0b65ea554..88ceae20b9 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -143,8 +143,8 @@ QT_BEGIN_NAMESPACE \snippet qstringlist/main.cpp 6 - The argument to split can be a single character, a string, or a - QRegExp. + The argument to split can be a single character, a string, a + QRegularExpression or a (deprecated) QRegExp. In addition, the \l {QStringList::operator+()}{operator+()} function allows you to concatenate two string lists into one. To diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 1530299303..bb5ae78d2b 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -77,7 +77,7 @@ public: : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array)) { if (args.size()) - append(args.begin(), args.size()); + append(args.begin(), int(args.size())); } #endif diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 4dbf95c315..5225b68d40 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -982,11 +982,13 @@ QT_BEGIN_INCLUDE_NAMESPACE #include <QtCore/qpoint.h> QT_END_INCLUDE_NAMESPACE +#ifndef Q_TEMPLATE_EXTERN #if defined(QT_BUILD_CORE_LIB) #define Q_TEMPLATE_EXTERN #else #define Q_TEMPLATE_EXTERN extern #endif +#endif Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector<QPointF>; Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector<QPoint>; #endif |
