mirror of https://github.com/qt/qtdatavis3d.git
Qml perf data generation on cpp
Change-Id: If770c96ff84e49a747c4355e56bff002556cd659 Reviewed-by: Mika Salmela <mika.salmela@theqtcompany.com>
This commit is contained in:
parent
0090db1602
commit
a1feedcf46
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>qml/qmlperf/main.qml</file>
|
||||
<file>qml/qmlperf/script.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
Loading…
Reference in New Issue