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 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
#include <qtest.h> |
|
43 |
#include <QGraphicsItem> |
|
44 |
#include <QGraphicsScene> |
|
45 |
#include <QGraphicsView> |
|
46 |
||
47 |
//TESTED_FILES= |
|
48 |
||
49 |
class tst_QGraphicsScene : public QObject |
|
50 |
{ |
|
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
tst_QGraphicsScene(); |
|
55 |
virtual ~tst_QGraphicsScene(); |
|
56 |
||
57 |
public slots: |
|
58 |
void init(); |
|
59 |
void cleanup(); |
|
60 |
||
61 |
private slots: |
|
62 |
void construct(); |
|
63 |
void addItem_data(); |
|
64 |
void addItem(); |
|
65 |
void itemAt_data(); |
|
66 |
void itemAt(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
void initialShow(); |
0 | 68 |
}; |
69 |
||
70 |
tst_QGraphicsScene::tst_QGraphicsScene() |
|
71 |
{ |
|
72 |
} |
|
73 |
||
74 |
tst_QGraphicsScene::~tst_QGraphicsScene() |
|
75 |
{ |
|
76 |
} |
|
77 |
||
78 |
void tst_QGraphicsScene::init() |
|
79 |
{ |
|
80 |
} |
|
81 |
||
82 |
void tst_QGraphicsScene::cleanup() |
|
83 |
{ |
|
84 |
} |
|
85 |
||
86 |
void tst_QGraphicsScene::construct() |
|
87 |
{ |
|
88 |
QBENCHMARK { |
|
89 |
QGraphicsScene scene; |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
void tst_QGraphicsScene::addItem_data() |
|
94 |
{ |
|
95 |
QTest::addColumn<int>("indexMethod"); |
|
96 |
QTest::addColumn<QRectF>("sceneRect"); |
|
97 |
QTest::addColumn<int>("numItems_X"); |
|
98 |
QTest::addColumn<int>("numItems_Y"); |
|
99 |
QTest::addColumn<int>("itemType"); |
|
100 |
QTest::addColumn<QRectF>("itemRect"); |
|
101 |
||
102 |
QTest::newRow("null") << 0 << QRectF() << 0 << 0 << 0 << QRectF(); |
|
103 |
QTest::newRow("0 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
104 |
QTest::newRow("0 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
105 |
QTest::newRow("0 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
106 |
QTest::newRow("0 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
107 |
QTest::newRow("0 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
108 |
QTest::newRow("0 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
109 |
QTest::newRow("0 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,0)") << 0 << QRectF() << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
110 |
QTest::newRow("0 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
111 |
QTest::newRow("0 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
112 |
QTest::newRow("0 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
113 |
QTest::newRow("0 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
114 |
QTest::newRow("0 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
115 |
QTest::newRow("0 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
116 |
QTest::newRow("0 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
117 |
QTest::newRow("0 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
118 |
QTest::newRow("0 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
119 |
QTest::newRow("1 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
120 |
QTest::newRow("1 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
121 |
QTest::newRow("1 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
122 |
QTest::newRow("1 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
123 |
QTest::newRow("1 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
124 |
QTest::newRow("1 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
125 |
QTest::newRow("1 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
126 |
QTest::newRow("1 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
127 |
QTest::newRow("1 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
128 |
QTest::newRow("1 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
129 |
QTest::newRow("1 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
130 |
QTest::newRow("1 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); |
|
131 |
QTest::newRow("1 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
132 |
QTest::newRow("1 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
133 |
QTest::newRow("1 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
134 |
QTest::newRow("1 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); |
|
135 |
} |
|
136 |
||
137 |
void tst_QGraphicsScene::addItem() |
|
138 |
{ |
|
139 |
QFETCH(int, indexMethod); |
|
140 |
QFETCH(QRectF, sceneRect); |
|
141 |
QFETCH(int, numItems_X); |
|
142 |
QFETCH(int, numItems_Y); |
|
143 |
QFETCH(int, itemType); |
|
144 |
QFETCH(QRectF, itemRect); |
|
145 |
||
146 |
QGraphicsScene scene; |
|
147 |
scene.setItemIndexMethod(indexMethod ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); |
|
148 |
if (!sceneRect.isNull()) |
|
149 |
scene.setSceneRect(sceneRect); |
|
150 |
||
151 |
QBENCHMARK { |
|
152 |
QGraphicsItem *item = 0; |
|
153 |
for (int y = 0; y < numItems_Y; ++y) { |
|
154 |
for (int x = 0; x < numItems_X; ++x) { |
|
155 |
switch (itemType) { |
|
156 |
case QGraphicsRectItem::Type: |
|
157 |
item = new QGraphicsRectItem(itemRect); |
|
158 |
break; |
|
159 |
case QGraphicsEllipseItem::Type: |
|
160 |
default: |
|
161 |
item = new QGraphicsEllipseItem(itemRect); |
|
162 |
break; |
|
163 |
} |
|
164 |
item->setPos(x * itemRect.width(), y * itemRect.height()); |
|
165 |
scene.addItem(item); |
|
166 |
} |
|
167 |
} |
|
168 |
scene.itemAt(0, 0); |
|
169 |
} |
|
170 |
//let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list |
|
171 |
qApp->processEvents(); |
|
172 |
} |
|
173 |
||
174 |
void tst_QGraphicsScene::itemAt_data() |
|
175 |
{ |
|
176 |
QTest::addColumn<int>("bspTreeDepth"); |
|
177 |
QTest::addColumn<QRectF>("sceneRect"); |
|
178 |
QTest::addColumn<int>("numItems_X"); |
|
179 |
QTest::addColumn<int>("numItems_Y"); |
|
180 |
QTest::addColumn<QRectF>("itemRect"); |
|
181 |
||
182 |
QTest::newRow("null") << 0 << QRectF() << 0 << 0 << QRectF(); |
|
183 |
QTest::newRow("NoIndex 10x10") << -1 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20); |
|
184 |
QTest::newRow("NoIndex 25x25") << -1 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20); |
|
185 |
QTest::newRow("NoIndex 100x100") << -1 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20); |
|
186 |
QTest::newRow("NoIndex 250x250") << -1 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20); |
|
187 |
QTest::newRow("BspTreeIndex depth=auto 10x10") << 0 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20); |
|
188 |
QTest::newRow("BspTreeIndex depth=auto 25x25") << 0 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20); |
|
189 |
QTest::newRow("BspTreeIndex depth=auto 100x100") << 0 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20); |
|
190 |
QTest::newRow("BspTreeIndex depth=auto 250x250") << 0 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20); |
|
191 |
QTest::newRow("BspTreeIndex depth=16 10x10") << 16 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20); |
|
192 |
QTest::newRow("BspTreeIndex depth=16 25x25") << 16 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20); |
|
193 |
QTest::newRow("BspTreeIndex depth=16 100x100") << 16 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20); |
|
194 |
QTest::newRow("BspTreeIndex depth=16 250x250") << 16 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20); |
|
195 |
} |
|
196 |
||
197 |
void tst_QGraphicsScene::itemAt() |
|
198 |
{ |
|
199 |
QFETCH(int, bspTreeDepth); |
|
200 |
QFETCH(QRectF, sceneRect); |
|
201 |
QFETCH(int, numItems_X); |
|
202 |
QFETCH(int, numItems_Y); |
|
203 |
QFETCH(QRectF, itemRect); |
|
204 |
||
205 |
QGraphicsScene scene; |
|
206 |
scene.setItemIndexMethod(bspTreeDepth >= 0 ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); |
|
207 |
if (bspTreeDepth > 0) |
|
208 |
scene.setBspTreeDepth(bspTreeDepth); |
|
209 |
if (!sceneRect.isNull()) |
|
210 |
scene.setSceneRect(sceneRect); |
|
211 |
||
212 |
QGraphicsItem *item = 0; |
|
213 |
for (int y = 0; y < numItems_Y; ++y) { |
|
214 |
for (int x = 0; x < numItems_X; ++x) { |
|
215 |
QGraphicsRectItem *item = new QGraphicsRectItem(itemRect); |
|
216 |
item->setPos((x - numItems_X/2) * itemRect.width(), (y - numItems_Y/2) * itemRect.height()); |
|
217 |
scene.addItem(item); |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
scene.itemAt(0, 0); // triggers indexing |
|
222 |
||
223 |
QBENCHMARK { |
|
224 |
scene.itemAt(0, 0); |
|
225 |
} |
|
226 |
||
227 |
//let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list |
|
228 |
qApp->processEvents(); |
|
229 |
} |
|
230 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
231 |
void tst_QGraphicsScene::initialShow() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
QGraphicsScene scene; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
QBENCHMARK { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
for (int y = 0; y < 30000; ++y) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
QGraphicsRectItem *item = new QGraphicsRectItem(0, 0, 50, 50); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
item->setPos((y/2) * item->rect().width(), (y/2) * item->rect().height()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
scene.addItem(item); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
scene.itemAt(0, 0); // triggers indexing |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
//This call polish the items so we bench their processing too. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
qApp->processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
|
0 | 247 |
QTEST_MAIN(tst_QGraphicsScene) |
248 |
#include "tst_qgraphicsscene.moc" |