summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-03-28 15:03:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-01 05:26:50 +0200
commitcc08fc7bfd1a5cf2da52d49b8b4989b33d3597cc (patch)
tree815e1145b6636635bbe5a7c2fd2c900a7f6739ea /tests/auto
parentf4f23bd5b047353a1a6f56810917e0c0f27de219 (diff)
Item views: respect focus policy when closing an editor
Task-number: QTBUG-31411 Change-Id: Ib0a72755c35a553653ea014672d59979a550b7ae Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index c3aaf6be16..b8875c638d 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -60,6 +60,7 @@
#include <qlineedit.h>
#include <qscreen.h>
#include <qscopedpointer.h>
+#include <qstyleditemdelegate.h>
static inline void setFrameless(QWidget *w)
{
@@ -244,6 +245,8 @@ private slots:
void testChangeEditorState();
void deselectInSingleSelection();
void testNoActivateOnDisabledItem();
+ void testFocusPolicy_data();
+ void testFocusPolicy();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -1728,5 +1731,56 @@ void tst_QAbstractItemView::testNoActivateOnDisabledItem()
QCOMPARE(activatedSpy.count(), 0);
}
+void tst_QAbstractItemView::testFocusPolicy_data()
+{
+ QTest::addColumn<QAbstractItemDelegate*>("delegate");
+
+ QAbstractItemDelegate *styledItemDelegate = new QStyledItemDelegate(this);
+ QAbstractItemDelegate *itemDelegate = new QItemDelegate(this);
+
+ QTest::newRow("QStyledItemDelegate") << styledItemDelegate;
+ QTest::newRow("QItemDelegate") << itemDelegate;
+}
+
+void tst_QAbstractItemView::testFocusPolicy()
+{
+ QFETCH(QAbstractItemDelegate*, delegate);
+
+ QWidget window;
+ QTableView *table = new QTableView(&window);
+ table->setItemDelegate(delegate);
+ QVBoxLayout *layout = new QVBoxLayout(&window);
+ layout->addWidget(table);
+
+ QStandardItemModel model;
+ model.setRowCount(10);
+ model.setColumnCount(10);
+ table->setModel(&model);
+ table->setCurrentIndex(model.index(1, 1));
+
+ centerOnScreen(&window);
+ moveCursorAway(&window);
+
+ window.show();
+ QApplication::setActiveWindow(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+
+ // itemview accepts focus => editor is closed => return focus to the itemview
+ QPoint clickpos = table->visualRect(model.index(1, 1)).center();
+ QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
+ QWidget *editor = qApp->focusWidget();
+ QVERIFY(editor);
+ QTest::keyClick(editor, Qt::Key_Escape, Qt::NoModifier);
+ QCOMPARE(qApp->focusWidget(), table);
+
+ // itemview doesn't accept focus => editor is closed => clear the focus
+ table->setFocusPolicy(Qt::NoFocus);
+ QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
+ editor = qApp->focusWidget();
+ QVERIFY(editor);
+ QTest::keyClick(editor, Qt::Key_Escape, Qt::NoModifier);
+ QVERIFY(!qApp->focusWidget());
+}
+
QTEST_MAIN(tst_QAbstractItemView)
#include "tst_qabstractitemview.moc"