diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-01-21 09:56:26 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2019-01-22 12:33:01 +0000 |
commit | 9822d57d858068cfe5a07281ef069ef8c4c7b7b3 (patch) | |
tree | f1eb8c5abbc09400cb74493d5db75f145e9b0eed /tests | |
parent | 8c0a7a46c691f7acad169f5949d3b3d76a227614 (diff) |
Stabilize tst_QItemDelegate::dateTimeEditor()
Add qWaitForWindowExposed() for the toplevel and use QTRY_VERIFY()
for finding the delegates consistently.
Change-Id: I430088a91b5cc1a8f856d0a58aba066b1baf179b
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index a8f6906056..5a789a1aa2 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -727,6 +727,16 @@ void tst_QItemDelegate::dateTimeEditor_data() << QDate(2006, 10, 31); } +static QDateTimeEdit *findDateTimeEdit(const QWidget *widget) +{ + const auto dateTimeEditors = widget->findChildren<QDateTimeEdit *>(); + for (auto dateTimeEditor : dateTimeEditors) { + if (qstrcmp(dateTimeEditor->metaObject()->className(), "QDateTimeEdit") == 0) + return dateTimeEditor; + } + return nullptr; +} + void tst_QItemDelegate::dateTimeEditor() { QFETCH(QTime, time); @@ -742,17 +752,24 @@ void tst_QItemDelegate::dateTimeEditor() item3->setData(Qt::DisplayRole, QDateTime(date, time)); QTableWidget widget(1, 3); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); widget.setItem(0, 0, item1); widget.setItem(0, 1, item2); widget.setItem(0, 2, item3); widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QApplication::setActiveWindow(&widget); widget.editItem(item1); QTestEventLoop::instance().enterLoop(1); - QTimeEdit *timeEditor = widget.viewport()->findChild<QTimeEdit *>(); - QVERIFY(timeEditor); + + QTimeEdit *timeEditor = nullptr; + auto viewport = widget.viewport(); + QTRY_VERIFY( (timeEditor = viewport->findChild<QTimeEdit *>()) ); QCOMPARE(timeEditor->time(), time); // The data must actually be different in order for the model // to be updated. @@ -763,8 +780,8 @@ void tst_QItemDelegate::dateTimeEditor() widget.setFocus(); widget.editItem(item2); - QTRY_VERIFY(widget.viewport()->findChild<QDateEdit *>()); - QDateEdit *dateEditor = widget.viewport()->findChild<QDateEdit *>(); + QDateEdit *dateEditor = nullptr; + QTRY_VERIFY( (dateEditor = viewport->findChild<QDateEdit *>()) ); QCOMPARE(dateEditor->date(), date); dateEditor->setDate(date.addDays(60)); @@ -774,12 +791,8 @@ void tst_QItemDelegate::dateTimeEditor() QTestEventLoop::instance().enterLoop(1); - QList<QDateTimeEdit *> dateTimeEditors = widget.findChildren<QDateTimeEdit *>(); - QDateTimeEdit *dateTimeEditor = 0; - foreach(dateTimeEditor, dateTimeEditors) - if (dateTimeEditor->metaObject()->className() == QLatin1String("QDateTimeEdit")) - break; - QVERIFY(dateTimeEditor); + QDateTimeEdit *dateTimeEditor = nullptr; + QTRY_VERIFY( (dateTimeEditor = findDateTimeEdit(viewport)) ); QCOMPARE(dateTimeEditor->date(), date); QCOMPARE(dateTimeEditor->time(), time); dateTimeEditor->setTime(time.addSecs(600)); |