diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index b91fd38a5f..a5e43e2ca5 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -475,6 +475,12 @@ void **QListData::erase(void **xi) If T is a QByteArray, this class has a couple more members that can be used. See the documentation for QByteArrayList for more information. + If T is QString, this class has the following additional members: + \l{QStringList::filter()}{filter}, + \l{QStringList::join()}{join}, + \l{QStringList::removeDuplicates()}{removeDuplicates}, + \l{QStringList::sort()}{sort}. + \sa QListIterator, QMutableListIterator, QLinkedList, QVector */ diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 533f1d6dbc..321c3e6765 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -948,6 +948,7 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) QT_END_NAMESPACE #include +#include #ifdef Q_CC_MSVC #pragma warning( pop ) diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index cce67820f8..542ab781c5 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -31,27 +31,64 @@ ** ****************************************************************************/ +#include + #ifndef QSTRINGLIST_H #define QSTRINGLIST_H #include -#include -#include #include #include #include QT_BEGIN_NAMESPACE - class QRegExp; class QRegularExpression; typedef QListIterator QStringListIterator; typedef QMutableListIterator QMutableStringListIterator; +class QStringList; + +#ifdef Q_QDOC +class QStringList : public QList +#else +template <> struct QListSpecialMethods +#endif +{ +public: + inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); + inline int removeDuplicates(); + + inline QString join(const QString &sep) const; + inline QString join(QChar sep) const; + + 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); + +#ifndef QT_NO_REGEXP + inline QStringList filter(const QRegExp &rx) const; + inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after); +#endif + +#ifndef QT_BOOTSTRAPPED +#ifndef QT_NO_REGULAREXPRESSION + inline QStringList filter(const QRegularExpression &re) const; + inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after); +#endif // QT_NO_REGULAREXPRESSION +#endif // QT_BOOTSTRAPPED + +#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: inline QStringList() { } inline explicit QStringList(const QString &i) { append(i); } @@ -70,17 +107,8 @@ public: { QList::operator=(std::move(other)); return *this; } #endif - inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); - inline int removeDuplicates(); - - inline QString join(const QString &sep) const; - inline QString join(QChar sep) const; - - inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; inline bool contains(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 operator+(const QStringList &other) const { QStringList n = *this; n += other; return n; } inline QStringList &operator<<(const QString &str) @@ -91,8 +119,6 @@ public: { *this += l; return *this; } #ifndef QT_NO_REGEXP - inline QStringList filter(const QRegExp &rx) const; - inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after); inline int indexOf(const QRegExp &rx, int from = 0) const; inline int lastIndexOf(const QRegExp &rx, int from = -1) const; inline int indexOf(QRegExp &rx, int from = 0) const; @@ -101,8 +127,6 @@ public: #ifndef QT_BOOTSTRAPPED #ifndef QT_NO_REGULAREXPRESSION - inline QStringList filter(const QRegularExpression &re) const; - inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after); inline int indexOf(const QRegularExpression &re, int from = 0) const; inline int lastIndexOf(const QRegularExpression &re, int from = -1) const; #endif // QT_NO_REGULAREXPRESSION @@ -114,6 +138,11 @@ public: Q_DECLARE_TYPEINFO(QStringList, Q_MOVABLE_TYPE); +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); int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); @@ -144,29 +173,29 @@ namespace QtPrivate { #endif // QT_BOOTSTRAPPED } -inline void QStringList::sort(Qt::CaseSensitivity cs) +inline void QListSpecialMethods::sort(Qt::CaseSensitivity cs) { - QtPrivate::QStringList_sort(this, cs); + QtPrivate::QStringList_sort(self(), cs); } -inline int QStringList::removeDuplicates() +inline int QListSpecialMethods::removeDuplicates() { - return QtPrivate::QStringList_removeDuplicates(this); + return QtPrivate::QStringList_removeDuplicates(self()); } -inline QString QStringList::join(const QString &sep) const +inline QString QListSpecialMethods::join(const QString &sep) const { - return QtPrivate::QStringList_join(this, sep.constData(), sep.length()); + return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); } -inline QString QStringList::join(QChar sep) const +inline QString QListSpecialMethods::join(QChar sep) const { - return QtPrivate::QStringList_join(this, &sep, 1); + return QtPrivate::QStringList_join(self(), &sep, 1); } -inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const +inline QStringList QListSpecialMethods::filter(const QString &str, Qt::CaseSensitivity cs) const { - return QtPrivate::QStringList_filter(this, str, cs); + return QtPrivate::QStringList_filter(self(), str, cs); } inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const @@ -174,22 +203,29 @@ inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) co return QtPrivate::QStringList_contains(this, str, cs); } -inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) +inline QStringList &QListSpecialMethods::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) { - QtPrivate::QStringList_replaceInStrings(this, before, after, cs); - return *this; + QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); + return *self(); +} + +inline QStringList operator+(const QList &one, const QStringList &other) +{ + QStringList n = one; + n += other; + return n; } #ifndef QT_NO_REGEXP -inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after) +inline QStringList &QListSpecialMethods::replaceInStrings(const QRegExp &rx, const QString &after) { - QtPrivate::QStringList_replaceInStrings(this, rx, after); - return *this; + QtPrivate::QStringList_replaceInStrings(self(), rx, after); + return *self(); } -inline QStringList QStringList::filter(const QRegExp &rx) const +inline QStringList QListSpecialMethods::filter(const QRegExp &rx) const { - return QtPrivate::QStringList_filter(this, rx); + return QtPrivate::QStringList_filter(self(), rx); } inline int QStringList::indexOf(const QRegExp &rx, int from) const @@ -215,15 +251,15 @@ inline int QStringList::lastIndexOf(QRegExp &rx, int from) const #ifndef QT_BOOTSTRAPPED #ifndef QT_NO_REGULAREXPRESSION -inline QStringList &QStringList::replaceInStrings(const QRegularExpression &rx, const QString &after) +inline QStringList &QListSpecialMethods::replaceInStrings(const QRegularExpression &rx, const QString &after) { - QtPrivate::QStringList_replaceInStrings(this, rx, after); - return *this; + QtPrivate::QStringList_replaceInStrings(self(), rx, after); + return *self(); } -inline QStringList QStringList::filter(const QRegularExpression &rx) const +inline QStringList QListSpecialMethods::filter(const QRegularExpression &rx) const { - return QtPrivate::QStringList_filter(this, rx); + return QtPrivate::QStringList_filter(self(), rx); } inline int QStringList::indexOf(const QRegularExpression &rx, int from) const