author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 4 | 3b1da2848fc7 |
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 |
// This file contains benchmarks for QRect/QRectF functions. |
|
42 |
||
43 |
#include <QtGui> |
|
44 |
#include <qtest.h> |
|
45 |
||
46 |
class tst_qstylesheetstyle : public QObject |
|
47 |
{ |
|
48 |
Q_OBJECT |
|
49 |
private slots: |
|
50 |
void empty(); |
|
51 |
void empty_events(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
|
0 | 53 |
void simple(); |
54 |
void simple_events(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
|
0 | 56 |
void grid_data(); |
57 |
void grid(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
|
0 | 59 |
private: |
60 |
QWidget *buildSimpleWidgets(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
|
0 | 62 |
}; |
63 |
||
64 |
||
65 |
QWidget *tst_qstylesheetstyle::buildSimpleWidgets() |
|
66 |
{ |
|
67 |
QWidget *w = new QWidget(); |
|
68 |
QGridLayout *layout = new QGridLayout(w); |
|
69 |
w->setLayout(layout); |
|
70 |
layout->addWidget(new QPushButton("pushButton") ,0,0); |
|
71 |
layout->addWidget(new QComboBox() ,0,1); |
|
72 |
layout->addWidget(new QCheckBox("checkBox") ,0,2); |
|
73 |
layout->addWidget(new QRadioButton("radioButton") ,0,3); |
|
74 |
layout->addWidget(new QLineEdit() ,1,0); |
|
75 |
layout->addWidget(new QLabel("label") ,1,1); |
|
76 |
layout->addWidget(new QSpinBox() ,1,2); |
|
77 |
layout->addWidget(new QProgressBar() ,1,3); |
|
78 |
return w; |
|
79 |
} |
|
80 |
||
81 |
void tst_qstylesheetstyle::empty() |
|
82 |
{ |
|
83 |
QWidget *w = buildSimpleWidgets(); |
|
84 |
w->setStyleSheet("/* */"); |
|
85 |
int i = 0; |
|
86 |
QBENCHMARK { |
|
87 |
w->setStyleSheet("/*" + QString::number(i) + "*/"); |
|
88 |
i++; // we want a different string in case we have severals iterations |
|
89 |
} |
|
90 |
delete w; |
|
91 |
} |
|
92 |
||
93 |
void tst_qstylesheetstyle::empty_events() |
|
94 |
{ |
|
95 |
QWidget *w = buildSimpleWidgets(); |
|
96 |
w->setStyleSheet("/* */"); |
|
97 |
int i = 0; |
|
98 |
QBENCHMARK { |
|
99 |
w->setStyleSheet("/*" + QString::number(i) + "*/"); |
|
100 |
i++; // we want a different string in case we have severals iterations |
|
101 |
qApp->processEvents(); |
|
102 |
} |
|
103 |
delete w; |
|
104 |
} |
|
105 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
static const char *simple_css = |
0 | 107 |
" QLineEdit { background: red; } QPushButton { border: 1px solid yellow; color: pink; } \n" |
108 |
" QCheckBox { margin: 3px 5px; background-color:red; } QAbstractButton { background-color: #456; } \n" |
|
109 |
" QFrame { padding: 3px; } QLabel { color: black } QSpinBox:hover { background-color:blue; } "; |
|
110 |
||
111 |
void tst_qstylesheetstyle::simple() |
|
112 |
{ |
|
113 |
QWidget *w = buildSimpleWidgets(); |
|
114 |
w->setStyleSheet("/* */"); |
|
115 |
int i = 0; |
|
116 |
QBENCHMARK { |
|
117 |
w->setStyleSheet(QString(simple_css) + "/*" + QString::number(i) + "*/"); |
|
118 |
i++; // we want a different string in case we have severals iterations |
|
119 |
} |
|
120 |
delete w; |
|
121 |
} |
|
122 |
||
123 |
void tst_qstylesheetstyle::simple_events() |
|
124 |
{ |
|
125 |
QWidget *w = buildSimpleWidgets(); |
|
126 |
w->setStyleSheet("/* */"); |
|
127 |
int i = 0; |
|
128 |
QBENCHMARK { |
|
129 |
w->setStyleSheet(QString(simple_css) + "/*" + QString::number(i) + "*/"); |
|
130 |
i++; // we want a different string in case we have severals iterations |
|
131 |
qApp->processEvents(); |
|
132 |
} |
|
133 |
delete w; |
|
134 |
} |
|
135 |
||
136 |
void tst_qstylesheetstyle::grid_data() |
|
137 |
{ |
|
138 |
QTest::addColumn<bool>("events"); |
|
139 |
QTest::addColumn<bool>("show"); |
|
140 |
QTest::addColumn<int>("N"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
for (int n = 5; n <= 25; n += 5) { |
0 | 142 |
const QByteArray nString = QByteArray::number(n*n); |
143 |
QTest::newRow(("simple--" + nString).constData()) << false << false << n; |
|
144 |
QTest::newRow(("events--" + nString).constData()) << true << false << n; |
|
145 |
QTest::newRow(("show--" + nString).constData()) << true << true << n; |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
||
150 |
void tst_qstylesheetstyle::grid() |
|
151 |
{ |
|
152 |
QFETCH(bool, events); |
|
153 |
QFETCH(bool, show); |
|
154 |
QFETCH(int, N); |
|
155 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
#ifdef Q_OS_SYMBIAN |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
// Symbian has limited stack (max 80k), which will run out when N >= 20 due to |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
// QWidget::show() using recursion among grid labels somewhere down the line. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
if (show && N >= 20) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
QSKIP("Grid too big for device to show", SkipSingle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
|
0 | 163 |
QWidget *w = new QWidget(); |
164 |
QGridLayout *layout = new QGridLayout(w); |
|
165 |
w->setLayout(layout); |
|
166 |
QString stylesheet; |
|
167 |
for(int x=0; x<N ;x++) |
|
168 |
for(int y=0; y<N ;y++) { |
|
169 |
QLabel *label = new QLabel(QString::number(y * N + x)); |
|
170 |
layout->addWidget(label ,x,y); |
|
171 |
label->setObjectName(QString("label%1").arg(y * N + x)); |
|
172 |
stylesheet += QString("#label%1 { background-color: rgb(0,%2,%3); color: rgb(%2,%3,255); } ").arg(y*N+x).arg(y*255/N).arg(x*255/N); |
|
173 |
} |
|
174 |
||
175 |
w->setStyleSheet("/* */"); |
|
176 |
if(show) { |
|
177 |
w->show(); |
|
178 |
QTest::qWait(30); |
|
179 |
} |
|
180 |
int i = 0; |
|
181 |
QBENCHMARK { |
|
182 |
w->setStyleSheet(stylesheet + "/*" + QString::number(i) + "*/"); |
|
183 |
i++; // we want a different string in case we have severals iterations |
|
184 |
if(events) |
|
185 |
qApp->processEvents(); |
|
186 |
} |
|
187 |
delete w; |
|
188 |
} |
|
189 |
||
190 |
QTEST_MAIN(tst_qstylesheetstyle) |
|
191 |
||
192 |
#include "main.moc" |