From 7c2360b762817743484ddc5bc9ba3f48a7b68d84 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 30 Mar 2015 11:10:27 +0200 Subject: Split out some inline qdebug formatting helpers to qdebug_p.h. Extract helpers to be able to format classes without type names and use those for formatting QEvents to reduce clutter. For example: QWidgetWindow/"MainWindowClassWindow" QMouseEvent(QEvent::Type(MouseMove), buttons=QFlags(LeftButton), localPos=QPointF(50,116), screenPos=QPointF(948,652)) QWidget/"qt_scrollarea_viewport" QMouseEvent(QEvent::Type(MouseMove), buttons=QFlags(LeftButton), localPos=QPointF(45,32), screenPos=QPointF(948,652)) becomes QWidgetWindow/"MainWindowClassWindow" QMouseEvent(MouseMove, LeftButton, localPos=50,116, screenPos=948,652) QWidget/"qt_scrollarea_viewport" QMouseEvent(MouseMove, LeftButton, localPos=45,32, screenPos=948,652) Change-Id: Ie5441d922962a05caed6b7079a74ea8a2b8a64fb Reviewed-by: Kai Koehne --- src/gui/kernel/qevent.cpp | 124 +++++++++++++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 41 deletions(-) (limited to 'src/gui') 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; -- cgit v1.2.3