From ae5c4500c5d717a79214c22a4f11e65381f4ccc8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 21 Jan 2016 17:12:46 +0100 Subject: Diaglib: Improve output of widgets. - Make it possible to pass an optional root widget to dumpAllWidgets(). - Add option to output size constraints of widgets/windows. - Output normal geometry of top levels. Change-Id: Ib48809d070c5721fe4688a2ad39cb99f286618de Reviewed-by: Joerg Bornemann --- tests/manual/diaglib/qwidgetdump.cpp | 31 +++++++++++++++++++++++++++++-- tests/manual/diaglib/qwidgetdump.h | 4 +++- tests/manual/diaglib/qwindowdump.cpp | 10 ++++++++++ tests/manual/diaglib/qwindowdump.h | 3 ++- 4 files changed, 44 insertions(+), 4 deletions(-) (limited to 'tests/manual') diff --git a/tests/manual/diaglib/qwidgetdump.cpp b/tests/manual/diaglib/qwidgetdump.cpp index f057a58ff0..e5fdfaeb71 100644 --- a/tests/manual/diaglib/qwidgetdump.cpp +++ b/tests/manual/diaglib/qwidgetdump.cpp @@ -61,10 +61,32 @@ static void dumpWidgetRecursion(QTextStream &str, const QWidget *w, if (const int states = w->windowState()) str << "windowState=" << hex << showbase << states << dec << noshowbase << ' '; formatRect(str, w->geometry()); + if (w->isWindow()) { + const QRect normalGeometry = w->normalGeometry(); + if (normalGeometry.isValid() && !normalGeometry.isEmpty() && normalGeometry != w->geometry()) { + str << " normal="; + formatRect(str, w->normalGeometry()); + } + } if (!(options & DontPrintWindowFlags)) { str << ' '; formatWindowFlags(str, w->windowFlags()); } + if (options & PrintSizeConstraints) { + str << ' '; + const QSize minimumSize = w->minimumSize(); + if (minimumSize.width() > 0 || minimumSize.height() > 0) + str << "minimumSize=" << minimumSize.width() << 'x' << minimumSize.height() << ' '; + const QSize sizeHint = w->sizeHint(); + const QSize minimumSizeHint = w->minimumSizeHint(); + if (minimumSizeHint.isValid() && !(sizeHint.isValid() && minimumSizeHint == sizeHint)) + str << "minimumSizeHint=" << minimumSizeHint.width() << 'x' << minimumSizeHint.height() << ' '; + if (sizeHint.isValid()) + str << "sizeHint=" << sizeHint.width() << 'x' << sizeHint.height() << ' '; + const QSize maximumSize = w->maximumSize(); + if (maximumSize.width() < QWIDGETSIZE_MAX || maximumSize.height() < QWIDGETSIZE_MAX) + str << "maximumSize=" << maximumSize.width() << 'x' << maximumSize.height() << ' '; + } str << '\n'; #if QT_VERSION > 0x050000 if (const QWindow *win = w->windowHandle()) { @@ -79,12 +101,17 @@ static void dumpWidgetRecursion(QTextStream &str, const QWidget *w, } } -void dumpAllWidgets(FormatWindowOptions options) +void dumpAllWidgets(FormatWindowOptions options, const QWidget *root) { QString d; QTextStream str(&d); str << "### QWidgets:\n"; - foreach (QWidget *tw, QApplication::topLevelWidgets()) + QWidgetList topLevels; + if (root) + topLevels.append(const_cast(root)); + else + topLevels = QApplication::topLevelWidgets(); + foreach (QWidget *tw, topLevels) dumpWidgetRecursion(str, tw, options); #if QT_VERSION >= 0x050400 qDebug().noquote() << d; diff --git a/tests/manual/diaglib/qwidgetdump.h b/tests/manual/diaglib/qwidgetdump.h index 0519a0307c..6f8d9548b3 100644 --- a/tests/manual/diaglib/qwidgetdump.h +++ b/tests/manual/diaglib/qwidgetdump.h @@ -36,9 +36,11 @@ #include "qwindowdump.h" +QT_FORWARD_DECLARE_CLASS(QWidget) + namespace QtDiag { -void dumpAllWidgets(FormatWindowOptions options = 0); +void dumpAllWidgets(FormatWindowOptions options = 0, const QWidget *root = 0); } // namespace QtDiag diff --git a/tests/manual/diaglib/qwindowdump.cpp b/tests/manual/diaglib/qwindowdump.cpp index c0faefb918..04576dbcf4 100644 --- a/tests/manual/diaglib/qwindowdump.cpp +++ b/tests/manual/diaglib/qwindowdump.cpp @@ -38,6 +38,7 @@ # include # include # include +# include # if QT_VERSION >= 0x050600 # include # endif @@ -151,6 +152,15 @@ void formatWindow(QTextStream &str, const QWindow *w, FormatWindowOptions option str << ' '; formatWindowFlags(str, w->flags()); } + if (options & PrintSizeConstraints) { + str << ' '; + const QSize minimumSize = w->minimumSize(); + if (minimumSize.width() > 0 || minimumSize.height() > 0) + str << "minimumSize=" << minimumSize.width() << 'x' << minimumSize.height() << ' '; + const QSize maximumSize = w->maximumSize(); + if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX) + str << "maximumSize=" << maximumSize.width() << 'x' << maximumSize.height() << ' '; + } str << '\n'; } diff --git a/tests/manual/diaglib/qwindowdump.h b/tests/manual/diaglib/qwindowdump.h index 9ab00790b6..2a7d69c915 100644 --- a/tests/manual/diaglib/qwindowdump.h +++ b/tests/manual/diaglib/qwindowdump.h @@ -44,7 +44,8 @@ QT_FORWARD_DECLARE_CLASS(QTextStream) namespace QtDiag { enum FormatWindowOption { - DontPrintWindowFlags = 0x001 + DontPrintWindowFlags = 0x001, + PrintSizeConstraints = 0x002 }; Q_DECLARE_FLAGS(FormatWindowOptions, FormatWindowOption) -- cgit v1.2.3