summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@nokia.com>2010-07-13 12:21:44 (GMT)
committerYoann Lopes <yoann.lopes@nokia.com>2010-07-13 13:07:33 (GMT)
commitb5b011a181bd187dcef5ee8f46a3ac2c5dc2e09c (patch)
tree60b9ffbc1b26a18e21312fab6f9be065f868939c /tests
parent7d09f690d5b4c56699092444665d1879deb86a6e (diff)
downloadQt-b5b011a181bd187dcef5ee8f46a3ac2c5dc2e09c.zip
Qt-b5b011a181bd187dcef5ee8f46a3ac2c5dc2e09c.tar.gz
Qt-b5b011a181bd187dcef5ee8f46a3ac2c5dc2e09c.tar.bz2
Fixes QGraphicsItem::focusItem() returning incorrect value.
When setting focus on an item, subfocus chain was previously updated only for items with a common ancestor. We now make sure that this chain is updated also for the previously focused item (possibly not sharing any common ancestor with the newly focused item). Autotest included. Task-number: QTBUG-12112 Reviewed-by: Alexis Ménard <alexis.menard@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 1ae3ecf..3634ce9 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -463,6 +463,7 @@ private slots:
void sortItemsWhileAdding();
void doNotMarkFullUpdateIfNotInScene();
void itemDiesDuringDraggingOperation();
+ void QTBUG_12112_focusItem();
private:
QList<QGraphicsItem *> paintedItems;
@@ -10724,5 +10725,31 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation()
delete item;
QVERIFY(QGraphicsScenePrivate::get(&scene)->dragDropItem == 0);
}
+
+void tst_QGraphicsItem::QTBUG_12112_focusItem()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 20, 20);
+ item1->setFlag(QGraphicsItem::ItemIsFocusable);
+ QGraphicsRectItem *item2 = new QGraphicsRectItem(20, 20, 20, 20);
+ item2->setFlag(QGraphicsItem::ItemIsFocusable);
+ item1->setFocus();
+ scene.addItem(item2);
+ scene.addItem(item1);
+
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+ QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view);
+
+ QVERIFY(item1->focusItem());
+ QVERIFY(!item2->focusItem());
+
+ item2->setFocus();
+ QVERIFY(!item1->focusItem());
+ QVERIFY(item2->focusItem());
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"