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 QCOMPARE(le->geometry().y() > lbl->geometry().y(), true);
277
278 //TODO: additional tests covering different wrapping cases
279}
280
281class CustomLayoutStyle : public QProxyStyle
282{
283 Q_OBJECT
284public:
285 CustomLayoutStyle() : QProxyStyle(QStyleFactory::create("windows"))
286 {
287 hspacing = 5;
288 vspacing = 10;
289 }
290
291 virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
292 const QWidget * widget = 0 ) const;
293
294 int hspacing;
295 int vspacing;
296};
297
298int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/,
299 const QWidget * widget /*= 0*/ ) const
300{
301 switch (metric) {
302 case PM_LayoutHorizontalSpacing:
303 return hspacing;
304 case PM_LayoutVerticalSpacing:
305 return vspacing;
306 break;
307 default:
308 break;
309 }
310 return QProxyStyle::pixelMetric(metric, option, widget);
311}
312
313void tst_QFormLayout::spacing()
314{
315 //TODO: confirm spacing behavior
316 QWidget w;
317 QScopedPointer<CustomLayoutStyle> style(new CustomLayoutStyle);
318 style->hspacing = 5;
319 style->vspacing = 10;
320 w.setStyle(style.data());
321 QFormLayout *fl = new QFormLayout(&w);
322 QCOMPARE(style->hspacing, fl->horizontalSpacing());
323 QCOMPARE(style->vspacing, fl->verticalSpacing());
324
325 //QCOMPARE(fl->spacing(), -1);
326 fl->setVerticalSpacing(5);
327 QCOMPARE(5, fl->horizontalSpacing());
328 QCOMPARE(5, fl->verticalSpacing());
329 //QCOMPARE(fl->spacing(), 5);
330 fl->setVerticalSpacing(-1);
331 QCOMPARE(style->hspacing, fl->horizontalSpacing());
332 QCOMPARE(style->vspacing, fl->verticalSpacing());
333
334 style->hspacing = 5;
335 style->vspacing = 5;
336 //QCOMPARE(fl->spacing(), 5);
337
338 fl->setHorizontalSpacing(20);
339 //QCOMPARE(fl->spacing(), -1);
340 style->vspacing = 20;
341 QCOMPARE(fl->horizontalSpacing(), 20);
342 QCOMPARE(fl->verticalSpacing(), 20);
343 //QCOMPARE(fl->spacing(), 20);
344 fl->setHorizontalSpacing(-1);
345 //QCOMPARE(fl->spacing(), -1);
346 style->hspacing = 20;
347 //QCOMPARE(fl->spacing(), 20);
348
349
350
351 // Do not assert if spacings are negative (QTBUG-34731)
352 style->vspacing = -1;
353 style->hspacing = -1;
354 QLabel *label = new QLabel(tr("Asserts"));
355 QCheckBox *checkBox = new QCheckBox(tr("Yes"));
356 fl->setWidget(0, QFormLayout::LabelRole, label);
357 fl->setWidget(1, QFormLayout::FieldRole, checkBox);
358 w.resize(200, 100);
359 w.setWindowTitle(QTest::currentTestFunction());
360 w.show();
361 QVERIFY(QTest::qWaitForWindowExposed(&w));
362}
363
364void tst_QFormLayout::contentsRect()
365{
366 QWidget w;
367 setFrameless(&w);
368 QFormLayout form;
369 w.setLayout(&form);
370 form.addRow("Label", new QPushButton(&w));
371 w.setWindowTitle(QTest::currentTestFunction());
372 w.show();
373 QVERIFY(QTest::qWaitForWindowExposed(&w));
374 int l, t, r, b;
375 form.getContentsMargins(&l, &t, &r, &b);
376 QRect geom = form.geometry();
377
378 QCOMPARE(geom.adjusted(+l, +t, -r, -b), form.contentsRect());
379}
380
381
382class DummyMacStyle : public QCommonStyle
383{
384public:
385 virtual int styleHint ( StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, QStyleHintReturn * returnData = 0 ) const
386 {
387 switch(hint) {
388 case SH_FormLayoutFormAlignment:
389 return Qt::AlignHCenter | Qt::AlignTop;
390 case SH_FormLayoutLabelAlignment:
391 return Qt::AlignRight;
392 case SH_FormLayoutWrapPolicy:
393 return QFormLayout::DontWrapRows;
394 case SH_FormLayoutFieldGrowthPolicy:
395 return QFormLayout::FieldsStayAtSizeHint;
396 default:
397 return QCommonStyle::styleHint(hint, option, widget, returnData);
398 }
399 }
400};
401
402class DummyQtopiaStyle : public QCommonStyle
403{
404public:
405 virtual int styleHint ( StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, QStyleHintReturn * returnData = 0 ) const
406 {
407 switch(hint) {
408 case SH_FormLayoutFormAlignment:
409 return Qt::AlignLeft | Qt::AlignTop;
410 case SH_FormLayoutLabelAlignment:
411 return Qt::AlignRight;
412 case SH_FormLayoutWrapPolicy:
413 return QFormLayout::WrapLongRows;
414 case SH_FormLayoutFieldGrowthPolicy:
415 return QFormLayout::AllNonFixedFieldsGrow;
416 default:
417 return QCommonStyle::styleHint(hint, option, widget, returnData);
418 }
419 }
420};
421
422void tst_QFormLayout::setFormStyle()
423{
424 QWidget widget;
425 QFormLayout layout;
426 widget.setLayout(&layout);
427
428#if 0 // QT_NO_STYLE_PLASTIQUE
429 widget.setStyle(new QPlastiqueStyle());
430
431 QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
432 QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
433 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::ExpandingFieldsGrow);
434 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
435#endif
436
437 const QScopedPointer<QStyle> windowsStyle(QStyleFactory::create("windows"));
438 widget.setStyle(windowsStyle.data());
439
440 QCOMPARE(layout.labelAlignment(), Qt::AlignLeft);
441 QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
442 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::AllNonFixedFieldsGrow);
443 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
444
445 /* can't directly create mac style or qtopia style, since
446 this test is cross platform.. so create dummy styles that
447 return all the right stylehints.
448 */
449 DummyMacStyle macStyle;
450 widget.setStyle(&macStyle);
451
452 QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
453 QVERIFY(layout.formAlignment() == (Qt::AlignHCenter | Qt::AlignTop));
454 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::FieldsStayAtSizeHint);
455 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
456
457 DummyQtopiaStyle qtopiaStyle;
458 widget.setStyle(&qtopiaStyle);
459
460 QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
461 QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
462 QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::AllNonFixedFieldsGrow);
463 QCOMPARE(layout.rowWrapPolicy(), QFormLayout::WrapLongRows);
464}
465
466void tst_QFormLayout::setFieldGrowthPolicy()
467{
468 QWidget window;
469 QLineEdit fld1, fld2, fld3;
470 fld1.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
471 fld2.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
472 fld3.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
473
474 QFormLayout layout;
475 layout.addRow("One:", &fld1);
476 layout.addRow("Two:", &fld2);
477 layout.addRow("Three:", &fld3);
478 window.setLayout(&layout);
479 window.resize(1000, 200);
480
481 for (int i = 0; i < 3; ++i) {
482 layout.setFieldGrowthPolicy(i == 0 ? QFormLayout::FieldsStayAtSizeHint :
483 i == 1 ? QFormLayout::ExpandingFieldsGrow :
484 QFormLayout::AllNonFixedFieldsGrow);
485 layout.activate();
486
487 if (i == 0) {
488 QCOMPARE(fld1.width(), fld2.width());
489 QCOMPARE(fld2.width(), fld3.width());
490 } else if (i == 1) {
491 QCOMPARE(fld1.width(), fld2.width());
492 QVERIFY(fld2.width() < fld3.width());
493 } else {
494 QVERIFY(fld1.width() < fld2.width());
495 QCOMPARE(fld2.width(), fld3.width());
496 }
497 }
498}
499
500void tst_QFormLayout::setRowWrapPolicy()
501{
502}
503
504void tst_QFormLayout::setLabelAlignment()
505{
506}
507
508void tst_QFormLayout::setFormAlignment()
509{
510}
511
512void tst_QFormLayout::addRow()
513{
514 QWidget topLevel;
515 QFormLayout *layout = new QFormLayout(&topLevel);
516 QWidget *w1 = new QWidget(&topLevel);
517 QWidget *w2 = new QWidget(&topLevel);
518 QWidget *w3 = new QWidget(&topLevel);
519 QHBoxLayout *l1 = new QHBoxLayout;
520 QHBoxLayout *l2 = new QHBoxLayout;
521 QHBoxLayout *l3 = new QHBoxLayout;
522 QLabel *lbl1 = new QLabel(&topLevel);
523 QLabel *lbl2 = new QLabel(&topLevel);
524
525 QCOMPARE(layout->rowCount(), 0);
526
527 layout->addRow(lbl1, w1);
528 layout->addRow(lbl2, l1);
529 layout->addRow("Foo:", w2);
530 layout->addRow("Bar:", l2);
531 layout->addRow(w3);
532 layout->addRow(l3);
533
534 QCOMPARE(layout->rowCount(), 6);
535
536 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
537 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
538 QCOMPARE(layout->itemAt(2, QFormLayout::LabelRole)->widget()->property("text").toString(), QLatin1String("Foo:"));
539 QCOMPARE(layout->itemAt(3, QFormLayout::LabelRole)->widget()->property("text").toString(), QLatin1String("Bar:"));
540 QVERIFY(layout->itemAt(4, QFormLayout::LabelRole) == 0);
541 QVERIFY(layout->itemAt(5, QFormLayout::LabelRole) == 0);
542
543 QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->widget() == w1);
544 QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->layout() == l1);
545 QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->widget() == w2);
546 QVERIFY(layout->itemAt(3, QFormLayout::FieldRole)->layout() == l2);
547// ### should have a third role, FullRowRole?
548// QVERIFY(layout.itemAt(4, QFormLayout::FieldRole) == 0);
549// QVERIFY(layout.itemAt(5, QFormLayout::FieldRole) == 0);
550}
551
552void tst_QFormLayout::insertRow_QWidget_QWidget()
553{
554 QWidget topLevel;
555 QFormLayout *layout = new QFormLayout(&topLevel);
556 QLabel *lbl1 = new QLabel(&topLevel);
557 QLabel *lbl2 = new QLabel(&topLevel);
558 QLabel *lbl3 = new QLabel(&topLevel);
559 QLabel *lbl4 = new QLabel(&topLevel);
560 QLineEdit *fld1 = new QLineEdit(&topLevel);
561 QLineEdit *fld2 = new QLineEdit(&topLevel);
562 QLineEdit *fld3 = new QLineEdit(&topLevel);
563 QLineEdit *fld4 = new QLineEdit(&topLevel);
564
565 layout->insertRow(0, lbl1, fld1);
566 QCOMPARE(layout->rowCount(), 1);
567
568 {
569 int row = -1;
570 QFormLayout::ItemRole role = invalidRole;
571 layout->getWidgetPosition(lbl1, &row, &role);
572 QCOMPARE(row, 0);
573 QCOMPARE(int(role), int(QFormLayout::LabelRole));
574 }
575
576 {
577 int row = -1;
578 QFormLayout::ItemRole role = invalidRole;
579 layout->getWidgetPosition(fld1, &row, &role);
580 QCOMPARE(row, 0);
581 QCOMPARE(int(role), int(QFormLayout::FieldRole));
582 }
583
584 // check that negative values append
585 layout->insertRow(-2, lbl2, fld2);
586 QCOMPARE(layout->rowCount(), 2);
587
588 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
589 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
590
591 // check that too large values append
592 layout->insertRow(100, lbl3, fld3);
593 QCOMPARE(layout->rowCount(), 3);
594 QCOMPARE(layout->count(), 6);
595
596 layout->insertRow(3, (QWidget *)0, (QWidget *)0);
597 QCOMPARE(layout->rowCount(), 4);
598 QCOMPARE(layout->count(), 6);
599
600 layout->insertRow(4, (QWidget *)0, fld4);
601 QCOMPARE(layout->rowCount(), 5);
602 QCOMPARE(layout->count(), 7);
603
604 layout->insertRow(5, lbl4, (QWidget *)0);
605 QCOMPARE(layout->rowCount(), 6);
606 QCOMPARE(layout->count(), 8);
607
608 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
609 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
610 QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget() == lbl3);
611 QVERIFY(layout->itemAt(3, QFormLayout::LabelRole) == 0);
612 QVERIFY(layout->itemAt(4, QFormLayout::LabelRole) == 0);
613 QVERIFY(layout->itemAt(5, QFormLayout::LabelRole)->widget() == lbl4);
614
615 QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->widget() == fld1);
616 QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->widget() == fld2);
617 QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->widget() == fld3);
618 QVERIFY(layout->itemAt(3, QFormLayout::FieldRole) == 0);
619 QVERIFY(layout->itemAt(4, QFormLayout::FieldRole)->widget() == fld4);
620 QVERIFY(layout->itemAt(5, QFormLayout::FieldRole) == 0);
621}
622
623void tst_QFormLayout::insertRow_QWidget_QLayout()
624{
625 QWidget topLevel;
626 QFormLayout *layout = new QFormLayout(&topLevel);
627 QLabel *lbl1 = new QLabel(&topLevel);
628 QLabel *lbl2 = new QLabel(&topLevel);
629 QLabel *lbl3 = new QLabel(&topLevel);
630 QHBoxLayout *fld1 = new QHBoxLayout;
631 QHBoxLayout *fld2 = new QHBoxLayout;
632 QHBoxLayout *fld3 = new QHBoxLayout;
633
634 layout->insertRow(0, lbl1, fld1);
635 QCOMPARE(layout->rowCount(), 1);
636
637 {
638 int row = -1;
639 QFormLayout::ItemRole role = invalidRole;
640 layout->getWidgetPosition(lbl1, &row, &role);
641 QCOMPARE(row, 0);
642 QCOMPARE(int(role), int(QFormLayout::LabelRole));
643 }
644
645 {
646 int row = -1;
647 QFormLayout::ItemRole role = invalidRole;
648 layout->getLayoutPosition(fld1, &row, &role);
649 QCOMPARE(row, 0);
650 QCOMPARE(int(role), int(QFormLayout::FieldRole));
651 }
652
653 // check that negative values append
654 layout->insertRow(-2, lbl2, fld2);
655 QCOMPARE(layout->rowCount(), 2);
656
657 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
658 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
659
660 // check that too large values append
661 layout->insertRow(100, lbl3, fld3);
662 QCOMPARE(layout->rowCount(), 3);
663
664 QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
665 QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
666 QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget() == lbl3);
667
668 QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->layout() == fld1);
669 QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->layout() == fld2);
670 QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->layout() == fld3);
671}
672
673void tst_QFormLayout::insertRow_QString_QWidget()
674{
675 QWidget topLevel;
676 QFormLayout *layout = new QFormLayout(&topLevel);
677 QLineEdit *fld1 = new QLineEdit(&topLevel);
678 QLineEdit *fld2 = new QLineEdit(&topLevel);
679 QLineEdit *fld3 = new QLineEdit(&topLevel);
680
681 layout->insertRow(-5, "&Name:", fld1);
682 QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
683 QVERIFY(label1 != 0);
684 QCOMPARE(label1->buddy(), fld1);
685
686 layout->insertRow(0, "&Email:", fld2);
687 QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
688 QVERIFY(label2 != 0);
689 QCOMPARE(label2->buddy(), fld2);
690
691 layout->insertRow(5, "&Age:", fld3);
692 QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
693 QVERIFY(label3 != 0);
694 QCOMPARE(label3->buddy(), fld3);
695}
696
697void tst_QFormLayout::insertRow_QString_QLayout()
698{
699 QWidget topLevel;
700 QFormLayout *layout = new QFormLayout(&topLevel);
701 QHBoxLayout *fld1 = new QHBoxLayout;
702 QHBoxLayout *fld2 = new QHBoxLayout;
703 QHBoxLayout *fld3 = new QHBoxLayout;
704
705 layout->insertRow(-5, "&Name:", fld1);
706 QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
707 QVERIFY(label1 != 0);
708 QVERIFY(!label1->buddy());
709
710 QCOMPARE(layout->rowCount(), 1);
711
712 layout->insertRow(0, "&Email:", fld2);
713 QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
714 QVERIFY(label2 != 0);
715 QVERIFY(!label2->buddy());
716
717 QCOMPARE(layout->rowCount(), 2);
718
719 layout->insertRow(5, "&Age:", fld3);
720 QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
721 QVERIFY(label3 != 0);
722 QVERIFY(!label3->buddy());
723
724 QCOMPARE(layout->rowCount(), 3);
725}
726
727void tst_QFormLayout::insertRow_QWidget()
728{
729 // ### come back to this later
730}
731
732void tst_QFormLayout::insertRow_QLayout()
733{
734 // ### come back to this later
735}
736
737void tst_QFormLayout::removeRow()
738{
739 QWidget topLevel;
740 QFormLayout *layout = new QFormLayout(&topLevel);
741
742 QCOMPARE(layout->count(), 0);
743 QCOMPARE(layout->rowCount(), 0);
744
745 QPointer<QWidget> w1 = new QWidget;
746 QPointer<QWidget> w2 = new QWidget;
747
748 layout->addRow("test1", w1);
749 layout->addRow(w2);
750
751 QCOMPARE(layout->count(), 3);
752 QCOMPARE(layout->rowCount(), 2);
753
754 layout->removeRow(1);
755
756 QVERIFY(w1);
757 QVERIFY(!w2);
758 QCOMPARE(layout->count(), 2);
759 QCOMPARE(layout->rowCount(), 1);
760
761 layout->removeRow(0);
762
763 QVERIFY(!w1);
764 QCOMPARE(layout->count(), 0);
765 QCOMPARE(layout->rowCount(), 0);
766}
767
768void tst_QFormLayout::removeRow_QWidget()
769{
770 QWidget topLevel;
771 QFormLayout *layout = new QFormLayout(&topLevel);
772
773 QCOMPARE(layout->count(), 0);
774 QCOMPARE(layout->rowCount(), 0);
775
776 QPointer<QWidget> w1 = new QWidget;
777 QPointer<QWidget> w2 = new QWidget;
778
779 layout->addRow("test1", w1);
780 layout->addRow(w2);
781
782 QCOMPARE(layout->count(), 3);
783 QCOMPARE(layout->rowCount(), 2);
784
785 layout->removeRow(w1);
786
787 QVERIFY(!w1);
788 QCOMPARE(layout->count(), 1);
789 QCOMPARE(layout->rowCount(), 1);
790
791 layout->removeRow(w2);
792
793 QVERIFY(!w2);
794 QCOMPARE(layout->count(), 0);
795 QCOMPARE(layout->rowCount(), 0);
796
797 QWidget *w3 = new QWidget;
798 layout->removeRow(w3);
799 delete w3;
800}
801
802void tst_QFormLayout::removeRow_QLayout()
803{
804 QWidget topLevel;
805 QFormLayout *layout = new QFormLayout(&topLevel);
806
807 QCOMPARE(layout->count(), 0);
808 QCOMPARE(layout->rowCount(), 0);
809
810 QPointer<QHBoxLayout> l1 = new QHBoxLayout;
811 QPointer<QWidget> w1 = new QWidget;
812 l1->addWidget(w1);
813 QPointer<QHBoxLayout> l2 = new QHBoxLayout;
814 QPointer<QWidget> w2 = new QWidget;
815 l2->addWidget(w2);
816
817 layout->addRow("test1", l1);
818 layout->addRow(l2);
819
820 QCOMPARE(layout->count(), 3);
821 QCOMPARE(layout->rowCount(), 2);
822
823 layout->removeRow(l1);
824
825 QVERIFY(!l1);
826 QVERIFY(!w1);
827 QCOMPARE(layout->count(), 1);
828 QCOMPARE(layout->rowCount(), 1);
829
830 layout->removeRow(l2);
831
832 QVERIFY(!l2);
833 QVERIFY(!w2);
834 QCOMPARE(layout->count(), 0);
835 QCOMPARE(layout->rowCount(), 0);
836
837 QHBoxLayout *l3 = new QHBoxLayout;
838 layout->removeRow(l3);
839 delete l3;
840}
841
842void tst_QFormLayout::takeRow()
843{
844 QWidget topLevel;
845 QFormLayout *layout = new QFormLayout(&topLevel);
846
847 QCOMPARE(layout->count(), 0);
848 QCOMPARE(layout->rowCount(), 0);
849
850 QPointer<QWidget> w1 = new QWidget;
851 QPointer<QWidget> w2 = new QWidget;
852
853 layout->addRow("test1", w1);
854 layout->addRow(w2);
855
856 QCOMPARE(layout->count(), 3);
857 QCOMPARE(layout->rowCount(), 2);
858
859 QFormLayoutTakeRowResultHolder result = layout->takeRow(1);
860
861 QVERIFY(w2);
862 QVERIFY(result.fieldItem);
863 QVERIFY(!result.labelItem);
864 QCOMPARE(layout->count(), 2);
865 QCOMPARE(layout->rowCount(), 1);
866 QCOMPARE(result.fieldItem->widget(), w2.data());
867
868 result = layout->takeRow(0);
869
870 QVERIFY(w1);
871 QVERIFY(result.fieldItem);
872 QVERIFY(result.labelItem);
873 QCOMPARE(layout->count(), 0);
874 QCOMPARE(layout->rowCount(), 0);
875 QCOMPARE(result.fieldItem->widget(), w1.data());
876
877 result = layout->takeRow(0);
878
879 QVERIFY(!result.fieldItem);
880 QVERIFY(!result.labelItem);
881}
882
883void tst_QFormLayout::takeRow_QWidget()
884{
885 QWidget topLevel;
886 QFormLayout *layout = new QFormLayout(&topLevel);
887
888 QCOMPARE(layout->count(), 0);
889 QCOMPARE(layout->rowCount(), 0);
890
891 QPointer<QWidget> w1 = new QWidget;
892 QPointer<QWidget> w2 = new QWidget;
893
894 layout->addRow("test1", w1);
895 layout->addRow(w2);
896
897 QCOMPARE(layout->count(), 3);
898 QCOMPARE(layout->rowCount(), 2);
899
900 QFormLayoutTakeRowResultHolder result = layout->takeRow(w1);
901
902 QVERIFY(w1);
903 QVERIFY(result.fieldItem);
904 QVERIFY(result.labelItem);
905 QCOMPARE(layout->count(), 1);
906 QCOMPARE(layout->rowCount(), 1);
907
908 result = layout->takeRow(w2);
909
910 QVERIFY(w2);
911 QVERIFY(result.fieldItem);
912 QVERIFY(!result.labelItem);
913 QCOMPARE(layout->count(), 0);
914 QCOMPARE(layout->rowCount(), 0);
915
916 QWidget *w3 = new QWidget;
917 result = layout->takeRow(w3);
918 delete w3;
919
920 QVERIFY(!result.fieldItem);
921 QVERIFY(!result.labelItem);
922}
923
924void tst_QFormLayout::takeRow_QLayout()
925{
926 QWidget topLevel;
927 QFormLayout *layout = new QFormLayout(&topLevel);
928
929 QCOMPARE(layout->count(), 0);
930 QCOMPARE(layout->rowCount(), 0);
931
932 QPointer<QHBoxLayout> l1 = new QHBoxLayout;
933 QPointer<QWidget> w1 = new QWidget;
934 l1->addWidget(w1);
935 QPointer<QHBoxLayout> l2 = new QHBoxLayout;
936 QPointer<QWidget> w2 = new QWidget;
937 l2->addWidget(w2);
938
939 layout->addRow("test1", l1);
940 layout->addRow(l2);
941
942 QCOMPARE(layout->count(), 3);
943 QCOMPARE(layout->rowCount(), 2);
944
945 QFormLayoutTakeRowResultHolder result = layout->takeRow(l1);
946
947 QVERIFY(l1);
948 QVERIFY(w1);
949 QVERIFY(result.fieldItem);
950 QVERIFY(result.labelItem);
951 QCOMPARE(layout->count(), 1);
952 QCOMPARE(layout->rowCount(), 1);
953
954 result = layout->takeRow(l2);
955
956 QVERIFY(l2);
957 QVERIFY(w2);
958 QVERIFY(result.fieldItem);
959 QVERIFY(!result.labelItem);
960 QCOMPARE(layout->count(), 0);
961 QCOMPARE(layout->rowCount(), 0);
962
963 QHBoxLayout *l3 = new QHBoxLayout;
964 result = layout->takeRow(l3);
965 delete l3;
966
967 QVERIFY(!result.fieldItem);
968 QVERIFY(!result.labelItem);
969}
970
971void tst_QFormLayout::setWidget()
972{
973 QFormLayout layout;
974
975 QWidget w1;
976 QWidget w2;
977 QWidget w3;
978 QWidget w4;
979
980 QCOMPARE(layout.count(), 0);
981 QCOMPARE(layout.rowCount(), 0);
982
983 layout.setWidget(5, QFormLayout::LabelRole, &w1);
984 QCOMPARE(layout.count(), 1);
985 QCOMPARE(layout.rowCount(), 6);
986
987 layout.setWidget(3, QFormLayout::FieldRole, &w2);
988 layout.setWidget(3, QFormLayout::LabelRole, &w3);
989 QCOMPARE(layout.count(), 3);
990 QCOMPARE(layout.rowCount(), 6);
991
992 // should be ignored and generate warnings
993 layout.setWidget(3, QFormLayout::FieldRole, &w4);
994 layout.setWidget(-1, QFormLayout::FieldRole, &w4);
995
996 {
997 int row = -1;
998 QFormLayout::ItemRole role = invalidRole;
999 layout.getWidgetPosition(&w1, &row, &role);
1000 QCOMPARE(row, 5);
1001 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1002 }
1003
1004 {
1005 int row = -1;
1006 QFormLayout::ItemRole role = invalidRole;
1007 layout.getWidgetPosition(&w2, &row, &role);
1008 QCOMPARE(row, 3);
1009 QCOMPARE(int(role), int(QFormLayout::FieldRole));
1010 }
1011
1012 {
1013 int row = -1;
1014 QFormLayout::ItemRole role = invalidRole;
1015 layout.getWidgetPosition(&w3, &row, &role);
1016 QCOMPARE(row, 3);
1017 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1018 }
1019
1020 {
1021 int row = -1;
1022 QFormLayout::ItemRole role = invalidRole;
1023 layout.getWidgetPosition(&w4, &row, &role);
1024 // not found
1025 QCOMPARE(row, -1);
1026 QCOMPARE(int(role), int(invalidRole));
1027 }
1028
1029 {
1030 int row = -1;
1031 QFormLayout::ItemRole role = invalidRole;
1032 layout.getWidgetPosition(0, &row, &role);
1033 // not found
1034 QCOMPARE(row, -1);
1035 QCOMPARE(int(role), int(invalidRole));
1036 }
1037}
1038
1039void tst_QFormLayout::setLayout()
1040{
1041 QFormLayout layout;
1042
1043 QHBoxLayout l1;
1044 QHBoxLayout l2;
1045 QHBoxLayout l3;
1046 QHBoxLayout l4;
1047
1048 QCOMPARE(layout.count(), 0);
1049 QCOMPARE(layout.rowCount(), 0);
1050
1051 layout.setLayout(5, QFormLayout::LabelRole, &l1);
1052 QCOMPARE(layout.count(), 1);
1053 QCOMPARE(layout.rowCount(), 6);
1054
1055 layout.setLayout(3, QFormLayout::FieldRole, &l2);
1056 layout.setLayout(3, QFormLayout::LabelRole, &l3);
1057 QCOMPARE(layout.count(), 3);
1058 QCOMPARE(layout.rowCount(), 6);
1059
1060 // should be ignored and generate warnings
1061 layout.setLayout(3, QFormLayout::FieldRole, &l4);
1062 layout.setLayout(-1, QFormLayout::FieldRole, &l4);
1063 QCOMPARE(layout.count(), 3);
1064 QCOMPARE(layout.rowCount(), 6);
1065
1066 {
1067 int row = -1;
1068 QFormLayout::ItemRole role = invalidRole;
1069 layout.getLayoutPosition(&l1, &row, &role);
1070 QCOMPARE(row, 5);
1071 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1072 }
1073
1074 {
1075 int row = -1;
1076 QFormLayout::ItemRole role = invalidRole;
1077 layout.getLayoutPosition(&l2, &row, &role);
1078 QCOMPARE(row, 3);
1079 QCOMPARE(int(role), int(QFormLayout::FieldRole));
1080 }
1081
1082 {
1083 int row = -1;
1084 QFormLayout::ItemRole role = invalidRole;
1085 layout.getLayoutPosition(&l3, &row, &role);
1086 QCOMPARE(row, 3);
1087 QCOMPARE(int(role), int(QFormLayout::LabelRole));
1088 }
1089
1090 {
1091 int row = -1;
1092 QFormLayout::ItemRole role = invalidRole;
1093 layout.getLayoutPosition(&l4, &row, &role);
1094 QCOMPARE(row, -1);
1095 QCOMPARE(int(role), int(invalidRole));
1096 }
1097
1098 {
1099 int row = -1;
1100 QFormLayout::ItemRole role = invalidRole;
1101 layout.getLayoutPosition(0, &row, &role);
1102 QCOMPARE(row, -1);
1103 QCOMPARE(int(role), int(invalidRole));
1104 }
1105}
1106
1107void tst_QFormLayout::itemAt()
1108{
1109 QWidget topLevel;
1110 QFormLayout *layout = new QFormLayout(&topLevel);
1111
1112 QWidget *w1 = new QWidget(&topLevel);
1113 QWidget *w2 = new QWidget(&topLevel);
1114 QWidget *w3 = new QWidget(&topLevel);
1115 QWidget *w4 = new QWidget(&topLevel);
1116 QWidget *w5 = new QWidget(&topLevel);
1117 QHBoxLayout *l6 = new QHBoxLayout;
1118
1119 layout->setWidget(5, QFormLayout::LabelRole, w1);
1120 layout->setWidget(3, QFormLayout::FieldRole, w2);
1121 layout->setWidget(3, QFormLayout::LabelRole, w3);
1122 layout->addRow(w4, w5);
1123 layout->addRow("Foo:", l6);
1124
1125 QCOMPARE(layout->count(), 7);
1126
1127 QBitArray scoreBoard(7);
1128 for (int i = 0; i < 7; ++i) {
1129 QLayoutItem *item = layout->itemAt(i);
1130 QVERIFY(item != 0);
1131
1132 if (item->widget() == w1) {
1133 scoreBoard[0] = true;
1134 } else if (item->widget() == w2) {
1135 scoreBoard[1] = true;
1136 } else if (item->widget() == w3) {
1137 scoreBoard[2] = true;
1138 } else if (item->widget() == w4) {
1139 scoreBoard[3] = true;
1140 } else if (item->widget() == w5) {
1141 scoreBoard[4] = true;
1142 } else if (item->layout() == l6) {
1143 scoreBoard[5] = true;
1144 } else if (qobject_cast<QLabel *>(item->widget())) {
1145 scoreBoard[6] = true;
1146 }
1147 }
1148 QCOMPARE(scoreBoard.count(false), 0);
1149}
1150
1151void tst_QFormLayout::takeAt()
1152{
1153 QWidget topLevel;
1154 QFormLayout *layout = new QFormLayout(&topLevel);
1155
1156 QWidget *w1 = new QWidget(&topLevel);
1157 QWidget *w2 = new QWidget(&topLevel);
1158 QWidget *w3 = new QWidget(&topLevel);
1159 QWidget *w4 = new QWidget(&topLevel);
1160 QWidget *w5 = new QWidget(&topLevel);
1161 QHBoxLayout *l6 = new QHBoxLayout;
1162
1163 layout->setWidget(5, QFormLayout::LabelRole, w1);
1164 layout->setWidget(3, QFormLayout::FieldRole, w2);
1165 layout->setWidget(3, QFormLayout::LabelRole, w3);
1166 layout->addRow(w4, w5);
1167 layout->addRow("Foo:", l6);
1168
1169 QCOMPARE(layout->count(), 7);
1170
1171 for (int i = 6; i >= 0; --i) {
1172 delete layout->takeAt(0);
1173 QCOMPARE(layout->count(), i);
1174 }
1175}
1176
1177void tst_QFormLayout::layoutAlone()
1178{
1179 QWidget w;
1180 QFormLayout layout;
1181 layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
1182 w.setLayout(&layout);
1183 QLabel label("Here is a strange test case");
1184 layout.setWidget(0, QFormLayout::LabelRole, &label);
1185 QHBoxLayout hlay;
1186 layout.setLayout(1, QFormLayout::LabelRole, &hlay);
1187 QCOMPARE(layout.count(), 2);
1188 w.setWindowTitle(QTest::currentTestFunction());
1189 w.show();
1190 layout.activate();
1191}
1192
1193void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout()
1194{
1195 QSharedPointer<QFormLayout> outer(new QFormLayout);
1196 QPointer<QFormLayout> inner = new QFormLayout;
1197
1198 outer->addRow(inner);
1199 QCOMPARE(outer->count(), 1);
1200 QCOMPARE(inner->parent(), outer.data());
1201
1202 QLayoutItem *item = outer->takeAt(0);
1203 QCOMPARE(item->layout(), inner.data());
1204 QVERIFY(!item->layout()->parent());
1205
1206 outer.reset();
1207
1208 if (inner)
1209 delete item; // success: a taken item/layout should not be deleted when the old parent is deleted
1210 else
1211 QVERIFY(!inner.isNull());
1212}
1213
1214void tst_QFormLayout::taskQTBUG_40609_addingWidgetToItsOwnLayout(){
1215 QWidget widget;
1216 widget.setObjectName("6435cbada60548b4522cbb6");
1217 QFormLayout layout(&widget);
1218 layout.setObjectName("c03c0e22c0b6d019a93a248");
1219
1220 QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add parent widget QWidget/6435cbada60548b4522cbb6 to its child layout QFormLayout/c03c0e22c0b6d019a93a248");
1221 layout.addRow(QLatin1String("48c81f39b7320082f8"), &widget);
1222 QCOMPARE(layout.count(), 0);
1223}
1224
1225void tst_QFormLayout::taskQTBUG_40609_addingLayoutToItself(){
1226 QWidget widget;
1227 widget.setObjectName("2bc425637d084c07ce65956");
1228 QFormLayout layout(&widget);
1229 layout.setObjectName("60e31de0c8800eaba713a4f2");
1230
1231 QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add layout QFormLayout/60e31de0c8800eaba713a4f2 to itself");
1232 layout.addRow(QLatin1String("9a2cd4f40c06b489f889"), &layout);
1233 QCOMPARE(layout.count(), 0);
1234}
1235
1236void tst_QFormLayout::replaceWidget()
1237{
1238 QWidget w;
1239 QFormLayout *layout = new QFormLayout();
1240 w.setLayout(layout);
1241 QLineEdit *edit1 = new QLineEdit();
1242 QLineEdit *edit2 = new QLineEdit();
1243 QLineEdit *edit3 = new QLineEdit();
1244 QLabel *label1 = new QLabel();
1245 QLabel *label2 = new QLabel();
1246
1247 layout->addRow("Label", edit1);
1248 layout->addRow(label1, edit2);
1249
1250 // Verify controls not in layout
1251 QCOMPARE(layout->indexOf(edit3), -1);
1252 QCOMPARE(layout->indexOf(label2), -1);
1253
1254 // Verify controls in layout
1255 int editIndex = layout->indexOf(edit1);
1256 int labelIndex = layout->indexOf(label1);
1257 QVERIFY(editIndex > 0);
1258 QVERIFY(labelIndex > 0);
1259 int rownum;
1260 QFormLayout::ItemRole role;
1261
1262 // replace editor
1263 delete layout->replaceWidget(edit1, edit3);
1264 edit1->hide(); // Not strictly needed for the test, but for normal usage it is.
1265 QCOMPARE(layout->indexOf(edit1), -1);
1266 QCOMPARE(layout->indexOf(edit3), editIndex);
1267 QCOMPARE(layout->indexOf(label1), labelIndex);
1268 rownum = -1;
1269 role = QFormLayout::SpanningRole;
1270 layout->getWidgetPosition(edit3, &rownum, &role);
1271 QCOMPARE(rownum, 0);
1272 QCOMPARE(role, QFormLayout::FieldRole);
1273
1274 delete layout->replaceWidget(label1, label2);
1275 label1->hide();
1276 QCOMPARE(layout->indexOf(label1), -1);
1277 QCOMPARE(layout->indexOf(label2), labelIndex);
1278 layout->getWidgetPosition(label2, &rownum, &role);
1279 QCOMPARE(rownum, 1);
1280 QCOMPARE(role, QFormLayout::LabelRole);
1281
1282}
1283
1284QTEST_MAIN(tst_QFormLayout)
1285
1286#include "tst_qformlayout.moc"
1287