1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qgraphicsgridlayoutengine_p.h"
5
6#include "qgraphicslayoutitem_p.h"
7#include "qgraphicslayout_p.h"
8#include "qgraphicswidget.h"
9
10QT_BEGIN_NAMESPACE
11
12/*
13 returns \c true if the size policy returns \c true for either hasHeightForWidth()
14 or hasWidthForHeight()
15 */
16bool QGraphicsGridLayoutEngineItem::hasDynamicConstraint() const
17{
18 return QGraphicsLayoutItemPrivate::get(q: q_layoutItem)->hasHeightForWidth()
19 || QGraphicsLayoutItemPrivate::get(q: q_layoutItem)->hasWidthForHeight();
20}
21
22Qt::Orientation QGraphicsGridLayoutEngineItem::dynamicConstraintOrientation() const
23{
24 if (QGraphicsLayoutItemPrivate::get(q: q_layoutItem)->hasHeightForWidth())
25 return Qt::Vertical;
26 else //if (QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasWidthForHeight())
27 return Qt::Horizontal;
28}
29
30/*!
31 \internal
32
33 If this returns true, the layout will arrange just as if the item was never added to the layout.
34 (Note that this shouldn't lead to a "double spacing" where the item was hidden)
35*/
36bool QGraphicsGridLayoutEngineItem::isEmpty() const
37{
38 return q_layoutItem->isEmpty();
39}
40
41void QGraphicsGridLayoutEngine::setAlignment(QGraphicsLayoutItem *graphicsLayoutItem, Qt::Alignment alignment)
42{
43 if (QGraphicsGridLayoutEngineItem *gridEngineItem = findLayoutItem(layoutItem: graphicsLayoutItem)) {
44 gridEngineItem->setAlignment(alignment);
45 invalidate();
46 }
47}
48
49Qt::Alignment QGraphicsGridLayoutEngine::alignment(QGraphicsLayoutItem *graphicsLayoutItem) const
50{
51 if (QGraphicsGridLayoutEngineItem *gridEngineItem = findLayoutItem(layoutItem: graphicsLayoutItem))
52 return gridEngineItem->alignment();
53 return { };
54}
55
56
57void QGraphicsGridLayoutEngine::setStretchFactor(QGraphicsLayoutItem *layoutItem, int stretch,
58 Qt::Orientation orientation)
59{
60 Q_ASSERT(stretch >= 0);
61
62 if (QGraphicsGridLayoutEngineItem *item = findLayoutItem(layoutItem))
63 item->setStretchFactor(stretch, orientation);
64}
65
66int QGraphicsGridLayoutEngine::stretchFactor(QGraphicsLayoutItem *layoutItem, Qt::Orientation orientation) const
67{
68 if (QGraphicsGridLayoutEngineItem *item = findLayoutItem(layoutItem))
69 return item->stretchFactor(orientation);
70 return 0;
71}
72
73QT_END_NAMESPACE
74

source code of qtbase/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp