From 3f720b8acfc3ee63d860a78b58e945923e8bae0a Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 29 Mar 2024 15:22:10 +0800 Subject: [PATCH] QGridLayoutEngine: print stringified layout item in warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This provides a way for the user to identify any items involved in warnings we may print, as e.g. their objectName will be included. Qt Quick's Layout types can use this to stringify the QQuickItem, which will result in the type and objectName being printed. Change-Id: I3d6b6ea0315df98629992afd29e4bf2aad847e22 Reviewed-by: Jan Arve Sæther --- src/gui/util/qgridlayoutengine.cpp | 7 +++++-- src/gui/util/qgridlayoutengine_p.h | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 83def02f7e..e8648eb91d 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -964,8 +964,11 @@ void QGridLayoutEngine::insertItem(QGridLayoutItem *item, int index) for (int i = item->firstRow(); i <= item->lastRow(); ++i) { for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) { - if (itemAt(i, j)) - qWarning("QGridLayoutEngine::addItem: Cell (%d, %d) already taken", i, j); + const auto existingItem = itemAt(i, j); + if (existingItem) { + qWarning("QGridLayoutEngine::addItem: Can't add %s at cell (%d, %d) because it's already taken by %s", + qPrintable(item->toString()), i, j, qPrintable(existingItem->toString())); + } setItemAt(i, j, item); } } diff --git a/src/gui/util/qgridlayoutengine_p.h b/src/gui/util/qgridlayoutengine_p.h index e21d89dd2e..2f60cb99fd 100644 --- a/src/gui/util/qgridlayoutengine_p.h +++ b/src/gui/util/qgridlayoutengine_p.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "qlayoutpolicy_p.h" @@ -283,6 +284,8 @@ public: virtual QLayoutPolicy::ControlTypes controlTypes(LayoutSide side) const; + inline virtual QString toString() const { return QDebug::toString(this); } + QRectF geometryWithin(qreal x, qreal y, qreal width, qreal height, qreal rowDescent, Qt::Alignment align, bool snapToPixelGrid) const; QGridLayoutBox box(Qt::Orientation orientation, bool snapToPixelGrid, qreal constraint = -1.0) const;