diff options
author | Sergio Martins <sergio.martins@kdab.com> | 2018-02-01 12:36:52 +0000 |
---|---|---|
committer | Sérgio Martins <sergio.martins@kdab.com> | 2018-02-10 21:14:55 +0000 |
commit | 7a342372bb1ecbe4146811cff48ede974c7761b5 (patch) | |
tree | f87909d4e5cd363bf031f07d40c988aedec26788 /tests/auto/widgets/kernel/qboxlayout | |
parent | dc9ce275be88e2c656f596d867be1db7f7dd3553 (diff) |
Introduce QLayout::indexOf(QLayoutItem *)
This was the missing counter-part to indexOf(QWidget *), which is
sometimes implemented in user code.
Not sure why the original code doesn't use a for-loop and instead accesses
an out-of-bounds element, but I'll preserve the behavior of very old working code.
Change-Id: I7d7fa56b56a4626789774c15c23fdfef41d723e7
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/widgets/kernel/qboxlayout')
-rw-r--r-- | tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index 2f1a305710..3dfb9c35b3 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -56,6 +56,7 @@ private slots: void taskQTBUG_40609_addingWidgetToItsOwnLayout(); void taskQTBUG_40609_addingLayoutToItself(); void replaceWidget(); + void indexOf(); }; class CustomLayoutStyle : public QProxyStyle @@ -514,5 +515,24 @@ void tst_QBoxLayout::replaceWidget() QCOMPARE(boxLayout->indexOf(replaceTo), 1); } +void tst_QBoxLayout::indexOf() +{ + QWidget w; + auto outer = new QVBoxLayout(&w); + auto inner = new QHBoxLayout(); + outer->addLayout(inner); + auto widget1 = new QWidget(); + QWidget widget2; + inner->addWidget(widget1); + + QCOMPARE(inner->indexOf(widget1), 0); + QCOMPARE(inner->indexOf(&widget2), -1); + QCOMPARE(outer->indexOf(widget1), -1); + QCOMPARE(outer->indexOf(&widget2), -1); + QCOMPARE(outer->indexOf(outer), -1); + QCOMPARE(outer->indexOf(inner), 0); + QCOMPARE(inner->indexOf(inner->itemAt(0)), 0); +} + QTEST_MAIN(tst_QBoxLayout) #include "tst_qboxlayout.moc" |