diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-22 13:48:23 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-22 15:25:01 (GMT) |
commit | 701bdcbc8b7751834f6d24844bcb91a23cbdc409 (patch) | |
tree | 08b01cf07b2cff2d7f51bceb8a06656f25f5d942 /tests/auto/qitemdelegate | |
parent | fc7a43cceba63b79a40183334ab97527483113e3 (diff) | |
download | Qt-701bdcbc8b7751834f6d24844bcb91a23cbdc409.zip Qt-701bdcbc8b7751834f6d24844bcb91a23cbdc409.tar.gz Qt-701bdcbc8b7751834f6d24844bcb91a23cbdc409.tar.bz2 |
Pressing enter in a QPlainTextEdit embedded on a itemview should insert a newline
Do the same special case as for QTextEdit
(yes, this is a pitty that we have special cases like that
Reviewed-by: Thierry
Task-number: 252532
Diffstat (limited to 'tests/auto/qitemdelegate')
-rw-r--r-- | tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 27741e0..615ac01 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -59,6 +59,8 @@ #include <QItemDelegate> #include <QAbstractItemDelegate> +#include <QTextEdit> +#include <QPlainTextEdit> Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) @@ -226,6 +228,8 @@ private slots: void decoration(); void editorEvent_data(); void editorEvent(); + void enterKey_data(); + void enterKey(); }; @@ -1048,6 +1052,80 @@ void tst_QItemDelegate::editorEvent() QCOMPARE(index.data(Qt::CheckStateRole).toInt(), expectedCheckState); } +void tst_QItemDelegate::enterKey_data() +{ + QTest::addColumn<int>("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; +} + +void tst_QItemDelegate::enterKey() +{ + QFETCH(int, widget); + QFETCH(int, key); + QFETCH(bool, expectedFocus); + + QStandardItemModel model; + model.appendRow(new QStandardItem()); + + QListView view; + view.setModel(&model); + view.show(); + QApplication::setActiveWindow(&view); + view.setFocus(); + QTest::qWait(30); + + struct TestDelegate : public QItemDelegate + { + int widgetType; + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const + { + QWidget *editor = 0; + switch(widgetType) { + case 1: + editor = new QLineEdit(parent); + break; + case 2: + editor = new QTextEdit(parent); + break; + case 3: + editor = new QPlainTextEdit(parent); + break; + } + editor->setObjectName(QString::fromLatin1("TheEditor")); + return editor; + } + } delegate; + + delegate.widgetType = widget; + + view.setItemDelegate(&delegate); + QModelIndex index = model.index(0, 0); + view.setCurrentIndex(index); // the editor will only selectAll on the current index + view.edit(index); + QTest::qWait(30); + + QList<QWidget*> lineEditors = qFindChildren<QWidget *>(view.viewport(), QString::fromLatin1("TheEditor")); + QCOMPARE(lineEditors.count(), 1); + + QWidget *editor = lineEditors.at(0); + QCOMPARE(editor->hasFocus(), true); + + QTest::keyClick(editor, Qt::Key(key)); + QApplication::processEvents(); + + QCOMPARE(editor->hasFocus(), expectedFocus); +} + + + // ### _not_ covered: // editing with a custom editor factory |