diff options
author | Jan Arve Sæther <[email protected]> | 2020-02-11 15:33:56 +0100 |
---|---|---|
committer | Jan Arve Sæther <[email protected]> | 2020-02-25 15:43:16 +0100 |
commit | aa9c6f983215b9a1e5eb0b6be1ed10f30a30f78a (patch) | |
tree | 794262d755bd2033b1d763557ee269c30958da1d | |
parent | 26059d1b9b84bbaaa6c5a50a7dea88ffa9051c5a (diff) |
Introduce QGraphicsLayoutItem::isEmpty()
This change does basically two things:
* Renames QGraphicsGridLayoutEngineItem::isIgnored() to
QGraphicsGridLayoutEngineItem::isEmpty() to be consistent with
QLayoutItem::isEmpty()
* Creates a new public API function QGraphicsLayoutItem::isEmpty() so
that there is a public method of overriding the behavior.
Change-Id: I771a8fb429f9764a75e220f0ff9d07f578f981d3
Reviewed-by: Paul Olav Tvete <[email protected]>
-rw-r--r-- | src/gui/util/qgridlayoutengine.cpp | 2 | ||||
-rw-r--r-- | src/gui/util/qgridlayoutengine_p.h | 2 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp | 30 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h | 6 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicslayoutitem.cpp | 17 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicslayoutitem.h | 1 |
6 files changed, 32 insertions, 26 deletions
diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 2b81d34848b..f2d549b48fb 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 181326103b1..908aeda0c38 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 5797d9e5396..3dd1b1652ae 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 <private/qgraphicswidget_p.h> 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 2f2c5479776..a3e42c7b772 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 8694dcb36be..2c484321e47 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 <QtDebug> @@ -826,6 +827,22 @@ void QGraphicsLayoutItem::updateGeometry() } /*! + * 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 (QGraphicsLayoutItem is often used through multiple inheritance with diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.h b/src/widgets/graphicsview/qgraphicslayoutitem.h index 86a0a87361b..04905c76543 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); |