OpenCoverage

qformlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qformlayout.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 "qapplication.h"-
41#include "qdebug.h"-
42#include "qformlayout.h"-
43#include "qlabel.h"-
44#include "qlayout_p.h"-
45#include "qlayoutengine_p.h"-
46#include "qrect.h"-
47#include "qvector.h"-
48#include "qwidget.h"-
49-
50QT_BEGIN_NAMESPACE-
51-
52namespace {-
53// Fixed column matrix, stores items as [i11, i12, i21, i22...],-
54// with FORTRAN-style index operator(r, c).-
55template <class T, int NumColumns>-
56class FixedColumnMatrix {-
57public:-
58 typedef QVector<T> Storage;-
59-
60 FixedColumnMatrix() { }-
61-
62 void clear() { m_storage.clear(); }
never executed: end of block
0
63-
64 const T &operator()(int r, int c) const { return m_storage[r * NumColumns + c]; }
never executed: return m_storage[r * NumColumns + c];
0
65 T &operator()(int r, int c) { return m_storage[r * NumColumns + c]; }
never executed: return m_storage[r * NumColumns + c];
0
66-
67 int rowCount() const { return m_storage.size() / NumColumns; }
never executed: return m_storage.size() / NumColumns;
0
68 void insertRow(int r, const T &value);-
69-
70 // Hmmpf.. Some things are faster that way.-
71 const Storage &storage() const { return m_storage; }
never executed: return m_storage;
0
72-
73 static void storageIndexToPosition(int idx, int *rowPtr, int *colPtr);-
74-
75private:-
76 Storage m_storage;-
77};-
78-
79template <class T, int NumColumns>-
80void FixedColumnMatrix<T, NumColumns>::insertRow(int r, const T &value)-
81{-
82 typename Storage::iterator it = m_storage.begin();-
83 it += r * NumColumns;-
84 m_storage.insert(it, NumColumns, value);-
85}
never executed: end of block
0
86-
87template <class T, int NumColumns>-
88void FixedColumnMatrix<T, NumColumns>::storageIndexToPosition(int idx, int *rowPtr, int *colPtr)-
89{-
90 *rowPtr = idx / NumColumns;-
91 *colPtr = idx % NumColumns;-
92}
never executed: end of block
0
93} // namespace-
94-
95// special values for unset fields; must not clash with values of FieldGrowthPolicy or-
96// RowWrapPolicy-
97const uint DefaultFieldGrowthPolicy = 255;-
98const uint DefaultRowWrapPolicy = 255;-
99-
100enum { ColumnCount = 2 };-
101-
102// -- our data structure for our items-
103// This owns the QLayoutItem-
104struct QFormLayoutItem-
105{-
106 QFormLayoutItem(QLayoutItem* i) : item(i), fullRow(false), isHfw(false) { }
never executed: end of block
0
107 ~QFormLayoutItem() { delete item; }
never executed: end of block
0
108-
109 // Wrappers-
110 QWidget *widget() const { return item->widget(); }
never executed: return item->widget();
0
111 QLayout *layout() const { return item->layout(); }
never executed: return item->layout();
0
112-
113 bool hasHeightForWidth() const { return item->hasHeightForWidth(); }
never executed: return item->hasHeightForWidth();
0
114 int heightForWidth(int width) const { return item->heightForWidth(width); }
never executed: return item->heightForWidth(width);
0
115 int minimumHeightForWidth(int width) const { return item->minimumHeightForWidth(width); }
never executed: return item->minimumHeightForWidth(width);
0
116 Qt::Orientations expandingDirections() const { return item->expandingDirections(); }
never executed: return item->expandingDirections();
0
117 QSizePolicy::ControlTypes controlTypes() const { return item->controlTypes(); }
never executed: return item->controlTypes();
0
118 int vStretch() const { return widget() ? widget()->sizePolicy().verticalStretch() : 0; }
never executed: return widget() ? widget()->sizePolicy().verticalStretch() : 0;
0
119-
120 void setGeometry(const QRect& r) { item->setGeometry(r); }
never executed: end of block
0
121 QRect geometry() const { return item->geometry(); }
never executed: return item->geometry();
0
122-
123 // For use with FixedColumnMatrix-
124 bool operator==(const QFormLayoutItem& other) { return item == other.item; }
never executed: return item == other.item;
0
125-
126 QLayoutItem *item;-
127 bool fullRow;-
128-
129 // set by updateSizes-
130 bool isHfw;-
131 QSize minSize;-
132 QSize sizeHint;-
133 QSize maxSize;-
134-
135 // also set by updateSizes-
136 int sbsHSpace; // only used for side by side, for the field item only (not label)-
137 int vSpace; // This is the spacing to the item in the row above-
138-
139 // set by setupVerticalLayoutData-
140 bool sideBySide;-
141 int vLayoutIndex;-
142-
143 // set by setupHorizontalLayoutData-
144 int layoutPos;-
145 int layoutWidth;-
146};-
147-
148class QFormLayoutPrivate : public QLayoutPrivate-
149{-
150 Q_DECLARE_PUBLIC(QFormLayout)-
151-
152public:-
153 typedef FixedColumnMatrix<QFormLayoutItem *, ColumnCount> ItemMatrix;-
154-
155 QFormLayoutPrivate();-
156 ~QFormLayoutPrivate() { }-
157-
158 int insertRow(int row);-
159 void insertRows(int row, int count);-
160 bool setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item);-
161 void setLayout(int row, QFormLayout::ItemRole role, QLayout *layout);-
162 void setWidget(int row, QFormLayout::ItemRole role, QWidget *widget);-
163-
164 void arrangeWidgets(const QVector<QLayoutStruct>& layouts, QRect &rect);-
165-
166 void updateSizes();-
167-
168 void setupVerticalLayoutData(int width);-
169 void setupHorizontalLayoutData(int width);-
170-
171 QStyle* getStyle() const;-
172-
173 inline bool haveHfwCached(int width) const-
174 {-
175 return (hfw_width == width) || (width == sh_width && hfw_sh_height >= 0);
never executed: return (hfw_width == width) || (width == sh_width && hfw_sh_height >= 0);
0
176 }-
177-
178 void recalcHFW(int w);-
179 void setupHfwLayoutData();-
180-
181 uint fieldGrowthPolicy : 8;-
182 uint rowWrapPolicy : 8;-
183 uint has_hfw : 2;-
184 uint dirty : 2; // have we laid out yet?-
185 uint sizesDirty : 2; // have we (not) gathered layout item sizes?-
186 uint expandVertical : 1; // Do we expand vertically?-
187 uint expandHorizontal : 1; // Do we expand horizonally?-
188 Qt::Alignment labelAlignment;-
189 Qt::Alignment formAlignment;-
190-
191 ItemMatrix m_matrix;-
192 QList<QFormLayoutItem *> m_things;-
193-
194 int layoutWidth; // the last width that we called setupVerticalLayoutData on (for vLayouts)-
195-
196 int hfw_width; // the last width we calculated HFW for-
197 int hfw_height; // what that height was-
198 int hfw_minheight; // what that minheight was-
199-
200 int hfw_sh_height; // the hfw for sh_width-
201 int hfw_sh_minheight; // the minhfw for sh_width-
202-
203 int min_width; // the width that gets turned into minSize (from updateSizes)-
204 int sh_width; // the width that gets turned into prefSize (from updateSizes)-
205 int thresh_width; // the width that we start splitting label/field pairs at (from updateSizes)-
206 QSize minSize;-
207 QSize prefSize;-
208 int formMaxWidth;-
209 void calcSizeHints();-
210-
211 QVector<QLayoutStruct> vLayouts; // set by setupVerticalLayoutData;-
212 int vLayoutCount; // Number of rows we calculated in setupVerticalLayoutData-
213 int maxLabelWidth; // the label width we calculated in setupVerticalLayoutData-
214-
215 QVector<QLayoutStruct> hfwLayouts;-
216-
217 int hSpacing;-
218 int vSpacing;-
219 QLayoutItem* replaceAt(int index, QLayoutItem*) Q_DECL_OVERRIDE;-
220};-
221-
222QFormLayoutPrivate::QFormLayoutPrivate()-
223 : fieldGrowthPolicy(DefaultFieldGrowthPolicy),-
224 rowWrapPolicy(DefaultRowWrapPolicy), has_hfw(false), dirty(true), sizesDirty(true),-
225 expandVertical(0), expandHorizontal(0), labelAlignment(0), formAlignment(0),-
226 layoutWidth(-1), hfw_width(-1), hfw_sh_height(-1), min_width(-1),-
227 sh_width(-1), thresh_width(QLAYOUTSIZE_MAX), hSpacing(-1), vSpacing(-1)-
228{-
229}
never executed: end of block
0
230-
231static Qt::Alignment fixedAlignment(Qt::Alignment alignment, Qt::LayoutDirection layoutDirection)-
232{-
233 if (layoutDirection == Qt::RightToLeft && alignment & Qt::AlignAbsolute) {
layoutDirectio...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
alignment & Qt::AlignAbsoluteDescription
TRUEnever evaluated
FALSEnever evaluated
0
234 // swap left and right, and eliminate absolute flag-
235 return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute))
never executed: return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute)) | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0) | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0));
0
236 | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0)
never executed: return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute)) | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0) | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0));
0
237 | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0));
never executed: return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute)) | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0) | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0));
0
238 } else {-
239 return alignment & ~Qt::AlignAbsolute;
never executed: return alignment & ~Qt::AlignAbsolute;
0
240 }-
241}-
242-
243static int storageIndexFromLayoutItem(const QFormLayoutPrivate::ItemMatrix &m,-
244 QFormLayoutItem *item)-
245{-
246 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
247 return m.storage().indexOf(item);
never executed: return m.storage().indexOf(item);
0
248 } else {-
249 return -1;
never executed: return -1;
0
250 }-
251}-
252-
253static void updateFormLayoutItem(QFormLayoutItem *item, int userVSpacing,-
254 QFormLayout::FieldGrowthPolicy fieldGrowthPolicy,-
255 bool fullRow)-
256{-
257 item->minSize = item->item->minimumSize();-
258 item->sizeHint = item->item->sizeHint();-
259 item->maxSize = item->item->maximumSize();-
260-
261 if (!fullRow && (fieldGrowthPolicy == QFormLayout::FieldsStayAtSizeHint
!fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
fieldGrowthPol...StayAtSizeHintDescription
TRUEnever evaluated
FALSEnever evaluated
0
262 || (fieldGrowthPolicy == QFormLayout::ExpandingFieldsGrow
fieldGrowthPol...dingFieldsGrowDescription
TRUEnever evaluated
FALSEnever evaluated
0
263 && !(item->item->expandingDirections() & Qt::Horizontal))))
!(item->item->...t::Horizontal)Description
TRUEnever evaluated
FALSEnever evaluated
0
264 item->maxSize.setWidth(item->sizeHint.width());
never executed: item->maxSize.setWidth(item->sizeHint.width());
0
265-
266 item->isHfw = item->item->hasHeightForWidth();-
267 item->vSpace = userVSpacing;-
268}
never executed: end of block
0
269-
270/*-
271 Iterate over all the controls and gather their size information-
272 (min, sizeHint and max). Also work out what the spacing between-
273 pairs of controls should be, and figure out the min and sizeHint-
274 widths.-
275*/-
276void QFormLayoutPrivate::updateSizes()-
277{-
278 Q_Q(QFormLayout);-
279-
280 if (sizesDirty) {
sizesDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
281 QFormLayout::RowWrapPolicy wrapPolicy = q->rowWrapPolicy();-
282 bool wrapAllRows = (wrapPolicy == QFormLayout::WrapAllRows);-
283 bool dontWrapRows = (wrapPolicy == QFormLayout::DontWrapRows);-
284 int rr = m_matrix.rowCount();-
285-
286 has_hfw = false;-
287-
288 // If any control can expand, so can this layout-
289 // Wrapping doesn't affect expansion, though, just the minsize-
290 bool expandH = false;-
291 bool expandV = false;-
292-
293 QFormLayoutItem *prevLbl = 0;-
294 QFormLayoutItem *prevFld = 0;-
295-
296 QWidget *parent = q->parentWidget();-
297 QStyle *style = parent ? parent->style() : 0;
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
298-
299 int userVSpacing = q->verticalSpacing();-
300 int userHSpacing = wrapAllRows ? 0 : q->horizontalSpacing();
wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
301-
302 int maxMinLblWidth = 0;-
303 int maxMinFldWidth = 0; // field with label-
304 int maxMinIfldWidth = 0; // independent field-
305-
306 int maxShLblWidth = 0;-
307 int maxShFldWidth = 0;-
308 int maxShIfldWidth = 0;-
309-
310 for (int i = 0; i < rr; ++i) {
i < rrDescription
TRUEnever evaluated
FALSEnever evaluated
0
311 QFormLayoutItem *label = m_matrix(i, 0);-
312 QFormLayoutItem *field = m_matrix(i, 1);-
313-
314 // Skip empty rows-
315 if (!label && !field)
!labelDescription
TRUEnever evaluated
FALSEnever evaluated
!fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
316 continue;
never executed: continue;
0
317-
318 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
319 updateFormLayoutItem(label, userVSpacing, q->fieldGrowthPolicy(), false);-
320 if (label->isHfw)
label->isHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
321 has_hfw = true;
never executed: has_hfw = true;
0
322 Qt::Orientations o = label->expandingDirections();-
323-
324 if (o & Qt::Vertical)
o & Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
325 expandV = true;
never executed: expandV = true;
0
326 if (o & Qt::Horizontal)
o & Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
327 expandH = true;
never executed: expandH = true;
0
328 }
never executed: end of block
0
329 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
330 updateFormLayoutItem(field, userVSpacing, q->fieldGrowthPolicy(), !label && field->fullRow);-
331 field->sbsHSpace = (!label && field->fullRow) ? 0 : userHSpacing;
!labelDescription
TRUEnever evaluated
FALSEnever evaluated
field->fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
332 if (field->isHfw)
field->isHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
333 has_hfw = true;
never executed: has_hfw = true;
0
334-
335 Qt::Orientations o = field->expandingDirections();-
336-
337 if (o & Qt::Vertical)
o & Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
338 expandV = true;
never executed: expandV = true;
0
339 if (o & Qt::Horizontal)
o & Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
340 expandH = true;
never executed: expandH = true;
0
341 }
never executed: end of block
0
342-
343 // See if we need to calculate default spacings-
344 if ((userHSpacing < 0 || userVSpacing < 0) && style) {
userHSpacing < 0Description
TRUEnever evaluated
FALSEnever evaluated
userVSpacing < 0Description
TRUEnever evaluated
FALSEnever evaluated
styleDescription
TRUEnever evaluated
FALSEnever evaluated
0
345 QSizePolicy::ControlTypes lbltypes =-
346 QSizePolicy::ControlTypes(label ? label->controlTypes() : QSizePolicy::DefaultType);-
347 QSizePolicy::ControlTypes fldtypes =-
348 QSizePolicy::ControlTypes(field ? field->controlTypes() : QSizePolicy::DefaultType);-
349-
350 // VSpacing-
351 if (userVSpacing < 0) {
userVSpacing < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
352 if (wrapAllRows) {
wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
353 // label spacing is to a previous item-
354 QFormLayoutItem *lbltop = prevFld ? prevFld : prevLbl;
prevFldDescription
TRUEnever evaluated
FALSEnever evaluated
0
355 // field spacing is to the label (or a previous item)-
356 QFormLayoutItem *fldtop = label ? label : lbltop;
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
357 QSizePolicy::ControlTypes lbltoptypes =-
358 QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType);-
359 QSizePolicy::ControlTypes fldtoptypes =-
360 QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType);-
361 if (label && lbltop)
labelDescription
TRUEnever evaluated
FALSEnever evaluated
lbltopDescription
TRUEnever evaluated
FALSEnever evaluated
0
362 label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
never executed: label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
0
363 if (field && fldtop)
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
fldtopDescription
TRUEnever evaluated
FALSEnever evaluated
0
364 field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
never executed: field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
0
365 } else {
never executed: end of block
0
366 // Side by side.. we have to also consider the spacings to empty cells, which can strangely be more than-
367 // non empty cells..-
368 QFormLayoutItem *lbltop = prevLbl ? prevLbl : prevFld;
prevLblDescription
TRUEnever evaluated
FALSEnever evaluated
0
369 QFormLayoutItem *fldtop = prevFld;-
370 QSizePolicy::ControlTypes lbltoptypes =-
371 QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType);-
372 QSizePolicy::ControlTypes fldtoptypes =-
373 QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType);-
374-
375 // To be compatible to QGridLayout, we have to compare solitary labels & fields with both predecessors-
376 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
377 if (!field) {
!fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
378 int lblspacing = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);-
379 int fldspacing = style->combinedLayoutSpacing(fldtoptypes, lbltypes, Qt::Vertical, 0, parent);-
380 label->vSpace = qMax(lblspacing, fldspacing);-
381 } else
never executed: end of block
0
382 label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
never executed: label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
0
383 }-
384-
385 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
386 // check spacing against both the previous label and field-
387 if (!label) {
!labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
388 int lblspacing = style->combinedLayoutSpacing(lbltoptypes, fldtypes, Qt::Vertical, 0, parent);-
389 int fldspacing = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);-
390 field->vSpace = qMax(lblspacing, fldspacing);-
391 } else
never executed: end of block
0
392 field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
never executed: field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
0
393 }-
394 }
never executed: end of block
0
395 }-
396-
397 // HSpacing-
398 // hard-coded the left and right control types so that all the rows have the same-
399 // inter-column spacing (otherwise the right column isn't always left aligned)-
400 if (userHSpacing < 0 && !wrapAllRows && (label || !field->fullRow) && field)
userHSpacing < 0Description
TRUEnever evaluated
FALSEnever evaluated
!wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
labelDescription
TRUEnever evaluated
FALSEnever evaluated
!field->fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
401 field->sbsHSpace = style->combinedLayoutSpacing(QSizePolicy::Label, QSizePolicy::LineEdit, Qt::Horizontal, 0, parent);
never executed: field->sbsHSpace = style->combinedLayoutSpacing(QSizePolicy::Label, QSizePolicy::LineEdit, Qt::Horizontal, 0, parent);
0
402 }
never executed: end of block
0
403-
404 // Now update our min/sizehint widths-
405 // We choose to put the spacing in the field side in sbs, so-
406 // the right edge of the labels will align, but fields may-
407 // be a little ragged.. since different controls may have-
408 // different appearances, a slight raggedness in the left-
409 // edges of fields can be tolerated.-
410 // (Note - field->sbsHSpace is 0 for WrapAllRows mode)-
411 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
412 maxMinLblWidth = qMax(maxMinLblWidth, label->minSize.width());-
413 maxShLblWidth = qMax(maxShLblWidth, label->sizeHint.width());-
414 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
415 maxMinFldWidth = qMax(maxMinFldWidth, field->minSize.width() + field->sbsHSpace);-
416 maxShFldWidth = qMax(maxShFldWidth, field->sizeHint.width() + field->sbsHSpace);-
417 }
never executed: end of block
0
418 } else if (field) {
never executed: end of block
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
419 maxMinIfldWidth = qMax(maxMinIfldWidth, field->minSize.width());-
420 maxShIfldWidth = qMax(maxShIfldWidth, field->sizeHint.width());-
421 }
never executed: end of block
0
422-
423 prevLbl = label;-
424 prevFld = field;-
425 }
never executed: end of block
0
426-
427 // Now, finally update the min/sizeHint widths-
428 if (wrapAllRows) {
wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
429 sh_width = qMax(maxShLblWidth, qMax(maxShIfldWidth, maxShFldWidth));-
430 min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth));-
431 // in two line, we don't care as much about the threshold width-
432 thresh_width = 0;-
433 } else if (dontWrapRows) {
never executed: end of block
dontWrapRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
434 // This is just the max widths glommed together-
435 sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth);-
436 min_width = qMax(maxMinLblWidth + maxMinFldWidth, maxMinIfldWidth);-
437 thresh_width = QWIDGETSIZE_MAX;-
438 } else {
never executed: end of block
0
439 // This is just the max widths glommed together-
440 sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth);-
441 // min width needs to be the min when everything is wrapped,-
442 // otherwise we'll never get set with a width that causes wrapping-
443 min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth));-
444 // We split a pair at label sh + field min (### for now..)-
445 thresh_width = maxShLblWidth + maxMinFldWidth;-
446 }
never executed: end of block
0
447-
448 // Update the expansions-
449 expandVertical = expandV;-
450 expandHorizontal = expandH;-
451 }
never executed: end of block
0
452 sizesDirty = false;-
453}
never executed: end of block
0
454-
455void QFormLayoutPrivate::recalcHFW(int w)-
456{-
457 setupHfwLayoutData();-
458-
459 int h = 0;-
460 int mh = 0;-
461-
462 for (int r = 0; r < vLayoutCount; ++r) {
r < vLayoutCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
463 int spacing = hfwLayouts.at(r).spacing;-
464 h += hfwLayouts.at(r).sizeHint + spacing;-
465 mh += hfwLayouts.at(r).minimumSize + spacing;-
466 }
never executed: end of block
0
467-
468 if (sh_width > 0 && sh_width == w) {
sh_width > 0Description
TRUEnever evaluated
FALSEnever evaluated
sh_width == wDescription
TRUEnever evaluated
FALSEnever evaluated
0
469 hfw_sh_height = qMin(QLAYOUTSIZE_MAX, h);-
470 hfw_sh_minheight = qMin(QLAYOUTSIZE_MAX, mh);-
471 } else {
never executed: end of block
0
472 hfw_width = w;-
473 hfw_height = qMin(QLAYOUTSIZE_MAX, h);-
474 hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);-
475 }
never executed: end of block
0
476}-
477-
478void QFormLayoutPrivate::setupHfwLayoutData()-
479{-
480 // setupVerticalLayoutData must be called before this-
481 // setupHorizontalLayoutData must also be called before this-
482 // copies non hfw data into hfw-
483 // then updates size and min-
484-
485-
486 // Note: QGridLayout doesn't call minimumHeightForWidth,-
487 // but instead uses heightForWidth for both min and sizeHint.-
488 // For the common case where minimumHeightForWidth just calls-
489 // heightForWidth, we do the calculation twice, which can be-
490 // very expensive for word wrapped QLabels/QTextEdits, for example.-
491 // So we just use heightForWidth as well.-
492 int i;-
493 int rr = m_matrix.rowCount();-
494-
495 hfwLayouts.clear();-
496 hfwLayouts.resize(vLayoutCount);-
497 for (i = 0; i < vLayoutCount; ++i)
i < vLayoutCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
498 hfwLayouts[i] = vLayouts.at(i);
never executed: hfwLayouts[i] = vLayouts.at(i);
0
499-
500 for (i = 0; i < rr; ++i) {
i < rrDescription
TRUEnever evaluated
FALSEnever evaluated
0
501 QFormLayoutItem *label = m_matrix(i, 0);-
502 QFormLayoutItem *field = m_matrix(i, 1);-
503-
504 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
505 if (label->isHfw) {
label->isHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
506 // We don't check sideBySide here, since a label is only-
507 // ever side by side with its field-
508 int hfw = label->heightForWidth(label->layoutWidth);-
509 hfwLayouts[label->vLayoutIndex].minimumSize = hfw;-
510 hfwLayouts[label->vLayoutIndex].sizeHint = hfw;-
511 } else {
never executed: end of block
0
512 // Reset these here, so the field can do a qMax below (the previous value may have-
513 // been the fields non-hfw values, which are often larger than hfw)-
514 hfwLayouts[label->vLayoutIndex].sizeHint = label->sizeHint.height();-
515 hfwLayouts[label->vLayoutIndex].minimumSize = label->minSize.height();-
516 }
never executed: end of block
0
517 }-
518-
519 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
520 int hfw = field->isHfw ? field->heightForWidth(field->layoutWidth) : 0;
field->isHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
521 int h = field->isHfw ? hfw : field->sizeHint.height();
field->isHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
522 int mh = field->isHfw ? hfw : field->minSize.height();
field->isHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
523-
524 if (field->sideBySide) {
field->sideBySideDescription
TRUEnever evaluated
FALSEnever evaluated
0
525 int oh = hfwLayouts.at(field->vLayoutIndex).sizeHint;-
526 int omh = hfwLayouts.at(field->vLayoutIndex).minimumSize;-
527-
528 hfwLayouts[field->vLayoutIndex].sizeHint = qMax(h, oh);-
529 hfwLayouts[field->vLayoutIndex].minimumSize = qMax(mh, omh);-
530 } else {
never executed: end of block
0
531 hfwLayouts[field->vLayoutIndex].sizeHint = h;-
532 hfwLayouts[field->vLayoutIndex].minimumSize = mh;-
533 }
never executed: end of block
0
534 }-
535 }
never executed: end of block
0
536}
never executed: end of block
0
537-
538/*-
539 Given up to four items involved in a vertical spacing calculation-
540 (two rows * two columns), return the max vertical spacing for the-
541 row containing item1 (which may also include item2)-
542 We assume parent and item1 are not null.-
543-
544 If a particular row is split, then the spacings for that row and-
545 the following row are affected, and this function should be-
546 called with recalculate = true for both rows (note: only rows with both-
547 a label and a field can be split).-
548-
549 In particular:-
550-
551 1) the split label's row vspace needs to be changed to qMax(label/prevLabel, label/prevField)-
552 [call with item1 = label, item2 = null, prevItem1 & prevItem2 as before]-
553 2) the split field's row vspace needs to be changed to the label/field spacing-
554 [call with item1 = field, item2 = null, prevItem1 = label, prevItem2 = null]-
555-
556 [if the next row has one item, 'item']-
557 3a) the following row's vspace needs to be changed to item/field spacing (would-
558 previously been the qMax(item/label, item/field) spacings)-
559 [call with item1 = item, item2 = null, prevItem1 = field, prevItem2 = null]-
560-
561 [if the next row has two items, 'label2' and 'field2']-
562 3b) the following row's vspace needs to be changed to be qMax(field/label2, field/field2) spacing-
563 [call with item1 = label2, item2 = field2, prevItem1 = field, prevItem2 = null]-
564-
565 In the (common) non split case, we can just use the precalculated vspace (possibly qMaxed between-
566 label and field).-
567-
568 If recalculate is true, we expect:-
569 - parent != null-
570 - item1 != null-
571 - item2 can be null-
572 - prevItem1 can be null-
573 - if item2 is not null, prevItem2 will be null (e.g. steps 1 or 3 above)-
574 - if prevItem1 is null, prevItem2 will be null-
575*/-
576static inline int spacingHelper(QWidget* parent, QStyle *style, int userVSpacing, bool recalculate, QFormLayoutItem* item1, QFormLayoutItem* item2, QFormLayoutItem* prevItem1, QFormLayoutItem *prevItem2)-
577{-
578 int spacing = userVSpacing;-
579 if (spacing < 0) {
spacing < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
580 if (!recalculate) {
!recalculateDescription
TRUEnever evaluated
FALSEnever evaluated
0
581 if (item1)
item1Description
TRUEnever evaluated
FALSEnever evaluated
0
582 spacing = item1->vSpace;
never executed: spacing = item1->vSpace;
0
583 if (item2)
item2Description
TRUEnever evaluated
FALSEnever evaluated
0
584 spacing = qMax(spacing, item2->vSpace);
never executed: spacing = qMax(spacing, item2->vSpace);
0
585 } else {
never executed: end of block
0
586 if (style && prevItem1) {
styleDescription
TRUEnever evaluated
FALSEnever evaluated
prevItem1Description
TRUEnever evaluated
FALSEnever evaluated
0
587 QSizePolicy::ControlTypes itemtypes =-
588 QSizePolicy::ControlTypes(item1 ? item1->controlTypes() : QSizePolicy::DefaultType);-
589 int spacing2 = 0;-
590-
591 spacing = style->combinedLayoutSpacing(itemtypes, prevItem1->controlTypes(), Qt::Vertical, 0, parent);-
592-
593 // At most of one of item2 and prevItem2 will be nonnull-
594 if (item2)
item2Description
TRUEnever evaluated
FALSEnever evaluated
0
595 spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, 0, parent);
never executed: spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, 0, parent);
0
596 else if (prevItem2)
prevItem2Description
TRUEnever evaluated
FALSEnever evaluated
0
597 spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, 0, parent);
never executed: spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, 0, parent);
0
598-
599 spacing = qMax(spacing, spacing2);-
600 }
never executed: end of block
0
601 }
never executed: end of block
0
602 } else {-
603 if (prevItem1) {
prevItem1Description
TRUEnever evaluated
FALSEnever evaluated
0
604 QWidget *wid = prevItem1->item->widget();-
605 if (wid)
widDescription
TRUEnever evaluated
FALSEnever evaluated
0
606 spacing = qMax(spacing, prevItem1->geometry().top() - wid->geometry().top() );
never executed: spacing = qMax(spacing, prevItem1->geometry().top() - wid->geometry().top() );
0
607 }
never executed: end of block
0
608 if (prevItem2) {
prevItem2Description
TRUEnever evaluated
FALSEnever evaluated
0
609 QWidget *wid = prevItem2->item->widget();-
610 if (wid)
widDescription
TRUEnever evaluated
FALSEnever evaluated
0
611 spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() );
never executed: spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() );
0
612 }
never executed: end of block
0
613 }
never executed: end of block
0
614 return qMax(spacing, 0);
never executed: return qMax(spacing, 0);
0
615}-
616-
617static inline void initLayoutStruct(QLayoutStruct& sl, QFormLayoutItem* item)-
618{-
619 sl.init(item->vStretch(), item->minSize.height());-
620 sl.sizeHint = item->sizeHint.height();-
621 sl.maximumSize = item->maxSize.height();-
622 sl.expansive = (item->expandingDirections() & Qt::Vertical);-
623 sl.empty = false;-
624}
never executed: end of block
0
625-
626void QFormLayoutPrivate::setupVerticalLayoutData(int width)-
627{-
628 Q_Q(QFormLayout);-
629-
630 // Early out if we have no changes that would cause a change in vertical layout-
631 if ((width == layoutWidth || (width >= thresh_width && layoutWidth >= thresh_width)) && !dirty && !sizesDirty)
width == layoutWidthDescription
TRUEnever evaluated
FALSEnever evaluated
width >= thresh_widthDescription
TRUEnever evaluated
FALSEnever evaluated
layoutWidth >= thresh_widthDescription
TRUEnever evaluated
FALSEnever evaluated
!dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
!sizesDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
632 return;
never executed: return;
0
633-
634 layoutWidth = width;-
635-
636 int rr = m_matrix.rowCount();-
637 int vidx = 1;-
638 QFormLayout::RowWrapPolicy rowWrapPolicy = q->rowWrapPolicy();-
639 bool wrapAllRows = (rowWrapPolicy == QFormLayout::WrapAllRows);-
640 bool addTopBottomStretch = true;-
641-
642 vLayouts.clear();-
643 vLayouts.resize((2 * rr) + 2); // a max, some may be unused-
644-
645 QStyle *style = 0;-
646-
647 int userVSpacing = q->verticalSpacing();-
648-
649 if (userVSpacing < 0) {
userVSpacing < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
650 if (QWidget *widget = q->parentWidget())
QWidget *widge...parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
651 style = widget->style();
never executed: style = widget->style();
0
652 }
never executed: end of block
0
653-
654 // make sure our sizes are up to date-
655 updateSizes();-
656-
657 // Grab the widest label width here-
658 // This might be different from the value computed during-
659 // sizeHint/minSize, since we don't count label/field pairs that-
660 // are split.-
661 maxLabelWidth = 0;-
662 if (!wrapAllRows) {
!wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
663 for (int i = 0; i < rr; ++i) {
i < rrDescription
TRUEnever evaluated
FALSEnever evaluated
0
664 const QFormLayoutItem *label = m_matrix(i, 0);-
665 const QFormLayoutItem *field = m_matrix(i, 1);-
666 if (label && (label->sizeHint.width() + (field ? field->minSize.width() : 0) <= width))
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
labelDescription
TRUEnever evaluated
FALSEnever evaluated
(label->sizeHi...: 0) <= width)Description
TRUEnever evaluated
FALSEnever evaluated
0
667 maxLabelWidth = qMax(maxLabelWidth, label->sizeHint.width());
never executed: maxLabelWidth = qMax(maxLabelWidth, label->sizeHint.width());
0
668 }
never executed: end of block
0
669 } else {
never executed: end of block
0
670 maxLabelWidth = width;-
671 }
never executed: end of block
0
672-
673 QFormLayoutItem *prevItem1 = 0;-
674 QFormLayoutItem *prevItem2 = 0;-
675 bool prevRowSplit = false;-
676-
677 for (int i = 0; i < rr; ++i) {
i < rrDescription
TRUEnever evaluated
FALSEnever evaluated
0
678 QFormLayoutItem *label = m_matrix(i, 0);-
679 QFormLayoutItem *field = m_matrix(i, 1);-
680-
681 // Totally ignore empty rows...-
682 if (!label && !field)
!labelDescription
TRUEnever evaluated
FALSEnever evaluated
!fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
683 continue;
never executed: continue;
0
684-
685 QSize min1;-
686 QSize min2;-
687 QSize sh1;-
688 QSize sh2;-
689 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
690 min1 = label->minSize;-
691 sh1 = label->sizeHint;-
692 }
never executed: end of block
0
693 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
694 min2 = field->minSize;-
695 sh2 = field->sizeHint;-
696 }
never executed: end of block
0
697-
698 // In separate lines, we make a vLayout for everything that isn't null-
699 // in side by side, we only separate label/field if we're going to wrap it-
700 bool splitSideBySide = (rowWrapPolicy == QFormLayout::WrapLongRows)
(rowWrapPolicy...:WrapLongRows)Description
TRUEnever evaluated
FALSEnever evaluated
0
701 && ((maxLabelWidth < sh1.width()) || (width < (maxLabelWidth + min2.width())));
(maxLabelWidth < sh1.width())Description
TRUEnever evaluated
FALSEnever evaluated
(width < (maxL...min2.width()))Description
TRUEnever evaluated
FALSEnever evaluated
0
702-
703 if (wrapAllRows || splitSideBySide) {
wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
splitSideBySideDescription
TRUEnever evaluated
FALSEnever evaluated
0
704 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
705 initLayoutStruct(vLayouts[vidx], label);-
706-
707 if (vidx > 1)
vidx > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
708 vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2);
never executed: vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2);
0
709-
710 label->vLayoutIndex = vidx;-
711 label->sideBySide = false;-
712-
713 prevItem1 = label;-
714 prevItem2 = 0;-
715-
716 if (vLayouts[vidx].stretch > 0)
vLayouts[vidx].stretch > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
717 addTopBottomStretch = false;
never executed: addTopBottomStretch = false;
0
718-
719 ++vidx;-
720 }
never executed: end of block
0
721-
722 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
723 initLayoutStruct(vLayouts[vidx], field);-
724-
725 if (vidx > 1)
vidx > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
726 vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2);
never executed: vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2);
0
727-
728 field->vLayoutIndex = vidx;-
729 field->sideBySide = false;-
730-
731 prevItem1 = field;-
732 prevItem2 = 0;-
733-
734 if (vLayouts[vidx].stretch > 0)
vLayouts[vidx].stretch > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
735 addTopBottomStretch = false;
never executed: addTopBottomStretch = false;
0
736-
737 ++vidx;-
738 }
never executed: end of block
0
739-
740 prevRowSplit = splitSideBySide;-
741 } else {
never executed: end of block
0
742 // we're in side by side mode, and we have enough space to do that-
743 QSize max1(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);-
744 QSize max2(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);-
745-
746 int stretch1 = 0;-
747 int stretch2 = 0;-
748 bool expanding = false;-
749-
750 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
751 max1 = label->maxSize;-
752 if (label->expandingDirections() & Qt::Vertical)
label->expandi...& Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
753 expanding = true;
never executed: expanding = true;
0
754-
755 label->sideBySide = (field != 0);-
756 label->vLayoutIndex = vidx;-
757 stretch1 = label->vStretch();-
758 }
never executed: end of block
0
759-
760 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
761 max2 = field->maxSize;-
762 if (field->expandingDirections() & Qt::Vertical)
field->expandi...& Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
763 expanding = true;
never executed: expanding = true;
0
764-
765 field->sideBySide = (label || !field->fullRow);
labelDescription
TRUEnever evaluated
FALSEnever evaluated
!field->fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
766 field->vLayoutIndex = vidx;-
767 stretch2 = field->vStretch();-
768 }
never executed: end of block
0
769-
770 vLayouts[vidx].init(qMax(stretch1, stretch2), qMax(min1.height(), min2.height()));-
771 vLayouts[vidx].sizeHint = qMax(sh1.height(), sh2.height());-
772 vLayouts[vidx].maximumSize = qMin(max1.height(), max2.height());-
773 vLayouts[vidx].expansive = expanding || (vLayouts[vidx].stretch > 0);
expandingDescription
TRUEnever evaluated
FALSEnever evaluated
(vLayouts[vidx].stretch > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
774 vLayouts[vidx].empty = false;-
775-
776 if (vLayouts[vidx].stretch > 0)
vLayouts[vidx].stretch > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
777 addTopBottomStretch = false;
never executed: addTopBottomStretch = false;
0
778-
779 if (vidx > 1)
vidx > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
780 vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, prevRowSplit, label, field, prevItem1, prevItem2);
never executed: vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, prevRowSplit, label, field, prevItem1, prevItem2);
0
781-
782 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
783 prevItem1 = label;-
784 prevItem2 = field;-
785 } else {
never executed: end of block
0
786 prevItem1 = field;-
787 prevItem2 = 0;-
788 }
never executed: end of block
0
789-
790 prevRowSplit = false;-
791 ++vidx;-
792 }
never executed: end of block
0
793 }-
794-
795 if (addTopBottomStretch) {
addTopBottomStretchDescription
TRUEnever evaluated
FALSEnever evaluated
0
796 Qt::Alignment formAlignment = q->formAlignment();-
797-
798 if (!(formAlignment & Qt::AlignBottom)) {
!(formAlignmen...::AlignBottom)Description
TRUEnever evaluated
FALSEnever evaluated
0
799 // AlignTop (default if unspecified) or AlignVCenter: We add a stretch at the bottom-
800 vLayouts[vidx].init(1, 0);-
801 vLayouts[vidx].expansive = true;-
802 ++vidx;-
803 }
never executed: end of block
0
804-
805 if (formAlignment & (Qt::AlignVCenter | Qt::AlignBottom)) {
formAlignment ...::AlignBottom)Description
TRUEnever evaluated
FALSEnever evaluated
0
806 // AlignVCenter or AlignBottom: We add a stretch at the top-
807 vLayouts[0].init(1, 0);-
808 vLayouts[0].expansive = true;-
809 } else {
never executed: end of block
0
810 vLayouts[0].init(0, 0);-
811 }
never executed: end of block
0
812 } else {-
813 vLayouts[0].init(0, 0);-
814 }
never executed: end of block
0
815-
816 vLayoutCount = vidx;-
817 dirty = false;-
818}
never executed: end of block
0
819-
820void QFormLayoutPrivate::setupHorizontalLayoutData(int width)-
821{-
822 Q_Q(QFormLayout);-
823-
824 // requires setupVerticalLayoutData to be called first-
825-
826 int fieldMaxWidth = 0;-
827-
828 int rr = m_matrix.rowCount();-
829 bool wrapAllRows = (q->rowWrapPolicy() == QFormLayout::WrapAllRows);-
830-
831 for (int i = 0; i < rr; ++i) {
i < rrDescription
TRUEnever evaluated
FALSEnever evaluated
0
832 QFormLayoutItem *label = m_matrix(i, 0);-
833 QFormLayoutItem *field = m_matrix(i, 1);-
834-
835 // Totally ignore empty rows...-
836 if (!label && !field)
!labelDescription
TRUEnever evaluated
FALSEnever evaluated
!fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
837 continue;
never executed: continue;
0
838-
839 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
840 // if there is a field, and we're side by side, we use maxLabelWidth-
841 // otherwise we just use the sizehint-
842 label->layoutWidth = (field && label->sideBySide) ? maxLabelWidth : label->sizeHint.width();
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
label->sideBySideDescription
TRUEnever evaluated
FALSEnever evaluated
0
843 label->layoutPos = 0;-
844 }
never executed: end of block
0
845-
846 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
847 // This is the default amount allotted to fields in sbs-
848 int fldwidth = width - maxLabelWidth - field->sbsHSpace;-
849-
850 // If we've split a row, we still decide to align-
851 // the field with all the other field if it will fit-
852 // Fields in sbs mode get the remnants of the maxLabelWidth-
853 if (!field->sideBySide) {
!field->sideBySideDescription
TRUEnever evaluated
FALSEnever evaluated
0
854 if (wrapAllRows || (!label && field->fullRow) || field->sizeHint.width() > fldwidth) {
wrapAllRowsDescription
TRUEnever evaluated
FALSEnever evaluated
!labelDescription
TRUEnever evaluated
FALSEnever evaluated
field->fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
field->sizeHin...h() > fldwidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
855 field->layoutWidth = width;-
856 field->layoutPos = 0;-
857 } else {
never executed: end of block
0
858 field->layoutWidth = fldwidth;-
859 field->layoutPos = width - fldwidth;-
860 }
never executed: end of block
0
861 } else {-
862 // We're sbs, so we should have a label-
863 field->layoutWidth = fldwidth;-
864 field->layoutPos = width - fldwidth;-
865 }
never executed: end of block
0
866-
867 fieldMaxWidth = qMax(fieldMaxWidth, field->maxSize.width());-
868 }
never executed: end of block
0
869 }
never executed: end of block
0
870-
871 formMaxWidth = maxLabelWidth + fieldMaxWidth;-
872}
never executed: end of block
0
873-
874void QFormLayoutPrivate::calcSizeHints()-
875{-
876 Q_Q(QFormLayout);-
877-
878 int leftMargin, topMargin, rightMargin, bottomMargin;-
879 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);-
880-
881 updateSizes();-
882 setupVerticalLayoutData(QLAYOUTSIZE_MAX);-
883 // Don't need to call setupHorizontal here-
884-
885 int h = topMargin + bottomMargin;-
886 int mh = topMargin + bottomMargin;-
887-
888 // The following are set in updateSizes-
889 int w = sh_width + leftMargin + rightMargin;-
890 int mw = min_width + leftMargin + rightMargin;-
891-
892 for (int i = 0; i < vLayoutCount; ++i) {
i < vLayoutCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
893 int spacing = vLayouts.at(i).spacing;-
894 h += vLayouts.at(i).sizeHint + spacing;-
895 mh += vLayouts.at(i).minimumSize + spacing;-
896 }
never executed: end of block
0
897-
898 minSize.rwidth() = qMin(mw, QLAYOUTSIZE_MAX);-
899 minSize.rheight() = qMin(mh, QLAYOUTSIZE_MAX);-
900 prefSize.rwidth() = qMin(w, QLAYOUTSIZE_MAX);-
901 prefSize.rheight() = qMin(h, QLAYOUTSIZE_MAX);-
902}
never executed: end of block
0
903-
904int QFormLayoutPrivate::insertRow(int row)-
905{-
906 int rowCnt = m_matrix.rowCount();-
907 if (uint(row) > uint(rowCnt))
uint(row) > uint(rowCnt)Description
TRUEnever evaluated
FALSEnever evaluated
0
908 row = rowCnt;
never executed: row = rowCnt;
0
909-
910 insertRows(row, 1);-
911 return row;
never executed: return row;
0
912}-
913-
914void QFormLayoutPrivate::insertRows(int row, int count)-
915{-
916 while (count > 0) {
count > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
917 m_matrix.insertRow(row, 0);-
918 --count;-
919 }
never executed: end of block
0
920}
never executed: end of block
0
921-
922bool QFormLayoutPrivate::setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item)-
923{-
924 const bool fullRow = role == QFormLayout::SpanningRole;-
925 const int column = role == QFormLayout::SpanningRole ? 1 : static_cast<int>(role);
role == QFormL...::SpanningRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
926 if (Q_UNLIKELY(uint(row) >= uint(m_matrix.rowCount()) || uint(column) > 1U)) {
__builtin_expe... > 1U), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
927 qWarning("QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column);-
928 return false;
never executed: return false;
0
929 }-
930-
931 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
932 return false;
never executed: return false;
0
933-
934 if (Q_UNLIKELY(m_matrix(row, column))) {
__builtin_expe...lumn)), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
935 qWarning("QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column);-
936 return false;
never executed: return false;
0
937 }-
938-
939 QFormLayoutItem *i = new QFormLayoutItem(item);-
940 i->fullRow = fullRow;-
941 m_matrix(row, column) = i;-
942-
943 m_things.append(i);-
944 return true;
never executed: return true;
0
945}-
946-
947void QFormLayoutPrivate::setLayout(int row, QFormLayout::ItemRole role, QLayout *layout)-
948{-
949 if (layout) {
layoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
950 Q_Q(QFormLayout);-
951 if (q->adoptLayout(layout))
q->adoptLayout(layout)Description
TRUEnever evaluated
FALSEnever evaluated
0
952 setItem(row, role, layout);
never executed: setItem(row, role, layout);
0
953 }
never executed: end of block
0
954}
never executed: end of block
0
955-
956void QFormLayoutPrivate::setWidget(int row, QFormLayout::ItemRole role, QWidget *widget)-
957{-
958 if (widget) {
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
959 Q_Q(QFormLayout);-
960 q->addChildWidget(widget);-
961 QWidgetItem *item = QLayoutPrivate::createWidgetItem(q, widget);-
962 if (!setItem(row, role, item))
!setItem(row, role, item)Description
TRUEnever evaluated
FALSEnever evaluated
0
963 delete item;
never executed: delete item;
0
964 }
never executed: end of block
0
965}
never executed: end of block
0
966-
967QStyle* QFormLayoutPrivate::getStyle() const-
968{-
969 Q_Q(const QFormLayout);-
970-
971 // ### cache-
972 if (QWidget *parentWidget = q->parentWidget())
QWidget *paren...parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
973 return parentWidget->style();
never executed: return parentWidget->style();
0
974 else-
975 return QApplication::style();
never executed: return QApplication::style();
0
976}-
977-
978QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem)-
979{-
980 Q_Q(QFormLayout);-
981 if (!newitem)
!newitemDescription
TRUEnever evaluated
FALSEnever evaluated
0
982 return 0;
never executed: return 0;
0
983 const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index));-
984 if (Q_UNLIKELY(storageIndex == -1)) {
__builtin_expe...== -1), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
985 // ### Qt6 - fix warning too when this class becomes public-
986 qWarning("QFormLayoutPrivate::replaceAt: Invalid index %d", index);-
987 return 0;
never executed: return 0;
0
988 }-
989-
990 int row, col;-
991 QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col);-
992 Q_ASSERT(m_matrix(row, col));-
993-
994 QFormLayoutItem *item = m_matrix(row, col);-
995 Q_ASSERT(item);-
996-
997 QLayoutItem *olditem = item->item;-
998 item->item = newitem;-
999-
1000 q->invalidate();-
1001 return olditem;
never executed: return olditem;
0
1002}-
1003-
1004/*!-
1005 \class QFormLayout-
1006 \since 4.4-
1007 \brief The QFormLayout class manages forms of input widgets and their associated labels.-
1008-
1009 \ingroup geomanagement-
1010 \inmodule QtWidgets-
1011-
1012 QFormLayout is a convenience layout class that lays out its-
1013 children in a two-column form. The left column consists of labels-
1014 and the right column consists of "field" widgets (line editors,-
1015 spin boxes, etc.).-
1016-
1017 Traditionally, such two-column form layouts were achieved using-
1018 QGridLayout. QFormLayout is a higher-level alternative that-
1019 provides the following advantages:-
1020-
1021 \list-
1022 \li \b{Adherence to the different platform's look and feel guidelines.}-
1023-
1024 For example, the-
1025 \l{http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/Intro/Intro.html}{\macos Aqua} and KDE guidelines specify that the-
1026 labels should be right-aligned, whereas Windows and GNOME-
1027 applications normally use left-alignment.-
1028-
1029 \li \b{Support for wrapping long rows.}-
1030-
1031 For devices with small displays, QFormLayout can be set to-
1032 \l{WrapLongRows}{wrap long rows}, or even to-
1033 \l{WrapAllRows}{wrap all rows}.-
1034-
1035 \li \b{Convenient API for creating label--field pairs.}-
1036-
1037 The addRow() overload that takes a QString and a QWidget *-
1038 creates a QLabel behind the scenes and automatically set up-
1039 its buddy. We can then write code like this:-
1040-
1041 \snippet code/src_gui_kernel_qformlayout.cpp 0-
1042-
1043 Compare this with the following code, written using QGridLayout:-
1044-
1045 \snippet code/src_gui_kernel_qformlayout.cpp 1-
1046 \endlist-
1047-
1048 The table below shows the default appearance in different styles.-
1049-
1050 \table-
1051 \header-
1052 \li QCommonStyle derived styles (except QPlastiqueStyle)-
1053 \li QMacStyle-
1054 \li QPlastiqueStyle-
1055 \li Qt Extended styles-
1056 \row-
1057 \li \inlineimage qformlayout-win.png-
1058 \li \inlineimage qformlayout-mac.png-
1059 \li \inlineimage qformlayout-kde.png-
1060 \li \inlineimage qformlayout-qpe.png-
1061 \row-
1062 \li Traditional style used for Windows, GNOME, and earlier-
1063 versions of KDE. Labels are left aligned, and expanding-
1064 fields grow to fill the available space. (This normally-
1065 corresponds to what we would get using a two-column-
1066 QGridLayout.)-
1067 \li Style based on the-
1068 \l{http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/Intro/Intro.html}{\macos Aqua} guidelines. Labels are right-aligned,-
1069 the fields don't grow beyond their size hint, and the-
1070 form is horizontally centered.-
1071 \li Recommended style for-
1072 \l{KDE applications}. Similar to MacStyle, except that the form-
1073 is left-aligned and all fields grow to fill the available-
1074 space.-
1075 \li Default style for Qt Extended styles. Labels are right-aligned,-
1076 expanding fields grow to fill the available space, and row-
1077 wrapping is enabled for long lines.-
1078 \endtable-
1079-
1080 The form styles can be also be overridden individually by calling-
1081 setLabelAlignment(), setFormAlignment(), setFieldGrowthPolicy(),-
1082 and setRowWrapPolicy(). For example, to simulate the form layout-
1083 appearance of QMacStyle on all platforms, but with left-aligned-
1084 labels, you could write:-
1085-
1086 \snippet code/src_gui_kernel_qformlayout.cpp 2-
1087-
1088 \sa QGridLayout, QBoxLayout, QStackedLayout-
1089*/-
1090-
1091-
1092/*!-
1093 \enum QFormLayout::FieldGrowthPolicy-
1094-
1095 This enum specifies the different policies that can be used to-
1096 control the way in which the form's fields grow.-
1097-
1098 \value FieldsStayAtSizeHint-
1099 The fields never grow beyond their-
1100 \l{QWidgetItem::sizeHint()}{effective size hint}. This is-
1101 the default for QMacStyle.-
1102-
1103 \value ExpandingFieldsGrow-
1104 Fields with an horizontal \l{QSizePolicy}{size policy} of-
1105 \l{QSizePolicy::}{Expanding} or-
1106 \l{QSizePolicy::}{MinimumExpanding} will grow to fill the-
1107 available space. The other fields will not grow beyond-
1108 their effective size hint. This is the default policy for-
1109 Plastique.-
1110-
1111 \value AllNonFixedFieldsGrow-
1112 All fields with a size policy that allows them to grow-
1113 will grow to fill the available space. This is the default-
1114 policy for most styles.-
1115-
1116 \sa fieldGrowthPolicy-
1117*/-
1118-
1119/*!-
1120 \enum QFormLayout::RowWrapPolicy-
1121-
1122 This enum specifies the different policies that can be used to-
1123 control the way in which the form's rows wrap.-
1124-
1125 \value DontWrapRows-
1126 Fields are always laid out next to their label. This is-
1127 the default policy for all styles except Qt Extended styles.-
1128-
1129 \value WrapLongRows-
1130 Labels are given enough horizontal space to fit the widest label,-
1131 and the rest of the space is given to the fields. If the minimum-
1132 size of a field pair is wider than the available space, the field-
1133 is wrapped to the next line. This is the default policy for-
1134 Qt Extended styles.-
1135-
1136 \value WrapAllRows-
1137 Fields are always laid out below their label.-
1138-
1139 \sa rowWrapPolicy-
1140*/-
1141-
1142/*!-
1143 \enum QFormLayout::ItemRole-
1144-
1145 This enum specifies the types of widgets (or other layout items)-
1146 that may appear in a row.-
1147-
1148 \value LabelRole A label widget.-
1149 \value FieldRole A field widget.-
1150 \value SpanningRole A widget that spans label and field columns.-
1151-
1152 \sa itemAt(), getItemPosition()-
1153*/-
1154-
1155/*!-
1156 Constructs a new form layout with the given \a parent widget.-
1157-
1158 \sa QWidget::setLayout()-
1159*/-
1160QFormLayout::QFormLayout(QWidget *parent)-
1161 : QLayout(*new QFormLayoutPrivate, 0, parent)-
1162{-
1163}
never executed: end of block
0
1164-
1165/*!-
1166 Destroys the form layout.-
1167*/-
1168QFormLayout::~QFormLayout()-
1169{-
1170 Q_D(QFormLayout);-
1171-
1172 /*-
1173 The clearing and destruction order here is important. We start by clearing-
1174 m_things so that QLayout and the rest of the world know that we don't babysit-
1175 the layout items anymore and don't care if they are destroyed.-
1176 */-
1177 d->m_things.clear();-
1178 qDeleteAll(d->m_matrix.storage());-
1179 d->m_matrix.clear();-
1180}
never executed: end of block
0
1181-
1182/*!-
1183 Adds a new row to the bottom of this form layout, with the given-
1184 \a label and \a field.-
1185-
1186 \sa insertRow()-
1187*/-
1188void QFormLayout::addRow(QWidget *label, QWidget *field)-
1189{-
1190 insertRow(-1, label, field);-
1191}
never executed: end of block
0
1192-
1193/*!-
1194 \overload-
1195*/-
1196void QFormLayout::addRow(QWidget *label, QLayout *field)-
1197{-
1198 insertRow(-1, label, field);-
1199}
never executed: end of block
0
1200-
1201/*!-
1202 \overload-
1203-
1204 This overload automatically creates a QLabel behind the scenes-
1205 with \a labelText as its text. The \a field is set as the new-
1206 QLabel's \l{QLabel::setBuddy()}{buddy}.-
1207*/-
1208void QFormLayout::addRow(const QString &labelText, QWidget *field)-
1209{-
1210 insertRow(-1, labelText, field);-
1211}
never executed: end of block
0
1212-
1213/*!-
1214 \overload-
1215-
1216 This overload automatically creates a QLabel behind the scenes-
1217 with \a labelText as its text.-
1218*/-
1219void QFormLayout::addRow(const QString &labelText, QLayout *field)-
1220{-
1221 insertRow(-1, labelText, field);-
1222}
never executed: end of block
0
1223-
1224/*!-
1225 \overload-
1226-
1227 Adds the specified \a widget at the end of this form layout. The-
1228 \a widget spans both columns.-
1229*/-
1230void QFormLayout::addRow(QWidget *widget)-
1231{-
1232 insertRow(-1, widget);-
1233}
never executed: end of block
0
1234-
1235/*!-
1236 \overload-
1237-
1238 Adds the specified \a layout at the end of this form layout. The-
1239 \a layout spans both columns.-
1240*/-
1241void QFormLayout::addRow(QLayout *layout)-
1242{-
1243 insertRow(-1, layout);-
1244}
never executed: end of block
0
1245-
1246/*!-
1247 Inserts a new row at position \a row in this form layout, with-
1248 the given \a label and \a field. If \a row is out of bounds, the-
1249 new row is added at the end.-
1250-
1251 \sa addRow()-
1252*/-
1253void QFormLayout::insertRow(int row, QWidget *label, QWidget *field)-
1254{-
1255 Q_D(QFormLayout);-
1256 if ((label && !d->checkWidget(label)) || (field && !d->checkWidget(field)))
labelDescription
TRUEnever evaluated
FALSEnever evaluated
!d->checkWidget(label)Description
TRUEnever evaluated
FALSEnever evaluated
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
!d->checkWidget(field)Description
TRUEnever evaluated
FALSEnever evaluated
0
1257 return;
never executed: return;
0
1258-
1259 row = d->insertRow(row);-
1260 if (label)
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1261 d->setWidget(row, LabelRole, label);
never executed: d->setWidget(row, LabelRole, label);
0
1262 if (field)
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
1263 d->setWidget(row, FieldRole, field);
never executed: d->setWidget(row, FieldRole, field);
0
1264 invalidate();-
1265}
never executed: end of block
0
1266-
1267/*!-
1268 \overload-
1269*/-
1270void QFormLayout::insertRow(int row, QWidget *label, QLayout *field)-
1271{-
1272 Q_D(QFormLayout);-
1273 if ((label && !d->checkWidget(label)) || (field && !d->checkLayout(field)))
labelDescription
TRUEnever evaluated
FALSEnever evaluated
!d->checkWidget(label)Description
TRUEnever evaluated
FALSEnever evaluated
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
!d->checkLayout(field)Description
TRUEnever evaluated
FALSEnever evaluated
0
1274 return;
never executed: return;
0
1275-
1276 row = d->insertRow(row);-
1277 if (label)
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1278 d->setWidget(row, LabelRole, label);
never executed: d->setWidget(row, LabelRole, label);
0
1279 if (field)
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
1280 d->setLayout(row, FieldRole, field);
never executed: d->setLayout(row, FieldRole, field);
0
1281 invalidate();-
1282}
never executed: end of block
0
1283-
1284/*!-
1285 \overload-
1286-
1287 This overload automatically creates a QLabel behind the scenes-
1288 with \a labelText as its text. The \a field is set as the new-
1289 QLabel's \l{QLabel::setBuddy()}{buddy}.-
1290*/-
1291void QFormLayout::insertRow(int row, const QString &labelText, QWidget *field)-
1292{-
1293 Q_D(QFormLayout);-
1294 if (field && !d->checkWidget(field))
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
!d->checkWidget(field)Description
TRUEnever evaluated
FALSEnever evaluated
0
1295 return;
never executed: return;
0
1296-
1297 QLabel *label = 0;-
1298 if (!labelText.isEmpty()) {
!labelText.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1299 label = new QLabel(labelText);-
1300#ifndef QT_NO_SHORTCUT-
1301 label->setBuddy(field);-
1302#endif-
1303 }
never executed: end of block
0
1304 insertRow(row, label, field);-
1305}
never executed: end of block
0
1306-
1307/*!-
1308 \overload-
1309-
1310 This overload automatically creates a QLabel behind the scenes-
1311 with \a labelText as its text.-
1312*/-
1313void QFormLayout::insertRow(int row, const QString &labelText, QLayout *field)-
1314{-
1315 Q_D(QFormLayout);-
1316 if (field && !d->checkLayout(field))
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
!d->checkLayout(field)Description
TRUEnever evaluated
FALSEnever evaluated
0
1317 return;
never executed: return;
0
1318-
1319 insertRow(row, labelText.isEmpty() ? 0 : new QLabel(labelText), field);-
1320}
never executed: end of block
0
1321-
1322/*!-
1323 \overload-
1324-
1325 Inserts the specified \a widget at position \a row in this form-
1326 layout. The \a widget spans both columns. If \a row is out of-
1327 bounds, the widget is added at the end.-
1328*/-
1329void QFormLayout::insertRow(int row, QWidget *widget)-
1330{-
1331 Q_D(QFormLayout);-
1332 if (!d->checkWidget(widget))
!d->checkWidget(widget)Description
TRUEnever evaluated
FALSEnever evaluated
0
1333 return;
never executed: return;
0
1334-
1335 row = d->insertRow(row);-
1336 d->setWidget(row, SpanningRole, widget);-
1337 invalidate();-
1338}
never executed: end of block
0
1339-
1340/*!-
1341 \overload-
1342-
1343 Inserts the specified \a layout at position \a row in this form-
1344 layout. The \a layout spans both columns. If \a row is out of-
1345 bounds, the widget is added at the end.-
1346*/-
1347void QFormLayout::insertRow(int row, QLayout *layout)-
1348{-
1349 Q_D(QFormLayout);-
1350 if (!d->checkLayout(layout))
!d->checkLayout(layout)Description
TRUEnever evaluated
FALSEnever evaluated
0
1351 return;
never executed: return;
0
1352-
1353 row = d->insertRow(row);-
1354 d->setLayout(row, SpanningRole, layout);-
1355 invalidate();-
1356}
never executed: end of block
0
1357-
1358/*!-
1359 \reimp-
1360*/-
1361void QFormLayout::addItem(QLayoutItem *item)-
1362{-
1363 Q_D(QFormLayout);-
1364-
1365 int row = d->insertRow(d->m_matrix.rowCount());-
1366 d->setItem(row, FieldRole, item);-
1367 invalidate();-
1368}
never executed: end of block
0
1369-
1370/*!-
1371 \reimp-
1372*/-
1373int QFormLayout::count() const-
1374{-
1375 Q_D(const QFormLayout);-
1376 return d->m_things.count();
never executed: return d->m_things.count();
0
1377}-
1378-
1379/*!-
1380 \reimp-
1381*/-
1382QLayoutItem *QFormLayout::itemAt(int index) const-
1383{-
1384 Q_D(const QFormLayout);-
1385 if (QFormLayoutItem *formItem = d->m_things.value(index))
QFormLayoutIte...s.value(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1386 return formItem->item;
never executed: return formItem->item;
0
1387 return 0;
never executed: return 0;
0
1388}-
1389-
1390/*!-
1391 \reimp-
1392*/-
1393QLayoutItem *QFormLayout::takeAt(int index)-
1394{-
1395 Q_D(QFormLayout);-
1396-
1397 const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index));-
1398 if (Q_UNLIKELY(storageIndex == -1)) {
__builtin_expe...== -1), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1399 qWarning("QFormLayout::takeAt: Invalid index %d", index);-
1400 return 0;
never executed: return 0;
0
1401 }-
1402-
1403 int row, col;-
1404 QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col);-
1405 Q_ASSERT(d->m_matrix(row, col));-
1406-
1407 QFormLayoutItem *item = d->m_matrix(row, col);-
1408 Q_ASSERT(item);-
1409 d->m_things.removeAt(index);-
1410 d->m_matrix(row, col) = 0;-
1411-
1412 invalidate();-
1413-
1414 // grab ownership back from the QFormLayoutItem-
1415 QLayoutItem *i = item->item;-
1416 item->item = 0;-
1417 delete item;-
1418-
1419 if (QLayout *l = i->layout()) {
QLayout *l = i->layout()Description
TRUEnever evaluated
FALSEnever evaluated
0
1420 // sanity check in case the user passed something weird to QObject::setParent()-
1421 if (l->parent() == this)
l->parent() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1422 l->setParent(0);
never executed: l->setParent(0);
0
1423 }
never executed: end of block
0
1424-
1425 return i;
never executed: return i;
0
1426}-
1427-
1428/*!-
1429 \reimp-
1430*/-
1431Qt::Orientations QFormLayout::expandingDirections() const-
1432{-
1433 Q_D(const QFormLayout);-
1434 QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d);-
1435 e->updateSizes();-
1436-
1437 Qt::Orientations o = 0;-
1438 if (e->expandHorizontal)
e->expandHorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1439 o = Qt::Horizontal;
never executed: o = Qt::Horizontal;
0
1440 if (e->expandVertical)
e->expandVerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1441 o |= Qt::Vertical;
never executed: o |= Qt::Vertical;
0
1442 return o;
never executed: return o;
0
1443}-
1444-
1445/*!-
1446 \reimp-
1447*/-
1448bool QFormLayout::hasHeightForWidth() const-
1449{-
1450 Q_D(const QFormLayout);-
1451 QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d);-
1452 e->updateSizes();-
1453 return (d->has_hfw || rowWrapPolicy() == WrapLongRows);
never executed: return (d->has_hfw || rowWrapPolicy() == WrapLongRows);
0
1454}-
1455-
1456/*!-
1457 \reimp-
1458*/-
1459int QFormLayout::heightForWidth(int width) const-
1460{-
1461 Q_D(const QFormLayout);-
1462 if (!hasHeightForWidth())
!hasHeightForWidth()Description
TRUEnever evaluated
FALSEnever evaluated
0
1463 return -1;
never executed: return -1;
0
1464-
1465 int leftMargin, topMargin, rightMargin, bottomMargin;-
1466 getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);-
1467-
1468 int targetWidth = width - leftMargin - rightMargin;-
1469-
1470 if (!d->haveHfwCached(targetWidth)) {
!d->haveHfwCached(targetWidth)Description
TRUEnever evaluated
FALSEnever evaluated
0
1471 QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d);-
1472 dat->setupVerticalLayoutData(targetWidth);-
1473 dat->setupHorizontalLayoutData(targetWidth);-
1474 dat->recalcHFW(targetWidth);-
1475 }
never executed: end of block
0
1476 if (targetWidth == d->sh_width)
targetWidth == d->sh_widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1477 return d->hfw_sh_height + topMargin + bottomMargin;
never executed: return d->hfw_sh_height + topMargin + bottomMargin;
0
1478 else-
1479 return d->hfw_height + topMargin + bottomMargin;
never executed: return d->hfw_height + topMargin + bottomMargin;
0
1480}-
1481-
1482/*!-
1483 \reimp-
1484*/-
1485void QFormLayout::setGeometry(const QRect &rect)-
1486{-
1487 Q_D(QFormLayout);-
1488 if (d->dirty || rect != geometry()) {
d->dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
rect != geometry()Description
TRUEnever evaluated
FALSEnever evaluated
0
1489 QRect cr = rect;-
1490 int leftMargin, topMargin, rightMargin, bottomMargin;-
1491 getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);-
1492 cr.adjust(+leftMargin, +topMargin, -rightMargin, -bottomMargin);-
1493-
1494 bool hfw = hasHeightForWidth();-
1495 d->setupVerticalLayoutData(cr.width());-
1496 d->setupHorizontalLayoutData(cr.width());-
1497 if (hfw && (!d->haveHfwCached(cr.width()) || d->hfwLayouts.size() != d->vLayoutCount))
hfwDescription
TRUEnever evaluated
FALSEnever evaluated
!d->haveHfwCached(cr.width())Description
TRUEnever evaluated
FALSEnever evaluated
d->hfwLayouts....->vLayoutCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1498 d->recalcHFW(cr.width());
never executed: d->recalcHFW(cr.width());
0
1499 if (hfw) {
hfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
1500 qGeomCalc(d->hfwLayouts, 0, d->vLayoutCount, cr.y(), cr.height());-
1501 d->arrangeWidgets(d->hfwLayouts, cr);-
1502 } else {
never executed: end of block
0
1503 qGeomCalc(d->vLayouts, 0, d->vLayoutCount, cr.y(), cr.height());-
1504 d->arrangeWidgets(d->vLayouts, cr);-
1505 }
never executed: end of block
0
1506 QLayout::setGeometry(rect);-
1507 }
never executed: end of block
0
1508}
never executed: end of block
0
1509-
1510/*!-
1511 \reimp-
1512*/-
1513QSize QFormLayout::sizeHint() const-
1514{-
1515 Q_D(const QFormLayout);-
1516 if (!d->prefSize.isValid()) {
!d->prefSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1517 QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d);-
1518 dat->calcSizeHints();-
1519 }
never executed: end of block
0
1520 return d->prefSize;
never executed: return d->prefSize;
0
1521}-
1522-
1523/*!-
1524 \reimp-
1525*/-
1526QSize QFormLayout::minimumSize() const-
1527{-
1528 // ### fix minimumSize if hfw-
1529 Q_D(const QFormLayout);-
1530 if (!d->minSize.isValid()) {
!d->minSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1531 QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d);-
1532 dat->calcSizeHints();-
1533 }
never executed: end of block
0
1534 return d->minSize;
never executed: return d->minSize;
0
1535}-
1536-
1537/*!-
1538 \reimp-
1539*/-
1540void QFormLayout::invalidate()-
1541{-
1542 Q_D(QFormLayout);-
1543 d->dirty = true;-
1544 d->sizesDirty = true;-
1545 d->minSize = QSize();-
1546 d->prefSize = QSize();-
1547 d->formMaxWidth = -1;-
1548 d->hfw_width = -1;-
1549 d->sh_width = -1;-
1550 d->layoutWidth = -1;-
1551 d->hfw_sh_height = -1;-
1552 QLayout::invalidate();-
1553}
never executed: end of block
0
1554-
1555/*!-
1556 Returns the number of rows in the form.-
1557-
1558 \sa QLayout::count()-
1559*/-
1560int QFormLayout::rowCount() const-
1561{-
1562 Q_D(const QFormLayout);-
1563 return d->m_matrix.rowCount();
never executed: return d->m_matrix.rowCount();
0
1564}-
1565-
1566/*!-
1567 Returns the layout item in the given \a row with the specified \a-
1568 role (column). Returns 0 if there is no such item.-
1569-
1570 \sa QLayout::itemAt(), setItem()-
1571*/-
1572QLayoutItem *QFormLayout::itemAt(int row, ItemRole role) const-
1573{-
1574 Q_D(const QFormLayout);-
1575 if (uint(row) >= uint(d->m_matrix.rowCount()))
uint(row) >= u...ix.rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
1576 return 0;
never executed: return 0;
0
1577 switch (role) {-
1578 case SpanningRole:
never executed: case SpanningRole:
0
1579 if (QFormLayoutItem *item = d->m_matrix(row, 1))
QFormLayoutIte...matrix(row, 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1580 if (item->fullRow)
item->fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1581 return item->item;
never executed: return item->item;
0
1582 break;
never executed: break;
0
1583 case LabelRole:
never executed: case LabelRole:
0
1584 case FieldRole:
never executed: case FieldRole:
0
1585 if (QFormLayoutItem *item = d->m_matrix(row, (role == LabelRole) ? 0 : 1))
QFormLayoutIte...Role) ? 0 : 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1586 return item->item;
never executed: return item->item;
0
1587 break;
never executed: break;
0
1588 }-
1589 return 0;
never executed: return 0;
0
1590}-
1591-
1592/*!-
1593 Retrieves the row and role (column) of the item at the specified-
1594 \a index. If \a index is out of bounds, *\a rowPtr is set to -1;-
1595 otherwise the row is stored in *\a rowPtr and the role is stored-
1596 in *\a rolePtr.-
1597-
1598 \sa itemAt(), count(), getLayoutPosition(), getWidgetPosition()-
1599*/-
1600void QFormLayout::getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const-
1601{-
1602 Q_D(const QFormLayout);-
1603 int col = -1;-
1604 int row = -1;-
1605-
1606 const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index));-
1607 if (storageIndex != -1)
storageIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1608 QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col);
never executed: QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col);
0
1609-
1610 if (rowPtr)
rowPtrDescription
TRUEnever evaluated
FALSEnever evaluated
0
1611 *rowPtr = row;
never executed: *rowPtr = row;
0
1612 if (rolePtr && col != -1) {
rolePtrDescription
TRUEnever evaluated
FALSEnever evaluated
col != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1613 const bool spanning = col == 1 && d->m_matrix(row, col)->fullRow;
col == 1Description
TRUEnever evaluated
FALSEnever evaluated
d->m_matrix(row, col)->fullRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1614 if (spanning) {
spanningDescription
TRUEnever evaluated
FALSEnever evaluated
0
1615 *rolePtr = SpanningRole;-
1616 } else {
never executed: end of block
0
1617 *rolePtr = ItemRole(col);-
1618 }
never executed: end of block
0
1619 }-
1620}
never executed: end of block
0
1621-
1622/*!-
1623 Retrieves the row and role (column) of the specified child \a-
1624 layout. If \a layout is not in the form layout, *\a rowPtr is set-
1625 to -1; otherwise the row is stored in *\a rowPtr and the role is stored-
1626 in *\a rolePtr.-
1627*/-
1628void QFormLayout::getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const-
1629{-
1630 int n = count();-
1631 int index = 0;-
1632 while (index < n) {
index < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
1633 if (itemAt(index) == layout)
itemAt(index) == layoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1634 break;
never executed: break;
0
1635 ++index;-
1636 }
never executed: end of block
0
1637 getItemPosition(index, rowPtr, rolePtr);-
1638}
never executed: end of block
0
1639-
1640/*!-
1641 Retrieves the row and role (column) of the specified \a widget in-
1642 the layout. If \a widget is not in the layout, *\a rowPtr is set-
1643 to -1; otherwise the row is stored in *\a rowPtr and the role is stored-
1644 in *\a rolePtr.-
1645-
1646 \sa getItemPosition(), itemAt()-
1647*/-
1648void QFormLayout::getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const-
1649{-
1650 getItemPosition(indexOf(widget), rowPtr, rolePtr);-
1651}
never executed: end of block
0
1652-
1653// ### eliminate labelForField()-
1654-
1655/*!-
1656 Returns the label associated with the given \a field.-
1657-
1658 \sa itemAt()-
1659*/-
1660QWidget *QFormLayout::labelForField(QWidget *field) const-
1661{-
1662 Q_D(const QFormLayout);-
1663-
1664 int row;-
1665 ItemRole role = LabelRole;-
1666-
1667 getWidgetPosition(field, &row, &role);-
1668-
1669 if (row != -1 && role == FieldRole) {
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
role == FieldRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1670 if (QFormLayoutItem *label = d->m_matrix(row, LabelRole))
QFormLayoutIte...ow, LabelRole)Description
TRUEnever evaluated
FALSEnever evaluated
0
1671 return label->widget();
never executed: return label->widget();
0
1672 }
never executed: end of block
0
1673 return 0;
never executed: return 0;
0
1674}-
1675-
1676/*!-
1677 \overload-
1678*/-
1679QWidget *QFormLayout::labelForField(QLayout *field) const-
1680{-
1681 Q_D(const QFormLayout);-
1682-
1683 int row;-
1684 ItemRole role;-
1685-
1686 getLayoutPosition(field, &row, &role);-
1687-
1688 if (row != -1 && role == FieldRole) {
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
role == FieldRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1689 if (QFormLayoutItem *label = d->m_matrix(row, LabelRole))
QFormLayoutIte...ow, LabelRole)Description
TRUEnever evaluated
FALSEnever evaluated
0
1690 return label->widget();
never executed: return label->widget();
0
1691 }
never executed: end of block
0
1692 return 0;
never executed: return 0;
0
1693}-
1694-
1695/*!-
1696 \property QFormLayout::fieldGrowthPolicy-
1697 \brief the way in which the form's fields grow-
1698-
1699 The default value depends on the widget or application style. For-
1700 QMacStyle, the default is FieldsStayAtSizeHint; for QCommonStyle-
1701 derived styles (like Plastique and Windows), the default-
1702 is ExpandingFieldsGrow; for Qt Extended styles, the default is-
1703 AllNonFixedFieldsGrow.-
1704-
1705 If none of the fields can grow and the form is resized, extra-
1706 space is distributed according to the current-
1707 \l{formAlignment}{form alignment}.-
1708-
1709 \sa formAlignment, rowWrapPolicy-
1710*/-
1711-
1712void QFormLayout::setFieldGrowthPolicy(FieldGrowthPolicy policy)-
1713{-
1714 Q_D(QFormLayout);-
1715 if (FieldGrowthPolicy(d->fieldGrowthPolicy) != policy) {
FieldGrowthPol...icy) != policyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1716 d->fieldGrowthPolicy = policy;-
1717 invalidate();-
1718 }
never executed: end of block
0
1719}
never executed: end of block
0
1720-
1721QFormLayout::FieldGrowthPolicy QFormLayout::fieldGrowthPolicy() const-
1722{-
1723 Q_D(const QFormLayout);-
1724 if (d->fieldGrowthPolicy == DefaultFieldGrowthPolicy) {
d->fieldGrowth...ldGrowthPolicyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1725 return QFormLayout::FieldGrowthPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutFieldGrowthPolicy));
never executed: return QFormLayout::FieldGrowthPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutFieldGrowthPolicy));
0
1726 } else {-
1727 return QFormLayout::FieldGrowthPolicy(d->fieldGrowthPolicy);
never executed: return QFormLayout::FieldGrowthPolicy(d->fieldGrowthPolicy);
0
1728 }-
1729}-
1730-
1731/*!-
1732 \property QFormLayout::rowWrapPolicy-
1733 \brief the way in which the form's rows wrap-
1734-
1735 The default value depends on the widget or application style. For-
1736 Qt Extended styles, the default is WrapLongRows;-
1737 for the other styles, the default is DontWrapRows.-
1738-
1739 If you want to display each label above its associated field-
1740 (instead of next to it), set this property to WrapAllRows.-
1741-
1742 \sa fieldGrowthPolicy-
1743*/-
1744-
1745void QFormLayout::setRowWrapPolicy(RowWrapPolicy policy)-
1746{-
1747 Q_D(QFormLayout);-
1748 if (RowWrapPolicy(d->rowWrapPolicy) != policy) {
RowWrapPolicy(...icy) != policyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1749 d->rowWrapPolicy = policy;-
1750 invalidate();-
1751 }
never executed: end of block
0
1752}
never executed: end of block
0
1753-
1754QFormLayout::RowWrapPolicy QFormLayout::rowWrapPolicy() const-
1755{-
1756 Q_D(const QFormLayout);-
1757 if (d->rowWrapPolicy == DefaultRowWrapPolicy) {
d->rowWrapPoli...tRowWrapPolicyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1758 return QFormLayout::RowWrapPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutWrapPolicy));
never executed: return QFormLayout::RowWrapPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutWrapPolicy));
0
1759 } else {-
1760 return QFormLayout::RowWrapPolicy(d->rowWrapPolicy);
never executed: return QFormLayout::RowWrapPolicy(d->rowWrapPolicy);
0
1761 }-
1762}-
1763-
1764/*!-
1765 \property QFormLayout::labelAlignment-
1766 \brief the horizontal alignment of the labels-
1767-
1768 The default value depends on the widget or application style. For-
1769 QCommonStyle derived styles, except for QPlastiqueStyle, the-
1770 default is Qt::AlignLeft; for the other styles, the default is-
1771 Qt::AlignRight.-
1772-
1773 \sa formAlignment-
1774*/-
1775-
1776void QFormLayout::setLabelAlignment(Qt::Alignment alignment)-
1777{-
1778 Q_D(QFormLayout);-
1779 if (d->labelAlignment != alignment) {
d->labelAlignment != alignmentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1780 d->labelAlignment = alignment;-
1781 invalidate();-
1782 }
never executed: end of block
0
1783}
never executed: end of block
0
1784-
1785Qt::Alignment QFormLayout::labelAlignment() const-
1786{-
1787 Q_D(const QFormLayout);-
1788 if (!d->labelAlignment) {
!d->labelAlignmentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1789 return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
never executed: return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
0
1790 } else {-
1791 return d->labelAlignment;
never executed: return d->labelAlignment;
0
1792 }-
1793}-
1794-
1795/*!-
1796 \property QFormLayout::formAlignment-
1797 \brief the alignment of the form layout's contents within the layout's geometry-
1798-
1799 The default value depends on the widget or application style. For-
1800 QMacStyle, the default is Qt::AlignHCenter | Qt::AlignTop; for the-
1801 other styles, the default is Qt::AlignLeft | Qt::AlignTop.-
1802-
1803 \sa labelAlignment, rowWrapPolicy-
1804*/-
1805-
1806void QFormLayout::setFormAlignment(Qt::Alignment alignment)-
1807{-
1808 Q_D(QFormLayout);-
1809 if (d->formAlignment != alignment) {
d->formAlignment != alignmentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1810 d->formAlignment = alignment;-
1811 invalidate();-
1812 }
never executed: end of block
0
1813}
never executed: end of block
0
1814-
1815Qt::Alignment QFormLayout::formAlignment() const-
1816{-
1817 Q_D(const QFormLayout);-
1818 if (!d->formAlignment) {
!d->formAlignmentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1819 return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutFormAlignment));
never executed: return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutFormAlignment));
0
1820 } else {-
1821 return d->formAlignment;
never executed: return d->formAlignment;
0
1822 }-
1823}-
1824-
1825/*!-
1826 \property QFormLayout::horizontalSpacing-
1827 \brief the spacing between widgets that are laid out side by side-
1828-
1829 By default, if no value is explicitly set, the layout's horizontal-
1830 spacing is inherited from the parent layout, or from the style settings-
1831 for the parent widget.-
1832-
1833 \sa verticalSpacing, QStyle::pixelMetric(), {QStyle::}{PM_LayoutHorizontalSpacing}-
1834*/-
1835void QFormLayout::setHorizontalSpacing(int spacing)-
1836{-
1837 Q_D(QFormLayout);-
1838 if (spacing != d->hSpacing) {
spacing != d->hSpacingDescription
TRUEnever evaluated
FALSEnever evaluated
0
1839 d->hSpacing = spacing;-
1840 invalidate();-
1841 }
never executed: end of block
0
1842}
never executed: end of block
0
1843-
1844int QFormLayout::horizontalSpacing() const-
1845{-
1846 Q_D(const QFormLayout);-
1847 if (d->hSpacing >= 0) {
d->hSpacing >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1848 return d->hSpacing;
never executed: return d->hSpacing;
0
1849 } else {-
1850 return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);
never executed: return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);
0
1851 }-
1852}-
1853-
1854/*!-
1855 \property QFormLayout::verticalSpacing-
1856 \brief the spacing between widgets that are laid out vertically-
1857-
1858 By default, if no value is explicitly set, the layout's vertical spacing is-
1859 inherited from the parent layout, or from the style settings for the parent-
1860 widget.-
1861-
1862 \sa horizontalSpacing, QStyle::pixelMetric(), {QStyle::}{PM_LayoutHorizontalSpacing}-
1863*/-
1864void QFormLayout::setVerticalSpacing(int spacing)-
1865{-
1866 Q_D(QFormLayout);-
1867 if (spacing != d->vSpacing) {
spacing != d->vSpacingDescription
TRUEnever evaluated
FALSEnever evaluated
0
1868 d->vSpacing = spacing;-
1869 invalidate();-
1870 }
never executed: end of block
0
1871}
never executed: end of block
0
1872-
1873int QFormLayout::verticalSpacing() const-
1874{-
1875 Q_D(const QFormLayout);-
1876 if (d->vSpacing >= 0) {
d->vSpacing >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1877 return d->vSpacing;
never executed: return d->vSpacing;
0
1878 } else {-
1879 return qSmartSpacing(this, QStyle::PM_LayoutVerticalSpacing);
never executed: return qSmartSpacing(this, QStyle::PM_LayoutVerticalSpacing);
0
1880 }-
1881}-
1882-
1883/*!-
1884 This function sets both the vertical and horizontal spacing to-
1885 \a spacing.-
1886-
1887 \sa setVerticalSpacing(), setHorizontalSpacing()-
1888*/-
1889void QFormLayout::setSpacing(int spacing)-
1890{-
1891 Q_D(QFormLayout);-
1892 d->vSpacing = d->hSpacing = spacing;-
1893 invalidate();-
1894}
never executed: end of block
0
1895-
1896/*!-
1897 If the vertical spacing is equal to the horizontal spacing,-
1898 this function returns that value; otherwise it returns -1.-
1899-
1900 \sa setSpacing(), verticalSpacing(), horizontalSpacing()-
1901*/-
1902int QFormLayout::spacing() const-
1903{-
1904 int hSpacing = horizontalSpacing();-
1905 if (hSpacing == verticalSpacing()) {
hSpacing == verticalSpacing()Description
TRUEnever evaluated
FALSEnever evaluated
0
1906 return hSpacing;
never executed: return hSpacing;
0
1907 } else {-
1908 return -1;
never executed: return -1;
0
1909 }-
1910}-
1911-
1912void QFormLayoutPrivate::arrangeWidgets(const QVector<QLayoutStruct>& layouts, QRect &rect)-
1913{-
1914 Q_Q(QFormLayout);-
1915-
1916 int i;-
1917 const int rr = m_matrix.rowCount();-
1918 QWidget *w = q->parentWidget();-
1919 Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : QApplication::layoutDirection();
wDescription
TRUEnever evaluated
FALSEnever evaluated
0
1920-
1921 Qt::Alignment formAlignment = fixedAlignment(q->formAlignment(), layoutDirection);-
1922 int leftOffset = 0;-
1923 int delta = rect.width() - formMaxWidth;-
1924 if (formAlignment & (Qt::AlignHCenter | Qt::AlignRight) && delta > 0) {
formAlignment ...t::AlignRight)Description
TRUEnever evaluated
FALSEnever evaluated
delta > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1925 leftOffset = delta;-
1926 if (formAlignment & Qt::AlignHCenter)
formAlignment ...::AlignHCenterDescription
TRUEnever evaluated
FALSEnever evaluated
0
1927 leftOffset >>= 1;
never executed: leftOffset >>= 1;
0
1928 }
never executed: end of block
0
1929-
1930 for (i = 0; i < rr; ++i) {
i < rrDescription
TRUEnever evaluated
FALSEnever evaluated
0
1931 QFormLayoutItem *label = m_matrix(i, 0);-
1932 QFormLayoutItem *field = m_matrix(i, 1);-
1933-
1934 if (label) {
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1935 int height = layouts.at(label->vLayoutIndex).size;-
1936 if ((label->expandingDirections() & Qt::Vertical) == 0) {
(label->expand...Vertical) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1937 /*-
1938 If the field on the right-hand side is tall,-
1939 we want the label to be top-aligned, but not too-
1940 much. So we introduce a 7 / 4 factor so that it-
1941 gets some extra pixels at the top.-
1942 */-
1943 height = qMin(height,-
1944 qMin(label->sizeHint.height() * 7 / 4,-
1945 label->maxSize.height()));-
1946 }
never executed: end of block
0
1947-
1948 QSize sz(qMin(label->layoutWidth, label->sizeHint.width()), height);-
1949 int x = leftOffset + rect.x() + label->layoutPos;-
1950 if (fixedAlignment(q->labelAlignment(), layoutDirection) & Qt::AlignRight)
fixedAlignment...Qt::AlignRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1951 x += label->layoutWidth - sz.width();
never executed: x += label->layoutWidth - sz.width();
0
1952 QPoint p(x, layouts.at(label->vLayoutIndex).pos);-
1953 // ### expansion & sizepolicy stuff-
1954-
1955 label->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz)));-
1956 }
never executed: end of block
0
1957-
1958 if (field) {
fieldDescription
TRUEnever evaluated
FALSEnever evaluated
0
1959 QSize sz(field->layoutWidth, layouts.at(field->vLayoutIndex).size);-
1960 QPoint p(field->layoutPos + leftOffset + rect.x(), layouts.at(field->vLayoutIndex).pos);-
1961/*-
1962 if ((field->widget() && field->widget()->sizePolicy().horizontalPolicy() & (QSizePolicy::GrowFlag | QSizePolicy::ExpandFlag | QSizePolicy::IgnoreFlag))-
1963 || (field->layout() && sz.width() < field->maxSize.width())) {-
1964 sz.rwidth() = field->layoutWidth;-
1965 }-
1966*/-
1967 if (field->maxSize.isValid())
field->maxSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1968 sz = sz.boundedTo(field->maxSize);
never executed: sz = sz.boundedTo(field->maxSize);
0
1969-
1970 field->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz)));-
1971 }
never executed: end of block
0
1972 }
never executed: end of block
0
1973}
never executed: end of block
0
1974-
1975/*!-
1976 Sets the widget in the given \a row for the given \a role to \a widget, extending the-
1977 layout with empty rows if necessary.-
1978-
1979 If the cell is already occupied, the \a widget is not inserted and an error message is-
1980 sent to the console.-
1981-
1982 \b{Note:} For most applications, addRow() or insertRow() should be used instead of setWidget().-
1983-
1984 \sa setLayout()-
1985*/-
1986void QFormLayout::setWidget(int row, ItemRole role, QWidget *widget)-
1987{-
1988 Q_D(QFormLayout);-
1989 int rowCnt = rowCount();-
1990 if (row >= rowCnt)
row >= rowCntDescription
TRUEnever evaluated
FALSEnever evaluated
0
1991 d->insertRows(rowCnt, row - rowCnt + 1);
never executed: d->insertRows(rowCnt, row - rowCnt + 1);
0
1992 d->setWidget(row, role, widget);-
1993}
never executed: end of block
0
1994-
1995/*!-
1996 Sets the sub-layout in the given \a row for the given \a role to \a layout, extending the-
1997 form layout with empty rows if necessary.-
1998-
1999 If the cell is already occupied, the \a layout is not inserted and an error message is-
2000 sent to the console.-
2001-
2002 \b{Note:} For most applications, addRow() or insertRow() should be used instead of setLayout().-
2003-
2004 \sa setWidget()-
2005*/-
2006void QFormLayout::setLayout(int row, ItemRole role, QLayout *layout)-
2007{-
2008 Q_D(QFormLayout);-
2009 int rowCnt = rowCount();-
2010 if (row >= rowCnt)
row >= rowCntDescription
TRUEnever evaluated
FALSEnever evaluated
0
2011 d->insertRows(rowCnt, row - rowCnt + 1);
never executed: d->insertRows(rowCnt, row - rowCnt + 1);
0
2012 d->setLayout(row, role, layout);-
2013}
never executed: end of block
0
2014-
2015/*!-
2016 Sets the item in the given \a row for the given \a role to \a item, extending the-
2017 layout with empty rows if necessary.-
2018-
2019 If the cell is already occupied, the \a item is not inserted and an error message is-
2020 sent to the console.-
2021 The \a item spans both columns.-
2022-
2023 \warning Do not use this function to add child layouts or child-
2024 widget items. Use setLayout() or setWidget() instead.-
2025-
2026 \sa setLayout()-
2027*/-
2028void QFormLayout::setItem(int row, ItemRole role, QLayoutItem *item)-
2029{-
2030 Q_D(QFormLayout);-
2031 int rowCnt = rowCount();-
2032 if (row >= rowCnt)
row >= rowCntDescription
TRUEnever evaluated
FALSEnever evaluated
0
2033 d->insertRows(rowCnt, row - rowCnt + 1);
never executed: d->insertRows(rowCnt, row - rowCnt + 1);
0
2034 d->setItem(row, role, item);-
2035}
never executed: end of block
0
2036-
2037/*!-
2038 \internal-
2039 */-
2040-
2041void QFormLayout::resetFieldGrowthPolicy()-
2042{-
2043 Q_D(QFormLayout);-
2044 d->fieldGrowthPolicy = DefaultFieldGrowthPolicy;-
2045}
never executed: end of block
0
2046-
2047/*!-
2048 \internal-
2049 */-
2050-
2051void QFormLayout::resetRowWrapPolicy()-
2052{-
2053 Q_D(QFormLayout);-
2054 d->rowWrapPolicy = DefaultRowWrapPolicy;-
2055}
never executed: end of block
0
2056-
2057/*!-
2058 \internal-
2059 */-
2060-
2061void QFormLayout::resetFormAlignment()-
2062{-
2063 Q_D(QFormLayout);-
2064 d->formAlignment = 0;-
2065}
never executed: end of block
0
2066-
2067/*!-
2068 \internal-
2069 */-
2070-
2071void QFormLayout::resetLabelAlignment()-
2072{-
2073 Q_D(QFormLayout);-
2074 d->labelAlignment = 0;-
2075}
never executed: end of block
0
2076-
2077#if 0-
2078void QFormLayout::dump() const-
2079{-
2080 Q_D(const QFormLayout);-
2081 for (int i = 0; i < rowCount(); ++i) {-
2082 for (int j = 0; j < 2; ++j) {-
2083 qDebug("m_matrix(%d, %d) = %p", i, j, d->m_matrix(i, j));-
2084 }-
2085 }-
2086 for (int i = 0; i < d->m_things.count(); ++i)-
2087 qDebug("m_things[%d] = %p", i, d->m_things.at(i));-
2088}-
2089#endif-
2090-
2091QT_END_NAMESPACE-
2092-
2093#include "moc_qformlayout.cpp"-
Source codeSwitch to Preprocessed file

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