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>bb10
parent
8c0a7a46c6
commit
9822d57d85
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue