From: JÄ™drzej Nowacki Date: Wed, 4 Jan 2012 13:14:08 +0000 (+0100) Subject: Implement QDebug stream operators for builtin classes X-Git-Tag: qt-v5.0.0-alpha1~1947 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18617f2824af67a690ade336f5d27f09752c7206;p=profile%2Fivi%2Fqtbase.git 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 Reviewed-by: Bradley T. Hughes Reviewed-by: Denis Dzyubenko --- diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 1cf171f..46589f8 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -43,6 +43,7 @@ #include "qdatastream.h" #include "qendian.h" +#include "qdebug.h" QT_BEGIN_NAMESPACE @@ -918,6 +919,14 @@ QUuid QUuid::createUuid() 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 */ diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index e7cc919..2eec157 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -189,6 +189,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUuid &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &); +#endif + Q_CORE_EXPORT uint qHash(const QUuid &uuid); QT_END_NAMESPACE diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index 4ef066c..96811cc 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -725,6 +725,24 @@ QDataStream &operator>>(QDataStream &in, QBitArray &ba) } #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() \internal diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index 29abf19..83c81ec 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -170,6 +170,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QBitArray &); +#endif + Q_DECLARE_TYPEINFO(QBitArray, Q_MOVABLE_TYPE); Q_DECLARE_SHARED(QBitArray) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index d977743..1dc3849 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -56,6 +56,7 @@ QT_END_NAMESPACE #include "qplatformdefs.h" #include "qdatastream.h" +#include "qdebug.h" #include "qstring.h" #include "qlocale.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); } +#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 diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index 100dcc9..9bc4ea7 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -806,6 +806,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLocale &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLocale &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QLocale &); +#endif + QT_END_NAMESPACE #ifndef QT_NO_SYSTEMLOCALE diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 9be4944..d300ed9 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -45,6 +45,7 @@ #include "qbitarray.h" #include "qcache.h" #include "qdatastream.h" +#include "qdebug.h" #include "qlist.h" #include "qmap.h" #include "qmutex.h" @@ -4571,4 +4572,13 @@ QDataStream &operator>>(QDataStream &in, QRegExp ®Exp) } #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 diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h index 583fa15..364745e 100644 --- a/src/corelib/tools/qregexp.h +++ b/src/corelib/tools/qregexp.h @@ -127,6 +127,10 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp ®Exp); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp ®Exp); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QRegExp &); +#endif + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 0e5a448..564abd2 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -5863,4 +5863,12 @@ bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFla \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 diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 3abf203..7a5a732 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -406,6 +406,11 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QImage &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QImage &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QImage &); +#endif + + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index cc7171a..48d393c 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -1631,4 +1631,12 @@ QPlatformPixmap* QPixmap::handle() const 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 diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index dfb729a..5e8ef70 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -238,6 +238,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &); +#endif + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index e2fc1e0..bd327e1 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -49,6 +49,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -564,6 +565,15 @@ QCursor::operator QVariant() const { 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 #endif // QT_NO_CURSOR diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index 121bd2c..7437da4 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -126,6 +126,11 @@ private: Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &inS, QCursor &cursor); #endif + +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QCursor &); +#endif + #endif // QT_NO_CURSOR QT_END_NAMESPACE diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 0e06739..2dd2ef0 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -43,6 +43,7 @@ #include "qguiapplication.h" #include "qdatastream.h" #include "qvariant.h" +#include "qdebug.h" QT_BEGIN_NAMESPACE @@ -1081,4 +1082,12 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &foreground, const QBru 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 diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h index 23cecd2..d47854d 100644 --- a/src/gui/kernel/qpalette.h +++ b/src/gui/kernel/qpalette.h @@ -190,6 +190,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p); #endif // QT_NO_DATASTREAM +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &); +#endif + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index a118462..4db5728 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -3321,4 +3321,19 @@ void QTextFormatCollection::setDefaultFont(const QFont &f) 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 diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index a535f90..2e1bcd8 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -81,6 +81,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextLength &); +#endif + class Q_GUI_EXPORT QTextLength { public: @@ -126,6 +130,10 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &); Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextFormat &); +#endif + class Q_GUI_EXPORT QTextFormat { Q_GADGET diff --git a/src/widgets/kernel/qicon.cpp b/src/widgets/kernel/qicon.cpp index 1b1b490..1855424 100644 --- a/src/widgets/kernel/qicon.cpp +++ b/src/widgets/kernel/qicon.cpp @@ -1161,6 +1161,14 @@ QDataStream &operator>>(QDataStream &s, QIcon &icon) #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() \internal diff --git a/src/widgets/kernel/qicon.h b/src/widgets/kernel/qicon.h index 76c7fda..a72ae23 100644 --- a/src/widgets/kernel/qicon.h +++ b/src/widgets/kernel/qicon.h @@ -136,6 +136,10 @@ Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QIcon &); +#endif + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp index 8479ae9..732c941 100644 --- a/src/widgets/kernel/qlayoutitem.cpp +++ b/src/widgets/kernel/qlayoutitem.cpp @@ -42,6 +42,7 @@ #include "qlayout.h" #include "qapplication.h" +#include "qdebug.h" #include "qlayoutengine_p.h" #include "qmenubar.h" #include "qtoolbar.h" @@ -836,4 +837,13 @@ int QWidgetItemV2::heightForWidth(int width) const 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 diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 32ef853..8932eb8 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -181,6 +181,10 @@ Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &); Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); #endif +#ifndef QT_NO_DEBUG_STREAM +Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &); +#endif + inline void QSizePolicy::transpose() { Policy hData = horizontalPolicy(); Policy vData = verticalPolicy();