6893 |
6899 |
6894 // Moving the middle item should case a repaint even if it's a move, |
6900 // Moving the middle item should case a repaint even if it's a move, |
6895 // because the parent is rotated with a perspective. |
6901 // because the parent is rotated with a perspective. |
6896 testerChild->setPos(1, 1); |
6902 testerChild->setPos(1, 1); |
6897 QTest::qWait(25); |
6903 QTest::qWait(25); |
6898 QTRY_COMPARE(tester->repaints, 10); |
6904 QTRY_COMPARE(tester->repaints, 11); |
6899 QCOMPARE(testerChild->repaints, 10); |
6905 QCOMPARE(testerChild->repaints, 10); |
6900 QCOMPARE(testerChild2->repaints, 5); |
6906 QCOMPARE(testerChild2->repaints, 5); |
|
6907 tester->resetTransform(); |
6901 |
6908 |
6902 // Make a huge item |
6909 // Make a huge item |
6903 tester->setGeometry(QRectF(-4000, -4000, 8000, 8000)); |
6910 tester->setGeometry(QRectF(-4000, -4000, 8000, 8000)); |
6904 QTest::qWait(25); |
6911 QTest::qWait(25); |
6905 QTRY_COMPARE(tester->repaints, 11); |
6912 QTRY_COMPARE(tester->repaints, 12); |
6906 QCOMPARE(testerChild->repaints, 10); |
6913 QCOMPARE(testerChild->repaints, 11); |
6907 QCOMPARE(testerChild2->repaints, 5); |
6914 QCOMPARE(testerChild2->repaints, 5); |
6908 |
6915 |
6909 // Move the large item - will cause a repaint as the |
6916 // Move the large item - will cause a repaint as the |
6910 // cache is clipped. |
6917 // cache is clipped. |
6911 tester->setPos(5, 0); |
6918 tester->setPos(5, 0); |
6912 QTest::qWait(25); |
6919 QTest::qWait(25); |
6913 QTRY_COMPARE(tester->repaints, 12); |
6920 QTRY_COMPARE(tester->repaints, 13); |
6914 QCOMPARE(testerChild->repaints, 10); |
6921 QCOMPARE(testerChild->repaints, 11); |
6915 QCOMPARE(testerChild2->repaints, 5); |
6922 QCOMPARE(testerChild2->repaints, 5); |
6916 |
6923 |
6917 // Hiding and showing should invalidate the cache |
6924 // Hiding and showing should invalidate the cache |
6918 tester->hide(); |
6925 tester->hide(); |
6919 QTest::qWait(25); |
6926 QTest::qWait(25); |
6920 tester->show(); |
6927 tester->show(); |
6921 QTest::qWait(25); |
6928 QTest::qWait(25); |
6922 QTRY_COMPARE(tester->repaints, 13); |
6929 QTRY_COMPARE(tester->repaints, 14); |
6923 QCOMPARE(testerChild->repaints, 11); |
6930 QCOMPARE(testerChild->repaints, 12); |
6924 QCOMPARE(testerChild2->repaints, 6); |
6931 QCOMPARE(testerChild2->repaints, 6); |
|
6932 } |
|
6933 |
|
6934 void tst_QGraphicsItem::cacheMode2() |
|
6935 { |
|
6936 QGraphicsScene scene(0, 0, 100, 100); |
|
6937 QGraphicsView view(&scene); |
|
6938 view.resize(150, 150); |
|
6939 view.show(); |
|
6940 QApplication::setActiveWindow(&view); |
|
6941 QTest::qWaitForWindowShown(&view); |
|
6942 |
|
6943 // Increase the probability of window activation |
|
6944 // not causing another repaint of test items. |
|
6945 QTest::qWait(50); |
|
6946 |
|
6947 EventTester *tester = new EventTester; |
|
6948 scene.addItem(tester); |
|
6949 QTest::qWait(10); |
|
6950 QTRY_COMPARE(tester->repaints, 1); |
|
6951 |
|
6952 // Switching from NoCache to NoCache (no repaint) |
|
6953 tester->setCacheMode(QGraphicsItem::NoCache); |
|
6954 QTest::qWait(50); |
|
6955 QTRY_COMPARE(tester->repaints, 1); |
|
6956 |
|
6957 // Switching from NoCache to DeviceCoordinateCache (no repaint) |
|
6958 tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6959 QTest::qWait(50); |
|
6960 QTRY_COMPARE(tester->repaints, 1); |
|
6961 |
|
6962 // Switching from DeviceCoordinateCache to DeviceCoordinateCache (no repaint) |
|
6963 tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6964 QTest::qWait(50); |
|
6965 QTRY_COMPARE(tester->repaints, 1); |
|
6966 |
|
6967 // Switching from DeviceCoordinateCache to NoCache (no repaint) |
|
6968 tester->setCacheMode(QGraphicsItem::NoCache); |
|
6969 QTest::qWait(50); |
|
6970 QTRY_COMPARE(tester->repaints, 1); |
|
6971 |
|
6972 // Switching from NoCache to ItemCoordinateCache (repaint) |
|
6973 tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
|
6974 QTest::qWait(50); |
|
6975 QTRY_COMPARE(tester->repaints, 2); |
|
6976 |
|
6977 // Switching from ItemCoordinateCache to ItemCoordinateCache (no repaint) |
|
6978 tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
|
6979 QTest::qWait(50); |
|
6980 QTRY_COMPARE(tester->repaints, 2); |
|
6981 |
|
6982 // Switching from ItemCoordinateCache to ItemCoordinateCache with different size (repaint) |
|
6983 tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(100, 100)); |
|
6984 QTest::qWait(50); |
|
6985 QTRY_COMPARE(tester->repaints, 3); |
|
6986 |
|
6987 // Switching from ItemCoordinateCache to NoCache (repaint) |
|
6988 tester->setCacheMode(QGraphicsItem::NoCache); |
|
6989 QTest::qWait(50); |
|
6990 QTRY_COMPARE(tester->repaints, 4); |
|
6991 |
|
6992 // Switching from DeviceCoordinateCache to ItemCoordinateCache (repaint) |
|
6993 tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6994 QTest::qWait(50); |
|
6995 QTRY_COMPARE(tester->repaints, 4); |
|
6996 tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
|
6997 QTest::qWait(50); |
|
6998 QTRY_COMPARE(tester->repaints, 5); |
|
6999 |
|
7000 // Switching from ItemCoordinateCache to DeviceCoordinateCache (repaint) |
|
7001 tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
7002 QTest::qWait(50); |
|
7003 QTRY_COMPARE(tester->repaints, 6); |
6925 } |
7004 } |
6926 |
7005 |
6927 void tst_QGraphicsItem::updateCachedItemAfterMove() |
7006 void tst_QGraphicsItem::updateCachedItemAfterMove() |
6928 { |
7007 { |
6929 // A simple item that uses ItemCoordinateCache |
7008 // A simple item that uses ItemCoordinateCache |
10000 |
10079 |
10001 QTRY_COMPARE(origView.repaints, 1); |
10080 QTRY_COMPARE(origView.repaints, 1); |
10002 QTRY_COMPARE(view.repaints, 1); |
10081 QTRY_COMPARE(view.repaints, 1); |
10003 } |
10082 } |
10004 |
10083 |
|
10084 void tst_QGraphicsItem::QT_2649_focusScope() |
|
10085 { |
|
10086 QGraphicsScene *scene = new QGraphicsScene; |
|
10087 |
|
10088 QGraphicsRectItem *subFocusItem = new QGraphicsRectItem; |
|
10089 subFocusItem->setFlags(QGraphicsItem::ItemIsFocusable); |
|
10090 subFocusItem->setFocus(); |
|
10091 QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10092 |
|
10093 QGraphicsRectItem *scope = new QGraphicsRectItem; |
|
10094 scope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
10095 scope->setFocus(); |
|
10096 subFocusItem->setParentItem(scope); |
|
10097 QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10098 QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10099 QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10100 QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
|
10101 |
|
10102 QGraphicsRectItem *rootItem = new QGraphicsRectItem; |
|
10103 rootItem->setFlags(QGraphicsItem::ItemIsFocusable); |
|
10104 scope->setParentItem(rootItem); |
|
10105 QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10106 QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10107 QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10108 QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10109 QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10110 QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
|
10111 |
|
10112 scene->addItem(rootItem); |
|
10113 |
|
10114 QEvent windowActivate(QEvent::WindowActivate); |
|
10115 qApp->sendEvent(scene, &windowActivate); |
|
10116 scene->setFocus(); |
|
10117 |
|
10118 QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10119 QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10120 QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10121 QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10122 QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
|
10123 QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10124 QVERIFY(subFocusItem->hasFocus()); |
|
10125 |
|
10126 scope->hide(); |
|
10127 |
|
10128 QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)0); |
|
10129 QCOMPARE(scope->focusItem(), (QGraphicsItem *)0); |
|
10130 QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)0); |
|
10131 QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10132 QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
|
10133 QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10134 QVERIFY(!subFocusItem->hasFocus()); |
|
10135 |
|
10136 scope->show(); |
|
10137 |
|
10138 QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10139 QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10140 QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
|
10141 QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10142 QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
|
10143 QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
|
10144 QVERIFY(subFocusItem->hasFocus()); |
|
10145 |
|
10146 // This should not crash |
|
10147 scope->hide(); |
|
10148 delete scene; |
|
10149 } |
|
10150 |
|
10151 class MyGraphicsItemWithItemChange : public QGraphicsWidget |
|
10152 { |
|
10153 public: |
|
10154 MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) |
|
10155 {} |
|
10156 |
|
10157 QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
|
10158 { |
|
10159 if (change == QGraphicsItem::ItemSceneHasChanged) { |
|
10160 foreach (QGraphicsView *view, scene()->views()) { |
|
10161 //We trigger a sort of unindexed items in the BSP |
|
10162 view->sceneRect(); |
|
10163 } |
|
10164 } |
|
10165 return QGraphicsWidget::itemChange(change, value); |
|
10166 } |
|
10167 }; |
|
10168 |
|
10169 void tst_QGraphicsItem::sortItemsWhileAdding() |
|
10170 { |
|
10171 QGraphicsScene scene; |
|
10172 QGraphicsView view(&scene); |
|
10173 QGraphicsWidget grandGrandParent; |
|
10174 grandGrandParent.resize(200, 200); |
|
10175 scene.addItem(&grandGrandParent); |
|
10176 QGraphicsWidget grandParent; |
|
10177 grandParent.resize(200, 200); |
|
10178 QGraphicsWidget parent(&grandParent); |
|
10179 parent.resize(200, 200); |
|
10180 MyGraphicsItemWithItemChange item(&parent); |
|
10181 grandParent.setParentItem(&grandGrandParent); |
|
10182 } |
|
10183 |
10005 QTEST_MAIN(tst_QGraphicsItem) |
10184 QTEST_MAIN(tst_QGraphicsItem) |
10006 #include "tst_qgraphicsitem.moc" |
10185 #include "tst_qgraphicsitem.moc" |