diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index 78349fbc49..4c189bfe57 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -7,6 +7,7 @@ HEADERS += \ io/qdatastream_p.h \ io/qdataurl_p.h \ io/qdebug.h \ + io/qdebug_p.h \ io/qdir.h \ io/qdir_p.h \ io/qdiriterator.h \ diff --git a/src/corelib/io/qdebug_p.h b/src/corelib/io/qdebug_p.h new file mode 100644 index 0000000000..0525929169 --- /dev/null +++ b/src/corelib/io/qdebug_p.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDEBUG_P_H +#define QDEBUG_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qdebug.h" +#include "QtCore/qmetaobject.h" +#include "QtCore/qflags.h" + +QT_BEGIN_NAMESPACE + +namespace QtDebugUtils { + +// inline helpers for formatting basic classes. + +template +static inline void formatQPoint(QDebug &debug, const Point &point) +{ + debug << point.x() << ',' << point.y(); +} + +template +static inline void formatQSize(QDebug &debug, const Size &size) +{ + debug << size.width() << ", " << size.height(); +} + +template +static inline void formatQRect(QDebug &debug, const Rect &rect) +{ + debug << rect.x() << ',' << rect.y() << ' ' << rect.width() << 'x' << rect.height(); +} + +template +static inline void formatQMargins(QDebug &debug, const Margins &margins) +{ + debug << margins.left() << ", " << margins.top() << ", " << margins.right() + << ", " << margins.bottom(); +} + +#ifndef QT_NO_QOBJECT +template +static inline void formatQEnum(QDebug &debug, QEnum value) +{ + const QMetaObject *metaObject = qt_getEnumMetaObject(value); + const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(value))); + if (const char *key = me.valueToKey(value)) + debug << key; + else + debug << int(value); +} + +template +static inline void formatNonNullQEnum(QDebug &debug, const char *prefix, QEnum value) +{ + if (value) { + debug << prefix; + formatQEnum(debug, value); + } +} + +template +static inline void formatQFlags(QDebug &debug, const QFlags &value) +{ + const QMetaObject *metaObject = qt_getEnumMetaObject(Enum()); + const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(Enum()))); + const QDebugStateSaver saver(debug); + debug.noquote(); + debug << me.valueToKeys(value); +} + +template +static inline void formatNonNullQFlags(QDebug &debug, const char *prefix, const QFlags &value) +{ + if (value) { + debug << prefix; + formatQFlags(debug, value); + } +} + +#endif // !QT_NO_QOBJECT + +} // namespace QtDebugUtils + +QT_END_NAMESPACE + +#endif // QDEBUG_P_H diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp index a9413d6b5c..92c977a73b 100644 --- a/src/corelib/tools/qmargins.cpp +++ b/src/corelib/tools/qmargins.cpp @@ -33,7 +33,8 @@ #include "qmargins.h" #include "qdatastream.h" -#include "qdebug.h" + +#include QT_BEGIN_NAMESPACE @@ -431,10 +432,13 @@ QDataStream &operator>>(QDataStream &s, QMargins &m) #endif // QT_NO_DATASTREAM #ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QMargins &m) { +QDebug operator<<(QDebug dbg, const QMargins &m) +{ QDebugStateSaver saver(dbg); - dbg.nospace() << "QMargins(" << m.left() << ", " - << m.top() << ", " << m.right() << ", " << m.bottom() << ')'; + dbg.nospace(); + dbg << "QMargins" << '('; + QtDebugUtils::formatQMargins(dbg, m); + dbg << ')'; return dbg; } #endif @@ -764,10 +768,13 @@ QDataStream &operator>>(QDataStream &s, QMarginsF &m) #endif // QT_NO_DATASTREAM #ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QMarginsF &m) { +QDebug operator<<(QDebug dbg, const QMarginsF &m) +{ QDebugStateSaver saver(dbg); - dbg.nospace() << "QMarginsF(" << m.left() << ", " - << m.top() << ", " << m.right() << ", " << m.bottom() << ')'; + dbg.nospace(); + dbg << "QMarginsF" << '('; + QtDebugUtils::formatQMargins(dbg, m); + dbg << ')'; return dbg; } #endif diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index ebce6c9422..dc2a2d9739 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -33,7 +33,8 @@ #include "qpoint.h" #include "qdatastream.h" -#include "qdebug.h" + +#include QT_BEGIN_NAMESPACE @@ -447,14 +448,20 @@ QDataStream &operator>>(QDataStream &s, QPoint &p) QDebug operator<<(QDebug dbg, const QPoint &p) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QPoint(" << p.x() << ',' << p.y() << ')'; + dbg.nospace(); + dbg << "QPoint" << '('; + QtDebugUtils::formatQPoint(dbg, p); + dbg << ')'; return dbg; } QDebug operator<<(QDebug dbg, const QPointF &p) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QPointF(" << p.x() << ',' << p.y() << ')'; + dbg.nospace(); + dbg << "QPointF" << '('; + QtDebugUtils::formatQPoint(dbg, p); + dbg << ')'; return dbg; } #endif diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 35cf2d5e5b..b2174745e4 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -33,9 +33,10 @@ #include "qrect.h" #include "qdatastream.h" -#include "qdebug.h" #include "qmath.h" +#include + QT_BEGIN_NAMESPACE /*! @@ -1279,8 +1280,10 @@ QDataStream &operator>>(QDataStream &s, QRect &r) QDebug operator<<(QDebug dbg, const QRect &r) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QRect(" << r.x() << ',' << r.y() << ' ' - << r.width() << 'x' << r.height() << ')'; + dbg.nospace(); + dbg << "QRect" << '('; + QtDebugUtils::formatQRect(dbg, r); + dbg << ')'; return dbg; } #endif @@ -2488,8 +2491,10 @@ QDataStream &operator>>(QDataStream &s, QRectF &r) QDebug operator<<(QDebug dbg, const QRectF &r) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QRectF(" << r.x() << ',' << r.y() << ' ' - << r.width() << 'x' << r.height() << ')'; + dbg.nospace(); + dbg << "QRectF" << '('; + QtDebugUtils::formatQRect(dbg, r); + dbg << ')'; return dbg; } #endif diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp index d91dd0d130..19227432f2 100644 --- a/src/corelib/tools/qsize.cpp +++ b/src/corelib/tools/qsize.cpp @@ -33,7 +33,8 @@ #include "qsize.h" #include "qdatastream.h" -#include "qdebug.h" + +#include QT_BEGIN_NAMESPACE @@ -440,7 +441,10 @@ QDataStream &operator>>(QDataStream &s, QSize &sz) QDebug operator<<(QDebug dbg, const QSize &s) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QSize(" << s.width() << ", " << s.height() << ')'; + dbg.nospace(); + dbg << "QSize("; + QtDebugUtils::formatQSize(dbg, s); + dbg << ')'; return dbg; } #endif @@ -867,7 +871,10 @@ QDataStream &operator>>(QDataStream &s, QSizeF &sz) QDebug operator<<(QDebug dbg, const QSizeF &s) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QSizeF(" << s.width() << ", " << s.height() << ')'; + dbg.nospace(); + dbg << "QSizeF("; + QtDebugUtils::formatQSize(dbg, s); + dbg << ')'; return dbg; } #endif diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index ccd7c37486..11f7f13552 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -37,13 +37,13 @@ #include "qpa/qplatformintegration.h" #include "qpa/qplatformdrag.h" #include "private/qevent_p.h" -#include "qdebug.h" #include "qmetaobject.h" #include "qmimedata.h" #include "private/qdnd_p.h" #include "qevent_p.h" #include "qmath.h" +#include QT_BEGIN_NAMESPACE @@ -3463,7 +3463,10 @@ QShortcutEvent::~QShortcutEvent() static inline void formatTouchEvent(QDebug d, const QTouchEvent &t) { - d << "QTouchEvent(" << t.type() << " states: " << t.touchPointStates(); + d << "QTouchEvent("; + QtDebugUtils::formatQEnum(d, t.type()); + d << " states: "; + QtDebugUtils::formatQFlags(d, t.touchPointStates()); d << ", " << t.touchPoints().size() << " points: " << t.touchPoints() << ')'; } @@ -3644,15 +3647,20 @@ static const char *eventClassName(QEvent::Type t) static void formatDropEvent(QDebug d, const QDropEvent *e) { const QEvent::Type type = e->type(); - d << eventClassName(type) << "(dropAction=" << e->dropAction() << ", proposedAction=" - << e->proposedAction() << ", possibleActions=" << e->possibleActions() - << ", posF=" << e->posF(); + d << eventClassName(type) << "(dropAction="; + QtDebugUtils::formatQEnum(d, e->dropAction()); + d << ", proposedAction="; + QtDebugUtils::formatQEnum(d, e->proposedAction()); + d << ", possibleActions="; + QtDebugUtils::formatQFlags(d, e->possibleActions()); + d << ", posF="; + QtDebugUtils::formatQPoint(d, e->posF()); if (type == QEvent::DragMove || type == QEvent::DragEnter) d << ", answerRect=" << static_cast(e)->answerRect(); d << ", formats=" << e->mimeData()->formats(); - if (const Qt::KeyboardModifiers mods = e->keyboardModifiers()) - d << ", keyboardModifiers=" << mods; - d << ", " << e->mouseButtons(); + QtDebugUtils::formatNonNullQFlags(d, ", keyboardModifiers=", e->keyboardModifiers()); + d << ", "; + QtDebugUtils::formatQFlags(d, e->mouseButtons()); } # endif // !QT_NO_DRAGANDDROP @@ -3663,15 +3671,19 @@ static void formatTabletEvent(QDebug d, const QTabletEvent *e) { const QEvent::Type type = e->type(); - d << eventClassName(type) << '(' << type - << ", device=" << e->device() - << ", pointerType=" << e->pointerType() - << ", uniqueId=" << e->uniqueId() + d << eventClassName(type) << '('; + QtDebugUtils::formatQEnum(d, type); + d << ", device="; + QtDebugUtils::formatQEnum(d, e->device()); + d << ", pointerType="; + QtDebugUtils::formatQEnum(d, e->pointerType()); + d << ", uniqueId=" << e->uniqueId() << ", pos=" << e->posF() << ", z=" << e->z() << ", xTilt=" << e->xTilt() << ", yTilt=" << e->yTilt() - << ", " << e->buttons(); + << ", "; + QtDebugUtils::formatQFlags(d, e->buttons()); if (type == QEvent::TabletPress || type == QEvent::TabletMove) d << ", pressure=" << e->pressure(); if (e->device() == QTabletEvent::RotationStylus || e->device() == QTabletEvent::FourDMouse) @@ -3685,8 +3697,19 @@ static void formatTabletEvent(QDebug d, const QTabletEvent *e) QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp) { QDebugStateSaver saver(dbg); - dbg.nospace() << "TouchPoint(" << tp.id() << ' ' << tp.rect() << ' ' << tp.state() << " press " << tp.pressure() - << " vel " << tp.velocity() << " start " << tp.startPos() << " last " << tp.lastPos() << " delta " << tp.pos() - tp.lastPos() << ')'; + dbg.nospace(); + dbg << "TouchPoint(" << tp.id() << " ("; + QtDebugUtils::formatQRect(dbg, tp.rect()); + dbg << ") "; + QtDebugUtils::formatQEnum(dbg, tp.state()); + dbg << " press " << tp.pressure() << " vel " << tp.velocity() + << " start ("; + QtDebugUtils::formatQPoint(dbg, tp.startPos()); + dbg << ") last ("; + QtDebugUtils::formatQPoint(dbg, tp.lastPos()); + dbg << ") delta ("; + QtDebugUtils::formatQPoint(dbg, tp.pos() - tp.lastPos()); + dbg << ')'; return dbg; } @@ -3716,18 +3739,23 @@ QDebug operator<<(QDebug dbg, const QEvent *e) const QMouseEvent *me = static_cast(e); const Qt::MouseButton button = me->button(); const Qt::MouseButtons buttons = me->buttons(); - dbg << "QMouseEvent(" << type; - if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) - dbg << ", " << button; - if (buttons && button != buttons) - dbg << ", buttons=" << buttons; - if (me->modifiers()) - dbg << ", " << me->modifiers(); - dbg << ", localPos=" << me->localPos() << ", screenPos=" << me->screenPos(); - if (me->source()) - dbg << ", " << me->source(); - if (const Qt::MouseEventFlags flags = me->flags()) - dbg << ", flags = " << hex << int(flags) << dec; + dbg << "QMouseEvent("; + QtDebugUtils::formatQEnum(dbg, type); + if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) { + dbg << ", "; + QtDebugUtils::formatQEnum(dbg, button); + } + if (buttons && button != buttons) { + dbg << ", buttons="; + QtDebugUtils::formatQFlags(dbg, buttons); + } + QtDebugUtils::formatNonNullQFlags(dbg, ", ", me->modifiers()); + dbg << ", localPos="; + QtDebugUtils::formatQPoint(dbg, me->localPos()); + dbg << ", screenPos="; + QtDebugUtils::formatQPoint(dbg, me->screenPos()); + QtDebugUtils::formatNonNullQEnum(dbg, ", ", me->source()); + QtDebugUtils::formatNonNullQFlags(dbg, ", flags=", me->flags()); dbg << ')'; } break; @@ -3743,10 +3771,11 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::ShortcutOverride: { const QKeyEvent *ke = static_cast(e); - dbg << "QKeyEvent(" << type - << ", " << static_cast(ke->key()); - if (ke->modifiers()) - dbg << ", " << ke->modifiers(); + dbg << "QKeyEvent("; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", "; + QtDebugUtils::formatQEnum(dbg, static_cast(ke->key())); + QtDebugUtils::formatNonNullQFlags(dbg, ", ", ke->modifiers()); if (!ke->text().isEmpty()) dbg << ", text=" << ke->text(); if (ke->isAutoRepeat()) @@ -3765,11 +3794,16 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::FocusAboutToChange: case QEvent::FocusIn: case QEvent::FocusOut: - dbg << "QFocusEvent(" << type << ", " << static_cast(e)->reason() << ')'; + dbg << "QFocusEvent("; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", "; + QtDebugUtils::formatQEnum(dbg, static_cast(e)->reason()); + dbg << ')'; break; case QEvent::Move: { const QMoveEvent *me = static_cast(e); - dbg << "QMoveEvent(" << me->pos(); + dbg << "QMoveEvent("; + QtDebugUtils::formatQPoint(dbg, me->pos()); if (!me->spontaneous()) dbg << ", non-spontaneous"; dbg << ')'; @@ -3777,7 +3811,8 @@ QDebug operator<<(QDebug dbg, const QEvent *e) break; case QEvent::Resize: { const QResizeEvent *re = static_cast(e); - dbg << "QResizeEvent(" << re->size(); + dbg << "QResizeEvent("; + QtDebugUtils::formatQSize(dbg, re->size()); if (!re->spontaneous()) dbg << ", non-spontaneous"; dbg << ')'; @@ -3804,19 +3839,25 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::ChildAdded: case QEvent::ChildPolished: case QEvent::ChildRemoved: - dbg << "QChildEvent(" << type << ", " << (static_cast(e))->child() << ')'; + dbg << "QChildEvent("; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", " << (static_cast(e))->child() << ')'; break; # ifndef QT_NO_GESTURES case QEvent::NativeGesture: { const QNativeGestureEvent *ne = static_cast(e); - dbg << "QNativeGestureEvent(" << ne->gestureType() - << "localPos=" << ne->localPos() << ", value=" << ne->value() << ')'; + dbg << "QNativeGestureEvent("; + QtDebugUtils::formatQEnum(dbg, ne->gestureType()); + dbg << "localPos="; + QtDebugUtils::formatQPoint(dbg, ne->localPos()); + dbg << ", value=" << ne->value() << ')'; } break; # endif // !QT_NO_GESTURES case QEvent::ApplicationStateChange: - dbg << "QApplicationStateChangeEvent(" - << static_cast(e)->applicationState() << ')'; + dbg << "QApplicationStateChangeEvent("; + QtDebugUtils::formatQEnum(dbg, static_cast(e)->applicationState()); + dbg << ')'; break; case QEvent::ContextMenu: dbg << "QContextMenuEvent(" << static_cast(e)->pos() << ')'; @@ -3849,8 +3890,9 @@ QDebug operator<<(QDebug dbg, const QEvent *e) dbg << ')'; break; default: - dbg << eventClassName(type) << '(' << type << ", " - << (const void *)e << ", type = " << e->type() << ')'; + dbg << eventClassName(type) << '('; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", " << (const void *)e << ')'; break; } return dbg;