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