Diaglib: Improve formatting of DebugProxyStyle
The class used the default debug operator for QObject, which outputs the object's address. This makes it hard to compare the log output. Make the existing QObject formatting helper from the EventFilter publicly usable by providing a helper with a stream operator. Change-Id: Ifab83e23cc792a5efe231fd9ae84e0439ab0d609 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
parent
224a60989e
commit
761f88f8ba
@ -27,6 +27,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "debugproxystyle.h"
|
||||
#include "eventfilter.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
@ -73,7 +74,7 @@ QDebug operator<<(QDebug debug, const QStyleOption *option)
|
||||
debug << ", state=" << option->state;
|
||||
#if QT_VERSION >= 0x050000
|
||||
if (option->styleObject && !option->styleObject->isWidgetType())
|
||||
debug << ", styleObject=" << option->styleObject;
|
||||
debug << ", styleObject=" << QtDiag::formatQObject(option->styleObject);
|
||||
#endif
|
||||
debug << ')';
|
||||
return debug;
|
||||
@ -97,19 +98,19 @@ DebugProxyStyle::DebugProxyStyle(QStyle *style) : QProxyStyle(style)
|
||||
|
||||
void DebugProxyStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
qDebug() << __FUNCTION__ << "element=" << element << option << widget;
|
||||
qDebug() << __FUNCTION__ << "element=" << element << option << QtDiag::formatQObject(widget);
|
||||
QProxyStyle::drawPrimitive( element, option, painter, widget);
|
||||
}
|
||||
|
||||
void DebugProxyStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
qDebug() << __FUNCTION__ << "element=" << element << option << widget;
|
||||
qDebug() << __FUNCTION__ << "element=" << element << option << QtDiag::formatQObject(widget);
|
||||
QProxyStyle::drawControl(element, option, painter, widget);
|
||||
}
|
||||
|
||||
void DebugProxyStyle::drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
qDebug() << __FUNCTION__ << "control=" << control << option << widget;
|
||||
qDebug() << __FUNCTION__ << "control=" << control << option << QtDiag::formatQObject(widget);
|
||||
QProxyStyle::drawComplexControl(control, option, painter, widget);
|
||||
}
|
||||
|
||||
@ -122,21 +123,24 @@ void DebugProxyStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int a
|
||||
QSize DebugProxyStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
|
||||
{
|
||||
const QSize result = QProxyStyle::sizeFromContents(type, option, size, widget);
|
||||
qDebug() << __FUNCTION__ << size << "type=" << type << option << widget << "returns" << result;
|
||||
qDebug() << __FUNCTION__ << size << "type=" << type << option
|
||||
<< QtDiag::formatQObject(widget) << "returns" << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
QRect DebugProxyStyle::subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
const QRect result = QProxyStyle::subElementRect(element, option, widget);
|
||||
qDebug() << __FUNCTION__ << "element=" << element << option << widget << "returns" << result;
|
||||
qDebug() << __FUNCTION__ << "element=" << element << option
|
||||
<< QtDiag::formatQObject(widget) << "returns" << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
QRect DebugProxyStyle::subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QStyle::SubControl sc, const QWidget *widget) const
|
||||
{
|
||||
const QRect result = QProxyStyle::subControlRect(cc, opt, sc, widget);
|
||||
qDebug() << __FUNCTION__ << "cc=" << cc << "sc=" << sc << opt << widget << "returns" << result;
|
||||
qDebug() << __FUNCTION__ << "cc=" << cc << "sc=" << sc << opt
|
||||
<< QtDiag::formatQObject(widget) << "returns" << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -159,7 +163,7 @@ int DebugProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const
|
||||
QStyleHintReturn *returnData) const
|
||||
{
|
||||
const int result = QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
qDebug() << __FUNCTION__ << hint << option << widget << "returnData="
|
||||
qDebug() << __FUNCTION__ << hint << option << QtDiag::formatQObject(widget) << "returnData="
|
||||
<< returnData << "returns" << result;
|
||||
return result;
|
||||
}
|
||||
@ -167,7 +171,8 @@ int DebugProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const
|
||||
int DebugProxyStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
const int result = QProxyStyle::pixelMetric(metric, option, widget);
|
||||
qDebug() << __FUNCTION__ << "metric=" << metric << option << widget << "returns" << result;
|
||||
qDebug() << __FUNCTION__ << "metric=" << metric << option
|
||||
<< QtDiag::formatQObject(widget) << "returns" << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ static inline bool matchesType(const QObject *o, EventFilter::ObjectTypes types)
|
||||
return types & EventFilter::OtherType;
|
||||
}
|
||||
|
||||
static void formatObject(const QObject *o, QDebug debug)
|
||||
void EventFilter::formatObject(const QObject *o, QDebug debug)
|
||||
{
|
||||
if (o) {
|
||||
debug << o->metaObject()->className();
|
||||
@ -166,32 +166,30 @@ static void formatObject(const QObject *o, QDebug debug)
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug d, const formatQObject &fo)
|
||||
{
|
||||
EventFilter::formatObject(fo.m_object, d);
|
||||
return d;
|
||||
}
|
||||
|
||||
static void formatApplicationState(QDebug debug)
|
||||
{
|
||||
#if defined(HAVE_APPLICATION)
|
||||
if (const QWidget *mw = QApplication::activeModalWidget()) {
|
||||
debug << "\n QApplication::activeModalWidget = ";
|
||||
formatObject(mw, debug);
|
||||
}
|
||||
if (const QWidget *pw = QApplication::activePopupWidget()) {
|
||||
debug << "\n QApplication::activePopupWidget = ";
|
||||
formatObject(pw, debug);
|
||||
}
|
||||
debug << "\n QApplication::activeWindow = ";
|
||||
formatObject(QApplication::activeWindow(), debug);
|
||||
if (const QWidget *mw = QApplication::activeModalWidget())
|
||||
debug << "\n QApplication::activeModalWidget = " << formatQObject(mw);
|
||||
if (const QWidget *pw = QApplication::activePopupWidget())
|
||||
debug << "\n QApplication::activePopupWidget = " << formatQObject(pw);
|
||||
debug << "\n QApplication::activeWindow = " << formatQObject(QApplication::activeWindow());
|
||||
#endif // HAVE_APPLICATION
|
||||
#if defined(HAVE_GUI_APPLICATION)
|
||||
if (const QWindow *mw = QGuiApplication::modalWindow()) {
|
||||
debug << "\n QGuiApplication::modalWindow = ";
|
||||
formatObject(mw, debug);
|
||||
debug << "\n QGuiApplication::modalWindow = " << formatQObject(mw);
|
||||
}
|
||||
const QObject *focusObject = QGuiApplication::focusObject();
|
||||
const QObject *focusWindow = QGuiApplication::focusWindow();
|
||||
debug << "\n QGuiApplication::focusObject = ";
|
||||
formatObject(focusObject, debug);
|
||||
debug << "\n QGuiApplication::focusObject = " << formatQObject(focusObject);
|
||||
if (focusWindow && focusWindow != focusObject)
|
||||
debug << "\n QGuiApplication::focusWindow = ";
|
||||
formatObject(focusWindow, debug);
|
||||
debug << "\n QGuiApplication::focusWindow = " << formatQObject(focusWindow);
|
||||
#endif // HAVE_GUI_APPLICATION
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include <QtCore/QEvent>
|
||||
#include <QtCore/QList>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QDebug)
|
||||
|
||||
namespace QtDiag {
|
||||
|
||||
// Event filter that can for example be installed on QApplication
|
||||
@ -74,6 +76,8 @@ public:
|
||||
ObjectTypes objectTypes() const { return m_objectTypes; }
|
||||
void setObjectTypes(ObjectTypes objectTypes) { m_objectTypes = objectTypes; }
|
||||
|
||||
static void formatObject(const QObject *o, QDebug debug);
|
||||
|
||||
private:
|
||||
void init(EventCategories eventCategories);
|
||||
|
||||
@ -84,6 +88,15 @@ private:
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::EventCategories)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::ObjectTypes)
|
||||
|
||||
struct formatQObject
|
||||
{
|
||||
explicit formatQObject(const QObject *o) : m_object(o) {}
|
||||
|
||||
const QObject *m_object;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug d, const formatQObject &fo);
|
||||
|
||||
} // namespace QtDiag
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user