From a1feedcf46975a65970fb946282c742b091b508e Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Mon, 3 Nov 2014 11:22:23 +0200 Subject: Qml perf data generation on cpp Change-Id: If770c96ff84e49a747c4355e56bff002556cd659 Reviewed-by: Mika Salmela --- tests/qmlperf/datagenerator.cpp | 67 +++++++++++++++++++++++++++++++++++++ tests/qmlperf/datagenerator.h | 41 +++++++++++++++++++++++ tests/qmlperf/main.cpp | 6 ++++ tests/qmlperf/qml/qmlperf/main.qml | 18 +++------- tests/qmlperf/qml/qmlperf/script.js | 33 ------------------ tests/qmlperf/qmlperf.pro | 6 +++- tests/qmlperf/qmlperf.qrc | 1 - 7 files changed, 123 insertions(+), 49 deletions(-) create mode 100644 tests/qmlperf/datagenerator.cpp create mode 100644 tests/qmlperf/datagenerator.h delete mode 100644 tests/qmlperf/qml/qmlperf/script.js (limited to 'tests') 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 + +using namespace QtDataVisualization; + +Q_DECLARE_METATYPE(QScatter3DSeries *) + +DataGenerator::DataGenerator(QObject *parent) : + QObject(parent) +{ + qRegisterMetaType(); +} + +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/datagenerator.h b/tests/qmlperf/datagenerator.h new file mode 100644 index 00000000..0687ecec --- /dev/null +++ b/tests/qmlperf/datagenerator.h @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** 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 +** +****************************************************************************/ + +#ifndef DATAGENERATOR_H +#define DATAGENERATOR_H + +#include + +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 #include +#include #include #include @@ -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/qml/qmlperf/script.js b/tests/qmlperf/qml/qmlperf/script.js deleted file mode 100644 index dc271e8d..00000000 --- a/tests/qmlperf/qml/qmlperf/script.js +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** -** -** 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 -** -****************************************************************************/ - -//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}); -// } -// } -//} - -function createData(base) { - for (var i = 0; i < base; i++) { - dataModel.append({"z": Math.random(), "x": Math.random(), "y": Math.random()}); - } -} 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 @@ qml/qmlperf/main.qml - qml/qmlperf/script.js -- cgit v1.2.3