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 <lars.knoll@nokia.com>
This commit is contained in:
David Faure 2012-01-20 11:22:09 +01:00 committed by Qt by Nokia
parent 841b0c4fac
commit 47d5d349d8
16 changed files with 57 additions and 146 deletions

6
dist/changes-5.0.0 vendored
View File

@ -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:

View File

@ -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<const void *>(this) : static_cast<const void *>(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)));

View File

@ -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)

View File

@ -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(); }

View File

@ -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.

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -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<T>::lastIndexOf(const T &t, int from) const
}
template <typename T>
Q_OUTOFLINE_TEMPLATE QBool QList<T>::contains(const T &t) const
Q_OUTOFLINE_TEMPLATE bool QList<T>::contains(const T &t) const
{
Node *b = reinterpret_cast<Node *>(p.begin());
Node *i = reinterpret_cast<Node *>(p.end());
while (i-- != b)
if (i->t() == t)
return QBool(true);
return QBool(false);
return true;
return false;
}
template <typename T>

View File

@ -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<const QChar*>(d->data() + d->size); }
inline QString::const_iterator QString::constEnd() const
{ return reinterpret_cast<const QChar*>(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)

View File

@ -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

View File

@ -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);
}

View File

@ -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)

View File

@ -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 = "";

View File

@ -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 "));
}