Implement QDebug streaming operators for QWindow, QScreen and QWidget.
The operators can be switched to verbose using QDebug::setVerbosity() and then provide more useful information than the standard operator for QObject. [ChangeLog][QtCore][QDebug] When streaming QWindow, QScreen, QWidget instances to a debug stream that has increased verbosity set, detailed information about geometries, states etc. will be printed. Change-Id: Ice26e00f6c713cd6244e1c1df54195e0b0de3c20 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
77c0c1ca65
commit
3d8c86881c
@ -37,6 +37,7 @@
|
||||
#include "qguiapplication_p.h"
|
||||
#include <qpa/qplatformscreen.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/private/qobject_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -654,4 +655,41 @@ QPixmap QScreen::grabWindow(WId window, int x, int y, int width, int height)
|
||||
return platformScreen->grabWindow(window, x, y, width, height);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
static inline void formatRect(QDebug &debug, const QRect r)
|
||||
{
|
||||
debug << r.width() << 'x' << r.height()
|
||||
<< forcesign << r.x() << r.y() << noforcesign;
|
||||
}
|
||||
|
||||
Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QScreen *screen)
|
||||
{
|
||||
const QDebugStateSaver saver(debug);
|
||||
debug.nospace();
|
||||
debug << "QScreen(" << (void *)screen;
|
||||
if (screen) {
|
||||
debug << ", name=" << screen->name();
|
||||
if (debug.verbosity() > 2) {
|
||||
if (screen == QGuiApplication::primaryScreen())
|
||||
debug << ", primary";
|
||||
debug << ", geometry=";
|
||||
formatRect(debug, screen->geometry());
|
||||
debug << ", available=";
|
||||
formatRect(debug, screen->availableGeometry());
|
||||
debug << ", logical DPI=" << screen->logicalDotsPerInchX()
|
||||
<< ',' << screen->logicalDotsPerInchY()
|
||||
<< ", physical DPI=" << screen->physicalDotsPerInchX()
|
||||
<< ',' << screen->physicalDotsPerInchY()
|
||||
<< ", devicePixelRatio=" << screen->devicePixelRatio()
|
||||
<< ", orientation=" << screen->orientation()
|
||||
<< ", physical size=" << screen->physicalSize().width()
|
||||
<< 'x' << screen->physicalSize().height() << "mm";
|
||||
}
|
||||
}
|
||||
debug << ')';
|
||||
return debug;
|
||||
}
|
||||
#endif // !QT_NO_DEBUG_STREAM
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -52,6 +52,9 @@ class QScreenPrivate;
|
||||
class QWindow;
|
||||
class QRect;
|
||||
class QPixmap;
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
class QDebug;
|
||||
#endif
|
||||
|
||||
class Q_GUI_EXPORT QScreen : public QObject
|
||||
{
|
||||
@ -153,6 +156,10 @@ private:
|
||||
friend class QPlatformScreen;
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
Q_GUI_EXPORT QDebug operator<<(QDebug, const QScreen *);
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QSCREEN_H
|
||||
|
@ -2456,6 +2456,45 @@ void QWindowPrivate::applyCursor()
|
||||
}
|
||||
#endif // QT_NO_CURSOR
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug debug, const QWindow *window)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.nospace();
|
||||
if (window) {
|
||||
debug << window->metaObject()->className() << '(' << (void *)window;
|
||||
if (!window->objectName().isEmpty())
|
||||
debug << ", name=" << window->objectName();
|
||||
if (debug.verbosity() > 2) {
|
||||
const QRect geometry = window->geometry();
|
||||
if (window->isVisible())
|
||||
debug << ", visible";
|
||||
if (window->isExposed())
|
||||
debug << ", exposed";
|
||||
debug << ", state=" << window->windowState()
|
||||
<< ", type=" << window->type() << ", flags=" << window->flags()
|
||||
<< ", surface type=" << window->surfaceType();
|
||||
if (window->isTopLevel())
|
||||
debug << ", toplevel";
|
||||
debug << ", " << geometry.width() << 'x' << geometry.height()
|
||||
<< forcesign << geometry.x() << geometry.y() << noforcesign;
|
||||
const QMargins margins = window->frameMargins();
|
||||
if (!margins.isNull())
|
||||
debug << ", margins=" << margins;
|
||||
debug << ", devicePixelRatio=" << window->devicePixelRatio();
|
||||
if (const QPlatformWindow *platformWindow = window->handle())
|
||||
debug << ", winId=0x" << hex << platformWindow->winId() << dec;
|
||||
if (const QScreen *screen = window->screen())
|
||||
debug << ", on " << screen->name();
|
||||
}
|
||||
debug << ')';
|
||||
} else {
|
||||
debug << "QWindow(0x0)";
|
||||
}
|
||||
return debug;
|
||||
}
|
||||
#endif // !QT_NO_DEBUG_STREAM
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qwindow.cpp"
|
||||
|
@ -78,6 +78,9 @@ class QBackingStore;
|
||||
class QScreen;
|
||||
class QAccessibleInterface;
|
||||
class QWindowContainer;
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
class QDebug;
|
||||
#endif
|
||||
|
||||
class Q_GUI_EXPORT QWindow : public QObject, public QSurface
|
||||
{
|
||||
@ -367,6 +370,10 @@ template <> inline const QWindow *qobject_cast<const QWindow*>(const QObject *o)
|
||||
}
|
||||
#endif // !Q_QDOC
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *);
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOW_H
|
||||
|
@ -12817,6 +12817,65 @@ void QWidgetPrivate::setWidgetParentHelper(QObject *widgetAsObject, QObject *new
|
||||
widget->setParent(static_cast<QWidget*>(newParent));
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
static inline void formatWidgetAttributes(QDebug debug, const QWidget *widget)
|
||||
{
|
||||
const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
|
||||
const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
|
||||
debug << ", attributes=[";
|
||||
int count = 0;
|
||||
for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
|
||||
if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
|
||||
if (count++)
|
||||
debug << ',';
|
||||
debug << me.valueToKey(a);
|
||||
}
|
||||
}
|
||||
debug << ']';
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const QWidget *widget)
|
||||
{
|
||||
const QDebugStateSaver saver(debug);
|
||||
debug.nospace();
|
||||
if (widget) {
|
||||
debug << widget->metaObject()->className() << '(' << (void *)widget;
|
||||
if (!widget->objectName().isEmpty())
|
||||
debug << ", name=" << widget->objectName();
|
||||
if (debug.verbosity() > 2) {
|
||||
const QRect geometry = widget->geometry();
|
||||
const QRect frameGeometry = widget->frameGeometry();
|
||||
if (widget->isVisible())
|
||||
debug << ", visible";
|
||||
if (!widget->isEnabled())
|
||||
debug << ", disabled";
|
||||
debug << ", states=" << widget->windowState()
|
||||
<< ", type=" << widget->windowType() << ", flags=" << widget->windowFlags();
|
||||
formatWidgetAttributes(debug, widget);
|
||||
if (widget->isWindow())
|
||||
debug << ", window";
|
||||
debug << ", " << geometry.width() << 'x' << geometry.height()
|
||||
<< forcesign << geometry.x() << geometry.y() << noforcesign;
|
||||
if (frameGeometry != geometry) {
|
||||
const QMargins margins(geometry.x() - frameGeometry.x(),
|
||||
geometry.y() - frameGeometry.y(),
|
||||
frameGeometry.right() - geometry.right(),
|
||||
frameGeometry.bottom() - geometry.bottom());
|
||||
debug << ", margins=" << margins;
|
||||
}
|
||||
debug << ", devicePixelRatio=" << widget->devicePixelRatio();
|
||||
if (const WId wid = widget->internalWinId())
|
||||
debug << ", winId=0x" << hex << wid << dec;
|
||||
}
|
||||
debug << ')';
|
||||
} else {
|
||||
debug << "QWidget(0x0)";
|
||||
}
|
||||
return debug;
|
||||
}
|
||||
#endif // !QT_NO_DEBUG_STREAM
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qwidget.cpp"
|
||||
|
@ -89,6 +89,9 @@ class QGraphicsEffect;
|
||||
class QRasterWindowSurface;
|
||||
class QUnifiedToolbarSurface;
|
||||
class QPixmap;
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
class QDebug;
|
||||
#endif
|
||||
|
||||
class QWidgetData
|
||||
{
|
||||
@ -858,6 +861,10 @@ inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
|
||||
|
||||
#define QWIDGETSIZE_MAX ((1<<24)-1)
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QWidget *);
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user