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 test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29
30#include <QtTest/QtTest>
31#include <qlayout.h>
32#include <qapplication.h>
33#include <qwidget.h>
34#include <qproxystyle.h>
35#include <qsizepolicy.h>
36
37#include <QtWidgets/QCheckBox>
38#include <QtWidgets/QLabel>
39#include <QtWidgets/QLineEdit>
40#include <QtWidgets/QPushButton>
41#include <QStyleFactory>
42#include <QSharedPointer>
43
44#include <qformlayout.h>
45
46// ItemRole has enumerators for numerical values 0..2, thus the only
47// valid numerical values for storing into an ItemRole variable are 0..3:
48Q_CONSTEXPR QFormLayout::ItemRole invalidRole = QFormLayout::ItemRole(3);
49
50static inline void setFrameless(QWidget *w)
51{
52 Qt::WindowFlags flags = w->windowFlags();
53 flags |= Qt::FramelessWindowHint;
54 flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
55 w->setWindowFlags(flags);
56}
57
58struct QFormLayoutTakeRowResultHolder {
59 QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) Q_DECL_NOTHROW
60 : labelItem(result.labelItem),
61 fieldItem(result.fieldItem)
62 {
63 }
64 ~QFormLayoutTakeRowResultHolder()
65 {
66 // re-use a QFormLayout to recursively reap the QLayoutItems:
67 QFormLayout disposer;
68 if (labelItem)
69 disposer.setItem(0, QFormLayout::LabelRole, labelItem);
70 if (fieldItem)
71 disposer.setItem(0, QFormLayout::FieldRole, fieldItem);
72 }
73 QFormLayoutTakeRowResultHolder(QFormLayoutTakeRowResultHolder &&other) Q_DECL_NOTHROW
74 : labelItem(other.labelItem),
75 fieldItem(other.fieldItem)
76 {
77 other.labelItem = nullptr;
78 other.fieldItem = nullptr;
79 }
80 QFormLayoutTakeRowResultHolder &operator=(QFormLayoutTakeRowResultHolder &&other) Q_DECL_NOTHROW
81 {
82 swap(other);
83 return *this;
84 }
85
86 void swap(QFormLayoutTakeRowResultHolder &other) Q_DECL_NOTHROW
87 {
88 qSwap(labelItem, other.labelItem);
89 qSwap(fieldItem, other.fieldItem);
90 }
91
92 QLayoutItem *labelItem;
93 QLayoutItem *fieldItem;
94};
95
96class tst_QFormLayout : public QObject
97{
98 Q_OBJECT
99
100private slots:
101 void cleanup();
102 void rowCount();
103 void buddies();
104 void getItemPosition();
105 void wrapping();
106 void spacing();
107 void contentsRect();
108
109 void setFormStyle();
110 void setFieldGrowthPolicy();
111 void setRowWrapPolicy();
112 void setLabelAlignment();
113 void setFormAlignment();
114
115/*
116 void setHorizontalSpacing(int spacing);
117 int horizontalSpacing() const;
118 void setVerticalSpacing(int spacing);
119 int verticalSpacing() const;
120*/
121
122 void addRow();
123 void insertRow_QWidget_QWidget();
124 void insertRow_QWidget_QLayout();
125 void insertRow_QString_QWidget();
126 void insertRow_QString_QLayout();
127 void insertRow_QWidget();
128 void insertRow_QLayout();
129 void removeRow();
130 void removeRow_QWidget();
131 void removeRow_QLayout();
132 void takeRow();
133 void takeRow_QWidget();
134 void takeRow_QLayout();
135 void setWidget();
136 void setLayout();
137
138/*
139 QLayoutItem *itemAt(int row, ItemRole role) const;
140 void getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const;
141 void getLayoutPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const;
142 void getItemPosition(QLayoutItem *item, int *rowPtr, ItemRole *rolePtr) const;
143 QWidget *labelForField(QWidget *widget) const;
144 QWidget *labelForField(QLayoutItem *item) const;
145
146 void addItem(QLayoutItem *item);
147*/
148
149 void itemAt();
150 void takeAt();
151 void layoutAlone();
152 void replaceWidget();
153/*
154 void setGeometry(const QRect &rect);
155 QSize minimumSize() const;
156 QSize sizeHint() const;
157
158 bool hasHeightForWidth() const;
159 int heightForWidth(int width) const;
160 Qt::Orientations expandingDirections() const;
161*/
162
163 void taskQTBUG_27420_takeAtShouldUnparentLayout();
164 void taskQTBUG_40609_addingWidgetToItsOwnLayout();
165 void taskQTBUG_40609_addingLayoutToItself();
166
167};
168
169void tst_QFormLayout::cleanup()
170{
171 QVERIFY(QApplication::topLevelWidgets().isEmpty());
172}
173
174void tst_QFormLayout::rowCount()
175{
176 QWidget w;
177 QFormLayout *fl = new QFormLayout(&w);
178
179 fl->addRow(tr("Label 1"), new QLineEdit);
180 fl->addRow(tr("Label 2"), new QLineEdit);
181 fl->addRow(tr("Label 3"), new QLineEdit);
182 QCOMPARE(fl->rowCount(), 3);
183
184 fl->addRow(new QWidget);
185 fl->addRow(new QHBoxLayout);
186 QCOMPARE(fl->rowCount(), 5);
187
188 fl->insertRow(1, tr("Label 0.5"), new QLineEdit);
189 QCOMPARE(fl->rowCount(), 6);
190
191 //TODO: remove items
192}
193
194void tst_QFormLayout::buddies()
195{
196 QWidget w;
197 QFormLayout *fl = new QFormLayout(&w);
198
199 //normal buddy case
200 QLineEdit *le = new QLineEdit;
201 fl->addRow(tr("Label 1"), le);
202 QLabel *label = qobject_cast<QLabel *>(fl->labelForField(le));
203 QVERIFY(label);
204 QWidget *lew = le;
205 QCOMPARE(label->buddy(), lew);
206
207 //null label
208 QLineEdit *le2 = new QLineEdit;
209 fl->addRow(0, le2);
210 QWidget *label2 = fl->labelForField(le2);
211 QVERIFY(!label2);
212
213 //no label
214 QLineEdit *le3 = new QLineEdit;
215 fl->addRow(le3);
216 QWidget *label3 = fl->labelForField(le3);
217 QVERIFY(!label3);
218
219 //TODO: empty label?
220}
221
222void tst_QFormLayout::getItemPosition()
223{
224 QWidget w;
225 QFormLayout *fl = new QFormLayout(&w);
226
227 QList<QLabel*> labels;
228 QList<QLineEdit*> fields;
229 for (int i = 0; i < 5; ++i) {
230 labels.append(new QLabel(QLatin1String("Label " ) + QString::number(i + 1)));
231 fields.append(new QLineEdit);
232 fl->addRow(labels[i], fields[i]);
233 }
234
235 //a field
236 {
237 int row;
238 QFormLayout::ItemRole role;
239 fl->getWidgetPosition(fields[3], &row, &role);
240 QCOMPARE(row, 3);
241 QCOMPARE(role, QFormLayout::FieldRole);
242 }
243
244 //a label
245 {
246 int row;
247 QFormLayout::ItemRole role;
248 fl->getWidgetPosition(labels[2], &row, &role);
249 QCOMPARE(row, 2);
250 QCOMPARE(role, QFormLayout::LabelRole);
251 }
252
253 //a layout that's been inserted
254 {
255 QVBoxLayout *vbl = new QVBoxLayout;
256 fl->insertRow(2, "Label 1.5", vbl);
257 int row;
258 QFormLayout::ItemRole role;
259 fl->getLayoutPosition(vbl, &row, &role);
260 QCOMPARE(row, 2);
261 QCOMPARE(role, QFormLayout::FieldRole);
262 }
263}
264
265void tst_QFormLayout::wrapping()
266{
267 QWidget w;
268 QFormLayout *fl = new QFormLayout(&w);
269 fl->setRowWrapPolicy(QFormLayout::WrapLongRows);
270
271 QLineEdit *le = new QLineEdit;
272 QLabel *lbl = new QLabel("A long label");
273 le->setMinimumWidth(200);
274 fl->addRow(lbl, le);
275
276 w.setFixedWidth(240);
277 w.setWindowTitle(QTest::currentTestFunction());
278 w.show();
279
280 QCOMPARE(le->geometry().y() > lbl->geometry().y(), true);
281
282 //TODO: additional tests covering different wrapping cases
283}
284
285class CustomLayoutStyle : public QProxyStyle
286{
287 Q_OBJECT
288public:
289 CustomLayoutStyle() : QProxyStyle(QStyleFactory::create("windows"))
290 {
291 hspacing = 5;
292 vspacing = 10;
293 }
294
295 virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
296 const QWidget * widget = 0 ) const;
297
298 int hspacing;
299 int vspacing;
300};
301
302int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/,
303 const QWidget * widget /*= 0*/ ) const
304{
305 switch (metric) {
306 case PM_LayoutHorizontalSpacing:
307 return hspacing;
308 case PM_LayoutVerticalSpacing:
309 return vspacing;
310 break;
311 default:
312 break;
313 }
314 return QProxyStyle::pixelMetric(metric, option, widget);
315}
316
317void tst_QFormLayout::spacing()
318{
319 //TODO: confirm spacing behavior
320 QWidget w;
321 QScopedPointer<CustomLayoutStyle> style(new CustomLayoutStyle);
322 style->hspacing = 5;
323 style->vspacing = 10;
324 w.setStyle(style.data());
325 QFormLayout *fl = new QFormLayout(&w);
326 QCOMPARE(style->hspacing, fl->horizontalSpacing());
327 QCOMPARE(style->vspacing, fl->verticalSpacing());
328
329 //QCOMPARE(fl->spacing(), -1);
330 fl->setVerticalSpacing(5);
331 QCOMPARE(5, fl->horizontalSpacing());
332 QCOMPARE(5, fl->verticalSpacing());
333 //QCOMPARE(fl->spacing(), 5);
334 fl->setVerticalSpacing(-1);
335 QCOMPARE(style->hspacing, fl->horizontalSpacing());
336 QCOMPARE(style->vspacing, fl->verticalSpacing());
337
338 style->hspacing = 5;
339 style->vspacing = 5;
340 //QCOMPARE(fl->spacing(), 5);
341
342 fl->setHorizontalSpacing(20);
343 //QCOMPARE(fl->spacing(), -1);
344 style->vspacing = 20;
345 QCOMPARE(fl->horizontalSpacing(), 20);
346 QCOMPARE(fl->verticalSpacing(), 20);
347 //QCOMPARE(fl->spacing(), 20);
348 fl->setHorizontalSpacing(-1);
349 //QCOMPARE(fl->spacing(), -1);
350 style->hspacing = 20;
351 //QCOMPARE(fl->spacing(), 20);
352
353
354
355 // Do not assert if spacings are negative (QTBUG-34731)
356 style->vspacing = -1;
357 style->hspacing = -1;
358 QLabel *label = new QLabel(tr("Asserts"));
359 QCheckBox *checkBox = new QCheckBox(tr("Yes"));
360 fl->setWidget(0, QFormLayout::LabelRole, label);
361 fl->setWidget(1, QFormLayout::FieldRole, checkBox);
362 w.resize(200, 100);
363 w.setWindowTitle(QTest::currentTestFunction());
364 w.show();
365 QVERIFY(QTest::qWaitForWindowExposed(&w));
366}
367
368void tst_QFormLayout::contentsRect()
369{
370 QWidget w;
371 setFrameless(&w);
372 QFormLayout form;
373 w.setLayout(&form);
374 form.addRow("Label", new QPushButton(&w));
375 w.setWindowTitle(QTest::currentTestFunction());
376 w.show();
377 QVERIFY(QTest::qWaitForWindowExposed(&w));
378 int l, t, r, b;
379 form.getContentsMargins(&l, &t, &r, &b);
380 QRect geom = form.geometry();
381
382 QCOMPARE(geom.adjusted(+l, +t, -r, -b), form.contentsRect());
383}
384
385
386class DummyMacStyle : public QCommonStyle
387{
388public:
389 virtual int styleHint ( StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, QStyleHintReturn * returnData = 0 ) const
390 {
391 switch(hint) {
392 case SH_FormLayoutFormAlignment:
393 return Qt::AlignHCenter | Qt::AlignTop;
394 case SH_FormLayoutLabelAlignment:
395 return Qt::AlignRight;
396 case SH_FormLayoutWrapPolicy:
397 return QFormLayout::DontWrapRows;
398 case SH_FormLayoutFieldGrowthPolicy:
399 return QFormLayout::FieldsStayAtSizeHint;
400 default:
401 return QCommonStyle::styleHint(hint, option, widget, returnData);
402 }
403 }
404};
405
406class DummyQtopiaStyle : public QCommonStyle
407{
408public:
409 virtual int styleHint ( StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, QStyleHintReturn * returnData = 0 ) const
410 {
411 switch(hint) {
412 case SH_FormLayoutFormAlignment:
413 return Qt::AlignLeft | Qt::AlignTop;
414 case SH_FormLayoutLabelAlignment:
415 return Qt::AlignRight;
416 case SH_FormLayoutWrapPolicy:
417 return QFormLayout::WrapLongRows;
418 case SH_FormLayoutFieldGrowthPolicy:
419 return QFormLayout::AllNonFixedFieldsGrow;
420 default:
421 return QCommonStyle::styleHint(hint, option, widget, returnData);
422 }
423 }
424};
425
426void tst_QFormLayout::setFormStyle()
427{
428 QWidget widget;
429 QFormLayout layout;
430 widget.setLayout(&layout);
431
432#if 0 // QT_NO_STYLE_PLASTIQUE
433 widget.setStyle(new QPlastiqueStyle());
434
435 QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
436 QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
437 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::ExpandingFieldsGrow);
438 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
439#endif
440
441 const QScopedPointer<QStyle> windowsStyle(QStyleFactory::create("windows"));
442 widget.setStyle(windowsStyle.data());
443
444 QCOMPARE(layout.labelAlignment(), Qt::AlignLeft);
445 QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
446 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::AllNonFixedFieldsGrow);
447 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
448
449 /* can't directly create mac style or qtopia style, since
450 this test is cross platform.. so create dummy styles that
451 return all the right stylehints.
452 */
453 DummyMacStyle macStyle;
454 widget.setStyle(&macStyle);
455
456 QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
457 QVERIFY(layout.formAlignment() == (Qt::AlignHCenter | Qt::AlignTop));
458 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::FieldsStayAtSizeHint);
459 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
460
461 DummyQtopiaStyle qtopiaStyle;
462 widget.setStyle(&qtopiaStyle);
463
464 QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
465 QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
466 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::AllNonFixedFieldsGrow);
467 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::WrapLongRows);
468}
469
470void tst_QFormLayout::setFieldGrowthPolicy()
471{
472 QWidget window;
473 QLineEdit fld1, fld2, fld3;
474 fld1.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
475 fld2.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
476 fld3.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
477
478 QFormLayout layout;
479 layout.addRow("One:", &fld1);
480 layout.addRow("Two:", &fld2);
481 layout.addRow("Three:", &fld3);
482 window.setLayout(&layout);
483 window.resize(1000, 200);
484
485 for (int i = 0; i < 3; ++i) {
486 layout.setFieldGrowthPolicy(i == 0 ? QFormLayout::FieldsStayAtSizeHint :
487 i == 1 ? QFormLayout::ExpandingFieldsGrow :
488 QFormLayout::AllNonFixedFieldsGrow);
489 layout.activate();
490
491 if (i == 0) {
492 QCOMPARE(fld1.width(), fld2.width());
493 QCOMPARE(fld2.width(), fld3.width());
494 } else if (i == 1) {
495 QCOMPARE(fld1.width(), fld2.width());
496 QVERIFY(fld2.width() < fld3.width());
497 } else {
498 QVERIFY(fld1.width() < fld2.width());
499 QCOMPARE(fld2.width(), fld3.width());
500 }
501 }
502}
503
504void tst_QFormLayout::setRowWrapPolicy()
505{
506}
507
508void tst_QFormLayout::setLabelAlignment()
509{
510}
511
512void tst_QFormLayout::setFormAlignment()
513{
514}
515
516void tst_QFormLayout::addRow()
517{
518 QWidget topLevel;
519 QFormLayout *layout = new QFormLayout(&topLevel);
520 QWidget *w1 = new QWidget(&topLevel);
521 QWidget *w2 = new QWidget(&topLevel);
522 QWidget *w3 = new QWidget(&topLevel);
523 QHBoxLayout *l1 = new QHBoxLayout;
524 QHBoxLayout *l2 = new QHBoxLayout;
525 QHBoxLayout *l3 = new QHBoxLayout;
526 QLabel *lbl1 = new QLabel(&topLevel);
527 QLabel *lbl2 = new QLabel(&topLevel);
528
529 QCOMPARE(layout->rowCount(), 0);
530
531 layout->addRow(lbl1, w1);
532 layout->addRow(lbl2, l1);
533 layout->addRow("Foo:", w2);
534 layout->addRow("Bar:", l2);
535 layout->addRow(w3);
536 layout->addRow(l3);
537
538 QCOMPARE(layout->rowCount(), 6);
539
540 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
541 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
542 QCOMPARE(layout->itemAt(2, QFormLayout::LabelRole)->widget()->property("text").toString(), QLatin1String("Foo:"));
543 QCOMPARE(layout->itemAt(3, QFormLayout::LabelRole)->widget()->property("text").toString(), QLatin1String("Bar:"));
544 QVERIFY(layout->itemAt(4, QFormLayout::LabelRole) == 0);
545 QVERIFY(layout->itemAt(5, QFormLayout::LabelRole) == 0);
546
547 QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->widget() == w1);
548 QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->layout() == l1);
549 QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->widget() == w2);
550 QVERIFY(layout->itemAt(3, QFormLayout::FieldRole)->layout() == l2);
551// ### should have a third role, FullRowRole?
552// QVERIFY(layout.itemAt(4, QFormLayout::FieldRole) == 0);
553// QVERIFY(layout.itemAt(5, QFormLayout::FieldRole) == 0);
554}
555
556void tst_QFormLayout::insertRow_QWidget_QWidget()
557{
558 QWidget topLevel;
559 QFormLayout *layout = new QFormLayout(&topLevel);
560 QLabel *lbl1 = new QLabel(&topLevel);
561 QLabel *lbl2 = new QLabel(&topLevel);
562 QLabel *lbl3 = new QLabel(&topLevel);
563 QLabel *lbl4 = new QLabel(&topLevel);
564 QLineEdit *fld1 = new QLineEdit(&topLevel);
565 QLineEdit *fld2 = new QLineEdit(&topLevel);
566 QLineEdit *fld3 = new QLineEdit(&topLevel);
567 QLineEdit *fld4 = new QLineEdit(&topLevel);
568
569 layout->insertRow(0, lbl1, fld1);
570 QCOMPARE(layout->rowCount(), 1);
571
572 {
573 int row = -1;
574 QFormLayout::ItemRole role = invalidRole;
575 layout->getWidgetPosition(lbl1, &row, &role);
576 QCOMPARE(row, 0);
577 QCOMPARE(int(role), int(QFormLayout::LabelRole));
578 }
579
580 {
581 int row = -1;
582 QFormLayout::ItemRole role = invalidRole;
583 layout->getWidgetPosition(fld1, &row, &role);
584 QCOMPARE(row, 0);
585 QCOMPARE(int(role), int(QFormLayout::FieldRole));
586 }
587
588 // check that negative values append
589 layout->insertRow(-2, lbl2, fld2);
590 QCOMPARE(layout->rowCount(), 2);
591
592 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
593 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
594
595 // check that too large values append
596 layout->insertRow(100, lbl3, fld3);
597 QCOMPARE(layout->rowCount(), 3);
598 QCOMPARE(layout->count(), 6);
599
600 layout->insertRow(3, (QWidget *)0, (QWidget *)0);
601 QCOMPARE(layout->rowCount(), 4);
602 QCOMPARE(layout->count(), 6);
603
604 layout->insertRow(4, (QWidget *)0, fld4);
605 QCOMPARE(layout->rowCount(), 5);
606 QCOMPARE(layout->count(), 7);
607
608 layout->insertRow(5, lbl4, (QWidget *)0);
609 QCOMPARE(layout->rowCount(), 6);
610 QCOMPARE(layout->count(), 8);
611
612 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
613 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
614 QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget() == lbl3);
615 QVERIFY(layout->itemAt(3, QFormLayout::LabelRole) == 0);
616 QVERIFY(layout->itemAt(4, QFormLayout::LabelRole) == 0);
617 QVERIFY(layout->itemAt(5, QFormLayout::LabelRole)->widget() == lbl4);
618
619 QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->widget() == fld1);
620 QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->widget() == fld2);
621 QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->widget() == fld3);
622 QVERIFY(layout->itemAt(3, QFormLayout::FieldRole) == 0);
623 QVERIFY(layout->itemAt(4, QFormLayout::FieldRole)->widget() == fld4);
624 QVERIFY(layout->itemAt(5, QFormLayout::FieldRole) == 0);
625}
626
627void tst_QFormLayout::insertRow_QWidget_QLayout()
628{
629 QWidget topLevel;
630 QFormLayout *layout = new QFormLayout(&topLevel);
631 QLabel *lbl1 = new QLabel(&topLevel);
632 QLabel *lbl2 = new QLabel(&topLevel);
633 QLabel *lbl3 = new QLabel(&topLevel);
634 QHBoxLayout *fld1 = new QHBoxLayout;
635 QHBoxLayout *fld2 = new QHBoxLayout;
636 QHBoxLayout *fld3 = new QHBoxLayout;
637
638 layout->insertRow(0, lbl1, fld1);
639 QCOMPARE(layout->rowCount(), 1);
640
641 {
642 int row = -1;
643 QFormLayout::ItemRole role = invalidRole;
644 layout->getWidgetPosition(lbl1, &row, &role);
645 QCOMPARE(row, 0);
646 QCOMPARE(int(role), int(QFormLayout::LabelRole));
647 }
648
649 {
650 int row = -1;
651 QFormLayout::ItemRole role = invalidRole;
652 layout->getLayoutPosition(fld1, &row, &role);
653 QCOMPARE(row, 0);
654 QCOMPARE(int(role), int(QFormLayout::FieldRole));
655 }
656
657 // check that negative values append
658 layout->insertRow(-2, lbl2, fld2);
659 QCOMPARE(layout->rowCount(), 2);
660
661 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
662 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
663
664 // check that too large values append
665 layout->insertRow(100, lbl3, fld3);
666 QCOMPARE(layout->rowCount(), 3);
667
668 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
669 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
670 QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget() == lbl3);
671
672 QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->layout() == fld1);
673 QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->layout() == fld2);
674 QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->layout() == fld3);
675}
676
677void tst_QFormLayout::insertRow_QString_QWidget()
678{
679 QWidget topLevel;
680 QFormLayout *layout = new QFormLayout(&topLevel);
681 QLineEdit *fld1 = new QLineEdit(&topLevel);
682 QLineEdit *fld2 = new QLineEdit(&topLevel);
683 QLineEdit *fld3 = new QLineEdit(&topLevel);
684
685 layout->insertRow(-5, "&Name:", fld1);
686 QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
687 QVERIFY(label1 != 0);
688 QCOMPARE(label1->buddy(), fld1);
689
690 layout->insertRow(0, "&Email:", fld2);
691 QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
692 QVERIFY(label2 != 0);
693 QCOMPARE(label2->buddy(), fld2);
694
695 layout->insertRow(5, "&Age:", fld3);
696 QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
697 QVERIFY(label3 != 0);
698 QCOMPARE(label3->buddy(), fld3);
699}
700
701void tst_QFormLayout::insertRow_QString_QLayout()
702{
703 QWidget topLevel;
704 QFormLayout *layout = new QFormLayout(&topLevel);
705 QHBoxLayout *fld1 = new QHBoxLayout;
706 QHBoxLayout *fld2 = new QHBoxLayout;
707 QHBoxLayout *fld3 = new QHBoxLayout;
708
709 layout->insertRow(-5, "&Name:", fld1);
710 QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
711 QVERIFY(label1 != 0);
712 QVERIFY(!label1->buddy());
713
714 QCOMPARE(layout->rowCount(), 1);
715
716 layout->insertRow(0, "&Email:", fld2);
717 QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
718 QVERIFY(label2 != 0);
719 QVERIFY(!label2->buddy());
720
721 QCOMPARE(layout->rowCount(), 2);
722
723 layout->insertRow(5, "&Age:", fld3);
724 QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
725 QVERIFY(label3 != 0);
726 QVERIFY(!label3->buddy());
727
728 QCOMPARE(layout->rowCount(), 3);
729}
730
731void tst_QFormLayout::insertRow_QWidget()
732{
733 // ### come back to this later
734}
735
736void tst_QFormLayout::insertRow_QLayout()
737{
738 // ### come back to this later
739}
740
741void tst_QFormLayout::removeRow()
742{
743 QWidget topLevel;
744 QFormLayout *layout = new QFormLayout(&topLevel);
745
746 QCOMPARE(layout->count(), 0);
747 QCOMPARE(layout->rowCount(), 0);
748
749 QPointer<QWidget> w1 = new QWidget;
750 QPointer<QWidget> w2 = new QWidget;
751
752 layout->addRow("test1", w1);
753 layout->addRow(w2);
754
755 QCOMPARE(layout->count(), 3);
756 QCOMPARE(layout->rowCount(), 2);
757
758 layout->removeRow(1);
759
760 QVERIFY(!w1);
761 QCOMPARE(layout->count(), 1);
762 QCOMPARE(layout->rowCount(), 1);
763
764 layout->removeRow(0);
765
766 QVERIFY(!w2);
767 QCOMPARE(layout->count(), 0);
768 QCOMPARE(layout->rowCount(), 0);
769}
770
771void tst_QFormLayout::removeRow_QWidget()
772{
773 QWidget topLevel;
774 QFormLayout *layout = new QFormLayout(&topLevel);
775
776 QCOMPARE(layout->count(), 0);
777 QCOMPARE(layout->rowCount(), 0);
778
779 QPointer<QWidget> w1 = new QWidget;
780 QPointer<QWidget> w2 = new QWidget;
781
782 layout->addRow("test1", w1);
783 layout->addRow(w2);
784
785 QCOMPARE(layout->count(), 3);
786 QCOMPARE(layout->rowCount(), 2);
787
788 layout->removeRow(w1);
789
790 QVERIFY(!w1);
791 QCOMPARE(layout->count(), 1);
792 QCOMPARE(layout->rowCount(), 1);
793
794 layout->removeRow(w2);
795
796 QVERIFY(!w2);
797 QCOMPARE(layout->count(), 0);
798 QCOMPARE(layout->rowCount(), 0);
799
800 QWidget *w3 = new QWidget;
801 layout->removeRow(w3);
802 delete w3;
803}
804
805void tst_QFormLayout::removeRow_QLayout()
806{
807 QWidget topLevel;
808 QFormLayout *layout = new QFormLayout(&topLevel);
809
810 QCOMPARE(layout->count(), 0);
811 QCOMPARE(layout->rowCount(), 0);
812
813 QPointer<QHBoxLayout> l1 = new QHBoxLayout;
814 QPointer<QWidget> w1 = new QWidget;
815 l1->addWidget(w1);
816 QPointer<QHBoxLayout> l2 = new QHBoxLayout;
817 QPointer<QWidget> w2 = new QWidget;
818 l2->addWidget(w2);
819
820 layout->addRow("test1", l1);
821 layout->addRow(l2);
822
823 QCOMPARE(layout->count(), 3);
824 QCOMPARE(layout->rowCount(), 2);
825
826 layout->removeRow(l1);
827
828 QVERIFY(!l1);
829 QVERIFY(!w1);
830 QCOMPARE(layout->count(), 1);
831 QCOMPARE(layout->rowCount(), 1);
832
833 layout->removeRow(l2);
834
835 QVERIFY(!l2);
836 QVERIFY(!w2);
837 QCOMPARE(layout->count(), 0);
838 QCOMPARE(layout->rowCount(), 0);
839
840 QHBoxLayout *l3 = new QHBoxLayout;
841 layout->removeRow(l3);
842 delete l3;
843}
844
845void tst_QFormLayout::takeRow()
846{
847 QWidget topLevel;
848 QFormLayout *layout = new QFormLayout(&topLevel);
849
850 QCOMPARE(layout->count(), 0);
851 QCOMPARE(layout->rowCount(), 0);
852
853 QPointer<QWidget> w1 = new QWidget;
854 QPointer<QWidget> w2 = new QWidget;
855
856 layout->addRow("test1", w1);
857 layout->addRow(w2);
858
859 QCOMPARE(layout->count(), 3);
860 QCOMPARE(layout->rowCount(), 2);
861
862 QFormLayoutTakeRowResultHolder result = layout->takeRow(1);
863
864 QVERIFY(w2);
865 QVERIFY(result.fieldItem);
866 QVERIFY(result.labelItem);
867 QCOMPARE(layout->count(), 1);
868 QCOMPARE(layout->rowCount(), 1);
869
870 result = layout->takeRow(0);
871
872 QVERIFY(w1);
873 QVERIFY(result.fieldItem);
874 QVERIFY(!result.labelItem);
875 QCOMPARE(layout->count(), 0);
876 QCOMPARE(layout->rowCount(), 0);
877
878 result = layout->takeRow(0);
879
880 QVERIFY(!result.fieldItem);
881 QVERIFY(!result.labelItem);
882}
883
884void tst_QFormLayout::takeRow_QWidget()
885{
886 QWidget topLevel;
887 QFormLayout *layout = new QFormLayout(&topLevel);
888
889 QCOMPARE(layout->count(), 0);
890 QCOMPARE(layout->rowCount(), 0);
891
892 QPointer<QWidget> w1 = new QWidget;
893 QPointer<QWidget> w2 = new QWidget;
894
895 layout->addRow("test1", w1);
896 layout->addRow(w2);
897
898 QCOMPARE(layout->count(), 3);
899 QCOMPARE(layout->rowCount(), 2);
900
901 QFormLayoutTakeRowResultHolder result = layout->takeRow(w1);
902
903 QVERIFY(w1);
904 QVERIFY(result.fieldItem);
905 QVERIFY(result.labelItem);
906 QCOMPARE(layout->count(), 1);
907 QCOMPARE(layout->rowCount(), 1);
908
909 result = layout->takeRow(w2);
910
911 QVERIFY(w2);
912 QVERIFY(result.fieldItem);
913 QVERIFY(!result.labelItem);
914 QCOMPARE(layout->count(), 0);
915 QCOMPARE(layout->rowCount(), 0);
916
917 QWidget *w3 = new QWidget;
918 result = layout->takeRow(w3);
919 delete w3;
920
921 QVERIFY(!result.fieldItem);
922 QVERIFY(!result.labelItem);
923}
924
925void tst_QFormLayout::takeRow_QLayout()
926{
927 QWidget topLevel;
928 QFormLayout *layout = new QFormLayout(&topLevel);
929
930 QCOMPARE(layout->count(), 0);
931 QCOMPARE(layout->rowCount(), 0);
932
933 QPointer<QHBoxLayout> l1 = new QHBoxLayout;
934 QPointer<QWidget> w1 = new QWidget;
935 l1->addWidget(w1);
936 QPointer<QHBoxLayout> l2 = new QHBoxLayout;
937 QPointer<QWidget> w2 = new QWidget;
938 l2->addWidget(w2);
939
940 layout->addRow("test1", l1);
941 layout->addRow(l2);
942
943 QCOMPARE(layout->count(), 3);
944 QCOMPARE(layout->rowCount(), 2);
945
946 QFormLayoutTakeRowResultHolder result = layout->takeRow(l1);
947
948 QVERIFY(l1);
949 QVERIFY(w1);
950 QVERIFY(result.fieldItem);
951 QVERIFY(result.labelItem);
952 QCOMPARE(layout->count(), 1);
953 QCOMPARE(layout->rowCount(), 1);
954
955 result = layout->takeRow(l2);
956
957 QVERIFY(l2);
958 QVERIFY(w2);
959 QVERIFY(result.fieldItem);
960 QVERIFY(!result.labelItem);
961 QCOMPARE(layout->count(), 0);
962 QCOMPARE(layout->rowCount(), 0);
963
964 QHBoxLayout *l3 = new QHBoxLayout;
965 result = layout->takeRow(l3);
966 delete l3;
967
968 QVERIFY(!result.fieldItem);
969 QVERIFY(!result.labelItem);
970}
971
972void tst_QFormLayout::setWidget()
973{
974 QFormLayout layout;
975
976 QWidget w1;
977 QWidget w2;
978 QWidget w3;
979 QWidget w4;
980
981 QCOMPARE(layout.count(), 0);
982 QCOMPARE(layout.rowCount(), 0);
983
984 layout.setWidget(5, QFormLayout::LabelRole, &w1);
985 QCOMPARE(layout.count(), 1);
986 QCOMPARE(layout.rowCount(), 6);
987
988 layout.setWidget(3, QFormLayout::FieldRole, &w2);
989 layout.setWidget(3, QFormLayout::LabelRole, &w3);
990 QCOMPARE(layout.count(), 3);
991 QCOMPARE(layout.rowCount(), 6);
992
993 // should be ignored and generate warnings
994 layout.setWidget(3, QFormLayout::FieldRole, &w4);
995 layout.setWidget(-1, QFormLayout::FieldRole, &w4);
996
997 {
998 int row = -1;
999 QFormLayout::ItemRole role = invalidRole;
1000 layout.getWidgetPosition(&w1, &row, &role);
1001 QCOMPARE(row, 5);
1002 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1003 }
1004
1005 {
1006 int row = -1;
1007 QFormLayout::ItemRole role = invalidRole;
1008 layout.getWidgetPosition(&w2, &row, &role);
1009 QCOMPARE(row, 3);
1010 QCOMPARE(int(role), int(QFormLayout::FieldRole));
1011 }
1012
1013 {
1014 int row = -1;
1015 QFormLayout::ItemRole role = invalidRole;
1016 layout.getWidgetPosition(&w3, &row, &role);
1017 QCOMPARE(row, 3);
1018 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1019 }
1020
1021 {
1022 int row = -1;
1023 QFormLayout::ItemRole role = invalidRole;
1024 layout.getWidgetPosition(&w4, &row, &role);
1025 // not found
1026 QCOMPARE(row, -1);
1027 QCOMPARE(int(role), int(invalidRole));
1028 }
1029
1030 {
1031 int row = -1;
1032 QFormLayout::ItemRole role = invalidRole;
1033 layout.getWidgetPosition(0, &row, &role);
1034 // not found
1035 QCOMPARE(row, -1);
1036 QCOMPARE(int(role), int(invalidRole));
1037 }
1038}
1039
1040void tst_QFormLayout::setLayout()
1041{
1042 QFormLayout layout;
1043
1044 QHBoxLayout l1;
1045 QHBoxLayout l2;
1046 QHBoxLayout l3;
1047 QHBoxLayout l4;
1048
1049 QCOMPARE(layout.count(), 0);
1050 QCOMPARE(layout.rowCount(), 0);
1051
1052 layout.setLayout(5, QFormLayout::LabelRole, &l1);
1053 QCOMPARE(layout.count(), 1);
1054 QCOMPARE(layout.rowCount(), 6);
1055
1056 layout.setLayout(3, QFormLayout::FieldRole, &l2);
1057 layout.setLayout(3, QFormLayout::LabelRole, &l3);
1058 QCOMPARE(layout.count(), 3);
1059 QCOMPARE(layout.rowCount(), 6);
1060
1061 // should be ignored and generate warnings
1062 layout.setLayout(3, QFormLayout::FieldRole, &l4);
1063 layout.setLayout(-1, QFormLayout::FieldRole, &l4);
1064 QCOMPARE(layout.count(), 3);
1065 QCOMPARE(layout.rowCount(), 6);
1066
1067 {
1068 int row = -1;
1069 QFormLayout::ItemRole role = invalidRole;
1070 layout.getLayoutPosition(&l1, &row, &role);
1071 QCOMPARE(row, 5);
1072 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1073 }
1074
1075 {
1076 int row = -1;
1077 QFormLayout::ItemRole role = invalidRole;
1078 layout.getLayoutPosition(&l2, &row, &role);
1079 QCOMPARE(row, 3);
1080 QCOMPARE(int(role), int(QFormLayout::FieldRole));
1081 }
1082
1083 {
1084 int row = -1;
1085 QFormLayout::ItemRole role = invalidRole;
1086 layout.getLayoutPosition(&l3, &row, &role);
1087 QCOMPARE(row, 3);
1088 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1089 }
1090
1091 {
1092 int row = -1;
1093 QFormLayout::ItemRole role = invalidRole;
1094 layout.getLayoutPosition(&l4, &row, &role);
1095 QCOMPARE(row, -1);
1096 QCOMPARE(int(role), int(invalidRole));
1097 }
1098
1099 {
1100 int row = -1;
1101 QFormLayout::ItemRole role = invalidRole;
1102 layout.getLayoutPosition(0, &row, &role);
1103 QCOMPARE(row, -1);
1104 QCOMPARE(int(role), int(invalidRole));
1105 }
1106}
1107
1108void tst_QFormLayout::itemAt()
1109{
1110 QWidget topLevel;
1111 QFormLayout *layout = new QFormLayout(&topLevel);
1112
1113 QWidget *w1 = new QWidget(&topLevel);
1114 QWidget *w2 = new QWidget(&topLevel);
1115 QWidget *w3 = new QWidget(&topLevel);
1116 QWidget *w4 = new QWidget(&topLevel);
1117 QWidget *w5 = new QWidget(&topLevel);
1118 QHBoxLayout *l6 = new QHBoxLayout;
1119
1120 layout->setWidget(5, QFormLayout::LabelRole, w1);
1121 layout->setWidget(3, QFormLayout::FieldRole, w2);
1122 layout->setWidget(3, QFormLayout::LabelRole, w3);
1123 layout->addRow(w4, w5);
1124 layout->addRow("Foo:", l6);
1125
1126 QCOMPARE(layout->count(), 7);
1127
1128 QBitArray scoreBoard(7);
1129 for (int i = 0; i < 7; ++i) {
1130 QLayoutItem *item = layout->itemAt(i);
1131 QVERIFY(item != 0);
1132
1133 if (item->widget() == w1) {
1134 scoreBoard[0] = true;
1135 } else if (item->widget() == w2) {
1136 scoreBoard[1] = true;
1137 } else if (item->widget() == w3) {
1138 scoreBoard[2] = true;
1139 } else if (item->widget() == w4) {
1140 scoreBoard[3] = true;
1141 } else if (item->widget() == w5) {
1142 scoreBoard[4] = true;
1143 } else if (item->layout() == l6) {
1144 scoreBoard[5] = true;
1145 } else if (qobject_cast<QLabel *>(item->widget())) {
1146 scoreBoard[6] = true;
1147 }
1148 }
1149 QCOMPARE(scoreBoard.count(false), 0);
1150}
1151
1152void tst_QFormLayout::takeAt()
1153{
1154 QWidget topLevel;
1155 QFormLayout *layout = new QFormLayout(&topLevel);
1156
1157 QWidget *w1 = new QWidget(&topLevel);
1158 QWidget *w2 = new QWidget(&topLevel);
1159 QWidget *w3 = new QWidget(&topLevel);
1160 QWidget *w4 = new QWidget(&topLevel);
1161 QWidget *w5 = new QWidget(&topLevel);
1162 QHBoxLayout *l6 = new QHBoxLayout;
1163
1164 layout->setWidget(5, QFormLayout::LabelRole, w1);
1165 layout->setWidget(3, QFormLayout::FieldRole, w2);
1166 layout->setWidget(3, QFormLayout::LabelRole, w3);
1167 layout->addRow(w4, w5);
1168 layout->addRow("Foo:", l6);
1169
1170 QCOMPARE(layout->count(), 7);
1171
1172 for (int i = 6; i >= 0; --i) {
1173 delete layout->takeAt(0);
1174 QCOMPARE(layout->count(), i);
1175 }
1176}
1177
1178void tst_QFormLayout::layoutAlone()
1179{
1180 QWidget w;
1181 QFormLayout layout;
1182 layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
1183 w.setLayout(&layout);
1184 QLabel label("Here is a strange test case");
1185 layout.setWidget(0, QFormLayout::LabelRole, &label);
1186 QHBoxLayout hlay;
1187 layout.setLayout(1, QFormLayout::LabelRole, &hlay);
1188 QCOMPARE(layout.count(), 2);
1189 w.setWindowTitle(QTest::currentTestFunction());
1190 w.show();
1191 layout.activate();
1192 QTest::qWait(500);
1193}
1194
1195void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout()
1196{
1197 QSharedPointer<QFormLayout> outer(new QFormLayout);
1198 QPointer<QFormLayout> inner = new QFormLayout;
1199
1200 outer->addRow(inner);
1201 QCOMPARE(outer->count(), 1);
1202 QCOMPARE(inner->parent(), outer.data());
1203
1204 QLayoutItem *item = outer->takeAt(0);
1205 QCOMPARE(item->layout(), inner.data());
1206 QVERIFY(!item->layout()->parent());
1207
1208 outer.reset();
1209
1210 if (inner)
1211 delete item; // success: a taken item/layout should not be deleted when the old parent is deleted
1212 else
1213 QVERIFY(!inner.isNull());
1214}
1215
1216void tst_QFormLayout::taskQTBUG_40609_addingWidgetToItsOwnLayout(){
1217 QWidget widget;
1218 widget.setObjectName("6435cbada60548b4522cbb6");
1219 QFormLayout layout(&widget);
1220 layout.setObjectName("c03c0e22c0b6d019a93a248");
1221
1222 QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add parent widget QWidget/6435cbada60548b4522cbb6 to its child layout QFormLayout/c03c0e22c0b6d019a93a248");
1223 layout.addRow(QLatin1String("48c81f39b7320082f8"), &widget);
1224 QCOMPARE(layout.count(), 0);
1225}
1226
1227void tst_QFormLayout::taskQTBUG_40609_addingLayoutToItself(){
1228 QWidget widget;
1229 widget.setObjectName("2bc425637d084c07ce65956");
1230 QFormLayout layout(&widget);
1231 layout.setObjectName("60e31de0c8800eaba713a4f2");
1232
1233 QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add layout QFormLayout/60e31de0c8800eaba713a4f2 to itself");
1234 layout.addRow(QLatin1String("9a2cd4f40c06b489f889"), &layout);
1235 QCOMPARE(layout.count(), 0);
1236}
1237
1238void tst_QFormLayout::replaceWidget()
1239{
1240 QWidget w;
1241 QFormLayout *layout = new QFormLayout();
1242 w.setLayout(layout);
1243 QLineEdit *edit1 = new QLineEdit();
1244 QLineEdit *edit2 = new QLineEdit();
1245 QLineEdit *edit3 = new QLineEdit();
1246 QLabel *label1 = new QLabel();
1247 QLabel *label2 = new QLabel();
1248
1249 layout->addRow("Label", edit1);
1250 layout->addRow(label1, edit2);
1251
1252 // Verify controls not in layout
1253 QCOMPARE(layout->indexOf(edit3), -1);
1254 QCOMPARE(layout->indexOf(label2), -1);
1255
1256 // Verify controls in layout
1257 int editIndex = layout->indexOf(edit1);
1258 int labelIndex = layout->indexOf(label1);
1259 QVERIFY(editIndex > 0);
1260 QVERIFY(labelIndex > 0);
1261 int rownum;
1262 QFormLayout::ItemRole role;
1263
1264 // replace editor
1265 delete layout->replaceWidget(edit1, edit3);
1266 edit1->hide(); // Not strictly needed for the test, but for normal usage it is.
1267 QCOMPARE(layout->indexOf(edit1), -1);
1268 QCOMPARE(layout->indexOf(edit3), editIndex);
1269 QCOMPARE(layout->indexOf(label1), labelIndex);
1270 rownum = -1;
1271 role = QFormLayout::SpanningRole;
1272 layout->getWidgetPosition(edit3, &rownum, &role);
1273 QCOMPARE(rownum, 0);
1274 QCOMPARE(role, QFormLayout::FieldRole);
1275
1276 delete layout->replaceWidget(label1, label2);
1277 label1->hide();
1278 QCOMPARE(layout->indexOf(label1), -1);
1279 QCOMPARE(layout->indexOf(label2), labelIndex);
1280 layout->getWidgetPosition(label2, &rownum, &role);
1281 QCOMPARE(rownum, 1);
1282 QCOMPARE(role, QFormLayout::LabelRole);
1283
1284}
1285
1286QTEST_MAIN(tst_QFormLayout)
1287
1288#include "tst_qformlayout.moc"
1289