From 47d5d349d8f5bc590ca7cdf30bf13b69bddf3225 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 20 Jan 2012 11:22:09 +0100 Subject: [PATCH] Remove QBool and use bool instead. QBool was introduced with Qt-4.0, to detect Qt3-like code like if (c.contains(d) == 2) and break compilation on such constructs. This isn't necessary anymore, given that such code couldn't possibly compile in Qt4 times. And QBool was confusing developers, and creating compile errors (e.g. QVariant doesn't have support for it), so better remove it for Qt 5. Change-Id: I6642f43f5e12b872f98abb56600186179f072b09 Reviewed-by: Lars Knoll --- dist/changes-5.0.0 | 6 ++ src/corelib/global/qglobal.h | 17 ------ src/corelib/io/qdebug.cpp | 8 --- src/corelib/io/qdebug.h | 1 - src/corelib/io/qtextstream.cpp | 9 --- src/corelib/io/qtextstream.h | 1 - src/corelib/tools/qbytearray.cpp | 6 +- src/corelib/tools/qbytearray.h | 18 +++--- src/corelib/tools/qlist.cpp | 2 +- src/corelib/tools/qlist.h | 8 +-- src/corelib/tools/qstring.h | 46 +++++++-------- src/corelib/tools/qstringlist.cpp | 10 ++-- src/corelib/tools/qstringlist.h | 6 +- src/tools/uic/qclass_lib_map.h | 1 - .../io/qdatastream/tst_qdatastream.cpp | 58 ------------------- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 6 +- 16 files changed, 57 insertions(+), 146 deletions(-) diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0 index eb9c1a8fdc..d74dd627d4 100644 --- a/dist/changes-5.0.0 +++ b/dist/changes-5.0.0 @@ -39,6 +39,12 @@ information about a particular change. - Qt::escape() is deprecated (but can be enabled via QT_DISABLE_DEPRECATED_BEFORE), use QString::toHtmlEscaped() instead. +- QBool is gone. QString::contains, QByteArray::contains, and QList::contains + used to return an internal QBool class so that the Qt3 code + "if (a.contains() == 2)" wouldn't compile anymore. Such code cannot exist + in Qt4, so these methods return a bool now. If your code used the undocumented + QBool, simply replace it with bool. + - QMetaType::construct() has been renamed to QMetaType::create(). - QTestLib: diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 2b868df75d..4a606f556e 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1922,23 +1922,6 @@ public: #endif -class QBool -{ - bool b; - -public: - inline explicit QBool(bool B) : b(B) {} - inline operator const void *() const - { return b ? static_cast(this) : static_cast(0); } -}; - -inline bool operator==(QBool b1, bool b2) { return !b1 == !b2; } -inline bool operator==(bool b1, QBool b2) { return !b1 == !b2; } -inline bool operator==(QBool b1, QBool b2) { return !b1 == !b2; } -inline bool operator!=(QBool b1, bool b2) { return !b1 != !b2; } -inline bool operator!=(bool b1, QBool b2) { return !b1 != !b2; } -inline bool operator!=(QBool b1, QBool b2) { return !b1 != !b2; } - Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(double p1, double p2) { return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2))); diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 8ca15b19ca..18f6d1692d 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -164,14 +164,6 @@ stream. */ -/*! - \fn QDebug &QDebug::operator<<(QBool t) - \internal - - Writes the boolean value, \a t, to the stream and returns a reference to the - stream. -*/ - /*! \fn QDebug &QDebug::operator<<(bool t) diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 54663d5d65..a86cdb68a8 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -93,7 +93,6 @@ public: inline QDebug &maybeSpace() { if (stream->space) stream->ts << ' '; return *this; } inline QDebug &operator<<(QChar t) { stream->ts << '\'' << t << '\''; return maybeSpace(); } - inline QDebug &operator<<(QBool t) { stream->ts << (bool(t != 0) ? "true" : "false"); return maybeSpace(); } inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); } inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); } diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 8c7f57fddf..e26a2034dc 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -2323,15 +2323,6 @@ void QTextStreamPrivate::putNumber(qulonglong number, bool negative) putString(result, true); } -/*! - \internal - \overload -*/ -QTextStream &QTextStream::operator<<(QBool b) -{ - return *this << bool(b); -} - /*! Writes the character \a c to the stream, then returns a reference to the QTextStream. diff --git a/src/corelib/io/qtextstream.h b/src/corelib/io/qtextstream.h index 0531d4017d..9c3b98d8ac 100644 --- a/src/corelib/io/qtextstream.h +++ b/src/corelib/io/qtextstream.h @@ -175,7 +175,6 @@ public: QTextStream &operator>>(QByteArray &array); QTextStream &operator>>(char *c); - QTextStream &operator<<(QBool b); QTextStream &operator<<(QChar ch); QTextStream &operator<<(char ch); QTextStream &operator<<(signed short i); diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 8c625c2868..ec68bbbd3e 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1143,7 +1143,7 @@ QByteArray &QByteArray::operator=(const char *str) \overload */ -/*! \fn QBool QByteArray::contains(const QByteArray &ba) const +/*! \fn bool QByteArray::contains(const QByteArray &ba) const Returns true if the byte array contains an occurrence of the byte array \a ba; otherwise returns false. @@ -1151,7 +1151,7 @@ QByteArray &QByteArray::operator=(const char *str) \sa indexOf(), count() */ -/*! \fn QBool QByteArray::contains(const char *str) const +/*! \fn bool QByteArray::contains(const char *str) const \overload @@ -1159,7 +1159,7 @@ QByteArray &QByteArray::operator=(const char *str) otherwise returns false. */ -/*! \fn QBool QByteArray::contains(char ch) const +/*! \fn bool QByteArray::contains(char ch) const \overload diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index e96997909f..49da83b041 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -232,9 +232,9 @@ public: int lastIndexOf(const char *c, int from = -1) const; int lastIndexOf(const QByteArray &a, int from = -1) const; - QBool contains(char c) const; - QBool contains(const char *a) const; - QBool contains(const QByteArray &a) const; + bool contains(char c) const; + bool contains(const char *a) const; + bool contains(const QByteArray &a) const; int count(char c) const; int count(const char *a) const; int count(const QByteArray &a) const; @@ -523,10 +523,10 @@ inline void QByteArray::push_front(const char *c) { prepend(c); } inline void QByteArray::push_front(const QByteArray &a) { prepend(a); } -inline QBool QByteArray::contains(const QByteArray &a) const -{ return QBool(indexOf(a) != -1); } -inline QBool QByteArray::contains(char c) const -{ return QBool(indexOf(c) != -1); } +inline bool QByteArray::contains(const QByteArray &a) const +{ return indexOf(a) != -1; } +inline bool QByteArray::contains(char c) const +{ return indexOf(c) != -1; } inline bool operator==(const QByteArray &a1, const QByteArray &a2) { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); } inline bool operator==(const QByteArray &a1, const char *a2) @@ -575,8 +575,8 @@ inline const QByteArray operator+(const char *a1, const QByteArray &a2) inline const QByteArray operator+(char a1, const QByteArray &a2) { return QByteArray(&a1, 1) += a2; } #endif // QT_USE_QSTRINGBUILDER -inline QBool QByteArray::contains(const char *c) const -{ return QBool(indexOf(c) != -1); } +inline bool QByteArray::contains(const char *c) const +{ return indexOf(c) != -1; } inline QByteArray &QByteArray::replace(char before, const char *c) { return replace(&before, 1, c, qstrlen(c)); } inline QByteArray &QByteArray::replace(const QByteArray &before, const char *c) diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index adc6ee7a4b..4e62b8d0b0 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -869,7 +869,7 @@ void **QListData::erase(void **xi) \sa indexOf() */ -/*! \fn QBool QList::contains(const T &value) const +/*! \fn bool QList::contains(const T &value) const Returns true if the list contains an occurrence of \a value; otherwise returns false. diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index d192d31234..194c65a4da 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -170,7 +170,7 @@ public: void swap(int i, int j); int indexOf(const T &t, int from = 0) const; int lastIndexOf(const T &t, int from = -1) const; - QBool contains(const T &t) const; + bool contains(const T &t) const; int count(const T &t) const; class const_iterator; @@ -859,14 +859,14 @@ Q_OUTOFLINE_TEMPLATE int QList::lastIndexOf(const T &t, int from) const } template -Q_OUTOFLINE_TEMPLATE QBool QList::contains(const T &t) const +Q_OUTOFLINE_TEMPLATE bool QList::contains(const T &t) const { Node *b = reinterpret_cast(p.begin()); Node *i = reinterpret_cast(p.end()); while (i-- != b) if (i->t() == t) - return QBool(true); - return QBool(false); + return true; + return false; } template diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index f2d1de9c00..5be5243029 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -266,9 +266,9 @@ public: int lastIndexOf(const QLatin1String &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int lastIndexOf(const QStringRef &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -276,12 +276,12 @@ public: #ifndef QT_NO_REGEXP int indexOf(const QRegExp &, int from = 0) const; int lastIndexOf(const QRegExp &, int from = -1) const; - inline QBool contains(const QRegExp &rx) const { return QBool(indexOf(rx) != -1); } + inline bool contains(const QRegExp &rx) const { return indexOf(rx) != -1; } int count(const QRegExp &) const; int indexOf(QRegExp &, int from = 0) const; int lastIndexOf(QRegExp &, int from = -1) const; - inline QBool contains(QRegExp &rx) const { return QBool(indexOf(rx) != -1); } + inline bool contains(QRegExp &rx) const { return indexOf(rx) != -1; } #endif enum SectionFlag { @@ -910,12 +910,12 @@ inline QString::const_iterator QString::end() const { return reinterpret_cast(d->data() + d->size); } inline QString::const_iterator QString::constEnd() const { return reinterpret_cast(d->data() + d->size); } -inline QBool QString::contains(const QString &s, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(s, 0, cs) != -1); } -inline QBool QString::contains(const QStringRef &s, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(s, 0, cs) != -1); } -inline QBool QString::contains(QChar c, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(c, 0, cs) != -1); } +inline bool QString::contains(const QString &s, Qt::CaseSensitivity cs) const +{ return indexOf(s, 0, cs) != -1; } +inline bool QString::contains(const QStringRef &s, Qt::CaseSensitivity cs) const +{ return indexOf(s, 0, cs) != -1; } +inline bool QString::contains(QChar c, Qt::CaseSensitivity cs) const +{ return indexOf(c, 0, cs) != -1; } inline bool operator==(QString::Null, QString::Null) { return true; } @@ -1115,10 +1115,10 @@ public: int lastIndexOf(QLatin1String str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int lastIndexOf(const QStringRef &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline bool contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -1258,14 +1258,14 @@ inline int QStringRef::localeAwareCompare(const QStringRef &s1, const QString &s inline int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef &s2) { return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } -inline QBool QStringRef::contains(const QString &s, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(s, 0, cs) != -1); } -inline QBool QStringRef::contains(QLatin1String s, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(s, 0, cs) != -1); } -inline QBool QStringRef::contains(QChar c, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(c, 0, cs) != -1); } -inline QBool QStringRef::contains(const QStringRef &s, Qt::CaseSensitivity cs) const -{ return QBool(indexOf(s, 0, cs) != -1); } +inline bool QStringRef::contains(const QString &s, Qt::CaseSensitivity cs) const +{ return indexOf(s, 0, cs) != -1; } +inline bool QStringRef::contains(QLatin1String s, Qt::CaseSensitivity cs) const +{ return indexOf(s, 0, cs) != -1; } +inline bool QStringRef::contains(QChar c, Qt::CaseSensitivity cs) const +{ return indexOf(c, 0, cs) != -1; } +inline bool QStringRef::contains(const QStringRef &s, Qt::CaseSensitivity cs) const +{ return indexOf(s, 0, cs) != -1; } namespace Qt { #if QT_DEPRECATED_SINCE(5, 0) diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index 1fca78b03b..f260f65c77 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -266,7 +266,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString /*! - \fn QBool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const + \fn bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const Returns true if the list contains the string \a str; otherwise returns false. The search is case insensitive if \a cs is @@ -274,15 +274,15 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString \sa indexOf(), lastIndexOf(), QString::contains() */ -QBool QtPrivate::QStringList_contains(const QStringList *that, const QString &str, - Qt::CaseSensitivity cs) +bool QtPrivate::QStringList_contains(const QStringList *that, const QString &str, + Qt::CaseSensitivity cs) { for (int i = 0; i < that->size(); ++i) { const QString & string = that->at(i); if (string.length() == str.length() && str.compare(string, cs) == 0) - return QBool(true); + return true; } - return QBool(false); + return false; } #ifndef QT_NO_REGEXP diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index 6c32f11096..6a9141c70e 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -77,7 +77,7 @@ public: inline QString join(const QString &sep) const; inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline QBool contains(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); @@ -114,7 +114,7 @@ namespace QtPrivate { QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); - QBool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); + bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs); @@ -148,7 +148,7 @@ inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity c return QtPrivate::QStringList_filter(this, str, cs); } -inline QBool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const +inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const { return QtPrivate::QStringList_contains(this, str, cs); } diff --git a/src/tools/uic/qclass_lib_map.h b/src/tools/uic/qclass_lib_map.h index 19664d4d01..9ef0e2fa7d 100644 --- a/src/tools/uic/qclass_lib_map.h +++ b/src/tools/uic/qclass_lib_map.h @@ -54,7 +54,6 @@ QT_CLASS_LIB(QtMsgHandler, QtCore, qglobal.h) QT_CLASS_LIB(QGlobalStatic, QtCore, qglobal.h) QT_CLASS_LIB(QGlobalStatic, QtCore, qglobal.h) QT_CLASS_LIB(QGlobalStaticDeleter, QtCore, qglobal.h) -QT_CLASS_LIB(QBool, QtCore, qglobal.h) QT_CLASS_LIB(QTypeInfo, QtCore, qglobal.h) QT_CLASS_LIB(QTypeInfo, QtCore, qglobal.h) QT_CLASS_LIB(QFlag, QtCore, qglobal.h) diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index d17bab3bc1..d81e341e73 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -65,11 +65,6 @@ private slots: void stream_bool_data(); void stream_bool(); - void stream_QBool_data(); - void stream_QBool(); - - void stream_QBool_in_4_0(); - void stream_QBitArray_data(); void stream_QBitArray(); @@ -193,7 +188,6 @@ private slots: private: void writebool(QDataStream *s); - void writeQBool(QDataStream *s); void writeQBitArray(QDataStream *s); void writeQBrush(QDataStream *s); void writeQColor(QDataStream *s); @@ -221,7 +215,6 @@ private: void writeQEasingCurve(QDataStream *s); void readbool(QDataStream *s); - void readQBool(QDataStream *s); void readQBitArray(QDataStream *s); void readQBrush(QDataStream *s); void readQColor(QDataStream *s); @@ -797,57 +790,6 @@ void tst_QDataStream::readbool(QDataStream *s) // ************************************ -static QBool QBoolData(int index) -{ - switch (index) { - case 0: return QBool(true); - case 1: return QBool(false); - case 2: return QBool(bool(2)); - case 3: return QBool(bool(-1)); - case 4: return QBool(bool(127)); - } - - return QBool(false); -} - -void tst_QDataStream::stream_QBool_data() -{ - stream_data(5); -} - -void tst_QDataStream::stream_QBool() -{ - STREAM_IMPL(QBool); -} - -void tst_QDataStream::writeQBool(QDataStream *s) -{ - QBool d1 = QBoolData(dataIndex(QTest::currentDataTag())); - *s << d1; -} - -void tst_QDataStream::readQBool(QDataStream *s) -{ - QBool expected = QBoolData(dataIndex(QTest::currentDataTag())); - - bool d1 = true; - *s >> d1; - QVERIFY(d1 == expected); -} - -void tst_QDataStream::stream_QBool_in_4_0() -{ - QByteArray byteArray; - QDataStream out(&byteArray, QIODevice::WriteOnly); - - QString str("ABC"); - out << str.contains('A') << str.contains('Z'); - - QCOMPARE(byteArray.size(), 2); -} - -// ************************************ - static void QBitArrayData(QBitArray *b, int index) { QString filler = ""; diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 535807bfc3..d54f6c9fbe 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -51,7 +51,7 @@ private slots: void assignment() const; void warningWithoutDebug() const; void criticalWithoutDebug() const; - void debugWithQBool() const; + void debugWithBool() const; void veryLongWarningMessage() const; void qDebugQStringRef() const; void defaultMessagehandler() const; @@ -122,10 +122,10 @@ void tst_QDebug::criticalWithoutDebug() const QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("A qCritical() message ")); } -void tst_QDebug::debugWithQBool() const +void tst_QDebug::debugWithBool() const { MessageHandlerSetter mhs(myMessageHandler); - { qDebug() << QBool(false) << QBool(true); } + { qDebug() << false << true; } QCOMPARE(s_msgType, QtDebugMsg); QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("false true ")); }