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<Qt::MouseButtons>(LeftButton), localPos=QPointF(50,116), screenPos=QPointF(948,652))
QWidget/"qt_scrollarea_viewport" QMouseEvent(QEvent::Type(MouseMove), buttons=QFlags<Qt::MouseButtons>(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 <kai.koehne@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-03-30 11:10:27 +02:00 committed by Shawn Rutledge
parent 17294c5e4d
commit 7c2360b762
7 changed files with 257 additions and 59 deletions

View File

@ -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 \

129
src/corelib/io/qdebug_p.h Normal file
View File

@ -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 <class Point>
static inline void formatQPoint(QDebug &debug, const Point &point)
{
debug << point.x() << ',' << point.y();
}
template <class Size>
static inline void formatQSize(QDebug &debug, const Size &size)
{
debug << size.width() << ", " << size.height();
}
template <class Rect>
static inline void formatQRect(QDebug &debug, const Rect &rect)
{
debug << rect.x() << ',' << rect.y() << ' ' << rect.width() << 'x' << rect.height();
}
template <class Margins>
static inline void formatQMargins(QDebug &debug, const Margins &margins)
{
debug << margins.left() << ", " << margins.top() << ", " << margins.right()
<< ", " << margins.bottom();
}
#ifndef QT_NO_QOBJECT
template <class QEnum>
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 <class QEnum>
static inline void formatNonNullQEnum(QDebug &debug, const char *prefix, QEnum value)
{
if (value) {
debug << prefix;
formatQEnum(debug, value);
}
}
template <class Enum>
static inline void formatQFlags(QDebug &debug, const QFlags<Enum> &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 <class Enum>
static inline void formatNonNullQFlags(QDebug &debug, const char *prefix, const QFlags<Enum> &value)
{
if (value) {
debug << prefix;
formatQFlags(debug, value);
}
}
#endif // !QT_NO_QOBJECT
} // namespace QtDebugUtils
QT_END_NAMESPACE
#endif // QDEBUG_P_H

View File

@ -33,7 +33,8 @@
#include "qmargins.h"
#include "qdatastream.h"
#include "qdebug.h"
#include <private/qdebug_p.h>
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

View File

@ -33,7 +33,8 @@
#include "qpoint.h"
#include "qdatastream.h"
#include "qdebug.h"
#include <private/qdebug_p.h>
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

View File

@ -33,9 +33,10 @@
#include "qrect.h"
#include "qdatastream.h"
#include "qdebug.h"
#include "qmath.h"
#include <private/qdebug_p.h>
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

View File

@ -33,7 +33,8 @@
#include "qsize.h"
#include "qdatastream.h"
#include "qdebug.h"
#include <private/qdebug_p.h>
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

View File

@ -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 <private/qdebug_p.h>
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<const QDragMoveEvent *>(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<const QMouseEvent*>(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<const QKeyEvent *>(e);
dbg << "QKeyEvent(" << type
<< ", " << static_cast<Qt::Key>(ke->key());
if (ke->modifiers())
dbg << ", " << ke->modifiers();
dbg << "QKeyEvent(";
QtDebugUtils::formatQEnum(dbg, type);
dbg << ", ";
QtDebugUtils::formatQEnum(dbg, static_cast<Qt::Key>(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<const QFocusEvent *>(e)->reason() << ')';
dbg << "QFocusEvent(";
QtDebugUtils::formatQEnum(dbg, type);
dbg << ", ";
QtDebugUtils::formatQEnum(dbg, static_cast<const QFocusEvent *>(e)->reason());
dbg << ')';
break;
case QEvent::Move: {
const QMoveEvent *me = static_cast<const QMoveEvent *>(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<const QResizeEvent *>(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<const QChildEvent*>(e))->child() << ')';
dbg << "QChildEvent(";
QtDebugUtils::formatQEnum(dbg, type);
dbg << ", " << (static_cast<const QChildEvent*>(e))->child() << ')';
break;
# ifndef QT_NO_GESTURES
case QEvent::NativeGesture: {
const QNativeGestureEvent *ne = static_cast<const QNativeGestureEvent *>(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<const QApplicationStateChangeEvent *>(e)->applicationState() << ')';
dbg << "QApplicationStateChangeEvent(";
QtDebugUtils::formatQEnum(dbg, static_cast<const QApplicationStateChangeEvent *>(e)->applicationState());
dbg << ')';
break;
case QEvent::ContextMenu:
dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(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;