Skip to content

Commit

Permalink
Remove QBool and use bool instead.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dfaure authored and Qt by Nokia committed Jan 20, 2012
1 parent 841b0c4 commit 47d5d34
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 146 deletions.
6 changes: 6 additions & 0 deletions dist/changes-5.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 0 additions & 17 deletions src/corelib/global/qglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1922,23 +1922,6 @@ class QGlobalStaticDeleter

#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)));
Expand Down
8 changes: 0 additions & 8 deletions src/corelib/io/qdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/corelib/io/qdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class Q_CORE_EXPORT QDebug
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(); }
Expand Down
9 changes: 0 additions & 9 deletions src/corelib/io/qtextstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/corelib/io/qtextstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class Q_CORE_EXPORT QTextStream // text stream cl
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);
Expand Down
6 changes: 3 additions & 3 deletions src/corelib/tools/qbytearray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,23 +1143,23 @@ 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.
\sa indexOf(), count()
*/

/*! \fn QBool QByteArray::contains(const char *str) const
/*! \fn bool QByteArray::contains(const char *str) const
\overload
Returns true if the byte array contains the string \a str;
otherwise returns false.
*/

/*! \fn QBool QByteArray::contains(char ch) const
/*! \fn bool QByteArray::contains(char ch) const
\overload
Expand Down
18 changes: 9 additions & 9 deletions src/corelib/tools/qbytearray.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ class Q_CORE_EXPORT QByteArray
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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/tools/qlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/corelib/tools/qlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class QList
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;
Expand Down Expand Up @@ -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>
Expand Down
46 changes: 23 additions & 23 deletions src/corelib/tools/qstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,22 @@ class Q_CORE_EXPORT QString
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;

#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 {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -1115,10 +1115,10 @@ class Q_CORE_EXPORT QStringRef {
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;
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/corelib/tools/qstringlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,23 @@ 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
Qt::CaseInsensitive; the search is case sensitive by default.
\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
Expand Down
6 changes: 3 additions & 3 deletions src/corelib/tools/qstringlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class QStringList : public QList<QString>
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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/tools/uic/qclass_lib_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 47d5d34

Please sign in to comment.