diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 2b81d34848..f2d549b48f 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -1336,7 +1336,7 @@ void QGridLayoutEngine::fillRowData(QGridLayoutRowData *rowData, if (rowIsIdenticalToPrevious && item != itemAt(row - 1, column, orientation)) rowIsIdenticalToPrevious = false; - if (item && !item->isIgnored()) + if (item && !item->isEmpty()) rowIsEmpty = false; } diff --git a/src/gui/util/qgridlayoutengine_p.h b/src/gui/util/qgridlayoutengine_p.h index 181326103b..908aeda0c3 100644 --- a/src/gui/util/qgridlayoutengine_p.h +++ b/src/gui/util/qgridlayoutengine_p.h @@ -303,7 +303,7 @@ public: virtual QLayoutPolicy::Policy sizePolicy(Qt::Orientation orientation) const = 0; virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const = 0; - virtual bool isIgnored() const { return false; } + virtual bool isEmpty() const { return false; } virtual void setGeometry(const QRectF &rect) = 0; /* diff --git a/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp b/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp index 5797d9e539..3dd1b1652a 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp +++ b/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp @@ -42,29 +42,9 @@ #include "qgraphicslayoutitem_p.h" #include "qgraphicslayout_p.h" #include "qgraphicswidget.h" -#include QT_BEGIN_NAMESPACE -bool QGraphicsGridLayoutEngineItem::isHidden() const -{ - if (QGraphicsItem *item = q_layoutItem->graphicsItem()) - return QGraphicsItemPrivate::get(item)->explicitlyHidden; - return false; -} - -/*! - \internal - - If this returns true, the layout will arrange just as if the item was never added to the layout. - (Note that this shouldn't lead to a "double spacing" where the item was hidden) - ### Qt6: Move to QGraphicsLayoutItem and make virtual -*/ -bool QGraphicsGridLayoutEngineItem::isIgnored() const -{ - return isHidden() && !q_layoutItem->sizePolicy().retainSizeWhenHidden(); -} - /* returns \c true if the size policy returns \c true for either hasHeightForWidth() or hasWidthForHeight() @@ -83,6 +63,16 @@ Qt::Orientation QGraphicsGridLayoutEngineItem::dynamicConstraintOrientation() co return Qt::Horizontal; } +/*! + \internal + + If this returns true, the layout will arrange just as if the item was never added to the layout. + (Note that this shouldn't lead to a "double spacing" where the item was hidden) +*/ +bool QGraphicsGridLayoutEngineItem::isEmpty() const +{ + return q_layoutItem->isEmpty(); +} void QGraphicsGridLayoutEngine::setAlignment(QGraphicsLayoutItem *graphicsLayoutItem, Qt::Alignment alignment) { diff --git a/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h b/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h index 2f2c547977..a3e42c7b77 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h +++ b/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h @@ -89,10 +89,6 @@ public: return q_layoutItem->effectiveSizeHint(which, constraint); } - bool isHidden() const; - - virtual bool isIgnored() const override; - virtual void setGeometry(const QRectF &rect) override { q_layoutItem->setGeometry(rect); @@ -101,6 +97,8 @@ public: virtual bool hasDynamicConstraint() const override; virtual Qt::Orientation dynamicConstraintOrientation() const override; + virtual bool isEmpty() const override; + QGraphicsLayoutItem *layoutItem() const { return q_layoutItem; } protected: diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.cpp b/src/widgets/graphicsview/qgraphicslayoutitem.cpp index 8694dcb36b..2c484321e4 100644 --- a/src/widgets/graphicsview/qgraphicslayoutitem.cpp +++ b/src/widgets/graphicsview/qgraphicslayoutitem.cpp @@ -45,6 +45,7 @@ #include "qgraphicslayoutitem_p.h" #include "qwidget.h" #include "qgraphicswidget.h" +#include "qgraphicsitem_p.h" #include @@ -825,6 +826,22 @@ void QGraphicsLayoutItem::updateGeometry() d->sizeHintWithConstraintCacheDirty = true; } +/*! + * returns \c true if this item is empty, i.e whether it has no content and + * should not occupy any space. + * + * The default implementation returns true if the item has been hidden unless + * its size policy has retainSizeWhenHidden set to \c true + */ +bool QGraphicsLayoutItem::isEmpty() const +{ + bool isHidden = false; + if (QGraphicsItem *item = graphicsItem()) + isHidden = QGraphicsItemPrivate::get(item)->explicitlyHidden; + + return isHidden && !sizePolicy().retainSizeWhenHidden(); +} + /*! Returns the parent of this QGraphicsLayoutItem, or \nullptr if there is no parent, or if the parent does not inherit from QGraphicsLayoutItem diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.h b/src/widgets/graphicsview/qgraphicslayoutitem.h index 86a0a87361..04905c7654 100644 --- a/src/widgets/graphicsview/qgraphicslayoutitem.h +++ b/src/widgets/graphicsview/qgraphicslayoutitem.h @@ -94,6 +94,7 @@ public: virtual void updateGeometry(); + virtual bool isEmpty() const; QGraphicsLayoutItem *parentLayoutItem() const; void setParentLayoutItem(QGraphicsLayoutItem *parent);