summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMika Salmela <mika.salmela@theqtcompany.com>2014-11-03 11:22:23 +0200
committerMika Salmela <mika.salmela@theqtcompany.com>2014-11-03 11:23:13 +0200
commita1feedcf46975a65970fb946282c742b091b508e (patch)
tree990cf6ee09700ebac84fb4cbe333ab91fde37aee /tests
parent0090db160242374d7ab6e3bedf064b366716f770 (diff)
Qml perf data generation on cpp
Change-Id: If770c96ff84e49a747c4355e56bff002556cd659 Reviewed-by: Mika Salmela <mika.salmela@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qmlperf/datagenerator.cpp67
-rw-r--r--tests/qmlperf/datagenerator.h (renamed from tests/qmlperf/qml/qmlperf/script.js)36
-rw-r--r--tests/qmlperf/main.cpp6
-rw-r--r--tests/qmlperf/qml/qmlperf/main.qml18
-rw-r--r--tests/qmlperf/qmlperf.pro6
-rw-r--r--tests/qmlperf/qmlperf.qrc1
6 files changed, 104 insertions, 30 deletions
diff --git a/tests/qmlperf/datagenerator.cpp b/tests/qmlperf/datagenerator.cpp
new file mode 100644
index 00000000..4819f59d
--- /dev/null
+++ b/tests/qmlperf/datagenerator.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "datagenerator.h"
+#include <QDebug>
+
+using namespace QtDataVisualization;
+
+Q_DECLARE_METATYPE(QScatter3DSeries *)
+
+DataGenerator::DataGenerator(QObject *parent) :
+ QObject(parent)
+{
+ qRegisterMetaType<QScatter3DSeries *>();
+}
+
+DataGenerator::~DataGenerator()
+{
+ qDebug() << __FUNCTION__;
+}
+
+void DataGenerator::generateData(QScatter3DSeries *series, uint count)
+{
+ QScatterDataArray *dataArray = new QScatterDataArray;
+ dataArray->resize(count);
+ QScatterDataItem *ptrToDataArray = &dataArray->first();
+
+ float rand_max = float(RAND_MAX);
+ for (uint i = 0; i < count; i++) {
+ ptrToDataArray->setPosition(QVector3D(float(qrand()) / rand_max,
+ float(qrand()) / rand_max,
+ float(qrand()) / rand_max));
+ ptrToDataArray++;
+ }
+
+ series->dataProxy()->resetArray(dataArray);
+}
+
+void DataGenerator::add(QScatter3DSeries *series, uint count)
+{
+ QScatterDataArray appendArray;
+ appendArray.resize(count);
+
+ float rand_max = float(RAND_MAX);
+ for (uint i = 0; i < count; i++) {
+ appendArray[i].setPosition(QVector3D(float(qrand()) / rand_max,
+ float(qrand()) / rand_max,
+ float(qrand()) / rand_max));
+ }
+
+ series->dataProxy()->addItems(appendArray);
+}
diff --git a/tests/qmlperf/qml/qmlperf/script.js b/tests/qmlperf/datagenerator.h
index dc271e8d..0687ecec 100644
--- a/tests/qmlperf/qml/qmlperf/script.js
+++ b/tests/qmlperf/datagenerator.h
@@ -16,18 +16,26 @@
**
****************************************************************************/
-//function createData(base) {
-// for (var z = 0; z < 30; z++) {
-// for (var x = 0; x < 30; x++) {
-// var angle = (((z - 16) * (x - 16)) / 144.0) * 1.57;
-// var y = Math.sin(angle + base);
-// dataModel.append({"z": z, "x": x, "y": y});
-// }
-// }
-//}
+#ifndef DATAGENERATOR_H
+#define DATAGENERATOR_H
-function createData(base) {
- for (var i = 0; i < base; i++) {
- dataModel.append({"z": Math.random(), "x": Math.random(), "y": Math.random()});
- }
-}
+#include <QtDataVisualization/QScatter3DSeries>
+
+using namespace QtDataVisualization;
+
+class DataGenerator : public QObject
+{
+ Q_OBJECT
+public:
+ DataGenerator(QObject *parent = 0);
+ virtual ~DataGenerator();
+
+public slots:
+ void generateData(QScatter3DSeries *series, uint count);
+ void add(QScatter3DSeries *series, uint count);
+
+private:
+ QScatter3DSeries m_series;
+};
+
+#endif // DATAGENERATOR_H
diff --git a/tests/qmlperf/main.cpp b/tests/qmlperf/main.cpp
index 7d35b2ed..06b18816 100644
--- a/tests/qmlperf/main.cpp
+++ b/tests/qmlperf/main.cpp
@@ -16,8 +16,11 @@
**
****************************************************************************/
+#include "datagenerator.h"
+
#include <QtGui/QGuiApplication>
#include <QtCore/QDir>
+#include <QtQml/QQmlContext>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
@@ -38,6 +41,9 @@ int main(int argc, char *argv[])
QString::fromLatin1("qml")));
QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
+ DataGenerator dataGenerator;
+ viewer.rootContext()->setContextProperty("dataGenerator", &dataGenerator);
+
viewer.setTitle(QStringLiteral("QML Performance"));
viewer.setSource(QUrl("qrc:/qml/qmlperf/main.qml"));
viewer.setResizeMode(QQuickView::SizeRootObjectToView);
diff --git a/tests/qmlperf/qml/qmlperf/main.qml b/tests/qmlperf/qml/qmlperf/main.qml
index 35f8df5d..bb3f1b82 100644
--- a/tests/qmlperf/qml/qmlperf/main.qml
+++ b/tests/qmlperf/qml/qmlperf/main.qml
@@ -20,7 +20,6 @@ import QtQuick 2.1
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import QtDataVisualization 1.1
-import "script.js" as Script
import "."
Rectangle {
@@ -29,7 +28,7 @@ Rectangle {
height: 1024
property var itemCount: 1000.0
- property var addItems: 1000.0
+ property var addItems: 500.0
Button {
id: changeButton
@@ -90,7 +89,7 @@ Rectangle {
text: "Add"
onClicked: {
itemCount = itemCount + addItems;
- Script.createData(addItems);
+ dataGenerator.add(scatterSeries, addItems);
}
}
@@ -102,11 +101,6 @@ Rectangle {
anchors.left: mainview.left
state: "meshsphere"
- ListModel {
- id: dataModel
- Component.onCompleted: Script.createData(itemCount)
- }
-
Scatter3D {
id: scatterPlot
width: graphView.width
@@ -134,13 +128,9 @@ Rectangle {
Scatter3DSeries {
id: scatterSeries
mesh: Abstract3DSeries.MeshSphere
- ItemModelScatterDataProxy {
- itemModel: dataModel
- xPosRole: "x"
- yPosRole: "y"
- zPosRole: "z"
- }
}
+
+ Component.onCompleted: dataGenerator.generateData(scatterSeries, itemCount);
}
states: [
diff --git a/tests/qmlperf/qmlperf.pro b/tests/qmlperf/qmlperf.pro
index 6560f55c..e29ef75d 100644
--- a/tests/qmlperf/qmlperf.pro
+++ b/tests/qmlperf/qmlperf.pro
@@ -3,10 +3,14 @@
}
# The .cpp file which was generated for your project. Feel free to hack it.
-SOURCES += main.cpp
+SOURCES += main.cpp \
+ datagenerator.cpp
RESOURCES += qmlperf.qrc
OTHER_FILES += doc/src/* \
doc/images/* \
qml/qmlperf/*
+
+HEADERS += \
+ datagenerator.h
diff --git a/tests/qmlperf/qmlperf.qrc b/tests/qmlperf/qmlperf.qrc
index e50815c5..b52f4bb9 100644
--- a/tests/qmlperf/qmlperf.qrc
+++ b/tests/qmlperf/qmlperf.qrc
@@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/">
<file>qml/qmlperf/main.qml</file>
- <file>qml/qmlperf/script.js</file>
</qresource>
</RCC>