summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/declarative
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-12-17 04:06:42 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-12-17 04:06:42 (GMT)
commite65add386385365f3ee5d3161198101afe2459a3 (patch)
treeda63f55a7998014ef18ff3d950025cdf12affd03 /tests/benchmarks/declarative
parent4d6001bd1d75b80c53fcc716b5a51043713ff6f9 (diff)
downloadQt-e65add386385365f3ee5d3161198101afe2459a3.zip
Qt-e65add386385365f3ee5d3161198101afe2459a3.tar.gz
Qt-e65add386385365f3ee5d3161198101afe2459a3.tar.bz2
Add -parent option
Diffstat (limited to 'tests/benchmarks/declarative')
-rw-r--r--tests/benchmarks/declarative/qmltime/qmltime.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp
index f065444..8da0f17 100644
--- a/tests/benchmarks/declarative/qmltime/qmltime.cpp
+++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp
@@ -4,6 +4,8 @@
#include <QApplication>
#include <QTime>
#include <QmlContext>
+#include <QGraphicsScene>
+#include <QGraphicsRectItem>
class Timer : public QObject
{
@@ -20,11 +22,18 @@ public:
void run(uint);
+ bool willParent() const;
+ void setWillParent(bool p);
+
private:
void runTest(QmlContext *, uint);
QmlComponent *m_component;
static Timer *m_timer;
+
+ bool m_willparent;
+ QGraphicsScene m_scene;
+ QGraphicsRectItem m_item;
};
QML_DECLARE_TYPE(Timer);
QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer);
@@ -32,11 +41,13 @@ QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer);
Timer *Timer::m_timer = 0;
Timer::Timer()
-: m_component(0)
+: m_component(0), m_willparent(false)
{
if (m_timer)
qWarning("Timer: Timer already registered");
m_timer = this;
+
+ m_scene.addItem(&m_item);
}
QmlComponent *Timer::component() const
@@ -59,18 +70,33 @@ void Timer::run(uint iterations)
QmlContext context(qmlContext(this));
QObject *o = m_component->create(&context);
+ QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o);
+ if (m_willparent && go)
+ go->setParentItem(&m_item);
delete o;
-
runTest(&context, iterations);
}
+bool Timer::willParent() const
+{
+ return m_willparent;
+}
+
+void Timer::setWillParent(bool p)
+{
+ m_willparent = p;
+}
+
void Timer::runTest(QmlContext *context, uint iterations)
{
QTime t;
t.start();
for (uint ii = 0; ii < iterations; ++ii) {
QObject *o = m_component->create(context);
+ QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o);
+ if (m_willparent && go)
+ go->setParentItem(&m_item);
delete o;
}
@@ -82,7 +108,7 @@ void Timer::runTest(QmlContext *context, uint iterations)
void usage(const char *name)
{
- qWarning("Usage: %s [-iterations <count>] <qml file>", name);
+ qWarning("Usage: %s [-iterations <count>] [-parent] <qml file>", name);
exit(-1);
}
@@ -92,6 +118,7 @@ int main(int argc, char ** argv)
uint iterations = 1024;
QString filename;
+ bool willParent = false;
for (int ii = 1; ii < argc; ++ii) {
QByteArray arg(argv[ii]);
@@ -107,11 +134,16 @@ int main(int argc, char ** argv)
} else {
usage(argv[0]);
}
+ } else if (arg == "-parent") {
+ willParent = true;
} else {
filename = QLatin1String(argv[ii]);
}
}
+ if (filename.isEmpty())
+ usage(argv[0]);
+
QmlEngine engine;
QmlComponent component(&engine, filename);
if (component.isError()) {
@@ -131,6 +163,8 @@ int main(int argc, char ** argv)
return -1;
}
+ timer->setWillParent(willParent);
+
if (!timer->component()) {
qWarning() << "The timer has no component";
return -1;