0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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();
|
|
67 |
};
|
|
68 |
|
|
69 |
tst_QGraphicsScene::tst_QGraphicsScene()
|
|
70 |
{
|
|
71 |
}
|
|
72 |
|
|
73 |
tst_QGraphicsScene::~tst_QGraphicsScene()
|
|
74 |
{
|
|
75 |
}
|
|
76 |
|
|
77 |
void tst_QGraphicsScene::init()
|
|
78 |
{
|
|
79 |
}
|
|
80 |
|
|
81 |
void tst_QGraphicsScene::cleanup()
|
|
82 |
{
|
|
83 |
}
|
|
84 |
|
|
85 |
void tst_QGraphicsScene::construct()
|
|
86 |
{
|
|
87 |
QBENCHMARK {
|
|
88 |
QGraphicsScene scene;
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
void tst_QGraphicsScene::addItem_data()
|
|
93 |
{
|
|
94 |
QTest::addColumn<int>("indexMethod");
|
|
95 |
QTest::addColumn<QRectF>("sceneRect");
|
|
96 |
QTest::addColumn<int>("numItems_X");
|
|
97 |
QTest::addColumn<int>("numItems_Y");
|
|
98 |
QTest::addColumn<int>("itemType");
|
|
99 |
QTest::addColumn<QRectF>("itemRect");
|
|
100 |
|
|
101 |
QTest::newRow("null") << 0 << QRectF() << 0 << 0 << 0 << QRectF();
|
|
102 |
QTest::newRow("0 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
103 |
QTest::newRow("0 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
104 |
QTest::newRow("0 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
105 |
QTest::newRow("0 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
106 |
QTest::newRow("0 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
107 |
QTest::newRow("0 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
108 |
QTest::newRow("0 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,0)") << 0 << QRectF() << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
109 |
QTest::newRow("0 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
110 |
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);
|
|
111 |
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);
|
|
112 |
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);
|
|
113 |
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);
|
|
114 |
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);
|
|
115 |
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);
|
|
116 |
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);
|
|
117 |
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);
|
|
118 |
QTest::newRow("1 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
119 |
QTest::newRow("1 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
120 |
QTest::newRow("1 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
121 |
QTest::newRow("1 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10);
|
|
122 |
QTest::newRow("1 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
123 |
QTest::newRow("1 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
124 |
QTest::newRow("1 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
125 |
QTest::newRow("1 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10);
|
|
126 |
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);
|
|
127 |
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);
|
|
128 |
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);
|
|
129 |
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);
|
|
130 |
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);
|
|
131 |
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);
|
|
132 |
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);
|
|
133 |
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);
|
|
134 |
}
|
|
135 |
|
|
136 |
void tst_QGraphicsScene::addItem()
|
|
137 |
{
|
|
138 |
QFETCH(int, indexMethod);
|
|
139 |
QFETCH(QRectF, sceneRect);
|
|
140 |
QFETCH(int, numItems_X);
|
|
141 |
QFETCH(int, numItems_Y);
|
|
142 |
QFETCH(int, itemType);
|
|
143 |
QFETCH(QRectF, itemRect);
|
|
144 |
|
|
145 |
QGraphicsScene scene;
|
|
146 |
scene.setItemIndexMethod(indexMethod ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex);
|
|
147 |
if (!sceneRect.isNull())
|
|
148 |
scene.setSceneRect(sceneRect);
|
|
149 |
|
|
150 |
QBENCHMARK {
|
|
151 |
QGraphicsItem *item = 0;
|
|
152 |
for (int y = 0; y < numItems_Y; ++y) {
|
|
153 |
for (int x = 0; x < numItems_X; ++x) {
|
|
154 |
switch (itemType) {
|
|
155 |
case QGraphicsRectItem::Type:
|
|
156 |
item = new QGraphicsRectItem(itemRect);
|
|
157 |
break;
|
|
158 |
case QGraphicsEllipseItem::Type:
|
|
159 |
default:
|
|
160 |
item = new QGraphicsEllipseItem(itemRect);
|
|
161 |
break;
|
|
162 |
}
|
|
163 |
item->setPos(x * itemRect.width(), y * itemRect.height());
|
|
164 |
scene.addItem(item);
|
|
165 |
}
|
|
166 |
}
|
|
167 |
scene.itemAt(0, 0);
|
|
168 |
}
|
|
169 |
//let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list
|
|
170 |
qApp->processEvents();
|
|
171 |
}
|
|
172 |
|
|
173 |
void tst_QGraphicsScene::itemAt_data()
|
|
174 |
{
|
|
175 |
QTest::addColumn<int>("bspTreeDepth");
|
|
176 |
QTest::addColumn<QRectF>("sceneRect");
|
|
177 |
QTest::addColumn<int>("numItems_X");
|
|
178 |
QTest::addColumn<int>("numItems_Y");
|
|
179 |
QTest::addColumn<QRectF>("itemRect");
|
|
180 |
|
|
181 |
QTest::newRow("null") << 0 << QRectF() << 0 << 0 << QRectF();
|
|
182 |
QTest::newRow("NoIndex 10x10") << -1 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20);
|
|
183 |
QTest::newRow("NoIndex 25x25") << -1 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20);
|
|
184 |
QTest::newRow("NoIndex 100x100") << -1 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20);
|
|
185 |
QTest::newRow("NoIndex 250x250") << -1 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20);
|
|
186 |
QTest::newRow("BspTreeIndex depth=auto 10x10") << 0 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20);
|
|
187 |
QTest::newRow("BspTreeIndex depth=auto 25x25") << 0 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20);
|
|
188 |
QTest::newRow("BspTreeIndex depth=auto 100x100") << 0 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20);
|
|
189 |
QTest::newRow("BspTreeIndex depth=auto 250x250") << 0 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20);
|
|
190 |
QTest::newRow("BspTreeIndex depth=16 10x10") << 16 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20);
|
|
191 |
QTest::newRow("BspTreeIndex depth=16 25x25") << 16 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20);
|
|
192 |
QTest::newRow("BspTreeIndex depth=16 100x100") << 16 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20);
|
|
193 |
QTest::newRow("BspTreeIndex depth=16 250x250") << 16 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20);
|
|
194 |
}
|
|
195 |
|
|
196 |
void tst_QGraphicsScene::itemAt()
|
|
197 |
{
|
|
198 |
QFETCH(int, bspTreeDepth);
|
|
199 |
QFETCH(QRectF, sceneRect);
|
|
200 |
QFETCH(int, numItems_X);
|
|
201 |
QFETCH(int, numItems_Y);
|
|
202 |
QFETCH(QRectF, itemRect);
|
|
203 |
|
|
204 |
QGraphicsScene scene;
|
|
205 |
scene.setItemIndexMethod(bspTreeDepth >= 0 ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex);
|
|
206 |
if (bspTreeDepth > 0)
|
|
207 |
scene.setBspTreeDepth(bspTreeDepth);
|
|
208 |
if (!sceneRect.isNull())
|
|
209 |
scene.setSceneRect(sceneRect);
|
|
210 |
|
|
211 |
QGraphicsItem *item = 0;
|
|
212 |
for (int y = 0; y < numItems_Y; ++y) {
|
|
213 |
for (int x = 0; x < numItems_X; ++x) {
|
|
214 |
QGraphicsRectItem *item = new QGraphicsRectItem(itemRect);
|
|
215 |
item->setPos((x - numItems_X/2) * itemRect.width(), (y - numItems_Y/2) * itemRect.height());
|
|
216 |
scene.addItem(item);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
scene.itemAt(0, 0); // triggers indexing
|
|
221 |
|
|
222 |
QBENCHMARK {
|
|
223 |
scene.itemAt(0, 0);
|
|
224 |
}
|
|
225 |
|
|
226 |
//let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list
|
|
227 |
qApp->processEvents();
|
|
228 |
}
|
|
229 |
|
|
230 |
QTEST_MAIN(tst_QGraphicsScene)
|
|
231 |
#include "tst_qgraphicsscene.moc"
|