QObject: restore flags printing in dumpObjectTree()

This was lost when QtCore, QtGui and QtWidgets were split up. Restored
now via a virtual function on QObjectPrivate.

Chose to return std::string instead of QString or QByteArray because
its SSO is usually sufficient to hold these flag strings.

[ChangeLog][QtCore][QObject] Restored printing of Qt3-style
information from dumpObjectTree().

[ChangeLog][QtWidgets][QWidget] Restored printing of Qt3-style
information from QWidget::dumpObjectTree().

Fixes: QTBUG-101732
Change-Id: I39ff5728ea5f5abbdbf81b5d7e13b8d16b6ee8b7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-03-16 12:57:29 +01:00
parent 6ec1dc904d
commit f97daab7a6
5 changed files with 75 additions and 17 deletions

View File

@ -4202,27 +4202,18 @@ QList<QByteArray> QObject::dynamicPropertyNames() const
QObject debugging output routines.
*****************************************************************************/
std::string QObjectPrivate::flagsForDumping() const
{
return {};
}
static void dumpRecursive(int level, const QObject *object)
{
if (object) {
const int indent = level * 4;
const QString name = object->objectName();
QString flags;
#if 0
if (qApp->focusWidget() == object)
flags += 'F';
if (object->isWidgetType()) {
QWidget * w = (QWidget *)object;
if (w->isVisible()) {
QString t("<%1,%2,%3,%4>");
flags += t.arg(w->x()).arg(w->y()).arg(w->width()).arg(w->height());
} else {
flags += 'I';
}
}
#endif
qDebug("%*s%s::%ls %ls", indent, "", object->metaObject()->className(),
qUtf16Printable(name), qUtf16Printable(flags));
qDebug("%*s%s::%ls %s", indent, "", object->metaObject()->className(),
qUtf16Printable(object->objectName()),
QObjectPrivate::get(object)->flagsForDumping().c_str());
for (auto child : object->children())
dumpRecursive(level + 1, child);
}

View File

@ -63,6 +63,8 @@
#include "QtCore/qproperty.h"
#include "QtCore/private/qproperty_p.h"
#include <string>
QT_BEGIN_NAMESPACE
class QVariant;
@ -412,6 +414,8 @@ public:
connections.storeRelaxed(cd);
}
virtual std::string flagsForDumping() const;
public:
mutable ExtraData *extraData; // extra data set by the user
// This atomic requires acquire/release semantics in a few places,

View File

@ -110,6 +110,8 @@
#include "qwindowcontainer_p.h"
#include <sstream>
// widget/widget data creation count
//#define QWIDGET_EXTRA_DEBUG
//#define ALIEN_DEBUG
@ -12961,6 +12963,25 @@ void QWidgetPrivate::setWidgetParentHelper(QObject *widgetAsObject, QObject *new
widget->setParent(static_cast<QWidget*>(newParent));
}
std::string QWidgetPrivate::flagsForDumping() const
{
Q_Q(const QWidget);
std::string flags = QObjectPrivate::flagsForDumping();
if (QApplication::focusWidget() == q)
flags += 'F';
if (q->isVisible()) {
std::stringstream s;
s << '<'
<< q->width() << 'x' << q->height()
<< std::showpos << q->x() << q->y()
<< '>';
flags += s.str();
} else {
flags += 'I';
}
return flags;
}
void QWidgetPrivate::setNetWmWindowTypes(bool skipIfMissing)
{
#if QT_CONFIG(xcb)

View File

@ -663,6 +663,8 @@ public:
static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
std::string flagsForDumping() const override;
// Variables.
// Regular pointers (keep them together to avoid gaps on 64 bit architectures).
std::unique_ptr<QWExtra> extra;

View File

@ -335,6 +335,8 @@ private slots:
void resizeInPaintEvent();
void opaqueChildren();
void dumpObjectTree();
void setMaskInResizeEvent();
void moveInResizeEvent();
@ -9060,6 +9062,44 @@ void tst_QWidget::opaqueChildren()
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion());
}
void tst_QWidget::dumpObjectTree()
{
QWidget w;
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
Q_SET_OBJECT_NAME(w);
w.move(100, 100);
w.resize(500, 500);
QLineEdit le(&w);
Q_SET_OBJECT_NAME(le);
le.resize(500, 500);
{
const char * const expected[] = {
"QWidget::w I",
" QLineEdit::le I",
" QWidgetLineControl:: ",
};
for (const char *line : expected)
QTest::ignoreMessage(QtDebugMsg, line);
w.dumpObjectTree();
}
w.show();
QApplication::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
{
const char * const expected[] = {
"QWidget::w <500x500+100+100>",
" QLineEdit::le F<500x500+0+0>",
" QWidgetLineControl:: ",
};
for (const char *line : expected)
QTest::ignoreMessage(QtDebugMsg, line);
w.dumpObjectTree();
}
}
class MaskSetWidget : public QWidget
{