From 652bd1efca34b7e114836f79c33b5e4a248faaee Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 3 Sep 2020 15:04:16 +0200 Subject: [PATCH] Make QStringList an alias to QList Fix our API, so that QStringList and QList are the same thing. This required a bit of refactoring in QList and moving the indexOf(), lastIndexOf() and contains() method into QListSpecialMethods. In addition, we need to ensure that the QStringList(const QString&) constructor is still available for compatibility with Qt 5. Once those two are done, all methods in QStringList can be moved into QListSpecialMethods. Change-Id: Ib8afbf5b6d9df4d0d47051252233506f62335fa3 Reviewed-by: Andrei Golubev Reviewed-by: Thiago Macieira --- .../tools/plugandpaint/app/interfaces.h | 1 - .../tools/plugandpaint/app/plugindialog.h | 1 - .../doc/snippets/qsignalmapper/buttonwidget.h | 1 - src/corelib/global/qlibraryinfo.h | 2 - src/corelib/kernel/qcoreapplication.h | 1 - src/corelib/kernel/qjnihelpers_p.h | 1 - src/corelib/kernel/qmetatype.h | 3 +- src/corelib/kernel/qvariant.h | 1 - src/corelib/serialization/qjsonarray.h | 1 - src/corelib/text/qbytearraylist.h | 8 +- src/corelib/text/qregularexpression.h | 1 - src/corelib/text/qstring.h | 1 - src/corelib/text/qstringlist.h | 296 +++++------------- src/corelib/tools/qcontainerfwd.h | 2 +- src/corelib/tools/qlist.h | 43 ++- src/gui/accessible/qaccessibleplugin.h | 1 - src/gui/image/qimage.h | 1 - src/gui/image/qimagereader.h | 1 - src/gui/text/qfont.h | 1 - src/gui/text/qfontdatabase.h | 1 - src/gui/util/qdesktopservices.h | 1 - src/network/ssl/qsslcertificate.h | 1 - .../platforms/cocoa/qcocoafiledialoghelper.mm | 2 - src/sql/kernel/qsqlrecord.h | 1 - src/testlib/qbenchmarkvalgrind_p.h | 2 - src/testlib/qtest.h | 7 - src/widgets/styles/qcommonstyle_p.h | 1 - 27 files changed, 115 insertions(+), 268 deletions(-) diff --git a/examples/widgets/tools/plugandpaint/app/interfaces.h b/examples/widgets/tools/plugandpaint/app/interfaces.h index 705e5788092..5e92b01dc39 100644 --- a/examples/widgets/tools/plugandpaint/app/interfaces.h +++ b/examples/widgets/tools/plugandpaint/app/interfaces.h @@ -61,7 +61,6 @@ class QPainterPath; class QPoint; class QRect; class QString; -class QStringList; QT_END_NAMESPACE //! [0] diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.h b/examples/widgets/tools/plugandpaint/app/plugindialog.h index b18b30e62c5..d480fe42830 100644 --- a/examples/widgets/tools/plugandpaint/app/plugindialog.h +++ b/examples/widgets/tools/plugandpaint/app/plugindialog.h @@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE class QLabel; class QPushButton; -class QStringList; class QTreeWidget; class QTreeWidgetItem; QT_END_NAMESPACE diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h index b9d59f8dd84..24acae997c5 100644 --- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h +++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h @@ -55,7 +55,6 @@ class QSignalMapper; class QString; -class QStringList; //! [0] class ButtonWidget : public QWidget diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 3ceb20336b4..bb5c9a8e080 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -class QStringList; - class Q_CORE_EXPORT QLibraryInfo { public: diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index 19ce85aa255..a67ac29bb9a 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -62,7 +62,6 @@ QT_BEGIN_NAMESPACE class QCoreApplicationPrivate; class QTranslator; class QPostEventList; -class QStringList; class QAbstractEventDispatcher; class QAbstractNativeEventFilter; diff --git a/src/corelib/kernel/qjnihelpers_p.h b/src/corelib/kernel/qjnihelpers_p.h index ea5103c173e..c849013ba22 100644 --- a/src/corelib/kernel/qjnihelpers_p.h +++ b/src/corelib/kernel/qjnihelpers_p.h @@ -60,7 +60,6 @@ QT_BEGIN_NAMESPACE class QRunnable; -class QStringList; namespace QtAndroidPrivate { diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index feabede0dd4..6d31441b739 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -125,7 +125,6 @@ inline constexpr int qMetaTypeId(); #define QT_FOR_EACH_STATIC_CORE_CLASS(F)\ F(QChar, 7, QChar) \ F(QString, 10, QString) \ - F(QStringList, 11, QStringList) \ F(QByteArray, 12, QByteArray) \ F(QBitArray, 13, QBitArray) \ F(QDate, 14, QDate) \ @@ -163,6 +162,7 @@ inline constexpr int qMetaTypeId(); F(QVariantHash, 28, QVariantHash) \ F(QVariantPair, 58, QVariantPair) \ F(QByteArrayList, 49, QByteArrayList) \ + F(QStringList, 11, QStringList) \ #if QT_CONFIG(shortcut) #define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)\ @@ -221,6 +221,7 @@ inline constexpr int qMetaTypeId(); F(QVariantHash, -1, QVariantHash, "QHash") \ F(QVariantPair, -1, QVariantPair, "QPair") \ F(QByteArrayList, -1, QByteArrayList, "QList") \ + F(QStringList, -1, QStringList, "QList") \ #define QT_FOR_EACH_STATIC_TYPE(F)\ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 47103725f88..ad766c9a8e4 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -74,7 +74,6 @@ class QLine; class QLineF; class QLocale; class QTransform; -class QStringList; class QTime; class QPoint; class QPointF; diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index b39e85a726a..406fbc2f47d 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE class QDebug; -class QStringList; typedef QList QVariantList; class Q_CORE_EXPORT QJsonArray diff --git a/src/corelib/text/qbytearraylist.h b/src/corelib/text/qbytearraylist.h index 3f85a24329b..1ce8d214458 100644 --- a/src/corelib/text/qbytearraylist.h +++ b/src/corelib/text/qbytearraylist.h @@ -54,7 +54,6 @@ typedef QMutableListIterator QMutableByteArrayListIterator; #endif #ifndef Q_CLANG_QDOC -typedef QList QByteArrayList; namespace QtPrivate { QByteArray Q_CORE_EXPORT QByteArrayList_join(const QByteArrayList *that, const char *separator, int separatorLength); @@ -73,6 +72,13 @@ protected: ~QListSpecialMethods() = default; #endif public: + qsizetype indexOf(const QByteArray &ba, qsizetype from = 0) const noexcept + { return QtPrivate::indexOf(*self(), ba, from); } + qsizetype lastIndexOf(const QByteArray &ba, qsizetype from = -1) const noexcept + { return QtPrivate::lastIndexOf(*self(), ba, from); } + bool contains(const QByteArray &ba) const noexcept + { return indexOf(ba) != -1; } + inline QByteArray join() const { return QtPrivate::QByteArrayList_join(self(), nullptr, 0); } inline QByteArray join(const QByteArray &sep) const diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index 24fa4ea9daa..6af48f5fb05 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -51,7 +51,6 @@ QT_REQUIRE_CONFIG(regularexpression); QT_BEGIN_NAMESPACE -class QStringList; class QLatin1String; class QRegularExpressionMatch; diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index e11457461cd..76ac8b11198 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -75,7 +75,6 @@ QT_BEGIN_NAMESPACE class QRegularExpression; class QRegularExpressionMatch; class QString; -class QStringList; namespace QtPrivate { template class BoolList; diff --git a/src/corelib/text/qstringlist.h b/src/corelib/text/qstringlist.h index 2b5c960b75a..3ed6a2f4999 100644 --- a/src/corelib/text/qstringlist.h +++ b/src/corelib/text/qstringlist.h @@ -57,101 +57,6 @@ using QStringListIterator = QListIterator; using QMutableStringListIterator = QMutableListIterator; #endif -class QStringList; - -#ifdef Q_QDOC -class QStringList : public QList -#else -template <> struct QListSpecialMethods -#endif -{ -#ifndef Q_QDOC -protected: - ~QListSpecialMethods() = default; -#endif -public: - inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); - inline qsizetype removeDuplicates(); - -#if QT_STRINGVIEW_LEVEL < 2 - inline QString join(const QString &sep) const; -#endif - inline QString join(QStringView sep) const; - inline QString join(QLatin1String sep) const; - inline QString join(QChar sep) const; - - inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive); -#if QT_STRINGVIEW_LEVEL < 2 - inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); - inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive); - inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); -#endif - -#if QT_CONFIG(regularexpression) - inline QStringList filter(const QRegularExpression &re) const; - inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after); -#endif // QT_CONFIG(regularexpression) - -#ifndef Q_QDOC -private: - inline QStringList *self(); - inline const QStringList *self() const; -}; - -// ### Qt6: check if there's a better way -class QStringList : public QList -{ -#endif -public: - using QList::QList; - inline explicit QStringList(const QString &i) { append(i); } - inline QStringList(const QList &l) : QList(l) { } - inline QStringList(QList &&l) noexcept : QList(std::move(l)) { } - - QStringList &operator=(const QList &other) - { QList::operator=(other); return *this; } - QStringList &operator=(QList &&other) noexcept - { QList::operator=(std::move(other)); return *this; } - -#if QT_STRINGVIEW_LEVEL < 2 - inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#endif - inline bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - - inline QStringList operator+(const QStringList &other) const - { QStringList n = *this; n += other; return n; } - inline QStringList &operator<<(const QString &str) - { append(str); return *this; } - inline QStringList &operator<<(const QStringList &l) - { *this += l; return *this; } - inline QStringList &operator<<(const QList &l) - { *this += l; return *this; } - - inline qsizetype indexOf(QStringView str, qsizetype from = 0) const; - inline qsizetype indexOf(QLatin1String str, qsizetype from = 0) const; - - inline qsizetype lastIndexOf(QStringView str, qsizetype from = -1) const; - inline qsizetype lastIndexOf(QLatin1String str, qsizetype from = -1) const; - -#if QT_CONFIG(regularexpression) - inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const; - inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const; -#endif // QT_CONFIG(regularexpression) - - using QList::indexOf; - using QList::lastIndexOf; -}; - -Q_DECLARE_TYPEINFO(QStringList, Q_MOVABLE_TYPE); - -#ifndef Q_QDOC -inline QStringList *QListSpecialMethods::self() -{ return static_cast(this); } -inline const QStringList *QListSpecialMethods::self() const -{ return static_cast(this); } namespace QtPrivate { void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs); @@ -174,143 +79,98 @@ namespace QtPrivate { #endif // QT_CONFIG(regularexpression) } -inline void QListSpecialMethods::sort(Qt::CaseSensitivity cs) +#ifdef Q_QDOC +class QStringList : public QList +#else +template <> struct QListSpecialMethods +#endif { - QtPrivate::QStringList_sort(self(), cs); -} + inline QStringList *self() + { return static_cast(this); } + inline const QStringList *self() const + { return static_cast(this); } -inline qsizetype QListSpecialMethods::removeDuplicates() -{ - return QtPrivate::QStringList_removeDuplicates(self()); -} +public: + inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive) + { QtPrivate::QStringList_sort(self(), cs); } + inline qsizetype removeDuplicates() + { return QtPrivate::QStringList_removeDuplicates(self()); } + + inline QString join(QStringView sep) const + { return QtPrivate::QStringList_join(self(), sep); } + inline QString join(QLatin1String sep) const + { return QtPrivate::QStringList_join(*self(), sep); } + inline QString join(QChar sep) const + { return QtPrivate::QStringList_join(self(), &sep, 1); } + + inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + { return QtPrivate::QStringList_filter(self(), str, cs); } + inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) + { + QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); + return *self(); + } #if QT_STRINGVIEW_LEVEL < 2 -inline QString QListSpecialMethods::join(const QString &sep) const -{ - return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); -} + inline QString join(const QString &sep) const + { return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); } + inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + { return QtPrivate::QStringList_filter(self(), str, cs); } + inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) + { + QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); + return *self(); + } + inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) + { + QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); + return *self(); + } + inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) + { + QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); + return *self(); + } #endif -inline QString QListSpecialMethods::join(QStringView sep) const -{ - return QtPrivate::QStringList_join(self(), sep); -} + inline bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::QStringList_contains(self(), str, cs); } + inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::QStringList_contains(self(), str, cs); } -QString QListSpecialMethods::join(QLatin1String sep) const -{ - return QtPrivate::QStringList_join(*self(), sep); -} + inline qsizetype indexOf(QStringView str, qsizetype from = 0) const noexcept + { return QtPrivate::indexOf(*self(), str, from); } + inline qsizetype indexOf(QLatin1String str, qsizetype from = 0) const noexcept + { return QtPrivate::indexOf(*self(), str, from); } -inline QString QListSpecialMethods::join(QChar sep) const -{ - return QtPrivate::QStringList_join(self(), &sep, 1); -} - -inline QStringList QListSpecialMethods::filter(QStringView str, Qt::CaseSensitivity cs) const -{ - return QtPrivate::QStringList_filter(self(), str, cs); -} + inline qsizetype lastIndexOf(QStringView str, qsizetype from = -1) const noexcept + { return QtPrivate::lastIndexOf(*self(), str, from); } + inline qsizetype lastIndexOf(QLatin1String str, qsizetype from = -1) const noexcept + { return QtPrivate::lastIndexOf(*self(), str, from); } #if QT_STRINGVIEW_LEVEL < 2 -inline QStringList QListSpecialMethods::filter(const QString &str, Qt::CaseSensitivity cs) const -{ - return QtPrivate::QStringList_filter(self(), str, cs); -} + inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::QStringList_contains(self(), str, cs); } + qsizetype indexOf(const QString &str, qsizetype from = 0) const noexcept + { return indexOf(QStringView(str), from); } + qsizetype lastIndexOf(const QString &str, qsizetype from = -1) const noexcept + { return lastIndexOf(QStringView(str), from); } #endif -#if QT_STRINGVIEW_LEVEL < 2 -inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const -{ - return QtPrivate::QStringList_contains(this, str, cs); -} -#endif - -inline bool QStringList::contains(QLatin1String str, Qt::CaseSensitivity cs) const -{ - return QtPrivate::QStringList_contains(this, str, cs); -} - -inline bool QStringList::contains(QStringView str, Qt::CaseSensitivity cs) const -{ - return QtPrivate::QStringList_contains(this, str, cs); -} - -inline QStringList &QListSpecialMethods::replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs) -{ - QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); - return *self(); -} - -#if QT_STRINGVIEW_LEVEL < 2 -inline QStringList &QListSpecialMethods::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) -{ - QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); - return *self(); -} - -inline QStringList &QListSpecialMethods::replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs) -{ - QtPrivate::QStringList_replaceInStrings(self(), before, qToStringViewIgnoringNull(after), cs); - return *self(); -} - -inline QStringList &QListSpecialMethods::replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs) -{ - QtPrivate::QStringList_replaceInStrings(self(), QStringView(before), after, cs); - return *self(); -} -#endif - -inline QStringList operator+(const QList &one, const QStringList &other) -{ - QStringList n = one; - n += other; - return n; -} - -inline qsizetype QStringList::indexOf(QStringView string, qsizetype from) const -{ - return QtPrivate::indexOf(*this, string, from); -} - -inline qsizetype QStringList::indexOf(QLatin1String string, qsizetype from) const -{ - return QtPrivate::indexOf(*this, string, from); -} - -inline qsizetype QStringList::lastIndexOf(QStringView string, qsizetype from) const -{ - return QtPrivate::lastIndexOf(*this, string, from); -} - -inline qsizetype QStringList::lastIndexOf(QLatin1String string, qsizetype from) const -{ - return QtPrivate::lastIndexOf(*this, string, from); -} - #if QT_CONFIG(regularexpression) -inline QStringList &QListSpecialMethods::replaceInStrings(const QRegularExpression &rx, const QString &after) -{ - QtPrivate::QStringList_replaceInStrings(self(), rx, after); - return *self(); -} - -inline QStringList QListSpecialMethods::filter(const QRegularExpression &rx) const -{ - return QtPrivate::QStringList_filter(self(), rx); -} - -inline qsizetype QStringList::indexOf(const QRegularExpression &rx, qsizetype from) const -{ - return QtPrivate::QStringList_indexOf(this, rx, from); -} - -inline qsizetype QStringList::lastIndexOf(const QRegularExpression &rx, qsizetype from) const -{ - return QtPrivate::QStringList_lastIndexOf(this, rx, from); -} + inline QStringList filter(const QRegularExpression &re) const + { return QtPrivate::QStringList_filter(self(), re); } + inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after) + { + QtPrivate::QStringList_replaceInStrings(self(), re, after); + return *self(); + } + inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const + { return QtPrivate::QStringList_indexOf(self(), re, from); } + inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const + { return QtPrivate::QStringList_lastIndexOf(self(), re, from); } #endif // QT_CONFIG(regularexpression) -#endif // Q_QDOC +}; QT_END_NAMESPACE diff --git a/src/corelib/tools/qcontainerfwd.h b/src/corelib/tools/qcontainerfwd.h index 069be4ef101..46c2801b000 100644 --- a/src/corelib/tools/qcontainerfwd.h +++ b/src/corelib/tools/qcontainerfwd.h @@ -61,7 +61,7 @@ template class QStack; template class QVarLengthArray; template class QList; template using QVector = QList; -class QStringList; +using QStringList = QList; using QByteArrayList = QList; class QMetaType; class QVariant; diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index ebb0fd95319..5bdc993b670 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -54,14 +54,22 @@ QT_BEGIN_NAMESPACE namespace QtPrivate { - template qsizetype indexOf(const QList &list, const U &u, qsizetype from); - template qsizetype lastIndexOf(const QList &list, const U &u, qsizetype from); + template qsizetype indexOf(const QList &list, const U &u, qsizetype from) noexcept; + template qsizetype lastIndexOf(const QList &list, const U &u, qsizetype from) noexcept; } template struct QListSpecialMethods { protected: ~QListSpecialMethods() = default; +public: + qsizetype indexOf(const T &t, qsizetype from = 0) const noexcept; + qsizetype lastIndexOf(const T &t, qsizetype from = -1) const noexcept; + + bool contains(const T &t) const noexcept + { + return indexOf(t) != -1; + } }; template <> struct QListSpecialMethods; template <> struct QListSpecialMethods; @@ -79,8 +87,8 @@ class QList DataPointer d; - template friend qsizetype QtPrivate::indexOf(const QList &list, const U &u, qsizetype from); - template friend qsizetype QtPrivate::lastIndexOf(const QList &list, const U &u, qsizetype from); + template friend qsizetype QtPrivate::indexOf(const QList &list, const U &u, qsizetype from) noexcept; + template friend qsizetype QtPrivate::lastIndexOf(const QList &list, const U &u, qsizetype from) noexcept; public: typedef T Type; @@ -158,6 +166,11 @@ public: std::copy(i1, i2, std::back_inserter(*this)); } + // This constructor is here for compatibility with QStringList in Qt 5, that has a QStringList(const QString &) constructor + template && std::is_convertible_v>> + inline explicit QList(const String &str) + { append(str); } + // compiler-generated special member functions are fine! void swap(QList &other) noexcept { qSwap(d, other.d); } @@ -289,12 +302,10 @@ public: QList &fill(parameter_type t, qsizetype size = -1); - qsizetype indexOf(const T &t, qsizetype from = 0) const noexcept; - qsizetype lastIndexOf(const T &t, qsizetype from = -1) const noexcept; - bool contains(const T &t) const noexcept - { - return indexOf(t) != -1; - } + using QListSpecialMethods::contains; + using QListSpecialMethods::indexOf; + using QListSpecialMethods::lastIndexOf; + qsizetype count(const T &t) const noexcept { return qsizetype(std::count(&*cbegin(), &*cend(), t)); @@ -705,7 +716,7 @@ inline QList &QList::fill(parameter_type t, qsizetype newSize) namespace QtPrivate { template -qsizetype indexOf(const QList &vector, const U &u, qsizetype from) +qsizetype indexOf(const QList &vector, const U &u, qsizetype from) noexcept { if (from < 0) from = qMax(from + vector.size(), qsizetype(0)); @@ -720,7 +731,7 @@ qsizetype indexOf(const QList &vector, const U &u, qsizetype from) } template -qsizetype lastIndexOf(const QList &vector, const U &u, qsizetype from) +qsizetype lastIndexOf(const QList &vector, const U &u, qsizetype from) noexcept { if (from < 0) from += vector.d->size; @@ -739,15 +750,15 @@ qsizetype lastIndexOf(const QList &vector, const U &u, qsizetype from) } template -qsizetype QList::indexOf(const T &t, qsizetype from) const noexcept +qsizetype QListSpecialMethods::indexOf(const T &t, qsizetype from) const noexcept { - return QtPrivate::indexOf(*this, t, from); + return QtPrivate::indexOf(*static_cast *>(this), t, from); } template -qsizetype QList::lastIndexOf(const T &t, qsizetype from) const noexcept +qsizetype QListSpecialMethods::lastIndexOf(const T &t, qsizetype from) const noexcept { - return QtPrivate::lastIndexOf(*this, t, from); + return QtPrivate::lastIndexOf(*static_cast *>(this), t, from); } template diff --git a/src/gui/accessible/qaccessibleplugin.h b/src/gui/accessible/qaccessibleplugin.h index 68e6a839d82..04169fdeac7 100644 --- a/src/gui/accessible/qaccessibleplugin.h +++ b/src/gui/accessible/qaccessibleplugin.h @@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_ACCESSIBILITY -class QStringList; class QAccessibleInterface; #define QAccessibleFactoryInterface_iid "org.qt-project.Qt.QAccessibleFactoryInterface" diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 0866984dec6..2ce9d96e6a4 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -61,7 +61,6 @@ QT_BEGIN_NAMESPACE class QColorSpace; class QColorTransform; class QIODevice; -class QStringList; class QTransform; class QVariant; diff --git a/src/gui/image/qimagereader.h b/src/gui/image/qimagereader.h index 4d418bd7d08..23c8a916d27 100644 --- a/src/gui/image/qimagereader.h +++ b/src/gui/image/qimagereader.h @@ -53,7 +53,6 @@ class QColor; class QIODevice; class QRect; class QSize; -class QStringList; class QImageReaderPrivate; class Q_GUI_EXPORT QImageReader diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index 65d126374ef..4079e48dda3 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE class QFontPrivate; /* don't touch */ -class QStringList; class QVariant; class Q_GUI_EXPORT QFont diff --git a/src/gui/text/qfontdatabase.h b/src/gui/text/qfontdatabase.h index eacce5a2c42..67f06b8485e 100644 --- a/src/gui/text/qfontdatabase.h +++ b/src/gui/text/qfontdatabase.h @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE -class QStringList; struct QFontDef; class QFontEngine; diff --git a/src/gui/util/qdesktopservices.h b/src/gui/util/qdesktopservices.h index 6e2836e26a6..658b601532b 100644 --- a/src/gui/util/qdesktopservices.h +++ b/src/gui/util/qdesktopservices.h @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_DESKTOPSERVICES -class QStringList; class QUrl; class QObject; diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h index 46119ae0464..8cfeaeb2732 100644 --- a/src/network/ssl/qsslcertificate.h +++ b/src/network/ssl/qsslcertificate.h @@ -61,7 +61,6 @@ class QIODevice; class QSslError; class QSslKey; class QSslCertificateExtension; -class QStringList; class QSslCertificate; // qHash is a friend, but we can't use default arguments for friends (ยง8.3.6.4) diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 92b4c9f09ae..bdf185d2752 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -68,8 +68,6 @@ #include -QT_FORWARD_DECLARE_CLASS(QString) -QT_FORWARD_DECLARE_CLASS(QStringList) QT_FORWARD_DECLARE_CLASS(QFileInfo) QT_FORWARD_DECLARE_CLASS(QWindow) QT_USE_NAMESPACE diff --git a/src/sql/kernel/qsqlrecord.h b/src/sql/kernel/qsqlrecord.h index 94631bafd9b..08aae535dae 100644 --- a/src/sql/kernel/qsqlrecord.h +++ b/src/sql/kernel/qsqlrecord.h @@ -47,7 +47,6 @@ QT_BEGIN_NAMESPACE class QSqlField; -class QStringList; class QVariant; class QSqlRecordPrivate; diff --git a/src/testlib/qbenchmarkvalgrind_p.h b/src/testlib/qbenchmarkvalgrind_p.h index 0619be9f22c..0cbb8bb1037 100644 --- a/src/testlib/qbenchmarkvalgrind_p.h +++ b/src/testlib/qbenchmarkvalgrind_p.h @@ -56,8 +56,6 @@ #include #include -class QStringList; - QT_REQUIRE_CONFIG(valgrind); QT_BEGIN_NAMESPACE diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 7a6bbb5edf6..f9cf7aa9418 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -499,13 +499,6 @@ bool qCompare(QList const &t1, const T (& t2)[N], actual, expected, file, line); } -template <> -inline bool qCompare(QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, - const char *file, int line) -{ - return qCompare(t1, t2, actual, expected, file, line); -} - template inline bool qCompare(QFlags const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index 55134631045..aaf0fc2ae3d 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -61,7 +61,6 @@ QT_BEGIN_NAMESPACE // We mean it. // -class QStringList; class QTextOption; // Private class