summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp67
1 files changed, 58 insertions, 9 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index cefff80..65837ae 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -704,6 +704,9 @@ void tst_QGraphicsItem::flags()
QCOMPARE(item->flags(), 0);
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
scene.addItem(item);
{
@@ -888,6 +891,9 @@ void tst_QGraphicsItem::visible()
QVERIFY(item->isVisible());
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
scene.addItem(item);
QVERIFY(item->isVisible());
QCOMPARE(scene.itemAt(0, 0), item);
@@ -1035,6 +1041,9 @@ void tst_QGraphicsItem::enabled()
item->setEnabled(false);
item->setFlag(QGraphicsItem::ItemIsFocusable);
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
scene.addItem(item);
item->setFocus();
QVERIFY(!item->hasFocus());
@@ -1714,6 +1723,9 @@ void tst_QGraphicsItem::hasFocus()
QVERIFY(!line->hasFocus());
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
scene.addItem(line);
line->setFocus();
@@ -1723,6 +1735,8 @@ void tst_QGraphicsItem::hasFocus()
QVERIFY(line->hasFocus());
QGraphicsScene scene2;
+ QApplication::sendEvent(&scene2, &activate);
+
scene2.addItem(line);
QVERIFY(!line->hasFocus());
@@ -3493,6 +3507,9 @@ void tst_QGraphicsItem::handlesChildEvents2()
void tst_QGraphicsItem::handlesChildEvents3()
{
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
ChildEventTester *group2 = new ChildEventTester(QRectF(), 0);
ChildEventTester *group1 = new ChildEventTester(QRectF(), group2);
ChildEventTester *leaf = new ChildEventTester(QRectF(), group1);
@@ -4466,8 +4483,13 @@ protected:
void tst_QGraphicsItem::sceneEventFilter()
{
QGraphicsScene scene;
+
QGraphicsView view(&scene);
view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(250);
QGraphicsTextItem *text1 = scene.addText(QLatin1String("Text1"));
QGraphicsTextItem *text2 = scene.addText(QLatin1String("Text2"));
@@ -4584,8 +4606,10 @@ void tst_QGraphicsItem::paint()
QGraphicsView view(&scene);
view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
QTest::qWait(250);
-
#ifdef Q_OS_WIN32
//we try to switch the desktop: if it fails, we skip the test
if (::SwitchDesktop( ::GetThreadDesktop( ::GetCurrentThreadId() ) ) == 0) {
@@ -4593,8 +4617,7 @@ void tst_QGraphicsItem::paint()
}
#endif
- QVERIFY(paintTester.widget == view.viewport());
-
+ QCOMPARE(paintTester.widget, view.viewport());
view.hide();
@@ -5599,6 +5622,9 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
QFETCH(int, textFlags);
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
QGraphicsTextItem *item = scene.addText("Hello");
item->setFlags(QGraphicsItem::GraphicsItemFlags(flags));
item->setTextInteractionFlags(Qt::TextInteractionFlags(textFlags));
@@ -6434,6 +6460,7 @@ void tst_QGraphicsItem::tabChangesFocus()
QDial *dial1 = new QDial;
QGraphicsView *view = new QGraphicsView(&scene);
+
QDial *dial2 = new QDial;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(dial1);
@@ -6446,6 +6473,8 @@ void tst_QGraphicsItem::tabChangesFocus()
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&widget);
#endif
+ QTest::qWait(250);
+ QVERIFY(scene.isActive());
dial1->setFocus();
QTest::qWait(125);
@@ -7472,6 +7501,9 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem()
void tst_QGraphicsItem::focusProxy()
{
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
QGraphicsItem *item = scene.addRect(0, 0, 10, 10);
item->setFlag(QGraphicsItem::ItemIsFocusable);
QVERIFY(!item->focusProxy());
@@ -7570,6 +7602,9 @@ void tst_QGraphicsItem::subFocus()
// Add both items to a scene and check that it's text that
// got input focus.
QGraphicsScene scene;
+ QEvent activate(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &activate);
+
scene.addItem(text);
scene.addItem(text2);
QVERIFY(text->hasFocus());
@@ -7578,18 +7613,15 @@ void tst_QGraphicsItem::subFocus()
text2->setData(0, "text2");
// Remove text2 and set subfocus on it. Then readd. Reparent it onto the
- // other item and see that although it becomes text's focus
- // item, it does not immediately gain input focus.
+ // other item and see that it gains input focus.
scene.removeItem(text2);
text2->setFocus();
scene.addItem(text2);
QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
text2->setParentItem(text);
- qDebug() << text->data(0).toString() << (void*)(QGraphicsItem *)text;
- qDebug() << text2->data(0).toString() << (void*)(QGraphicsItem *)text2;
QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
- QVERIFY(text->hasFocus());
- QVERIFY(!text2->hasFocus());
+ QVERIFY(!text->hasFocus());
+ QVERIFY(text2->hasFocus());
// Remove both items from the scene, restore subfocus and
// readd them. Now the subfocus should kick in and give
@@ -7605,6 +7637,23 @@ void tst_QGraphicsItem::subFocus()
// Hiding and showing text should pass focus to text2.
QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
QVERIFY(text2->hasFocus());
+
+ // Subfocus should repropagate to root when reparenting.
+ QGraphicsRectItem *rect = new QGraphicsRectItem;
+ QGraphicsRectItem *rect2 = new QGraphicsRectItem(rect);
+ QGraphicsRectItem *rect3 = new QGraphicsRectItem(rect2);
+ rect3->setFlag(QGraphicsItem::ItemIsFocusable);
+
+ rect3->setFocus();
+ QVERIFY(!rect3->hasFocus());
+ QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3);
+ QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3);
+ QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3);
+ rect->setParentItem(text2);
+ QCOMPARE(text->focusItem(), (QGraphicsItem *)rect3);
+ QVERIFY(!rect->hasFocus());
+ QVERIFY(!rect2->hasFocus());
+ QVERIFY(rect3->hasFocus());
}
void tst_QGraphicsItem::focusProxyDeletion()