diff options
author | Frans Englich <frans.englich@nokia.com> | 2009-08-20 12:49:13 (GMT) |
---|---|---|
committer | Frans Englich <frans.englich@nokia.com> | 2009-08-20 12:51:57 (GMT) |
commit | 08b157b930850a154557d41d2e11d61391fadf63 (patch) | |
tree | fb9bc209336ed694db71a783a508a3fc07ddeac5 /tests/auto/qitemdelegate/tst_qitemdelegate.cpp | |
parent | adc732da98be7c2c13ffafaf6535e3cc47ebc0c3 (diff) | |
download | Qt-08b157b930850a154557d41d2e11d61391fadf63.zip Qt-08b157b930850a154557d41d2e11d61391fadf63.tar.gz Qt-08b157b930850a154557d41d2e11d61391fadf63.tar.bz2 |
Document, partly by making the code self-documenting, a crash fix.
Addresses a review comment.
Diffstat (limited to 'tests/auto/qitemdelegate/tst_qitemdelegate.cpp')
-rw-r--r-- | tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 35 |
1 files 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<int>("widget"); + QTest::addColumn<WidgetType>("widget"); QTest::addColumn<int>("key"); QTest::addColumn<bool>("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); } |