author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtGui/qgraphicsscene.h> |
|
45 |
#include <private/qgraphicsscenebsptreeindex_p.h> |
|
46 |
#include <private/qgraphicssceneindex_p.h> |
|
47 |
#include <private/qgraphicsscenelinearindex_p.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
#include "../../shared/util.h" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
|
0 | 50 |
|
51 |
//TESTED_CLASS= |
|
52 |
//TESTED_FILES= |
|
53 |
||
54 |
class tst_QGraphicsSceneIndex : public QObject |
|
55 |
{ |
|
56 |
Q_OBJECT |
|
57 |
public slots: |
|
58 |
void initTestCase(); |
|
59 |
||
60 |
private slots: |
|
61 |
void customIndex_data(); |
|
62 |
void customIndex(); |
|
63 |
void scatteredItems_data(); |
|
64 |
void scatteredItems(); |
|
65 |
void overlappedItems_data(); |
|
66 |
void overlappedItems(); |
|
67 |
void movingItems_data(); |
|
68 |
void movingItems(); |
|
69 |
void connectedToSceneRectChanged(); |
|
70 |
void items(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
void removeItems(); |
0 | 72 |
void clear(); |
73 |
||
74 |
private: |
|
75 |
void common_data(); |
|
76 |
QGraphicsSceneIndex *createIndex(const QString &name); |
|
77 |
}; |
|
78 |
||
79 |
void tst_QGraphicsSceneIndex::initTestCase() |
|
80 |
{ |
|
81 |
} |
|
82 |
||
83 |
void tst_QGraphicsSceneIndex::common_data() |
|
84 |
{ |
|
85 |
QTest::addColumn<QString>("indexMethod"); |
|
86 |
||
87 |
QTest::newRow("BSP") << QString("bsp"); |
|
88 |
QTest::newRow("Linear") << QString("linear"); |
|
89 |
} |
|
90 |
||
91 |
QGraphicsSceneIndex *tst_QGraphicsSceneIndex::createIndex(const QString &indexMethod) |
|
92 |
{ |
|
93 |
QGraphicsSceneIndex *index = 0; |
|
94 |
QGraphicsScene *scene = new QGraphicsScene(); |
|
95 |
if (indexMethod == "bsp") |
|
96 |
index = new QGraphicsSceneBspTreeIndex(scene); |
|
97 |
||
98 |
if (indexMethod == "linear") |
|
99 |
index = new QGraphicsSceneLinearIndex(scene); |
|
100 |
||
101 |
return index; |
|
102 |
} |
|
103 |
||
104 |
void tst_QGraphicsSceneIndex::customIndex_data() |
|
105 |
{ |
|
106 |
common_data(); |
|
107 |
} |
|
108 |
||
109 |
void tst_QGraphicsSceneIndex::customIndex() |
|
110 |
{ |
|
111 |
#if 0 |
|
112 |
QFETCH(QString, indexMethod); |
|
113 |
QGraphicsSceneIndex *index = createIndex(indexMethod); |
|
114 |
||
115 |
QGraphicsScene scene; |
|
116 |
scene.setSceneIndex(index); |
|
117 |
||
118 |
scene.addRect(0, 0, 30, 40); |
|
119 |
QCOMPARE(scene.items(QRectF(0, 0, 10, 10)).count(), 1); |
|
120 |
#endif |
|
121 |
} |
|
122 |
||
123 |
void tst_QGraphicsSceneIndex::scatteredItems_data() |
|
124 |
{ |
|
125 |
common_data(); |
|
126 |
} |
|
127 |
||
128 |
void tst_QGraphicsSceneIndex::scatteredItems() |
|
129 |
{ |
|
130 |
QFETCH(QString, indexMethod); |
|
131 |
||
132 |
QGraphicsScene scene; |
|
133 |
#if 1 |
|
134 |
scene.setItemIndexMethod(indexMethod == "linear" ? QGraphicsScene::NoIndex : QGraphicsScene::BspTreeIndex); |
|
135 |
#else |
|
136 |
QGraphicsSceneIndex *index = createIndex(indexMethod); |
|
137 |
scene.setSceneIndex(index); |
|
138 |
#endif |
|
139 |
||
140 |
for (int i = 0; i < 10; ++i) |
|
141 |
scene.addRect(i*50, i*50, 40, 35); |
|
142 |
||
143 |
QCOMPARE(scene.items(QPointF(5, 5)).count(), 1); |
|
144 |
QCOMPARE(scene.items(QPointF(55, 55)).count(), 1); |
|
145 |
QCOMPARE(scene.items(QPointF(-100, -100)).count(), 0); |
|
146 |
||
147 |
QCOMPARE(scene.items(QRectF(0, 0, 10, 10)).count(), 1); |
|
148 |
QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 10); |
|
149 |
QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).count(), 0); |
|
150 |
} |
|
151 |
||
152 |
void tst_QGraphicsSceneIndex::overlappedItems_data() |
|
153 |
{ |
|
154 |
common_data(); |
|
155 |
} |
|
156 |
||
157 |
void tst_QGraphicsSceneIndex::overlappedItems() |
|
158 |
{ |
|
159 |
QFETCH(QString, indexMethod); |
|
160 |
||
161 |
QGraphicsScene scene; |
|
162 |
#if 1 |
|
163 |
scene.setItemIndexMethod(indexMethod == "linear" ? QGraphicsScene::NoIndex : QGraphicsScene::BspTreeIndex); |
|
164 |
#else |
|
165 |
QGraphicsSceneIndex *index = createIndex(indexMethod); |
|
166 |
scene.setSceneIndex(index); |
|
167 |
#endif |
|
168 |
||
169 |
for (int i = 0; i < 10; ++i) |
|
170 |
for (int j = 0; j < 10; ++j) |
|
171 |
scene.addRect(i*50, j*50, 200, 200); |
|
172 |
||
173 |
QCOMPARE(scene.items(QPointF(5, 5)).count(), 1); |
|
174 |
QCOMPARE(scene.items(QPointF(55, 55)).count(), 4); |
|
175 |
QCOMPARE(scene.items(QPointF(105, 105)).count(), 9); |
|
176 |
QCOMPARE(scene.items(QPointF(-100, -100)).count(), 0); |
|
177 |
||
178 |
QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 100); |
|
179 |
QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).count(), 0); |
|
180 |
QCOMPARE(scene.items(QRectF(0, 0, 200, 200)).count(), 16); |
|
181 |
QCOMPARE(scene.items(QRectF(0, 0, 100, 100)).count(), 4); |
|
182 |
QCOMPARE(scene.items(QRectF(0, 0, 1, 100)).count(), 2); |
|
183 |
QCOMPARE(scene.items(QRectF(0, 0, 1, 1000)).count(), 10); |
|
184 |
} |
|
185 |
||
186 |
void tst_QGraphicsSceneIndex::movingItems_data() |
|
187 |
{ |
|
188 |
common_data(); |
|
189 |
} |
|
190 |
||
191 |
void tst_QGraphicsSceneIndex::movingItems() |
|
192 |
{ |
|
193 |
QFETCH(QString, indexMethod); |
|
194 |
||
195 |
QGraphicsScene scene; |
|
196 |
#if 1 |
|
197 |
scene.setItemIndexMethod(indexMethod == "linear" ? QGraphicsScene::NoIndex : QGraphicsScene::BspTreeIndex); |
|
198 |
#else |
|
199 |
QGraphicsSceneIndex *index = createIndex(indexMethod); |
|
200 |
scene.setSceneIndex(index); |
|
201 |
#endif |
|
202 |
||
203 |
for (int i = 0; i < 10; ++i) |
|
204 |
scene.addRect(i*50, i*50, 40, 35); |
|
205 |
||
206 |
QGraphicsRectItem *box = scene.addRect(0, 0, 10, 10); |
|
207 |
QCOMPARE(scene.items(QPointF(5, 5)).count(), 2); |
|
208 |
QCOMPARE(scene.items(QPointF(-1, -1)).count(), 0); |
|
209 |
QCOMPARE(scene.items(QRectF(0, 0, 5, 5)).count(), 2); |
|
210 |
||
211 |
box->setPos(10, 10); |
|
212 |
QCOMPARE(scene.items(QPointF(9, 9)).count(), 1); |
|
213 |
QCOMPARE(scene.items(QPointF(15, 15)).count(), 2); |
|
214 |
QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).count(), 1); |
|
215 |
||
216 |
box->setPos(-5, -5); |
|
217 |
QCOMPARE(scene.items(QPointF(-1, -1)).count(), 1); |
|
218 |
QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).count(), 2); |
|
219 |
||
220 |
QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 11); |
|
221 |
} |
|
222 |
||
223 |
void tst_QGraphicsSceneIndex::connectedToSceneRectChanged() |
|
224 |
{ |
|
225 |
||
226 |
class MyScene : public QGraphicsScene |
|
227 |
{ public: using QGraphicsScene::receivers; }; |
|
228 |
||
229 |
MyScene scene; // Uses QGraphicsSceneBspTreeIndex by default. |
|
230 |
QCOMPARE(scene.receivers(SIGNAL(sceneRectChanged(const QRectF&))), 1); |
|
231 |
||
232 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); // QGraphicsSceneLinearIndex |
|
233 |
QCOMPARE(scene.receivers(SIGNAL(sceneRectChanged(const QRectF&))), 1); |
|
234 |
} |
|
235 |
||
236 |
void tst_QGraphicsSceneIndex::items() |
|
237 |
{ |
|
238 |
QGraphicsScene scene; |
|
239 |
QGraphicsItem *item1 = scene.addRect(0, 0, 10, 10); |
|
240 |
QGraphicsItem *item2 = scene.addRect(10, 10, 10, 10); |
|
241 |
QCOMPARE(scene.items().size(), 2); |
|
242 |
||
243 |
// Move from unindexed items into bsp tree. |
|
244 |
QTest::qWait(50); |
|
245 |
QCOMPARE(scene.items().size(), 2); |
|
246 |
||
247 |
// Add untransformable item. |
|
248 |
QGraphicsItem *item3 = new QGraphicsRectItem(QRectF(20, 20, 10, 10)); |
|
249 |
item3->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
250 |
scene.addItem(item3); |
|
251 |
QCOMPARE(scene.items().size(), 3); |
|
252 |
||
253 |
// Move from unindexed items into untransformable items. |
|
254 |
QTest::qWait(50); |
|
255 |
QCOMPARE(scene.items().size(), 3); |
|
256 |
||
257 |
// Move from untransformable items into unindexed items. |
|
258 |
item3->setFlag(QGraphicsItem::ItemIgnoresTransformations, false); |
|
259 |
QCOMPARE(scene.items().size(), 3); |
|
260 |
QTest::qWait(50); |
|
261 |
QCOMPARE(scene.items().size(), 3); |
|
262 |
||
263 |
// Make all items untransformable. |
|
264 |
item1->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
265 |
item2->setParentItem(item1); |
|
266 |
item3->setParentItem(item2); |
|
267 |
QCOMPARE(scene.items().size(), 3); |
|
268 |
||
269 |
// Move from unindexed items into untransformable items. |
|
270 |
QTest::qWait(50); |
|
271 |
QCOMPARE(scene.items().size(), 3); |
|
272 |
} |
|
273 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
class RectWidget : public QGraphicsWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
painter->setBrush(brush); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
painter->drawRect(boundingRect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
QBrush brush; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
void tst_QGraphicsSceneIndex::removeItems() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
RectWidget *parent = new RectWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
parent->brush = QBrush(QColor(Qt::magenta)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
parent->setGeometry(250, 250, 400, 400); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
RectWidget *widget = new RectWidget(parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
widget->brush = QBrush(QColor(Qt::blue)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
widget->setGeometry(10, 10, 200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
RectWidget *widgetChild1 = new RectWidget(widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
widgetChild1->brush = QBrush(QColor(Qt::green)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
widgetChild1->setGeometry(20, 20, 100, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
RectWidget *widgetChild2 = new RectWidget(widgetChild1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
widgetChild2->brush = QBrush(QColor(Qt::yellow)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
widgetChild2->setGeometry(25, 25, 50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
scene.addItem(parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
view.resize(600, 600); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
QApplication::setActiveWindow(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
scene.removeItem(widgetChild1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
delete widgetChild1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
//We move the parent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
scene.items(295, 295, 50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
//This should not crash |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
|
0 | 331 |
void tst_QGraphicsSceneIndex::clear() |
332 |
{ |
|
333 |
class MyItem : public QGraphicsItem |
|
334 |
{ |
|
335 |
public: |
|
336 |
MyItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent), numPaints(0) {} |
|
337 |
int numPaints; |
|
338 |
protected: |
|
339 |
QRectF boundingRect() const { return QRectF(0, 0, 10, 10); } |
|
340 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
341 |
{ ++numPaints; } |
|
342 |
}; |
|
343 |
||
344 |
QGraphicsScene scene; |
|
345 |
scene.setSceneRect(0, 0, 100, 100); |
|
346 |
scene.addItem(new MyItem); |
|
347 |
||
348 |
QGraphicsView view(&scene); |
|
349 |
view.show(); |
|
350 |
#ifdef Q_WS_X11 |
|
351 |
qt_x11_wait_for_window_manager(&view); |
|
352 |
#endif |
|
353 |
QTest::qWait(250); |
|
354 |
scene.clear(); |
|
355 |
||
356 |
// Make sure the index is re-generated after QGraphicsScene::clear(); |
|
357 |
// otherwise no items will be painted. |
|
358 |
MyItem *item = new MyItem; |
|
359 |
scene.addItem(item); |
|
360 |
qApp->processEvents(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
361 |
QTRY_COMPARE(item->numPaints, 1); |
0 | 362 |
} |
363 |
||
364 |
QTEST_MAIN(tst_QGraphicsSceneIndex) |
|
365 |
#include "tst_qgraphicssceneindex.moc" |