From 08b157b930850a154557d41d2e11d61391fadf63 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Thu, 20 Aug 2009 14:49:13 +0200 Subject: Document, partly by making the code self-documenting, a crash fix. Addresses a review comment. --- tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 35 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 87a12d6..75d9c8f 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -1055,23 +1055,31 @@ void tst_QItemDelegate::editorEvent() QCOMPARE(index.data(Qt::CheckStateRole).toInt(), expectedCheckState); } +enum WidgetType +{ + LineEdit, + TextEdit, + PlainTextEdit +}; +Q_DECLARE_METATYPE(WidgetType); + void tst_QItemDelegate::enterKey_data() { - QTest::addColumn("widget"); + QTest::addColumn("widget"); QTest::addColumn("key"); QTest::addColumn("expectedFocus"); - QTest::newRow("lineedit enter") << 1 << int(Qt::Key_Enter) << false; - QTest::newRow("textedit enter") << 2 << int(Qt::Key_Enter) << true; - QTest::newRow("plaintextedit enter") << 3 << int(Qt::Key_Enter) << true; - QTest::newRow("plaintextedit return") << 3 << int(Qt::Key_Return) << true; - QTest::newRow("plaintextedit tab") << 3 << int(Qt::Key_Tab) << false; - QTest::newRow("lineedit tab") << 1 << int(Qt::Key_Tab) << false; + QTest::newRow("lineedit enter") << LineEdit << int(Qt::Key_Enter) << false; + QTest::newRow("textedit enter") << TextEdit << int(Qt::Key_Enter) << true; + QTest::newRow("plaintextedit enter") << PlainTextEdit << int(Qt::Key_Enter) << true; + QTest::newRow("plaintextedit return") << PlainTextEdit << int(Qt::Key_Return) << true; + QTest::newRow("plaintextedit tab") << PlainTextEdit << int(Qt::Key_Tab) << false; + QTest::newRow("lineedit tab") << LineEdit << int(Qt::Key_Tab) << false; } void tst_QItemDelegate::enterKey() { - QFETCH(int, widget); + QFETCH(WidgetType, widget); QFETCH(int, key); QFETCH(bool, expectedFocus); @@ -1087,18 +1095,18 @@ void tst_QItemDelegate::enterKey() struct TestDelegate : public QItemDelegate { - int widgetType; + WidgetType widgetType; virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const { QWidget *editor = 0; switch(widgetType) { - case 1: + case LineEdit: editor = new QLineEdit(parent); break; - case 2: + case TextEdit: editor = new QTextEdit(parent); break; - case 3: + case PlainTextEdit: editor = new QPlainTextEdit(parent); break; } @@ -1124,7 +1132,8 @@ void tst_QItemDelegate::enterKey() QTest::keyClick(editor, Qt::Key(key)); QApplication::processEvents(); - if (widget == 2 || widget == 3) { + // The line edit has already been destroyed, so avoid that case. + if (widget == TextEdit || widget == PlainTextEdit) { QVERIFY(!editor.isNull()); QCOMPARE(editor && editor->hasFocus(), expectedFocus); } -- cgit v0.12