diff options
Diffstat (limited to 'tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 140 |
1 files changed, 118 insertions, 22 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 541b5ba..517380e 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -289,6 +289,8 @@ private slots: void setGraphicsEffect(); void panel(); void addPanelToActiveScene(); + void activate(); + void setActivePanelOnInactiveScene(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -7823,26 +7825,15 @@ void tst_QGraphicsItem::panel() // No previous activation, so the scene is active. QVERIFY(scene.isActive()); - QVERIFY(!scene.activePanel()); - QVERIFY(!panel1->isActive()); - QVERIFY(!panel2->isActive()); - QVERIFY(!panel3->isActive()); - QVERIFY(!panel4->isActive()); - QVERIFY(notPanel1->isActive()); - QVERIFY(notPanel2->isActive()); - QCOMPARE(spy_activate_notPanel1.count(), 1); - QCOMPARE(spy_activate_notPanel2.count(), 1); - - // Switch to panel1. - scene.setActivePanel(panel1); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)panel1); QVERIFY(panel1->isActive()); QVERIFY(!panel2->isActive()); QVERIFY(!panel3->isActive()); QVERIFY(!panel4->isActive()); QVERIFY(!notPanel1->isActive()); QVERIFY(!notPanel2->isActive()); - QCOMPARE(spy_deactivate_notPanel1.count(), 1); - QCOMPARE(spy_deactivate_notPanel2.count(), 1); + QCOMPARE(spy_deactivate_notPanel1.count(), 0); + QCOMPARE(spy_deactivate_notPanel2.count(), 0); QCOMPARE(spy_activate_panel1.count(), 1); QCOMPARE(spy_activate_panel2.count(), 0); QCOMPARE(spy_activate_panel3.count(), 0); @@ -7857,8 +7848,8 @@ void tst_QGraphicsItem::panel() QVERIFY(!panel4->isActive()); QVERIFY(notPanel1->isActive()); QVERIFY(notPanel2->isActive()); - QCOMPARE(spy_activate_notPanel1.count(), 2); - QCOMPARE(spy_activate_notPanel2.count(), 2); + QCOMPARE(spy_activate_notPanel1.count(), 1); + QCOMPARE(spy_activate_notPanel2.count(), 1); // Deactivate the scene QApplication::sendEvent(&scene, &deactivate); @@ -7869,8 +7860,8 @@ void tst_QGraphicsItem::panel() QVERIFY(!panel4->isActive()); QVERIFY(!notPanel1->isActive()); QVERIFY(!notPanel2->isActive()); - QCOMPARE(spy_deactivate_notPanel1.count(), 2); - QCOMPARE(spy_deactivate_notPanel2.count(), 2); + QCOMPARE(spy_deactivate_notPanel1.count(), 1); + QCOMPARE(spy_deactivate_notPanel2.count(), 1); // Reactivate the scene QApplication::sendEvent(&scene, &activate); @@ -7881,14 +7872,14 @@ void tst_QGraphicsItem::panel() QVERIFY(!panel4->isActive()); QVERIFY(notPanel1->isActive()); QVERIFY(notPanel2->isActive()); - QCOMPARE(spy_activate_notPanel1.count(), 3); - QCOMPARE(spy_activate_notPanel2.count(), 3); + QCOMPARE(spy_activate_notPanel1.count(), 2); + QCOMPARE(spy_activate_notPanel2.count(), 2); // Switch to panel1 scene.setActivePanel(panel1); QVERIFY(panel1->isActive()); - QCOMPARE(spy_deactivate_notPanel1.count(), 3); - QCOMPARE(spy_deactivate_notPanel2.count(), 3); + QCOMPARE(spy_deactivate_notPanel1.count(), 2); + QCOMPARE(spy_deactivate_notPanel2.count(), 2); QCOMPARE(spy_activate_panel1.count(), 2); // Deactivate the scene @@ -7942,5 +7933,110 @@ void tst_QGraphicsItem::addPanelToActiveScene() QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect); } +void tst_QGraphicsItem::activate() +{ + QGraphicsScene scene; + QGraphicsRectItem *rect = scene.addRect(-10, -10, 20, 20); + QVERIFY(!rect->isActive()); + + QEvent activate(QEvent::WindowActivate); + QEvent deactivate(QEvent::WindowDeactivate); + + QApplication::sendEvent(&scene, &activate); + + // Non-panel item (active when scene is active). + QVERIFY(rect->isActive()); + + QGraphicsRectItem *rect2 = new QGraphicsRectItem; + rect2->setFlag(QGraphicsItem::ItemIsPanel); + QGraphicsRectItem *rect3 = new QGraphicsRectItem; + rect3->setFlag(QGraphicsItem::ItemIsPanel); + + // Test normal activation. + QVERIFY(!rect2->isActive()); + scene.addItem(rect2); + QVERIFY(rect2->isActive()); // first panel item is activated + scene.addItem(rect3); + QVERIFY(!rect3->isActive()); // second panel item is _not_ activated + rect3->setActive(true); + QVERIFY(rect3->isActive()); + scene.removeItem(rect3); + QVERIFY(!rect3->isActive()); // no panel is active anymore + QCOMPARE(scene.activePanel(), (QGraphicsItem *)0); + scene.addItem(rect3); + QVERIFY(rect3->isActive()); // second panel item is activated + + // Test pending activation. + scene.removeItem(rect3); + rect2->setActive(true); + QVERIFY(rect2->isActive()); // first panel item is activated + rect3->setActive(true); + QVERIFY(!rect3->isActive()); // not active (yet) + scene.addItem(rect3); + QVERIFY(rect3->isActive()); // now becomes active + + // Test pending deactivation. + scene.removeItem(rect3); + rect3->setActive(false); + scene.addItem(rect3); + QVERIFY(!rect3->isActive()); // doesn't become active + + // Child of panel activation. + rect3->setActive(true); + QGraphicsRectItem *rect4 = new QGraphicsRectItem; + rect4->setFlag(QGraphicsItem::ItemIsPanel); + QGraphicsRectItem *rect5 = new QGraphicsRectItem(rect4); + QGraphicsRectItem *rect6 = new QGraphicsRectItem(rect5); + scene.addItem(rect4); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect3); + scene.removeItem(rect4); + rect6->setActive(true); + scene.addItem(rect4); + QVERIFY(rect4->isActive()); + QVERIFY(rect5->isActive()); + QVERIFY(rect6->isActive()); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect4); + scene.removeItem(rect4); // no active panel + rect6->setActive(false); + scene.addItem(rect4); + QVERIFY(!rect4->isActive()); + QVERIFY(!rect5->isActive()); + QVERIFY(!rect6->isActive()); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)0); + + // Controlling auto-activation when the scene changes activation. + rect4->setActive(true); + QApplication::sendEvent(&scene, &deactivate); + QVERIFY(!scene.isActive()); + QVERIFY(!rect4->isActive()); + rect4->setActive(false); + QApplication::sendEvent(&scene, &activate); + QVERIFY(scene.isActive()); + QVERIFY(!scene.activePanel()); + QVERIFY(!rect4->isActive()); +} + +void tst_QGraphicsItem::setActivePanelOnInactiveScene() +{ + QGraphicsScene scene; + QGraphicsRectItem *item = scene.addRect(QRectF()); + QGraphicsRectItem *panel = scene.addRect(QRectF()); + panel->setFlag(QGraphicsItem::ItemIsPanel); + + EventSpy itemActivateSpy(&scene, item, QEvent::WindowActivate); + EventSpy itemDeactivateSpy(&scene, item, QEvent::WindowDeactivate); + EventSpy panelActivateSpy(&scene, panel, QEvent::WindowActivate); + EventSpy panelDeactivateSpy(&scene, panel, QEvent::WindowDeactivate); + EventSpy sceneActivationChangeSpy(&scene, QEvent::ActivationChange); + + scene.setActivePanel(panel); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)0); + QCOMPARE(itemActivateSpy.count(), 0); + QCOMPARE(itemDeactivateSpy.count(), 0); + QCOMPARE(panelActivateSpy.count(), 0); + QCOMPARE(panelDeactivateSpy.count(), 0); + QCOMPARE(sceneActivationChangeSpy.count(), 0); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" |