qgraphicsgridlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsgridlayout.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40/*!-
41 \class QGraphicsGridLayout-
42 \brief The QGraphicsGridLayout class provides a grid layout for managing-
43 widgets in Graphics View.-
44 \since 4.4-
45-
46 \ingroup graphicsview-api-
47 \inmodule QtWidgets-
48-
49 The most common way to use QGraphicsGridLayout is to construct an object-
50 on the heap with no parent, add widgets and layouts by calling addItem(),-
51 and finally assign the layout to a widget by calling-
52 QGraphicsWidget::setLayout(). QGraphicsGridLayout automatically computes-
53 the dimensions of the grid as you add items.-
54-
55 \snippet code/src_gui_graphicsview_qgraphicsgridlayout.cpp 0-
56-
57 The layout takes ownership of the items. In some cases when the layout-
58 item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a-
59 ambiguity in ownership because the layout item belongs to two ownership hierarchies.-
60 See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle-
61 this.-
62 You can access each item in the layout by calling count() and itemAt(). Calling-
63 removeAt() will remove an item from the layout, without-
64 destroying it.-
65-
66 \section1 Size Hints and Size Policies in QGraphicsGridLayout-
67-
68 QGraphicsGridLayout respects each item's size hints and size policies,-
69 and when a cell in the grid has more space than the items can fill, each item-
70 is arranged according to the layout's alignment for that item. You can set-
71 an alignment for each item by calling setAlignment(), and check the-
72 alignment for any item by calling alignment(). You can also set the alignment-
73 for an entire row or column by calling setRowAlignment() and setColumnAlignment()-
74 respectively. By default, items are aligned to the top left.-
75-
76-
77 \sa QGraphicsLinearLayout, QGraphicsWidget-
78*/-
79-
80#include "qglobal.h"-
81-
82#ifndef QT_NO_GRAPHICSVIEW-
83-
84#include "qapplication.h"-
85#include "qwidget.h"-
86#include "qgraphicslayout_p.h"-
87#include "qgraphicslayoutitem.h"-
88#include "qgraphicsgridlayout.h"-
89#include "qgraphicswidget.h"-
90#include "qgraphicsgridlayoutengine_p.h"-
91#include "qgraphicslayoutstyleinfo_p.h"-
92#include "qscopedpointer.h"-
93#ifdef QT_DEBUG-
94# include <QtCore/qdebug.h>-
95#endif-
96-
97QT_BEGIN_NAMESPACE-
98-
99class QGraphicsGridLayoutPrivate : public QGraphicsLayoutPrivate-
100{-
101public:-
102 QGraphicsGridLayoutPrivate() { }-
103 QGraphicsLayoutStyleInfo *styleInfo() const;-
104-
105 mutable QScopedPointer<QGraphicsLayoutStyleInfo> m_styleInfo;-
106 QGraphicsGridLayoutEngine engine;-
107-
108#ifdef QGRIDLAYOUTENGINE_DEBUG-
109 void dump(int indent) const;-
110#endif-
111};-
112-
113-
114QGraphicsLayoutStyleInfo *QGraphicsGridLayoutPrivate::styleInfo() const-
115{-
116 if (!m_styleInfo)
!m_styleInfoDescription
TRUEnever evaluated
FALSEnever evaluated
0
117 m_styleInfo.reset(new QGraphicsLayoutStyleInfo(this));
never executed: m_styleInfo.reset(new QGraphicsLayoutStyleInfo(this));
0
118 return m_styleInfo.data();
never executed: return m_styleInfo.data();
0
119}-
120-
121/*!-
122 Constructs a QGraphicsGridLayout instance. \a parent is passed to-
123 QGraphicsLayout's constructor.-
124*/-
125QGraphicsGridLayout::QGraphicsGridLayout(QGraphicsLayoutItem *parent)-
126 : QGraphicsLayout(*new QGraphicsGridLayoutPrivate(), parent)-
127{-
128}
never executed: end of block
0
129-
130/*!-
131 Destroys the QGraphicsGridLayout object.-
132*/-
133QGraphicsGridLayout::~QGraphicsGridLayout()-
134{-
135 for (int i = count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
136 QGraphicsLayoutItem *item = itemAt(i);-
137 // The following lines can be removed, but this removes the item-
138 // from the layout more efficiently than the implementation of-
139 // ~QGraphicsLayoutItem.-
140 removeAt(i);-
141 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
142 item->setParentLayoutItem(0);-
143 if (item->ownedByLayout())
item->ownedByLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
144 delete item;
never executed: delete item;
0
145 }
never executed: end of block
0
146 }
never executed: end of block
0
147}
never executed: end of block
0
148-
149/*!-
150 Adds \a item to the grid on \a row and \a column. You can specify a-
151 \a rowSpan and \a columnSpan and an optional \a alignment.-
152*/-
153void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column,-
154 int rowSpan, int columnSpan, Qt::Alignment alignment)-
155{-
156 Q_D(QGraphicsGridLayout);-
157 if (row < 0 || column < 0) {
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
158 qWarning("QGraphicsGridLayout::addItem: invalid row/column: %d",-
159 row < 0 ? row : column);-
160 return;
never executed: return;
0
161 }-
162 if (columnSpan < 1 || rowSpan < 1) {
columnSpan < 1Description
TRUEnever evaluated
FALSEnever evaluated
rowSpan < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
163 qWarning("QGraphicsGridLayout::addItem: invalid row span/column span: %d",-
164 rowSpan < 1 ? rowSpan : columnSpan);-
165 return;
never executed: return;
0
166 }-
167 if (!item) {
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
168 qWarning("QGraphicsGridLayout::addItem: cannot add null item");-
169 return;
never executed: return;
0
170 }-
171 if (item == this) {
item == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
172 qWarning("QGraphicsGridLayout::addItem: cannot insert itself");-
173 return;
never executed: return;
0
174 }-
175-
176 d->addChildLayoutItem(item);-
177-
178 QGraphicsGridLayoutEngineItem *gridEngineItem = new QGraphicsGridLayoutEngineItem(item, row, column, rowSpan, columnSpan, alignment);-
179 d->engine.insertItem(gridEngineItem, -1);-
180 invalidate();-
181}
never executed: end of block
0
182-
183/*!-
184 \fn QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = 0)-
185-
186 Adds \a item to the grid on \a row and \a column. You can specify-
187 an optional \a alignment for \a item.-
188*/-
189-
190/*!-
191 Sets the default horizontal spacing for the grid layout to \a spacing.-
192*/-
193void QGraphicsGridLayout::setHorizontalSpacing(qreal spacing)-
194{-
195 Q_D(QGraphicsGridLayout);-
196 d->engine.setSpacing(spacing, Qt::Horizontal);-
197 invalidate();-
198}
never executed: end of block
0
199-
200/*!-
201 Returns the default horizontal spacing for the grid layout.-
202*/-
203qreal QGraphicsGridLayout::horizontalSpacing() const-
204{-
205 Q_D(const QGraphicsGridLayout);-
206 return d->engine.spacing(Qt::Horizontal, d->styleInfo());
never executed: return d->engine.spacing(Qt::Horizontal, d->styleInfo());
0
207}-
208-
209/*!-
210 Sets the default vertical spacing for the grid layout to \a spacing.-
211*/-
212void QGraphicsGridLayout::setVerticalSpacing(qreal spacing)-
213{-
214 Q_D(QGraphicsGridLayout);-
215 d->engine.setSpacing(spacing, Qt::Vertical);-
216 invalidate();-
217}
never executed: end of block
0
218-
219/*!-
220 Returns the default vertical spacing for the grid layout.-
221*/-
222qreal QGraphicsGridLayout::verticalSpacing() const-
223{-
224 Q_D(const QGraphicsGridLayout);-
225 return d->engine.spacing(Qt::Vertical, d->styleInfo());
never executed: return d->engine.spacing(Qt::Vertical, d->styleInfo());
0
226}-
227-
228/*!-
229 Sets the grid layout's default spacing, both vertical and-
230 horizontal, to \a spacing.-
231-
232 \sa rowSpacing(), columnSpacing()-
233*/-
234void QGraphicsGridLayout::setSpacing(qreal spacing)-
235{-
236 Q_D(QGraphicsGridLayout);-
237 d->engine.setSpacing(spacing, Qt::Horizontal | Qt::Vertical);-
238 invalidate();-
239}
never executed: end of block
0
240-
241/*!-
242 Sets the spacing for \a row to \a spacing.-
243*/-
244void QGraphicsGridLayout::setRowSpacing(int row, qreal spacing)-
245{-
246 Q_D(QGraphicsGridLayout);-
247 d->engine.setRowSpacing(row, spacing, Qt::Vertical);-
248 invalidate();-
249}
never executed: end of block
0
250-
251/*!-
252 Returns the row spacing for \a row.-
253*/-
254qreal QGraphicsGridLayout::rowSpacing(int row) const-
255{-
256 Q_D(const QGraphicsGridLayout);-
257 return d->engine.rowSpacing(row, Qt::Vertical);
never executed: return d->engine.rowSpacing(row, Qt::Vertical);
0
258}-
259-
260/*!-
261 Sets the spacing for \a column to \a spacing.-
262*/-
263void QGraphicsGridLayout::setColumnSpacing(int column, qreal spacing)-
264{-
265 Q_D(QGraphicsGridLayout);-
266 d->engine.setRowSpacing(column, spacing, Qt::Horizontal);-
267 invalidate();-
268}
never executed: end of block
0
269-
270/*!-
271 Returns the column spacing for \a column.-
272*/-
273qreal QGraphicsGridLayout::columnSpacing(int column) const-
274{-
275 Q_D(const QGraphicsGridLayout);-
276 return d->engine.rowSpacing(column, Qt::Horizontal);
never executed: return d->engine.rowSpacing(column, Qt::Horizontal);
0
277}-
278-
279/*!-
280 Sets the stretch factor for \a row to \a stretch.-
281*/-
282void QGraphicsGridLayout::setRowStretchFactor(int row, int stretch)-
283{-
284 Q_D(QGraphicsGridLayout);-
285 d->engine.setRowStretchFactor(row, stretch, Qt::Vertical);-
286 invalidate();-
287}
never executed: end of block
0
288-
289/*!-
290 Returns the stretch factor for \a row.-
291*/-
292int QGraphicsGridLayout::rowStretchFactor(int row) const-
293{-
294 Q_D(const QGraphicsGridLayout);-
295 return d->engine.rowStretchFactor(row, Qt::Vertical);
never executed: return d->engine.rowStretchFactor(row, Qt::Vertical);
0
296}-
297-
298/*!-
299 Sets the stretch factor for \a column to \a stretch.-
300*/-
301void QGraphicsGridLayout::setColumnStretchFactor(int column, int stretch)-
302{-
303 Q_D(QGraphicsGridLayout);-
304 d->engine.setRowStretchFactor(column, stretch, Qt::Horizontal);-
305 invalidate();-
306}
never executed: end of block
0
307-
308/*!-
309 Returns the stretch factor for \a column.-
310*/-
311int QGraphicsGridLayout::columnStretchFactor(int column) const-
312{-
313 Q_D(const QGraphicsGridLayout);-
314 return d->engine.rowStretchFactor(column, Qt::Horizontal);
never executed: return d->engine.rowStretchFactor(column, Qt::Horizontal);
0
315}-
316-
317/*!-
318 Sets the minimum height for row, \a row, to \a height.-
319*/-
320void QGraphicsGridLayout::setRowMinimumHeight(int row, qreal height)-
321{-
322 Q_D(QGraphicsGridLayout);-
323 d->engine.setRowSizeHint(Qt::MinimumSize, row, height, Qt::Vertical);-
324 invalidate();-
325}
never executed: end of block
0
326-
327/*!-
328 Returns the minimum height for row, \a row.-
329*/-
330qreal QGraphicsGridLayout::rowMinimumHeight(int row) const-
331{-
332 Q_D(const QGraphicsGridLayout);-
333 return d->engine.rowSizeHint(Qt::MinimumSize, row, Qt::Vertical);
never executed: return d->engine.rowSizeHint(Qt::MinimumSize, row, Qt::Vertical);
0
334}-
335-
336/*!-
337 Sets the preferred height for row, \a row, to \a height.-
338*/-
339void QGraphicsGridLayout::setRowPreferredHeight(int row, qreal height)-
340{-
341 Q_D(QGraphicsGridLayout);-
342 d->engine.setRowSizeHint(Qt::PreferredSize, row, height, Qt::Vertical);-
343 invalidate();-
344}
never executed: end of block
0
345-
346/*!-
347 Returns the preferred height for row, \a row.-
348*/-
349qreal QGraphicsGridLayout::rowPreferredHeight(int row) const-
350{-
351 Q_D(const QGraphicsGridLayout);-
352 return d->engine.rowSizeHint(Qt::PreferredSize, row, Qt::Vertical);
never executed: return d->engine.rowSizeHint(Qt::PreferredSize, row, Qt::Vertical);
0
353}-
354-
355/*!-
356 Sets the maximum height for row, \a row, to \a height.-
357*/-
358void QGraphicsGridLayout::setRowMaximumHeight(int row, qreal height)-
359{-
360 Q_D(QGraphicsGridLayout);-
361 d->engine.setRowSizeHint(Qt::MaximumSize, row, height, Qt::Vertical);-
362 invalidate();-
363}
never executed: end of block
0
364-
365/*!-
366 Returns the maximum height for row, \a row.-
367*/-
368qreal QGraphicsGridLayout::rowMaximumHeight(int row) const-
369{-
370 Q_D(const QGraphicsGridLayout);-
371 return d->engine.rowSizeHint(Qt::MaximumSize, row, Qt::Vertical);
never executed: return d->engine.rowSizeHint(Qt::MaximumSize, row, Qt::Vertical);
0
372}-
373-
374/*!-
375 Sets the fixed height for row, \a row, to \a height.-
376*/-
377void QGraphicsGridLayout::setRowFixedHeight(int row, qreal height)-
378{-
379 Q_D(QGraphicsGridLayout);-
380 d->engine.setRowSizeHint(Qt::MinimumSize, row, height, Qt::Vertical);-
381 d->engine.setRowSizeHint(Qt::MaximumSize, row, height, Qt::Vertical);-
382 invalidate();-
383}
never executed: end of block
0
384-
385/*!-
386 Sets the minimum width for \a column to \a width.-
387*/-
388void QGraphicsGridLayout::setColumnMinimumWidth(int column, qreal width)-
389{-
390 Q_D(QGraphicsGridLayout);-
391 d->engine.setRowSizeHint(Qt::MinimumSize, column, width, Qt::Horizontal);-
392 invalidate();-
393}
never executed: end of block
0
394-
395/*!-
396 Returns the minimum width for \a column.-
397*/-
398qreal QGraphicsGridLayout::columnMinimumWidth(int column) const-
399{-
400 Q_D(const QGraphicsGridLayout);-
401 return d->engine.rowSizeHint(Qt::MinimumSize, column, Qt::Horizontal);
never executed: return d->engine.rowSizeHint(Qt::MinimumSize, column, Qt::Horizontal);
0
402}-
403-
404/*!-
405 Sets the preferred width for \a column to \a width.-
406*/-
407void QGraphicsGridLayout::setColumnPreferredWidth(int column, qreal width)-
408{-
409 Q_D(QGraphicsGridLayout);-
410 d->engine.setRowSizeHint(Qt::PreferredSize, column, width, Qt::Horizontal);-
411 invalidate();-
412}
never executed: end of block
0
413-
414/*!-
415 Returns the preferred width for \a column.-
416*/-
417qreal QGraphicsGridLayout::columnPreferredWidth(int column) const-
418{-
419 Q_D(const QGraphicsGridLayout);-
420 return d->engine.rowSizeHint(Qt::PreferredSize, column, Qt::Horizontal);
never executed: return d->engine.rowSizeHint(Qt::PreferredSize, column, Qt::Horizontal);
0
421}-
422-
423/*!-
424 Sets the maximum width of \a column to \a width.-
425*/-
426void QGraphicsGridLayout::setColumnMaximumWidth(int column, qreal width)-
427{-
428 Q_D(QGraphicsGridLayout);-
429 d->engine.setRowSizeHint(Qt::MaximumSize, column, width, Qt::Horizontal);-
430 invalidate();-
431}
never executed: end of block
0
432-
433/*!-
434 Returns the maximum width for \a column.-
435*/-
436qreal QGraphicsGridLayout::columnMaximumWidth(int column) const-
437{-
438 Q_D(const QGraphicsGridLayout);-
439 return d->engine.rowSizeHint(Qt::MaximumSize, column, Qt::Horizontal);
never executed: return d->engine.rowSizeHint(Qt::MaximumSize, column, Qt::Horizontal);
0
440}-
441-
442/*!-
443 Sets the fixed width of \a column to \a width.-
444*/-
445void QGraphicsGridLayout::setColumnFixedWidth(int column, qreal width)-
446{-
447 Q_D(QGraphicsGridLayout);-
448 d->engine.setRowSizeHint(Qt::MinimumSize, column, width, Qt::Horizontal);-
449 d->engine.setRowSizeHint(Qt::MaximumSize, column, width, Qt::Horizontal);-
450 invalidate();-
451}
never executed: end of block
0
452-
453/*!-
454 Sets the alignment of \a row to \a alignment.-
455*/-
456void QGraphicsGridLayout::setRowAlignment(int row, Qt::Alignment alignment)-
457{-
458 Q_D(QGraphicsGridLayout);-
459 d->engine.setRowAlignment(row, alignment, Qt::Vertical);-
460 invalidate();-
461}
never executed: end of block
0
462-
463/*!-
464 Returns the alignment of \a row.-
465*/-
466Qt::Alignment QGraphicsGridLayout::rowAlignment(int row) const-
467{-
468 Q_D(const QGraphicsGridLayout);-
469 return d->engine.rowAlignment(row, Qt::Vertical);
never executed: return d->engine.rowAlignment(row, Qt::Vertical);
0
470}-
471-
472/*!-
473 Sets the alignment for \a column to \a alignment.-
474*/-
475void QGraphicsGridLayout::setColumnAlignment(int column, Qt::Alignment alignment)-
476{-
477 Q_D(QGraphicsGridLayout);-
478 d->engine.setRowAlignment(column, alignment, Qt::Horizontal);-
479 invalidate();-
480}
never executed: end of block
0
481-
482/*!-
483 Returns the alignment for \a column.-
484*/-
485Qt::Alignment QGraphicsGridLayout::columnAlignment(int column) const-
486{-
487 Q_D(const QGraphicsGridLayout);-
488 return d->engine.rowAlignment(column, Qt::Horizontal);
never executed: return d->engine.rowAlignment(column, Qt::Horizontal);
0
489}-
490-
491/*!-
492 Sets the alignment for \a item to \a alignment.-
493*/-
494void QGraphicsGridLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)-
495{-
496 Q_D(QGraphicsGridLayout);-
497 d->engine.setAlignment(item, alignment);-
498 invalidate();-
499}
never executed: end of block
0
500-
501/*!-
502 Returns the alignment for \a item.-
503*/-
504Qt::Alignment QGraphicsGridLayout::alignment(QGraphicsLayoutItem *item) const-
505{-
506 Q_D(const QGraphicsGridLayout);-
507 return d->engine.alignment(item);
never executed: return d->engine.alignment(item);
0
508}-
509-
510/*!-
511 Returns the number of rows in the grid layout. This is always one more-
512 than the index of the last row that is occupied by a layout item (empty-
513 rows are counted except for those at the end).-
514*/-
515int QGraphicsGridLayout::rowCount() const-
516{-
517 Q_D(const QGraphicsGridLayout);-
518 return d->engine.effectiveLastRow(Qt::Vertical) + 1;
never executed: return d->engine.effectiveLastRow(Qt::Vertical) + 1;
0
519}-
520-
521/*!-
522 Returns the number of columns in the grid layout. This is always one more-
523 than the index of the last column that is occupied by a layout item (empty-
524 columns are counted except for those at the end).-
525*/-
526int QGraphicsGridLayout::columnCount() const-
527{-
528 Q_D(const QGraphicsGridLayout);-
529 return d->engine.effectiveLastRow(Qt::Horizontal) + 1;
never executed: return d->engine.effectiveLastRow(Qt::Horizontal) + 1;
0
530}-
531-
532/*!-
533 Returns a pointer to the layout item at (\a row, \a column).-
534*/-
535QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const-
536{-
537 Q_D(const QGraphicsGridLayout);-
538 if (row < 0 || row >= rowCount() || column < 0 || column >= columnCount()) {
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
row >= rowCount()Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column >= columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
539 qWarning("QGraphicsGridLayout::itemAt: invalid row, column %d, %d", row, column);-
540 return 0;
never executed: return 0;
0
541 }-
542 if (QGraphicsGridLayoutEngineItem *engineItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(row, column)))
QGraphicsGridL...(row, column))Description
TRUEnever evaluated
FALSEnever evaluated
0
543 return engineItem->layoutItem();
never executed: return engineItem->layoutItem();
0
544 return 0;
never executed: return 0;
0
545}-
546-
547/*!-
548 Returns the number of layout items in this grid layout.-
549*/-
550int QGraphicsGridLayout::count() const-
551{-
552 Q_D(const QGraphicsGridLayout);-
553 return d->engine.itemCount();
never executed: return d->engine.itemCount();
0
554}-
555-
556/*!-
557 Returns the layout item at \a index, or 0 if there is no layout item at-
558 this index.-
559*/-
560QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const-
561{-
562 Q_D(const QGraphicsGridLayout);-
563 if (index < 0 || index >= d->engine.itemCount()) {
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= d->engine.itemCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
564 qWarning("QGraphicsGridLayout::itemAt: invalid index %d", index);-
565 return 0;
never executed: return 0;
0
566 }-
567 QGraphicsLayoutItem *item = 0;-
568 if (QGraphicsGridLayoutEngineItem *engineItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index)))
QGraphicsGridL...itemAt(index))Description
TRUEnever evaluated
FALSEnever evaluated
0
569 item = engineItem->layoutItem();
never executed: item = engineItem->layoutItem();
0
570 return item;
never executed: return item;
0
571}-
572-
573/*!-
574 Removes the layout item at \a index without destroying it. Ownership of-
575 the item is transferred to the caller.-
576-
577 \sa addItem()-
578*/-
579void QGraphicsGridLayout::removeAt(int index)-
580{-
581 Q_D(QGraphicsGridLayout);-
582 if (index < 0 || index >= d->engine.itemCount()) {
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= d->engine.itemCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
583 qWarning("QGraphicsGridLayout::removeAt: invalid index %d", index);-
584 return;
never executed: return;
0
585 }-
586-
587 if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index))) {
QGraphicsGridL...itemAt(index))Description
TRUEnever evaluated
FALSEnever evaluated
0
588 if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
QGraphicsLayou...->layoutItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
589 layoutItem->setParentLayoutItem(0);
never executed: layoutItem->setParentLayoutItem(0);
0
590 d->engine.removeItem(gridItem);-
591-
592 // recalculate rowInfo.count if we remove an item that is on the right/bottommost row-
593 for (int j = 0; j < NOrientations; ++j) {
j < NOrientationsDescription
TRUEnever evaluated
FALSEnever evaluated
0
594 // 0: Hor, 1: Ver-
595 const Qt::Orientation orient = (j == 0 ? Qt::Horizontal : Qt::Vertical);
j == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
596 const int oldCount = d->engine.rowCount(orient);-
597 if (gridItem->lastRow(orient) == oldCount - 1) {
gridItem->last...= oldCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
598 const int newCount = d->engine.effectiveLastRow(orient) + 1;-
599 d->engine.removeRows(newCount, oldCount - newCount, orient);-
600 }
never executed: end of block
0
601 }
never executed: end of block
0
602-
603 delete gridItem;-
604 invalidate();-
605 }
never executed: end of block
0
606}
never executed: end of block
0
607-
608/*!-
609 Removes the layout item \a item without destroying it.-
610 Ownership of the item is transferred to the caller.-
611-
612 \sa addItem()-
613*/-
614void QGraphicsGridLayout::removeItem(QGraphicsLayoutItem *item)-
615{-
616 Q_D(QGraphicsGridLayout);-
617 int index = d->engine.indexOf(item);-
618 removeAt(index);-
619}
never executed: end of block
0
620/*!-
621 \reimp-
622*/-
623void QGraphicsGridLayout::invalidate()-
624{-
625 Q_D(QGraphicsGridLayout);-
626 d->engine.invalidate();-
627 if (d->m_styleInfo)
d->m_styleInfoDescription
TRUEnever evaluated
FALSEnever evaluated
0
628 d->m_styleInfo->invalidate();
never executed: d->m_styleInfo->invalidate();
0
629 QGraphicsLayout::invalidate();-
630}
never executed: end of block
0
631-
632#ifdef QGRIDLAYOUTENGINE_DEBUG-
633void QGraphicsGridLayoutPrivate::dump(int indent) const-
634{-
635 if (qt_graphicsLayoutDebug()) {-
636 engine.dump(indent + 1);-
637 }-
638}-
639#endif-
640-
641/*!-
642 Sets the bounding geometry of the grid layout to \a rect.-
643*/-
644void QGraphicsGridLayout::setGeometry(const QRectF &rect)-
645{-
646 Q_D(QGraphicsGridLayout);-
647 QGraphicsLayout::setGeometry(rect);-
648 QRectF effectiveRect = geometry();-
649 qreal left, top, right, bottom;-
650 getContentsMargins(&left, &top, &right, &bottom);-
651 Qt::LayoutDirection visualDir = d->visualDirection();-
652 d->engine.setVisualDirection(visualDir);-
653 if (visualDir == Qt::RightToLeft)
visualDir == Qt::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
654 qSwap(left, right);
never executed: qSwap(left, right);
0
655 effectiveRect.adjust(+left, +top, -right, -bottom);-
656 d->engine.setGeometries(effectiveRect, d->styleInfo());-
657#ifdef QGRIDLAYOUTENGINE_DEBUG-
658 if (qt_graphicsLayoutDebug()) {-
659 static int counter = 0;-
660 qDebug("==== BEGIN DUMP OF QGraphicsGridLayout (%d)====", counter++);-
661 d->dump(1);-
662 qDebug("==== END DUMP OF QGraphicsGridLayout ====");-
663 }-
664#endif-
665}
never executed: end of block
0
666-
667/*!-
668 \reimp-
669*/-
670QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const-
671{-
672 Q_D(const QGraphicsGridLayout);-
673 qreal left, top, right, bottom;-
674 getContentsMargins(&left, &top, &right, &bottom);-
675 const QSizeF extraMargins(left + right, top + bottom);-
676 return d->engine.sizeHint(which , constraint - extraMargins, d->styleInfo()) + extraMargins;
never executed: return d->engine.sizeHint(which , constraint - extraMargins, d->styleInfo()) + extraMargins;
0
677}-
678-
679-
680#if 0-
681// ### kill? (implement and kill?)-
682QRect QGraphicsGridLayout::cellRect(int row, int column, int rowSpan, int columnSpan) const-
683{-
684 Q_D(const QGraphicsGridLayout);-
685 return QRect();-
686// return d->engine.cellRect(parentLayoutable(), contentsGeometry(), row, column, rowSpan, columnSpan);-
687}-
688-
689QSizePolicy::ControlTypes QGraphicsGridLayout::controlTypes(LayoutSide side) const-
690{-
691 Q_D(const QGraphicsGridLayout);-
692 return d->engine.controlTypes(side);-
693}-
694#endif-
695-
696QT_END_NAMESPACE-
697-
698#endif //QT_NO_GRAPHICSVIEW-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9