Implement QDebug stream operators for builtin classes

QDebug stream operator was added for:
QPixmap, QImage, QUuid, QBitArray, QLocale, QRegExp, QCursor,
QPalette, QTextFormat, QTextLength, QIcon and QSizePolicy

Change-Id: Ibcf5c9b599ba322d53cb106d8e5e157427ebe757
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
This commit is contained in:
Jędrzej Nowacki 2012-01-04 14:14:08 +01:00 committed by Qt by Nokia
parent b03fa845a7
commit 18617f2824
22 changed files with 165 additions and 0 deletions

View File

@ -43,6 +43,7 @@
#include "qdatastream.h" #include "qdatastream.h"
#include "qendian.h" #include "qendian.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -918,6 +919,14 @@ QUuid QUuid::createUuid()
guid; otherwise returns false. guid; otherwise returns false.
*/ */
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QUuid &id)
{
dbg.nospace() << "QUuid(" << id.toString() << ')';
return dbg.space();
}
#endif
/** /**
Returns a hash of the QUuid Returns a hash of the QUuid
*/ */

View File

@ -189,6 +189,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUuid &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &);
#endif
Q_CORE_EXPORT uint qHash(const QUuid &uuid); Q_CORE_EXPORT uint qHash(const QUuid &uuid);
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -725,6 +725,24 @@ QDataStream &operator>>(QDataStream &in, QBitArray &ba)
} }
#endif // QT_NO_DATASTREAM #endif // QT_NO_DATASTREAM
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QBitArray &array)
{
dbg.nospace() << "QBitArray(";
for (int i = 0; i < array.size();) {
if (array.testBit(i))
dbg.nospace() << '1';
else
dbg.nospace() << '0';
i += 1;
if (!(i % 4) && (i < array.size()))
dbg.nospace() << ' ';
}
dbg.nospace() << ')';
return dbg.space();
}
#endif
/*! /*!
\fn DataPtr &QBitArray::data_ptr() \fn DataPtr &QBitArray::data_ptr()
\internal \internal

View File

@ -170,6 +170,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QBitArray &);
#endif
Q_DECLARE_TYPEINFO(QBitArray, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(QBitArray, Q_MOVABLE_TYPE);
Q_DECLARE_SHARED(QBitArray) Q_DECLARE_SHARED(QBitArray)

View File

@ -56,6 +56,7 @@ QT_END_NAMESPACE
#include "qplatformdefs.h" #include "qplatformdefs.h"
#include "qdatastream.h" #include "qdatastream.h"
#include "qdebug.h"
#include "qstring.h" #include "qstring.h"
#include "qlocale.h" #include "qlocale.h"
#include "qlocale_p.h" #include "qlocale_p.h"
@ -3325,4 +3326,13 @@ QString QLocale::nativeCountryName() const
return getLocaleData(endonyms_data + d()->m_country_endonym_idx, d()->m_country_endonym_size); return getLocaleData(endonyms_data + d()->m_country_endonym_idx, d()->m_country_endonym_size);
} }
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QLocale &l)
{
dbg.nospace() << "QLocale(" << qPrintable(QLocale::languageToString(l.language()))
<< ", " << qPrintable(QLocale::scriptToString(l.script()))
<< ", " << qPrintable(QLocale::countryToString(l.country())) << ')';
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -806,6 +806,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLocale &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLocale &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLocale &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QLocale &);
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
#ifndef QT_NO_SYSTEMLOCALE #ifndef QT_NO_SYSTEMLOCALE

View File

@ -45,6 +45,7 @@
#include "qbitarray.h" #include "qbitarray.h"
#include "qcache.h" #include "qcache.h"
#include "qdatastream.h" #include "qdatastream.h"
#include "qdebug.h"
#include "qlist.h" #include "qlist.h"
#include "qmap.h" #include "qmap.h"
#include "qmutex.h" #include "qmutex.h"
@ -4571,4 +4572,13 @@ QDataStream &operator>>(QDataStream &in, QRegExp &regExp)
} }
#endif // QT_NO_DATASTREAM #endif // QT_NO_DATASTREAM
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QRegExp &r)
{
dbg.nospace() << "QRegExp(patternSyntax=" << r.patternSyntax()
<< ", pattern='"<< r.pattern() << "')";
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -127,6 +127,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QRegExp &);
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER

View File

@ -5863,4 +5863,12 @@ bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFla
\internal \internal
*/ */
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QImage &i)
{
dbg.nospace() << "QImage(" << i.size() << ')';
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -406,6 +406,11 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QImage &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QImage &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QImage &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QImage &);
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER

View File

@ -1631,4 +1631,12 @@ QPlatformPixmap* QPixmap::handle() const
return data.data(); return data.data();
} }
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QPixmap &r)
{
dbg.nospace() << "QPixmap(" << r.size() << ')';
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -238,6 +238,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &);
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER

View File

@ -49,6 +49,7 @@
#include <qdatastream.h> #include <qdatastream.h>
#include <qvariant.h> #include <qvariant.h>
#include <private/qcursor_p.h> #include <private/qcursor_p.h>
#include <qdebug.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -564,6 +565,15 @@ QCursor::operator QVariant() const
{ {
return QVariant(QVariant::Cursor, this); return QVariant(QVariant::Cursor, this);
} }
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QCursor &c)
{
dbg.nospace() << "QCursor(Qt::CursorShape(" << c.shape() << "))";
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QT_NO_CURSOR #endif // QT_NO_CURSOR

View File

@ -126,6 +126,11 @@ private:
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor); Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &inS, QCursor &cursor); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &inS, QCursor &cursor);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QCursor &);
#endif
#endif // QT_NO_CURSOR #endif // QT_NO_CURSOR
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -43,6 +43,7 @@
#include "qguiapplication.h" #include "qguiapplication.h"
#include "qdatastream.h" #include "qdatastream.h"
#include "qvariant.h" #include "qvariant.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -1081,4 +1082,12 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &foreground, const QBru
setBrush(cg, ToolTipText, toolTipText); setBrush(cg, ToolTipText, toolTipText);
} }
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QPalette &)
{
dbg.nospace() << "QPalette()";
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -190,6 +190,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
#endif // QT_NO_DATASTREAM #endif // QT_NO_DATASTREAM
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER

View File

@ -3321,4 +3321,19 @@ void QTextFormatCollection::setDefaultFont(const QFont &f)
formats[i].d->resolveFont(defaultFnt); formats[i].d->resolveFont(defaultFnt);
} }
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QTextLength &l)
{
dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";
return dbg.space();
}
QDebug operator<<(QDebug dbg, const QTextFormat &f)
{
dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -81,6 +81,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextLength &);
#endif
class Q_GUI_EXPORT QTextLength class Q_GUI_EXPORT QTextLength
{ {
public: public:
@ -126,6 +130,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextFormat &);
#endif
class Q_GUI_EXPORT QTextFormat class Q_GUI_EXPORT QTextFormat
{ {
Q_GADGET Q_GADGET

View File

@ -1161,6 +1161,14 @@ QDataStream &operator>>(QDataStream &s, QIcon &icon)
#endif //QT_NO_DATASTREAM #endif //QT_NO_DATASTREAM
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QIcon &i)
{
dbg.nospace() << "QIcon(" << i.name() << ')';
return dbg.space();
}
#endif
/*! /*!
\fn DataPtr &QIcon::data_ptr() \fn DataPtr &QIcon::data_ptr()
\internal \internal

View File

@ -136,6 +136,10 @@ Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER

View File

@ -42,6 +42,7 @@
#include "qlayout.h" #include "qlayout.h"
#include "qapplication.h" #include "qapplication.h"
#include "qdebug.h"
#include "qlayoutengine_p.h" #include "qlayoutengine_p.h"
#include "qmenubar.h" #include "qmenubar.h"
#include "qtoolbar.h" #include "qtoolbar.h"
@ -836,4 +837,13 @@ int QWidgetItemV2::heightForWidth(int width) const
return height; return height;
} }
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QSizePolicy &p)
{
dbg.nospace() << "QSizePolicy(horizontalPolicy = " << p.horizontalPolicy()
<< ", verticalPolicy = " << p.verticalPolicy() << ')';
return dbg.space();
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -181,6 +181,10 @@ Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
#endif #endif
#ifndef QT_NO_DEBUG_STREAM
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
#endif
inline void QSizePolicy::transpose() { inline void QSizePolicy::transpose() {
Policy hData = horizontalPolicy(); Policy hData = horizontalPolicy();
Policy vData = verticalPolicy(); Policy vData = verticalPolicy();