QGridLayoutEngine: print stringified layout item in warnings

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 <jan-arve.saether@qt.io>
bb10
Mitch Curtis 2024-03-29 15:22:10 +08:00
parent ce23c9083f
commit 3f720b8acf
2 changed files with 8 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -24,6 +24,7 @@
#include <QtCore/qpair.h>
#include <QtCore/qsize.h>
#include <QtCore/qrect.h>
#include <QtCore/qdebug.h>
#include <float.h>
#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;