Improve debug operator for QGraphicsItem/QGraphicsObject.

Introduce QDebugStateSaver, use new formatting helpers and
output parent, flags and z only when necessary. Output the
widget contained in QGraphicsProxyWidget.

For example,

QGraphicsProxyWidget (this = 0x1877550 , parent = 0x0 , pos = QPointF(870,491) , z = 1e+30 , flags =  ( ItemIsFocusable | ItemUsesExtendedStyleOpton | ItemSendsGeometryChanges | ItemIsPanel ) )

becomes:

QGraphicsProxyWidget(0x1877550, widget=ItemDialog(0x1e29dc0), pos=870,491, z=1e+30, flags=(ItemIsFocusable|ItemUsesExtendedStyleOption|ItemSendsGeometryChanges|ItemIsPanel))

Change-Id: Ia554dc3e2eb6f16d9d9220d1067194a4424b7cf5
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-04-01 13:20:31 +02:00
parent cbf28577ef
commit 2012c8e866

View File

@ -736,7 +736,6 @@
#include "qgraphicsproxywidget.h" #include "qgraphicsproxywidget.h"
#include "qgraphicsscenebsptreeindex_p.h" #include "qgraphicsscenebsptreeindex_p.h"
#include <QtCore/qbitarray.h> #include <QtCore/qbitarray.h>
#include <QtCore/qdebug.h>
#include <QtCore/qpoint.h> #include <QtCore/qpoint.h>
#include <QtCore/qstack.h> #include <QtCore/qstack.h>
#include <QtCore/qtimer.h> #include <QtCore/qtimer.h>
@ -761,6 +760,7 @@
#include <private/qwidget_p.h> #include <private/qwidget_p.h>
#include <private/qapplication_p.h> #include <private/qapplication_p.h>
#include <private/qgesturemanager_p.h> #include <private/qgesturemanager_p.h>
#include <private/qdebug_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -11283,8 +11283,24 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP
#endif //QT_NO_GRAPHICSEFFECT #endif //QT_NO_GRAPHICSEFFECT
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
static void formatGraphicsItemHelper(QDebug debug, const QGraphicsItem *item)
{
if (const QGraphicsItem *parent = item->parentItem())
debug << ", parent=" << static_cast<const void *>(parent);
debug << ", pos=";
QtDebugUtils::formatQPoint(debug, item->pos());
if (const qreal z = item->zValue())
debug << ", z=" << item->zValue();
if (item->flags())
debug << ", flags=" << item->flags();
}
// FIXME: Qt 6: Make this QDebug operator<<(QDebug debug, const QGraphicsItem *item)
QDebug operator<<(QDebug debug, QGraphicsItem *item) QDebug operator<<(QDebug debug, QGraphicsItem *item)
{ {
QDebugStateSaver saver(debug);
debug.nospace();
if (!item) { if (!item) {
debug << "QGraphicsItem(0)"; debug << "QGraphicsItem(0)";
return debug; return debug;
@ -11294,29 +11310,40 @@ QDebug operator<<(QDebug debug, QGraphicsItem *item)
debug << o->metaObject()->className(); debug << o->metaObject()->className();
else else
debug << "QGraphicsItem"; debug << "QGraphicsItem";
debug << "(this =" << (void*)item debug << '(' << static_cast<const void *>(item);
<< ", parent =" << (void*)item->parentItem() if (const QGraphicsProxyWidget *pw = qgraphicsitem_cast<const QGraphicsProxyWidget *>(item)) {
<< ", pos =" << item->pos() debug << ", widget=";
<< ", z =" << item->zValue() << ", flags = " if (const QWidget *w = pw->widget()) {
<< item->flags() << ")"; debug << w->metaObject()->className() << '(' << static_cast<const void *>(w);
if (!w->objectName().isEmpty())
debug << ", name=" << w->objectName();
debug << ')';
} else {
debug << "QWidget(0)";
}
}
formatGraphicsItemHelper(debug, item);
debug << ')';
return debug; return debug;
} }
// FIXME: Qt 6: Make this QDebug operator<<(QDebug debug, const QGraphicsObject *item)
QDebug operator<<(QDebug debug, QGraphicsObject *item) QDebug operator<<(QDebug debug, QGraphicsObject *item)
{ {
QDebugStateSaver saver(debug);
debug.nospace();
if (!item) { if (!item) {
debug << "QGraphicsObject(0)"; debug << "QGraphicsObject(0)";
return debug; return debug;
} }
debug.nospace() << item->metaObject()->className() << '(' << (void*)item; debug << item->metaObject()->className() << '(' << static_cast<const void *>(item);
if (!item->objectName().isEmpty()) if (!item->objectName().isEmpty())
debug << ", name = " << item->objectName(); debug << ", name=" << item->objectName();
debug.nospace() << ", parent = " << ((void*)item->parentItem()) formatGraphicsItemHelper(debug, item);
<< ", pos = " << item->pos() debug << ')';
<< ", z = " << item->zValue() << ", flags = " return debug;
<< item->flags() << ')';
return debug.space();
} }
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change) QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change)