qgridlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qgridlayout.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#include "qgridlayout.h"-
41#include "qapplication.h"-
42#include "qwidget.h"-
43#include "qlist.h"-
44#include "qsizepolicy.h"-
45#include "qvector.h"-
46#include "qvarlengtharray.h"-
47#include "qlayoutengine_p.h"-
48#include "qlayout_p.h"-
49-
50QT_BEGIN_NAMESPACE-
51-
52struct QGridLayoutSizeTriple-
53{-
54 QSize minS;-
55 QSize hint;-
56 QSize maxS;-
57};-
58-
59/*-
60 Three internal classes related to QGridLayout: (1) QGridBox is a-
61 QLayoutItem with (row, column) information and (torow, tocolumn) information; (3) QGridLayoutData is-
62 the internal representation of a QGridLayout.-
63*/-
64-
65class QGridBox-
66{-
67public:-
68 QGridBox(QLayoutItem *lit) { item_ = lit; }-
69-
70 QGridBox(const QLayout *l, QWidget *wid) { item_ = QLayoutPrivate::createWidgetItem(l, wid); }-
71 ~QGridBox() { delete item_; }-
72-
73 QSize sizeHint() const { return item_->sizeHint(); }-
74 QSize minimumSize() const { return item_->minimumSize(); }-
75 QSize maximumSize() const { return item_->maximumSize(); }-
76 Qt::Orientations expandingDirections() const { return item_->expandingDirections(); }-
77 bool isEmpty() const { return item_->isEmpty(); }-
78-
79 bool hasHeightForWidth() const { return item_->hasHeightForWidth(); }-
80 int heightForWidth(int w) const { return item_->heightForWidth(w); }-
81-
82 void setAlignment(Qt::Alignment a) { item_->setAlignment(a); }-
83 void setGeometry(const QRect &r) { item_->setGeometry(r); }-
84 Qt::Alignment alignment() const { return item_->alignment(); }-
85 QLayoutItem *item() { return item_; }-
86 void setItem(QLayoutItem *newitem) { item_ = newitem; }-
87 QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = 0; return i; }-
88-
89 int hStretch() { return item_->widget() ?-
90 item_->widget()->sizePolicy().horizontalStretch() : 0; }-
91 int vStretch() { return item_->widget() ?-
92 item_->widget()->sizePolicy().verticalStretch() : 0; }-
93-
94private:-
95 friend class QGridLayoutPrivate;-
96 friend class QGridLayout;-
97-
98 inline int toRow(int rr) const { return torow >= 0 ? torow : rr - 1; }-
99 inline int toCol(int cc) const { return tocol >= 0 ? tocol : cc - 1; }-
100-
101 QLayoutItem *item_;-
102 int row, col;-
103 int torow, tocol;-
104};-
105-
106class QGridLayoutPrivate : public QLayoutPrivate-
107{-
108 Q_DECLARE_PUBLIC(QGridLayout)-
109public:-
110 QGridLayoutPrivate();-
111-
112 void add(QGridBox*, int row, int col);-
113 void add(QGridBox*, int row1, int row2, int col1, int col2);-
114 QSize sizeHint(int hSpacing, int vSpacing) const;-
115 QSize minimumSize(int hSpacing, int vSpacing) const;-
116 QSize maximumSize(int hSpacing, int vSpacing) const;-
117-
118 Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const;-
119-
120 void distribute(QRect rect, int hSpacing, int vSpacing);-
121 inline int numRows() const { return rr; }-
122 inline int numCols() const { return cc; }-
123 inline void expand(int rows, int cols)-
124 { setSize(qMax(rows, rr), qMax(cols, cc)); }-
125 inline void setRowStretch(int r, int s)-
126 { expand(r + 1, 0); rStretch[r] = s; setDirty(); }-
127 inline void setColStretch(int c, int s)-
128 { expand(0, c + 1); cStretch[c] = s; setDirty(); }-
129 inline int rowStretch(int r) const { return rStretch.at(r); }-
130 inline int colStretch(int c) const { return cStretch.at(c); }-
131 inline void setRowMinimumHeight(int r, int s)-
132 { expand(r + 1, 0); rMinHeights[r] = s; setDirty(); }-
133 inline void setColumnMinimumWidth(int c, int s)-
134 { expand(0, c + 1); cMinWidths[c] = s; setDirty(); }-
135 inline int rowSpacing(int r) const { return rMinHeights.at(r); }-
136 inline int colSpacing(int c) const { return cMinWidths.at(c); }-
137-
138 inline void setReversed(bool r, bool c) { hReversed = c; vReversed = r; }-
139 inline bool horReversed() const { return hReversed; }-
140 inline bool verReversed() const { return vReversed; }-
141 inline void setDirty() { needRecalc = true; hfw_width = -1; }-
142 inline bool isDirty() const { return needRecalc; }-
143 bool hasHeightForWidth(int hSpacing, int vSpacing);-
144 int heightForWidth(int width, int hSpacing, int vSpacing);-
145 int minimumHeightForWidth(int width, int hSpacing, int vSpacing);-
146-
147 inline void getNextPos(int &row, int &col) { row = nextR; col = nextC; }-
148 inline int count() const { return things.count(); }-
149 QRect cellRect(int row, int col) const;-
150-
151 inline QLayoutItem *itemAt(int index) const {-
152 if (index < things.count())-
153 return things.at(index)->item();-
154 else-
155 return 0;-
156 }-
157 inline QLayoutItem *takeAt(int index) {-
158 Q_Q(QGridLayout);-
159 if (index < things.count()) {-
160 if (QGridBox *b = things.takeAt(index)) {-
161 QLayoutItem *item = b->takeItem();-
162 if (QLayout *l = item->layout()) {-
163 // sanity check in case the user passed something weird to QObject::setParent()-
164 if (l->parent() == q)-
165 l->setParent(0);-
166 }-
167 delete b;-
168 return item;-
169 }-
170 }-
171 return 0;-
172 }-
173 QLayoutItem* replaceAt(int index, QLayoutItem *newitem) Q_DECL_OVERRIDE-
174 {-
175 if (!newitem)-
176 return 0;-
177 QLayoutItem *item = 0;-
178 QGridBox *b = things.value(index);-
179 if (b) {-
180 item = b->takeItem();-
181 b->setItem(newitem);-
182 }-
183 return item;-
184 }-
185-
186 void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const {-
187 if (index < things.count()) {-
188 const QGridBox *b = things.at(index);-
189 int toRow = b->toRow(rr);-
190 int toCol = b->toCol(cc);-
191 *row = b->row;-
192 *column = b->col;-
193 *rowSpan = toRow - *row + 1;-
194 *columnSpan = toCol - *column +1;-
195 }-
196 }-
197 void deleteAll();-
198-
199private:-
200 void setNextPosAfter(int r, int c);-
201 void recalcHFW(int w);-
202 void addHfwData(QGridBox *box, int width);-
203 void init();-
204 QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const;-
205 void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c);-
206 void setSize(int rows, int cols);-
207 void setupSpacings(QVector<QLayoutStruct> &chain, QGridBox *grid[], int fixedSpacing,-
208 Qt::Orientation orientation);-
209 void setupLayoutData(int hSpacing, int vSpacing);-
210 void setupHfwLayoutData();-
211 void effectiveMargins(int *left, int *top, int *right, int *bottom) const;-
212-
213 int rr;-
214 int cc;-
215 QVector<QLayoutStruct> rowData;-
216 QVector<QLayoutStruct> colData;-
217 QVector<QLayoutStruct> *hfwData;-
218 QVector<int> rStretch;-
219 QVector<int> cStretch;-
220 QVector<int> rMinHeights;-
221 QVector<int> cMinWidths;-
222 QList<QGridBox *> things;-
223-
224 int hfw_width;-
225 int hfw_height;-
226 int hfw_minheight;-
227 int nextR;-
228 int nextC;-
229-
230 int horizontalSpacing;-
231 int verticalSpacing;-
232 int leftMargin;-
233 int topMargin;-
234 int rightMargin;-
235 int bottomMargin;-
236-
237 uint hReversed : 1;-
238 uint vReversed : 1;-
239 uint needRecalc : 1;-
240 uint has_hfw : 1;-
241 uint addVertical : 1;-
242};-
243-
244void QGridLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const-
245{-
246 int l = leftMargin;-
247 int t = topMargin;-
248 int r = rightMargin;-
249 int b = bottomMargin;-
250#ifdef Q_OS_MAC-
251 int leftMost = INT_MAX;-
252 int topMost = INT_MAX;-
253 int rightMost = 0;-
254 int bottomMost = 0;-
255-
256 QWidget *w = 0;-
257 const int n = things.count();-
258 for (int i = 0; i < n; ++i) {-
259 QGridBox *box = things.at(i);-
260 QLayoutItem *itm = box->item();-
261 w = itm->widget();-
262 if (w) {-
263 bool visualHReversed = hReversed != (w->layoutDirection() == Qt::RightToLeft);-
264 QRect lir = itm->geometry();-
265 QRect wr = w->geometry();-
266 if (box->col <= leftMost) {-
267 if (box->col < leftMost) {-
268 // we found an item even closer to the margin, discard.-
269 leftMost = box->col;-
270 if (visualHReversed)-
271 r = rightMargin;-
272 else-
273 l = leftMargin;-
274 }-
275 if (visualHReversed) {-
276 r = qMax(r, wr.right() - lir.right());-
277 } else {-
278 l = qMax(l, lir.left() - wr.left());-
279 }-
280 }-
281 if (box->row <= topMost) {-
282 if (box->row < topMost) {-
283 // we found an item even closer to the margin, discard.-
284 topMost = box->row;-
285 if (vReversed)-
286 b = bottomMargin;-
287 else-
288 t = topMargin;-
289 }-
290 if (vReversed)-
291 b = qMax(b, wr.bottom() - lir.bottom());-
292 else-
293 t = qMax(t, lir.top() - wr.top());-
294 }-
295 if (box->toCol(cc) >= rightMost) {-
296 if (box->toCol(cc) > rightMost) {-
297 // we found an item even closer to the margin, discard.-
298 rightMost = box->toCol(cc);-
299 if (visualHReversed)-
300 l = leftMargin;-
301 else-
302 r = rightMargin;-
303 }-
304 if (visualHReversed) {-
305 l = qMax(l, lir.left() - wr.left());-
306 } else {-
307 r = qMax(r, wr.right() - lir.right());-
308 }-
309-
310 }-
311 if (box->toRow(rr) >= bottomMost) {-
312 if (box->toRow(rr) > bottomMost) {-
313 // we found an item even closer to the margin, discard.-
314 bottomMost = box->toRow(rr);-
315 if (vReversed)-
316 t = topMargin;-
317 else-
318 b = bottomMargin;-
319 }-
320 if (vReversed)-
321 t = qMax(t, lir.top() - wr.top());-
322 else-
323 b = qMax(b, wr.bottom() - lir.bottom());-
324 }-
325 }-
326 }-
327-
328#endif-
329 if (left)-
330 *left = l;-
331 if (top)-
332 *top = t;-
333 if (right)-
334 *right = r;-
335 if (bottom)-
336 *bottom = b;-
337}-
338-
339QGridLayoutPrivate::QGridLayoutPrivate()-
340{-
341 addVertical = false;-
342 setDirty();-
343 rr = cc = 0;-
344 nextR = nextC = 0;-
345 hfwData = 0;-
346 hReversed = false;-
347 vReversed = false;-
348 horizontalSpacing = -1;-
349 verticalSpacing = -1;-
350}-
351-
352#if 0-
353QGridLayoutPrivate::QGridLayoutPrivate(int nRows, int nCols)-
354 : rowData(0), colData(0)-
355{-
356 init();-
357 if (nRows < 0) {-
358 nRows = 1;-
359 addVertical = false;-
360 }-
361 if (nCols < 0) {-
362 nCols = 1;-
363 addVertical = true;-
364 }-
365 setSize(nRows, nCols);-
366}-
367#endif-
368-
369void QGridLayoutPrivate::deleteAll()-
370{-
371 while (!things.isEmpty())-
372 delete things.takeFirst();-
373 delete hfwData;-
374}-
375-
376bool QGridLayoutPrivate::hasHeightForWidth(int hSpacing, int vSpacing)-
377{-
378 setupLayoutData(hSpacing, vSpacing);-
379 return has_hfw;-
380}-
381-
382/*-
383 Assumes that setupLayoutData() has been called, and that-
384 qGeomCalc() has filled in colData with appropriate values.-
385*/-
386void QGridLayoutPrivate::recalcHFW(int w)-
387{-
388 /*-
389 Go through all children, using colData and heightForWidth()-
390 and put the results in hfwData.-
391 */-
392 if (!hfwData)-
393 hfwData = new QVector<QLayoutStruct>(rr);-
394 setupHfwLayoutData();-
395 QVector<QLayoutStruct> &rData = *hfwData;-
396-
397 int h = 0;-
398 int mh = 0;-
399 for (int r = 0; r < rr; r++) {-
400 int spacing = rData.at(r).spacing;-
401 h += rData.at(r).sizeHint + spacing;-
402 mh += rData.at(r).minimumSize + spacing;-
403 }-
404-
405 hfw_width = w;-
406 hfw_height = qMin(QLAYOUTSIZE_MAX, h);-
407 hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);-
408}-
409-
410int QGridLayoutPrivate::heightForWidth(int w, int hSpacing, int vSpacing)-
411{-
412 setupLayoutData(hSpacing, vSpacing);-
413 if (!has_hfw)-
414 return -1;-
415 int left, top, right, bottom;-
416 effectiveMargins(&left, &top, &right, &bottom);-
417-
418 int hMargins = left + right;-
419 if (w - hMargins != hfw_width) {-
420 qGeomCalc(colData, 0, cc, 0, w - hMargins);-
421 recalcHFW(w - hMargins);-
422 }-
423 return hfw_height + top + bottom;-
424}-
425-
426int QGridLayoutPrivate::minimumHeightForWidth(int w, int hSpacing, int vSpacing)-
427{-
428 (void)heightForWidth(w, hSpacing, vSpacing);-
429 if (!has_hfw)-
430 return -1;-
431 int top, bottom;-
432 effectiveMargins(0, &top, 0, &bottom);-
433 return hfw_minheight + top + bottom;-
434}-
435-
436QSize QGridLayoutPrivate::findSize(int QLayoutStruct::*size, int hSpacing, int vSpacing) const-
437{-
438 QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);-
439 that->setupLayoutData(hSpacing, vSpacing);-
440-
441 int w = 0;-
442 int h = 0;-
443-
444 for (int r = 0; r < rr; r++)-
445 h += rowData.at(r).*size + rowData.at(r).spacing;-
446 for (int c = 0; c < cc; c++)-
447 w += colData.at(c).*size + colData.at(c).spacing;-
448-
449 w = qMin(QLAYOUTSIZE_MAX, w);-
450 h = qMin(QLAYOUTSIZE_MAX, h);-
451-
452 return QSize(w, h);-
453}-
454-
455Qt::Orientations QGridLayoutPrivate::expandingDirections(int hSpacing, int vSpacing) const-
456{-
457 QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);-
458 that->setupLayoutData(hSpacing, vSpacing);-
459 Qt::Orientations ret;-
460-
461 for (int r = 0; r < rr; r++) {-
462 if (rowData.at(r).expansive) {-
463 ret |= Qt::Vertical;-
464 break;-
465 }-
466 }-
467 for (int c = 0; c < cc; c++) {-
468 if (colData.at(c).expansive) {-
469 ret |= Qt::Horizontal;-
470 break;-
471 }-
472 }-
473 return ret;-
474}-
475-
476QSize QGridLayoutPrivate::sizeHint(int hSpacing, int vSpacing) const-
477{-
478 return findSize(&QLayoutStruct::sizeHint, hSpacing, vSpacing);-
479}-
480-
481QSize QGridLayoutPrivate::maximumSize(int hSpacing, int vSpacing) const-
482{-
483 return findSize(&QLayoutStruct::maximumSize, hSpacing, vSpacing);-
484}-
485-
486QSize QGridLayoutPrivate::minimumSize(int hSpacing, int vSpacing) const-
487{-
488 return findSize(&QLayoutStruct::minimumSize, hSpacing, vSpacing);-
489}-
490-
491void QGridLayoutPrivate::setSize(int r, int c)-
492{-
493 if ((int)rowData.size() < r) {-
494 int newR = qMax(r, rr * 2);-
495 rowData.resize(newR);-
496 rStretch.resize(newR);-
497 rMinHeights.resize(newR);-
498 for (int i = rr; i < newR; i++) {-
499 rowData[i].init();-
500 rowData[i].maximumSize = 0;-
501 rowData[i].pos = 0;-
502 rowData[i].size = 0;-
503 rStretch[i] = 0;-
504 rMinHeights[i] = 0;-
505 }-
506 }-
507 if ((int)colData.size() < c) {-
508 int newC = qMax(c, cc * 2);-
509 colData.resize(newC);-
510 cStretch.resize(newC);-
511 cMinWidths.resize(newC);-
512 for (int i = cc; i < newC; i++) {-
513 colData[i].init();-
514 colData[i].maximumSize = 0;-
515 colData[i].pos = 0;-
516 colData[i].size = 0;-
517 cStretch[i] = 0;-
518 cMinWidths[i] = 0;-
519 }-
520 }-
521-
522 if (hfwData && (int)hfwData->size() < r) {-
523 delete hfwData;-
524 hfwData = 0;-
525 hfw_width = -1;-
526 }-
527 rr = r;-
528 cc = c;-
529}-
530-
531void QGridLayoutPrivate::setNextPosAfter(int row, int col)-
532{-
533 if (addVertical) {-
534 if (col > nextC || (col == nextC && row >= nextR)) {-
535 nextR = row + 1;-
536 nextC = col;-
537 if (nextR >= rr) {-
538 nextR = 0;-
539 nextC++;-
540 }-
541 }-
542 } else {-
543 if (row > nextR || (row == nextR && col >= nextC)) {-
544 nextR = row;-
545 nextC = col + 1;-
546 if (nextC >= cc) {-
547 nextC = 0;-
548 nextR++;-
549 }-
550 }-
551 }-
552}-
553-
554void QGridLayoutPrivate::add(QGridBox *box, int row, int col)-
555{-
556 expand(row + 1, col + 1);-
557 box->row = box->torow = row;-
558 box->col = box->tocol = col;-
559 things.append(box);-
560 setDirty();-
561 setNextPosAfter(row, col);-
562}-
563-
564void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int col2)-
565{-
566 if (Q_UNLIKELY(row2 >= 0 && row2 < row1)))
__builtin_expe... row1), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
567 qWarning("QGridLayout: Multi-cell fromRow greater than toRow");
never executed: QMessageLogger(__FILE__, 567, __PRETTY_FUNCTION__).warning("QGridLayout: Multi-cell fromRow greater than toRow");
0
568 if (Q_UNLIKELY(col2 >= 0 && col2 < col1)))
__builtin_expe... col1), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
569 qWarning("QGridLayout: Multi-cell fromCol greater than toCol");
never executed: QMessageLogger(__FILE__, 569, __PRETTY_FUNCTION__).warning("QGridLayout: Multi-cell fromCol greater than toCol");
0
570 if (row1 == row2 && col1 == col2) {
row1 == row2Description
TRUEnever evaluated
FALSEnever evaluated
col1 == col2Description
TRUEnever evaluated
FALSEnever evaluated
0
571 add(box, row1, col1);-
572 return;
never executed: return;
0
573 }-
574 expand(qMax(row1, row2) + 1, qMax(col1, col2) + 1);-
575 box->row = row1;-
576 box->col = col1;-
577-
578 box->torow = row2;-
579 box->tocol = col2;-
580-
581 things.append(box);-
582 setDirty();-
583 if (col2 < 0)
col2 < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
584 col2 = cc - 1;
never executed: col2 = cc - 1;
0
585-
586 setNextPosAfter(row2, col2);-
587}
never executed: end of block
0
588-
589void QGridLayoutPrivate::addData(QGridBox *box, const QGridLayoutSizeTriple &sizes, bool r, bool c)-
590{-
591 const QWidget *widget = box->item()->widget();-
592-
593 if (box->isEmpty() && widget)-
594 return;-
595-
596 if (c) {-
597 QLayoutStruct *data = &colData[box->col];-
598 if (!cStretch.at(box->col))-
599 data->stretch = qMax(data->stretch, box->hStretch());-
600 data->sizeHint = qMax(sizes.hint.width(), data->sizeHint);-
601 data->minimumSize = qMax(sizes.minS.width(), data->minimumSize);-
602-
603 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.width(),-
604 box->expandingDirections() & Qt::Horizontal, box->isEmpty());-
605 }-
606 if (r) {-
607 QLayoutStruct *data = &rowData[box->row];-
608 if (!rStretch.at(box->row))-
609 data->stretch = qMax(data->stretch, box->vStretch());-
610 data->sizeHint = qMax(sizes.hint.height(), data->sizeHint);-
611 data->minimumSize = qMax(sizes.minS.height(), data->minimumSize);-
612-
613 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.height(),-
614 box->expandingDirections() & Qt::Vertical, box->isEmpty());-
615 }-
616}-
617-
618static void initEmptyMultiBox(QVector<QLayoutStruct> &chain, int start, int end)-
619{-
620 for (int i = start; i <= end; i++) {-
621 QLayoutStruct *data = &chain[i];-
622 if (data->empty && data->maximumSize == 0) // truly empty box-
623 data->maximumSize = QWIDGETSIZE_MAX;-
624 data->empty = false;-
625 }-
626}-
627-
628static void distributeMultiBox(QVector<QLayoutStruct> &chain, int start, int end, int minSize,-
629 int sizeHint, QVector<int> &stretchArray, int stretch)-
630{-
631 int i;-
632 int w = 0;-
633 int wh = 0;-
634 int max = 0;-
635-
636 for (i = start; i <= end; i++) {-
637 QLayoutStruct *data = &chain[i];-
638 w += data->minimumSize;-
639 wh += data->sizeHint;-
640 max += data->maximumSize;-
641 if (stretchArray.at(i) == 0)-
642 data->stretch = qMax(data->stretch, stretch);-
643-
644 if (i != end) {-
645 int spacing = data->spacing;-
646 w += spacing;-
647 wh += spacing;-
648 max += spacing;-
649 }-
650 }-
651-
652 if (max < minSize) { // implies w < minSize-
653 /*-
654 We must increase the maximum size of at least one of the-
655 items. qGeomCalc() will put the extra space in between the-
656 items. We must recover that extra space and put it-
657 somewhere. It does not really matter where, since the user-
658 can always specify stretch factors and avoid this code.-
659 */-
660 qGeomCalc(chain, start, end - start + 1, 0, minSize);-
661 int pos = 0;-
662 for (i = start; i <= end; i++) {-
663 QLayoutStruct *data = &chain[i];-
664 int nextPos = (i == end) ? minSize : chain.at(i + 1).pos;-
665 int realSize = nextPos - pos;-
666 if (i != end)-
667 realSize -= data->spacing;-
668 if (data->minimumSize < realSize)-
669 data->minimumSize = realSize;-
670 if (data->maximumSize < data->minimumSize)-
671 data->maximumSize = data->minimumSize;-
672 pos = nextPos;-
673 }-
674 } else if (w < minSize) {-
675 qGeomCalc(chain, start, end - start + 1, 0, minSize);-
676 for (i = start; i <= end; i++) {-
677 QLayoutStruct *data = &chain[i];-
678 if (data->minimumSize < data->size)-
679 data->minimumSize = data->size;-
680 }-
681 }-
682-
683 if (wh < sizeHint) {-
684 qGeomCalc(chain, start, end - start + 1, 0, sizeHint);-
685 for (i = start; i <= end; i++) {-
686 QLayoutStruct *data = &chain[i];-
687 if (data->sizeHint < data->size)-
688 data->sizeHint = data->size;-
689 }-
690 }-
691}-
692-
693static QGridBox *&gridAt(QGridBox *grid[], int r, int c, int cc,-
694 Qt::Orientation orientation = Qt::Vertical)-
695{-
696 if (orientation == Qt::Horizontal)-
697 qSwap(r, c);-
698 return grid[(r * cc) + c];-
699}-
700-
701void QGridLayoutPrivate::setupSpacings(QVector<QLayoutStruct> &chain,-
702 QGridBox *grid[], int fixedSpacing,-
703 Qt::Orientation orientation)-
704{-
705 Q_Q(QGridLayout);-
706 int numRows = rr; // or columns if orientation is horizontal-
707 int numColumns = cc; // or rows if orientation is horizontal-
708-
709 if (orientation == Qt::Horizontal) {-
710 qSwap(numRows, numColumns);-
711 }-
712-
713 QStyle *style = 0;-
714 if (fixedSpacing < 0) {-
715 if (QWidget *parentWidget = q->parentWidget())-
716 style = parentWidget->style();-
717 }-
718-
719 for (int c = 0; c < numColumns; ++c) {-
720 QGridBox *previousBox = 0;-
721 int previousRow = -1; // previous *non-empty* row-
722-
723 for (int r = 0; r < numRows; ++r) {-
724 if (chain.at(r).empty)-
725 continue;-
726-
727 QGridBox *box = gridAt(grid, r, c, cc, orientation);-
728 if (previousRow != -1 && (!box || previousBox != box)) {-
729 int spacing = fixedSpacing;-
730 if (spacing < 0) {-
731 QSizePolicy::ControlTypes controlTypes1 = QSizePolicy::DefaultType;-
732 QSizePolicy::ControlTypes controlTypes2 = QSizePolicy::DefaultType;-
733 if (previousBox)-
734 controlTypes1 = previousBox->item()->controlTypes();-
735 if (box)-
736 controlTypes2 = box->item()->controlTypes();-
737-
738 if ((orientation == Qt::Horizontal && hReversed)-
739 || (orientation == Qt::Vertical && vReversed))-
740 qSwap(controlTypes1, controlTypes2);-
741-
742 if (style)-
743 spacing = style->combinedLayoutSpacing(controlTypes1, controlTypes2,-
744 orientation, 0, q->parentWidget());-
745 } else {-
746 if (orientation == Qt::Vertical) {-
747 QGridBox *sibling = vReversed ? previousBox : box;-
748 if (sibling) {-
749 QWidget *wid = sibling->item()->widget();-
750 if (wid)-
751 spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top() );-
752 }-
753 }-
754 }-
755-
756 if (spacing > chain.at(previousRow).spacing)-
757 chain[previousRow].spacing = spacing;-
758 }-
759-
760 previousBox = box;-
761 previousRow = r;-
762 }-
763 }-
764}-
765-
766//#define QT_LAYOUT_DISABLE_CACHING-
767-
768void QGridLayoutPrivate::setupLayoutData(int hSpacing, int vSpacing)-
769{-
770 Q_Q(QGridLayout);-
771-
772#ifndef QT_LAYOUT_DISABLE_CACHING-
773 if (!needRecalc)-
774 return;-
775#endif-
776 has_hfw = false;-
777 int i;-
778-
779 for (i = 0; i < rr; i++) {-
780 rowData[i].init(rStretch.at(i), rMinHeights.at(i));-
781 rowData[i].maximumSize = rStretch.at(i) ? QLAYOUTSIZE_MAX : rMinHeights.at(i);-
782 }-
783 for (i = 0; i < cc; i++) {-
784 colData[i].init(cStretch.at(i), cMinWidths.at(i));-
785 colData[i].maximumSize = cStretch.at(i) ? QLAYOUTSIZE_MAX : cMinWidths.at(i);-
786 }-
787-
788 int n = things.size();-
789 QVarLengthArray<QGridLayoutSizeTriple> sizes(n);-
790-
791 bool has_multi = false;-
792-
793 /*-
794 Grid of items. We use it to determine which items are-
795 adjacent to which and compute the spacings correctly.-
796 */-
797 QVarLengthArray<QGridBox *> grid(rr * cc);-
798 memset(grid.data(), 0, rr * cc * sizeof(QGridBox *));-
799-
800 /*-
801 Initialize 'sizes' and 'grid' data structures, and insert-
802 non-spanning items to our row and column data structures.-
803 */-
804 for (i = 0; i < n; ++i) {-
805 QGridBox * const box = things.at(i);-
806 sizes[i].minS = box->minimumSize();-
807 sizes[i].hint = box->sizeHint();-
808 sizes[i].maxS = box->maximumSize();-
809-
810 if (box->hasHeightForWidth())-
811 has_hfw = true;-
812-
813 if (box->row == box->toRow(rr)) {-
814 addData(box, sizes[i], true, false);-
815 } else {-
816 initEmptyMultiBox(rowData, box->row, box->toRow(rr));-
817 has_multi = true;-
818 }-
819-
820 if (box->col == box->toCol(cc)) {-
821 addData(box, sizes[i], false, true);-
822 } else {-
823 initEmptyMultiBox(colData, box->col, box->toCol(cc));-
824 has_multi = true;-
825 }-
826-
827 for (int r = box->row; r <= box->toRow(rr); ++r) {-
828 for (int c = box->col; c <= box->toCol(cc); ++c) {-
829 gridAt(grid.data(), r, c, cc) = box;-
830 }-
831 }-
832 }-
833-
834 setupSpacings(colData, grid.data(), hSpacing, Qt::Horizontal);-
835 setupSpacings(rowData, grid.data(), vSpacing, Qt::Vertical);-
836-
837 /*-
838 Insert multicell items to our row and column data structures.-
839 This must be done after the non-spanning items to obtain a-
840 better distribution in distributeMultiBox().-
841 */-
842 if (has_multi) {-
843 for (i = 0; i < n; ++i) {-
844 QGridBox * const box = things.at(i);-
845-
846 if (box->row != box->toRow(rr))-
847 distributeMultiBox(rowData, box->row, box->toRow(rr), sizes[i].minS.height(),-
848 sizes[i].hint.height(), rStretch, box->vStretch());-
849 if (box->col != box->toCol(cc))-
850 distributeMultiBox(colData, box->col, box->toCol(cc), sizes[i].minS.width(),-
851 sizes[i].hint.width(), cStretch, box->hStretch());-
852 }-
853 }-
854-
855 for (i = 0; i < rr; i++)-
856 rowData[i].expansive = rowData.at(i).expansive || rowData.at(i).stretch > 0;-
857 for (i = 0; i < cc; i++)-
858 colData[i].expansive = colData.at(i).expansive || colData.at(i).stretch > 0;-
859-
860 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);-
861-
862 needRecalc = false;-
863}-
864-
865void QGridLayoutPrivate::addHfwData(QGridBox *box, int width)-
866{-
867 QVector<QLayoutStruct> &rData = *hfwData;-
868 if (box->hasHeightForWidth()) {-
869 int hint = box->heightForWidth(width);-
870 rData[box->row].sizeHint = qMax(hint, rData.at(box->row).sizeHint);-
871 rData[box->row].minimumSize = qMax(hint, rData.at(box->row).minimumSize);-
872 } else {-
873 QSize hint = box->sizeHint();-
874 QSize minS = box->minimumSize();-
875 rData[box->row].sizeHint = qMax(hint.height(), rData.at(box->row).sizeHint);-
876 rData[box->row].minimumSize = qMax(minS.height(), rData.at(box->row).minimumSize);-
877 }-
878}-
879-
880/*-
881 Similar to setupLayoutData(), but uses heightForWidth(colData)-
882 instead of sizeHint(). Assumes that setupLayoutData() and-
883 qGeomCalc(colData) has been called.-
884*/-
885void QGridLayoutPrivate::setupHfwLayoutData()-
886{-
887 QVector<QLayoutStruct> &rData = *hfwData;-
888 for (int i = 0; i < rr; i++) {-
889 rData[i] = rowData.at(i);-
890 rData[i].minimumSize = rData[i].sizeHint = rMinHeights.at(i);-
891 }-
892-
893 for (int pass = 0; pass < 2; ++pass) {-
894 for (int i = 0; i < things.size(); ++i) {-
895 QGridBox *box = things.at(i);-
896 int r1 = box->row;-
897 int c1 = box->col;-
898 int r2 = box->toRow(rr);-
899 int c2 = box->toCol(cc);-
900 int w = colData.at(c2).pos + colData.at(c2).size - colData.at(c1).pos;-
901-
902 if (r1 == r2) {-
903 if (pass == 0)-
904 addHfwData(box, w);-
905 } else {-
906 if (pass == 0) {-
907 initEmptyMultiBox(rData, r1, r2);-
908 } else {-
909 QSize hint = box->sizeHint();-
910 QSize min = box->minimumSize();-
911 if (box->hasHeightForWidth()) {-
912 int hfwh = box->heightForWidth(w);-
913 if (hfwh > hint.height())-
914 hint.setHeight(hfwh);-
915 if (hfwh > min.height())-
916 min.setHeight(hfwh);-
917 }-
918 distributeMultiBox(rData, r1, r2, min.height(), hint.height(),-
919 rStretch, box->vStretch());-
920 }-
921 }-
922 }-
923 }-
924 for (int i = 0; i < rr; i++)-
925 rData[i].expansive = rData.at(i).expansive || rData.at(i).stretch > 0;-
926}-
927-
928void QGridLayoutPrivate::distribute(QRect r, int hSpacing, int vSpacing)-
929{-
930 Q_Q(QGridLayout);-
931 bool visualHReversed = hReversed;-
932 QWidget *parent = q->parentWidget();-
933 if (parent && parent->isRightToLeft())-
934 visualHReversed = !visualHReversed;-
935-
936 setupLayoutData(hSpacing, vSpacing);-
937-
938 int left, top, right, bottom;-
939 effectiveMargins(&left, &top, &right, &bottom);-
940 r.adjust(+left, +top, -right, -bottom);-
941-
942 qGeomCalc(colData, 0, cc, r.x(), r.width());-
943 QVector<QLayoutStruct> *rDataPtr;-
944 if (has_hfw) {-
945 recalcHFW(r.width());-
946 qGeomCalc(*hfwData, 0, rr, r.y(), r.height());-
947 rDataPtr = hfwData;-
948 } else {-
949 qGeomCalc(rowData, 0, rr, r.y(), r.height());-
950 rDataPtr = &rowData;-
951 }-
952 QVector<QLayoutStruct> &rData = *rDataPtr;-
953 int i;-
954-
955 bool reverse = ((r.bottom() > rect.bottom()) || (r.bottom() == rect.bottom()-
956 && ((r.right() > rect.right()) != visualHReversed)));-
957 int n = things.size();-
958 for (i = 0; i < n; ++i) {-
959 QGridBox *box = things.at(reverse ? n-i-1 : i);-
960 int r2 = box->toRow(rr);-
961 int c2 = box->toCol(cc);-
962-
963 int x = colData.at(box->col).pos;-
964 int y = rData.at(box->row).pos;-
965 int x2p = colData.at(c2).pos + colData.at(c2).size; // x2+1-
966 int y2p = rData.at(r2).pos + rData.at(r2).size; // y2+1-
967 int w = x2p - x;-
968 int h = y2p - y;-
969-
970 if (visualHReversed)-
971 x = r.left() + r.right() - x - w + 1;-
972 if (vReversed)-
973 y = r.top() + r.bottom() - y - h + 1;-
974-
975 box->setGeometry(QRect(x, y, w, h));-
976 }-
977}-
978-
979QRect QGridLayoutPrivate::cellRect(int row, int col) const-
980{-
981 if (row < 0 || row >= rr || col < 0 || col >= cc)-
982 return QRect();-
983-
984 const QVector<QLayoutStruct> *rDataPtr;-
985 if (has_hfw && hfwData)-
986 rDataPtr = hfwData;-
987 else-
988 rDataPtr = &rowData;-
989 return QRect(colData.at(col).pos, rDataPtr->at(row).pos,-
990 colData.at(col).size, rDataPtr->at(row).size);-
991}-
992-
993/*!-
994 \class QGridLayout-
995-
996 \brief The QGridLayout class lays out widgets in a grid.-
997-
998 \ingroup geomanagement-
999 \inmodule QtWidgets-
1000-
1001 QGridLayout takes the space made available to it (by its parent-
1002 layout or by the parentWidget()), divides it up into rows and-
1003 columns, and puts each widget it manages into the correct cell.-
1004-
1005 Columns and rows behave identically; we will discuss columns, but-
1006 there are equivalent functions for rows.-
1007-
1008 Each column has a minimum width and a stretch factor. The minimum-
1009 width is the greatest of that set using setColumnMinimumWidth() and the-
1010 minimum width of each widget in that column. The stretch factor is-
1011 set using setColumnStretch() and determines how much of the available-
1012 space the column will get over and above its necessary minimum.-
1013-
1014 Normally, each managed widget or layout is put into a cell of its-
1015 own using addWidget(). It is also possible for a widget to occupy-
1016 multiple cells using the row and column spanning overloads of-
1017 addItem() and addWidget(). If you do this, QGridLayout will guess-
1018 how to distribute the size over the columns/rows (based on the-
1019 stretch factors).-
1020-
1021 To remove a widget from a layout, call removeWidget(). Calling-
1022 QWidget::hide() on a widget also effectively removes the widget-
1023 from the layout until QWidget::show() is called.-
1024-
1025 This illustration shows a fragment of a dialog with a five-column,-
1026 three-row grid (the grid is shown overlaid in magenta):-
1027-
1028 \image gridlayout.png A grid layout-
1029-
1030 Columns 0, 2 and 4 in this dialog fragment are made up of a-
1031 QLabel, a QLineEdit, and a QListBox. Columns 1 and 3 are-
1032 placeholders made with setColumnMinimumWidth(). Row 0 consists of three-
1033 QLabel objects, row 1 of three QLineEdit objects and row 2 of-
1034 three QListBox objects. We used placeholder columns (1 and 3) to-
1035 get the right amount of space between the columns.-
1036-
1037 Note that the columns and rows are not equally wide or tall. If-
1038 you want two columns to have the same width, you must set their-
1039 minimum widths and stretch factors to be the same yourself. You do-
1040 this using setColumnMinimumWidth() and setColumnStretch().-
1041-
1042 If the QGridLayout is not the top-level layout (i.e. does not-
1043 manage all of the widget's area and children), you must add it to-
1044 its parent layout when you create it, but before you do anything-
1045 with it. The normal way to add a layout is by calling-
1046 addLayout() on the parent layout.-
1047-
1048 Once you have added your layout you can start putting widgets and-
1049 other layouts into the cells of your grid layout using-
1050 addWidget(), addItem(), and addLayout().-
1051-
1052 QGridLayout also includes two margin widths:-
1053 the \l{getContentsMargins()}{contents margin} and the spacing().-
1054 The contents margin is the width of the reserved space along each-
1055 of the QGridLayout's four sides. The spacing() is the width of the-
1056 automatically allocated spacing between neighboring boxes.-
1057-
1058 The default contents margin values are provided by the-
1059 \l{QStyle::pixelMetric()}{style}. The default value Qt styles specify-
1060 is 9 for child widgets and 11 for windows. The spacing defaults to the same as-
1061 the margin width for a top-level layout, or to the same as the-
1062 parent layout.-
1063-
1064 \sa QBoxLayout, QStackedLayout, {Layout Management}, {Basic Layouts Example}-
1065*/-
1066-
1067-
1068/*!-
1069 Constructs a new QGridLayout with parent widget, \a parent. The-
1070 layout has one row and one column initially, and will expand when-
1071 new items are inserted.-
1072*/-
1073QGridLayout::QGridLayout(QWidget *parent)-
1074 : QLayout(*new QGridLayoutPrivate, 0, parent)-
1075{-
1076 Q_D(QGridLayout);-
1077 d->expand(1, 1);-
1078}-
1079-
1080/*!-
1081 Constructs a new grid layout.-
1082-
1083 You must insert this grid into another layout. You can insert-
1084 widgets and layouts into this layout at any time, but laying out-
1085 will not be performed before this is inserted into another layout.-
1086*/-
1087QGridLayout::QGridLayout()-
1088 : QLayout(*new QGridLayoutPrivate, 0, 0)-
1089{-
1090 Q_D(QGridLayout);-
1091 d->expand(1, 1);-
1092}-
1093-
1094-
1095-
1096-
1097/*!-
1098\internal (mostly)-
1099-
1100Sets the positioning mode used by addItem(). If \a orient is-
1101Qt::Horizontal, this layout is expanded to \a n columns, and items-
1102will be added columns-first. Otherwise it is expanded to \a n rows and-
1103items will be added rows-first.-
1104*/-
1105-
1106void QGridLayout::setDefaultPositioning(int n, Qt::Orientation orient)-
1107{-
1108 Q_D(QGridLayout);-
1109 if (orient == Qt::Horizontal) {-
1110 d->expand(1, n);-
1111 d->addVertical = false;-
1112 } else {-
1113 d->expand(n,1);-
1114 d->addVertical = true;-
1115 }-
1116}-
1117-
1118-
1119/*!-
1120 Destroys the grid layout. Geometry management is terminated if-
1121 this is a top-level grid.-
1122-
1123 The layout's widgets aren't destroyed.-
1124*/-
1125QGridLayout::~QGridLayout()-
1126{-
1127 Q_D(QGridLayout);-
1128 d->deleteAll();-
1129}-
1130-
1131/*!-
1132 \property QGridLayout::horizontalSpacing-
1133 \brief the spacing between widgets that are laid out side by side-
1134 \since 4.3-
1135-
1136 If no value is explicitly set, the layout's horizontal spacing is-
1137 inherited from the parent layout, or from the style settings for-
1138 the parent widget.-
1139-
1140 \sa verticalSpacing, QStyle::pixelMetric(), {QStyle::}{PM_LayoutHorizontalSpacing}-
1141*/-
1142void QGridLayout::setHorizontalSpacing(int spacing)-
1143{-
1144 Q_D(QGridLayout);-
1145 d->horizontalSpacing = spacing;-
1146 invalidate();-
1147}-
1148-
1149int QGridLayout::horizontalSpacing() const-
1150{-
1151 Q_D(const QGridLayout);-
1152 if (d->horizontalSpacing >= 0) {-
1153 return d->horizontalSpacing;-
1154 } else {-
1155 return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);-
1156 }-
1157}-
1158-
1159/*!-
1160 \property QGridLayout::verticalSpacing-
1161 \brief the spacing between widgets that are laid out on top of each other-
1162 \since 4.3-
1163-
1164 If no value is explicitly set, the layout's vertical spacing is-
1165 inherited from the parent layout, or from the style settings for-
1166 the parent widget.-
1167-
1168 \sa horizontalSpacing, QStyle::pixelMetric(), {QStyle::}{PM_LayoutHorizontalSpacing}-
1169*/-
1170void QGridLayout::setVerticalSpacing(int spacing)-
1171{-
1172 Q_D(QGridLayout);-
1173 d->verticalSpacing = spacing;-
1174 invalidate();-
1175}-
1176-
1177int QGridLayout::verticalSpacing() const-
1178{-
1179 Q_D(const QGridLayout);-
1180 if (d->verticalSpacing >= 0) {-
1181 return d->verticalSpacing;-
1182 } else {-
1183 return qSmartSpacing(this, QStyle::PM_LayoutVerticalSpacing);-
1184 }-
1185}-
1186-
1187/*!-
1188 This function sets both the vertical and horizontal spacing to-
1189 \a spacing.-
1190-
1191 \sa setVerticalSpacing(), setHorizontalSpacing()-
1192*/-
1193void QGridLayout::setSpacing(int spacing)-
1194{-
1195 Q_D(QGridLayout);-
1196 d->horizontalSpacing = d->verticalSpacing = spacing;-
1197 invalidate();-
1198}-
1199-
1200/*!-
1201 If the vertical spacing is equal to the horizontal spacing,-
1202 this function returns that value; otherwise it return -1.-
1203-
1204 \sa setSpacing(), verticalSpacing(), horizontalSpacing()-
1205*/-
1206int QGridLayout::spacing() const-
1207{-
1208 int hSpacing = horizontalSpacing();-
1209 if (hSpacing == verticalSpacing()) {-
1210 return hSpacing;-
1211 } else {-
1212 return -1;-
1213 }-
1214}-
1215-
1216/*!-
1217 Returns the number of rows in this grid.-
1218*/-
1219int QGridLayout::rowCount() const-
1220{-
1221 Q_D(const QGridLayout);-
1222 return d->numRows();-
1223}-
1224-
1225/*!-
1226 Returns the number of columns in this grid.-
1227*/-
1228int QGridLayout::columnCount() const-
1229{-
1230 Q_D(const QGridLayout);-
1231 return d->numCols();-
1232}-
1233-
1234/*!-
1235 \reimp-
1236*/-
1237QSize QGridLayout::sizeHint() const-
1238{-
1239 Q_D(const QGridLayout);-
1240 QSize result(d->sizeHint(horizontalSpacing(), verticalSpacing()));-
1241 int left, top, right, bottom;-
1242 d->effectiveMargins(&left, &top, &right, &bottom);-
1243 result += QSize(left + right, top + bottom);-
1244 return result;-
1245}-
1246-
1247/*!-
1248 \reimp-
1249*/-
1250QSize QGridLayout::minimumSize() const-
1251{-
1252 Q_D(const QGridLayout);-
1253 QSize result(d->minimumSize(horizontalSpacing(), verticalSpacing()));-
1254 int left, top, right, bottom;-
1255 d->effectiveMargins(&left, &top, &right, &bottom);-
1256 result += QSize(left + right, top + bottom);-
1257 return result;-
1258}-
1259-
1260/*!-
1261 \reimp-
1262*/-
1263QSize QGridLayout::maximumSize() const-
1264{-
1265 Q_D(const QGridLayout);-
1266-
1267 QSize s = d->maximumSize(horizontalSpacing(), verticalSpacing());-
1268 int left, top, right, bottom;-
1269 d->effectiveMargins(&left, &top, &right, &bottom);-
1270 s += QSize(left + right, top + bottom);-
1271 s = s.boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX));-
1272 if (alignment() & Qt::AlignHorizontal_Mask)-
1273 s.setWidth(QLAYOUTSIZE_MAX);-
1274 if (alignment() & Qt::AlignVertical_Mask)-
1275 s.setHeight(QLAYOUTSIZE_MAX);-
1276 return s;-
1277}-
1278-
1279/*!-
1280 \reimp-
1281*/-
1282bool QGridLayout::hasHeightForWidth() const-
1283{-
1284 return const_cast<QGridLayout*>(this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing());-
1285}-
1286-
1287/*!-
1288 \reimp-
1289*/-
1290int QGridLayout::heightForWidth(int w) const-
1291{-
1292 Q_D(const QGridLayout);-
1293 QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);-
1294 return dat->heightForWidth(w, horizontalSpacing(), verticalSpacing());-
1295}-
1296-
1297/*!-
1298 \reimp-
1299*/-
1300int QGridLayout::minimumHeightForWidth(int w) const-
1301{-
1302 Q_D(const QGridLayout);-
1303 QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);-
1304 return dat->minimumHeightForWidth(w, horizontalSpacing(), verticalSpacing());-
1305}-
1306-
1307/*!-
1308 \reimp-
1309*/-
1310int QGridLayout::count() const-
1311{-
1312 Q_D(const QGridLayout);-
1313 return d->count();-
1314}-
1315-
1316-
1317/*!-
1318 \reimp-
1319*/-
1320QLayoutItem *QGridLayout::itemAt(int index) const-
1321{-
1322 Q_D(const QGridLayout);-
1323 return d->itemAt(index);-
1324}-
1325-
1326/*!-
1327 \since 4.4-
1328-
1329 Returns the layout item that occupies cell (\a row, \a column), or 0 if-
1330 the cell is empty.-
1331-
1332 \sa getItemPosition(), indexOf()-
1333*/-
1334QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const-
1335{-
1336 Q_D(const QGridLayout);-
1337 int n = d->things.count();-
1338 for (int i = 0; i < n; ++i) {-
1339 QGridBox *box = d->things.at(i);-
1340 if (row >= box->row && row <= box->toRow(d->rr)-
1341 && column >= box->col && column <= box->toCol(d->cc)) {-
1342 return box->item();-
1343 }-
1344 }-
1345 return 0;-
1346}-
1347-
1348/*!-
1349 \reimp-
1350*/-
1351QLayoutItem *QGridLayout::takeAt(int index)-
1352{-
1353 Q_D(QGridLayout);-
1354 return d->takeAt(index);-
1355}-
1356-
1357/*!-
1358 Returns the position information of the item with the given \a index.-
1359-
1360 The variables passed as \a row and \a column are updated with the position of the-
1361 item in the layout, and the \a rowSpan and \a columnSpan variables are updated-
1362 with the vertical and horizontal spans of the item.-
1363-
1364 \sa itemAtPosition(), itemAt()-
1365*/-
1366void QGridLayout::getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const-
1367{-
1368 Q_D(const QGridLayout);-
1369 d->getItemPosition(index, row, column, rowSpan, columnSpan);-
1370}-
1371-
1372-
1373/*!-
1374 \reimp-
1375*/-
1376void QGridLayout::setGeometry(const QRect &rect)-
1377{-
1378 Q_D(QGridLayout);-
1379 if (d->isDirty() || rect != geometry()) {-
1380 QRect cr = alignment() ? alignmentRect(rect) : rect;-
1381 d->distribute(cr, horizontalSpacing(), verticalSpacing());-
1382 QLayout::setGeometry(rect);-
1383 }-
1384}-
1385-
1386/*!-
1387 Returns the geometry of the cell with row \a row and column \a column-
1388 in the grid. Returns an invalid rectangle if \a row or \a column is-
1389 outside the grid.-
1390-
1391 \warning in the current version of Qt this function does not-
1392 return valid results until setGeometry() has been called, i.e.-
1393 after the parentWidget() is visible.-
1394*/-
1395QRect QGridLayout::cellRect(int row, int column) const-
1396{-
1397 Q_D(const QGridLayout);-
1398 return d->cellRect(row, column);-
1399}-
1400-
1401/*!-
1402 \reimp-
1403*/-
1404void QGridLayout::addItem(QLayoutItem *item)-
1405{-
1406 Q_D(QGridLayout);-
1407 int r, c;-
1408 d->getNextPos(r, c);-
1409 addItem(item, r, c);-
1410}-
1411-
1412/*!-
1413 Adds \a item at position \a row, \a column, spanning \a rowSpan-
1414 rows and \a columnSpan columns, and aligns it according to \a-
1415 alignment. If \a rowSpan and/or \a columnSpan is -1, then the item-
1416 will extend to the bottom and/or right edge, respectively. The-
1417 layout takes ownership of the \a item.-
1418-
1419 \warning Do not use this function to add child layouts or child-
1420 widget items. Use addLayout() or addWidget() instead.-
1421*/-
1422void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment)-
1423{-
1424 Q_D(QGridLayout);-
1425 QGridBox *b = new QGridBox(item);-
1426 b->setAlignment(alignment);-
1427 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);-
1428 invalidate();-
1429}-
1430-
1431/*!-
1432 Adds the given \a widget to the cell grid at \a row, \a column. The-
1433 top-left position is (0, 0) by default.-
1434-
1435 The alignment is specified by \a alignment. The default-
1436 alignment is 0, which means that the widget fills the entire cell.-
1437-
1438*/-
1439void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)-
1440{-
1441 Q_D(QGridLayout);-
1442 if (!d->checkWidget(widget))
!d->checkWidget(widget)Description
TRUEnever evaluated
FALSEnever evaluated
0
1443 return;
never executed: return;
0
1444 if (Q_UNLIKELY(row < 0 || column < 0))) {
__builtin_expe...n < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1445 qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",-
1446 widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(),-
1447 metaObject()->className(), objectName().toLocal8Bit().data(), row, column);-
1448 return;
never executed: return;
0
1449 }-
1450 addChildWidget(widget);-
1451 QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget);-
1452 addItem(b, row, column, 1, 1, alignment);-
1453}
never executed: end of block
0
1454-
1455/*!-
1456 \overload-
1457-
1458 This version adds the given \a widget to the cell grid, spanning-
1459 multiple rows/columns. The cell will start at \a fromRow, \a-
1460 fromColumn spanning \a rowSpan rows and \a columnSpan columns. The-
1461 \a widget will have the given \a alignment.-
1462-
1463 If \a rowSpan and/or \a columnSpan is -1, then the widget will-
1464 extend to the bottom and/or right edge, respectively.-
1465-
1466*/-
1467void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn,-
1468 int rowSpan, int columnSpan, Qt::Alignment alignment)-
1469{-
1470 Q_D(QGridLayout);-
1471 if (!d->checkWidget(widget))-
1472 return;-
1473 int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;-
1474 int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;-
1475 addChildWidget(widget);-
1476 QGridBox *b = new QGridBox(this, widget);-
1477 b->setAlignment(alignment);-
1478 d->add(b, fromRow, toRow, fromColumn, toColumn);-
1479 invalidate();-
1480}-
1481-
1482/*!-
1483 \fn void QGridLayout::addWidget(QWidget *widget)-
1484-
1485 \overload-
1486 \internal-
1487*/-
1488-
1489/*!-
1490 Places the \a layout at position (\a row, \a column) in the grid. The-
1491 top-left position is (0, 0).-
1492-
1493 The alignment is specified by \a alignment. The default-
1494 alignment is 0, which means that the widget fills the entire cell.-
1495-
1496 A non-zero alignment indicates that the layout should not grow to-
1497 fill the available space but should be sized according to-
1498 sizeHint().-
1499-
1500-
1501 \a layout becomes a child of the grid layout.-
1502*/-
1503void QGridLayout::addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment)-
1504{-
1505 Q_D(QGridLayout);-
1506 if (!d->checkLayout(layout))-
1507 return;-
1508 if (!adoptLayout(layout))-
1509 return;-
1510 QGridBox *b = new QGridBox(layout);-
1511 b->setAlignment(alignment);-
1512 d->add(b, row, column);-
1513}-
1514-
1515/*!-
1516 \overload-
1517 This version adds the layout \a layout to the cell grid, spanning multiple-
1518 rows/columns. The cell will start at \a row, \a column spanning \a-
1519 rowSpan rows and \a columnSpan columns.-
1520-
1521 If \a rowSpan and/or \a columnSpan is -1, then the layout will extend to the bottom-
1522 and/or right edge, respectively.-
1523*/-
1524void QGridLayout::addLayout(QLayout *layout, int row, int column,-
1525 int rowSpan, int columnSpan, Qt::Alignment alignment)-
1526{-
1527 Q_D(QGridLayout);-
1528 if (!d->checkLayout(layout))-
1529 return;-
1530 if (!adoptLayout(layout))-
1531 return;-
1532 QGridBox *b = new QGridBox(layout);-
1533 b->setAlignment(alignment);-
1534 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);-
1535}-
1536-
1537/*!-
1538 Sets the stretch factor of row \a row to \a stretch. The first row-
1539 is number 0.-
1540-
1541 The stretch factor is relative to the other rows in this grid.-
1542 Rows with a higher stretch factor take more of the available-
1543 space.-
1544-
1545 The default stretch factor is 0. If the stretch factor is 0 and no-
1546 other row in this table can grow at all, the row may still grow.-
1547-
1548 \sa rowStretch(), setRowMinimumHeight(), setColumnStretch()-
1549*/-
1550void QGridLayout::setRowStretch(int row, int stretch)-
1551{-
1552 Q_D(QGridLayout);-
1553 d->setRowStretch(row, stretch);-
1554 invalidate();-
1555}-
1556-
1557/*!-
1558 Returns the stretch factor for row \a row.-
1559-
1560 \sa setRowStretch()-
1561*/-
1562int QGridLayout::rowStretch(int row) const-
1563{-
1564 Q_D(const QGridLayout);-
1565 return d->rowStretch(row);-
1566}-
1567-
1568/*!-
1569 Returns the stretch factor for column \a column.-
1570-
1571 \sa setColumnStretch()-
1572*/-
1573int QGridLayout::columnStretch(int column) const-
1574{-
1575 Q_D(const QGridLayout);-
1576 return d->colStretch(column);-
1577}-
1578-
1579/*!-
1580 Sets the stretch factor of column \a column to \a stretch. The first-
1581 column is number 0.-
1582-
1583 The stretch factor is relative to the other columns in this grid.-
1584 Columns with a higher stretch factor take more of the available-
1585 space.-
1586-
1587 The default stretch factor is 0. If the stretch factor is 0 and no-
1588 other column in this table can grow at all, the column may still-
1589 grow.-
1590-
1591 An alternative approach is to add spacing using addItem() with a-
1592 QSpacerItem.-
1593-
1594 \sa columnStretch(), setRowStretch()-
1595*/-
1596void QGridLayout::setColumnStretch(int column, int stretch)-
1597{-
1598 Q_D(QGridLayout);-
1599 d->setColStretch(column, stretch);-
1600 invalidate();-
1601}-
1602-
1603-
1604-
1605/*!-
1606 Sets the minimum height of row \a row to \a minSize pixels.-
1607-
1608 \sa rowMinimumHeight(), setColumnMinimumWidth()-
1609*/-
1610void QGridLayout::setRowMinimumHeight(int row, int minSize)-
1611{-
1612 Q_D(QGridLayout);-
1613 d->setRowMinimumHeight(row, minSize);-
1614 invalidate();-
1615}-
1616-
1617/*!-
1618 Returns the minimum width set for row \a row.-
1619-
1620 \sa setRowMinimumHeight()-
1621*/-
1622int QGridLayout::rowMinimumHeight(int row) const-
1623{-
1624 Q_D(const QGridLayout);-
1625 return d->rowSpacing(row);-
1626}-
1627-
1628/*!-
1629 Sets the minimum width of column \a column to \a minSize pixels.-
1630-
1631 \sa columnMinimumWidth(), setRowMinimumHeight()-
1632*/-
1633void QGridLayout::setColumnMinimumWidth(int column, int minSize)-
1634{-
1635 Q_D(QGridLayout);-
1636 d->setColumnMinimumWidth(column, minSize);-
1637 invalidate();-
1638}-
1639-
1640/*!-
1641 Returns the column spacing for column \a column.-
1642-
1643 \sa setColumnMinimumWidth()-
1644*/-
1645int QGridLayout::columnMinimumWidth(int column) const-
1646{-
1647 Q_D(const QGridLayout);-
1648 return d->colSpacing(column);-
1649}-
1650-
1651/*!-
1652 \reimp-
1653*/-
1654Qt::Orientations QGridLayout::expandingDirections() const-
1655{-
1656 Q_D(const QGridLayout);-
1657 return d->expandingDirections(horizontalSpacing(), verticalSpacing());-
1658}-
1659-
1660/*!-
1661 Sets the grid's origin corner, i.e. position (0, 0), to \a corner.-
1662*/-
1663void QGridLayout::setOriginCorner(Qt::Corner corner)-
1664{-
1665 Q_D(QGridLayout);-
1666 d->setReversed(corner == Qt::BottomLeftCorner || corner == Qt::BottomRightCorner,-
1667 corner == Qt::TopRightCorner || corner == Qt::BottomRightCorner);-
1668}-
1669-
1670/*!-
1671 Returns the corner that's used for the grid's origin, i.e. for-
1672 position (0, 0).-
1673*/-
1674Qt::Corner QGridLayout::originCorner() const-
1675{-
1676 Q_D(const QGridLayout);-
1677 if (d->horReversed()) {-
1678 return d->verReversed() ? Qt::BottomRightCorner : Qt::TopRightCorner;-
1679 } else {-
1680 return d->verReversed() ? Qt::BottomLeftCorner : Qt::TopLeftCorner;-
1681 }-
1682}-
1683-
1684/*!-
1685 \reimp-
1686*/-
1687void QGridLayout::invalidate()-
1688{-
1689 Q_D(QGridLayout);-
1690 d->setDirty();-
1691 QLayout::invalidate();-
1692}-
1693-
1694QT_END_NAMESPACE-
1695-
1696#include "moc_qgridlayout.cpp"-
Source codeSwitch to Preprocessed file

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