summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp')
-rw-r--r--tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
index b970de8e87..135605f185 100644
--- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
+++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
@@ -122,6 +122,7 @@ private slots:
void itemAt();
void takeAt();
void layoutAlone();
+ void replaceWidget();
/*
void setGeometry(const QRect &rect);
QSize minimumSize() const;
@@ -934,6 +935,54 @@ void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout()
QVERIFY(!inner.isNull());
}
+void tst_QFormLayout::replaceWidget()
+{
+ QWidget w;
+ QFormLayout *layout = new QFormLayout();
+ w.setLayout(layout);
+ QLineEdit *edit1 = new QLineEdit();
+ QLineEdit *edit2 = new QLineEdit();
+ QLineEdit *edit3 = new QLineEdit();
+ QLabel *label1 = new QLabel();
+ QLabel *label2 = new QLabel();
+
+ layout->addRow("Label", edit1);
+ layout->addRow(label1, edit2);
+
+ // Verify controls not in layout
+ QCOMPARE(layout->indexOf(edit3), -1);
+ QCOMPARE(layout->indexOf(label2), -1);
+
+ // Verify controls in layout
+ int editIndex = layout->indexOf(edit1);
+ int labelIndex = layout->indexOf(label1);
+ QVERIFY(editIndex > 0);
+ QVERIFY(labelIndex > 0);
+ int rownum;
+ QFormLayout::ItemRole role;
+
+ // replace editor
+ layout->replaceWidget(edit1, edit3);
+ edit1->hide(); // Not strictly needed for the test, but for normal usage it is.
+ QCOMPARE(layout->indexOf(edit1), -1);
+ QCOMPARE(layout->indexOf(edit3), editIndex);
+ QCOMPARE(layout->indexOf(label1), labelIndex);
+ rownum = -1;
+ role = QFormLayout::SpanningRole;
+ layout->getWidgetPosition(edit3, &rownum, &role);
+ QCOMPARE(rownum, 0);
+ QCOMPARE(role, QFormLayout::FieldRole);
+
+ layout->replaceWidget(label1, label2);
+ label1->hide();
+ QCOMPARE(layout->indexOf(label1), -1);
+ QCOMPARE(layout->indexOf(label2), labelIndex);
+ layout->getWidgetPosition(label2, &rownum, &role);
+ QCOMPARE(rownum, 1);
+ QCOMPARE(role, QFormLayout::LabelRole);
+
+}
+
QTEST_MAIN(tst_QFormLayout)
#include "tst_qformlayout.moc"