summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp')
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index 24acd63..e9d6f1d 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -252,6 +252,8 @@ private slots:
void stickyFocus_data();
void stickyFocus();
void sendEvent();
+ void inputMethod_data();
+ void inputMethod();
// task specific tests below me
void task139710_bspTreeCrash();
@@ -3634,5 +3636,61 @@ void tst_QGraphicsScene::sendEvent()
QCOMPARE(spy->count(), 1);
}
+void tst_QGraphicsScene::inputMethod_data()
+{
+ QTest::addColumn<int>("flags");
+ QTest::addColumn<bool>("callFocusItem");
+ QTest::newRow("0") << 0 << false;
+ QTest::newRow("1") << (int)QGraphicsItem::ItemAcceptsInputMethod << false;
+ QTest::newRow("2") << (int)QGraphicsItem::ItemIsFocusable << false;
+ QTest::newRow("3") <<
+ (int)(QGraphicsItem::ItemAcceptsInputMethod|QGraphicsItem::ItemIsFocusable) << true;
+}
+
+class InputMethodTester : public QGraphicsRectItem
+{
+ void inputMethodEvent(QInputMethodEvent *) { ++eventCalls; }
+ QVariant inputMethodQuery(Qt::InputMethodQuery) const { ++queryCalls; return QVariant(); }
+public:
+ int eventCalls;
+ mutable int queryCalls;
+};
+
+void tst_QGraphicsScene::inputMethod()
+{
+ QFETCH(int, flags);
+ QFETCH(bool, callFocusItem);
+
+ InputMethodTester *item = new InputMethodTester;
+ item->setFlags((QGraphicsItem::GraphicsItemFlags)flags);
+
+ QGraphicsScene scene;
+ scene.addItem(item);
+ QInputMethodEvent event;
+
+ scene.setFocusItem(item);
+ QCOMPARE(!!(item->flags() & QGraphicsItem::ItemIsFocusable), scene.focusItem() == item);
+
+ item->eventCalls = 0;
+ qApp->sendEvent(&scene, &event);
+ QCOMPARE(item->eventCalls, callFocusItem ? 1 : 0);
+
+ item->queryCalls = 0;
+ scene.inputMethodQuery((Qt::InputMethodQuery)0);
+ QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0);
+
+ scene.setFocusItem(0);
+ QCOMPARE(item->eventCalls, callFocusItem ? 2 : 0); // verify correct delivery of "reset" event
+ QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); // verify that value is unaffected
+
+ item->eventCalls = 0;
+ qApp->sendEvent(&scene, &event);
+ QCOMPARE(item->eventCalls, 0);
+
+ item->queryCalls = 0;
+ scene.inputMethodQuery((Qt::InputMethodQuery)0);
+ QCOMPARE(item->queryCalls, 0);
+}
+
QTEST_MAIN(tst_QGraphicsScene)
#include "tst_qgraphicsscene.moc"