From 877cb0e9991f5fe9b134427d90ca831bc6a3a534 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 21 May 2019 13:07:34 +0200 Subject: [PATCH] [libcalamaresui] Debug-tool to dump widget tree - Adds another tool to the debug window, which dumps (to the debug log) a tree-like view of all the widgets in the application. This can be used when writing stylesheets. --- src/libcalamaresui/utils/DebugWindow.cpp | 24 ++++++++++++++++++++++++ src/libcalamaresui/utils/DebugWindow.ui | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/src/libcalamaresui/utils/DebugWindow.cpp b/src/libcalamaresui/utils/DebugWindow.cpp index 0925ac908..8e83ad18b 100644 --- a/src/libcalamaresui/utils/DebugWindow.cpp +++ b/src/libcalamaresui/utils/DebugWindow.cpp @@ -23,6 +23,7 @@ #include "Branding.h" #include "utils/Retranslator.h" #include "utils/qjsonmodel.h" +#include "utils/Logger.h" #include "JobQueue.h" #include "Job.h" @@ -51,6 +52,20 @@ crash() *a = 1; } +/// @brief Print out the widget tree (names) in indented form. +static void dumpWidgetTree( QDebug& deb, const QWidget* widget, int depth ) +{ + if ( !widget ) + return; + + deb << Logger::Continuation; + for (int i = 0; i < depth; ++i ) + deb << ' '; + deb << widget->objectName(); + + for ( const auto* w : widget->findChildren( QString(), Qt::FindDirectChildrenOnly ) ) + dumpWidgetTree( deb, w, depth+1 ); +} namespace Calamares { @@ -202,6 +217,15 @@ DebugWindow::DebugWindow() } } }); + connect( m_ui->widgetTreeButton, &QPushButton::clicked, + []() + { + for ( auto* w : qApp->topLevelWidgets() ) + { + auto deb = cDebug(); + dumpWidgetTree( deb, w, 0 ); + } + }); CALAMARES_RETRANSLATE( m_ui->retranslateUi( this ); diff --git a/src/libcalamaresui/utils/DebugWindow.ui b/src/libcalamaresui/utils/DebugWindow.ui index bbbf24f2a..63a6a840a 100644 --- a/src/libcalamaresui/utils/DebugWindow.ui +++ b/src/libcalamaresui/utils/DebugWindow.ui @@ -107,6 +107,13 @@ + + + + Widget Tree + + +