From fe21dc562504ccb87f8a1b01ea96cc7865064b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Thu, 7 Mar 2013 12:28:15 +0200 Subject: Initial version of QtDataVis3D Includes: - initial version of q3dbars - an example using it --- examples/datavis3d/barchart/barchart.pro | 9 ++ examples/datavis3d/barchart/main.cpp | 158 +++++++++++++++++++++++++++++++ examples/datavis3d/datavis3d.pro | 3 + examples/examples.pro | 2 + 4 files changed, 172 insertions(+) create mode 100644 examples/datavis3d/barchart/barchart.pro create mode 100644 examples/datavis3d/barchart/main.cpp create mode 100644 examples/datavis3d/datavis3d.pro create mode 100644 examples/examples.pro (limited to 'examples') diff --git a/examples/datavis3d/barchart/barchart.pro b/examples/datavis3d/barchart/barchart.pro new file mode 100644 index 00000000..80d6fd6c --- /dev/null +++ b/examples/datavis3d/barchart/barchart.pro @@ -0,0 +1,9 @@ +SOURCES += main.cpp +HEADERS += +QT += datavis3d + +target.path = $$[QT_INSTALL_EXAMPLES]/datavis3d/barchart +INSTALLS += target + +RESOURCES += + diff --git a/examples/datavis3d/barchart/main.cpp b/examples/datavis3d/barchart/main.cpp new file mode 100644 index 00000000..c4acd2f8 --- /dev/null +++ b/examples/datavis3d/barchart/main.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "q3dbars.h" + +#include +#include +#include + +class ChartDataGenerator : public QObject +{ +public: + explicit ChartDataGenerator(QtDataVis3D::Q3DBars *barchart); + ~ChartDataGenerator(); + + void addBars(); + void changeStyle(); + void start(); + +private: + QtDataVis3D::Q3DBars *m_chart; + QTimer *m_dataTimer; + QTimer *m_testTimer; + int m_columnCount; +}; + +ChartDataGenerator::ChartDataGenerator(QtDataVis3D::Q3DBars *barchart) + : m_chart(barchart) + , m_dataTimer(0) + , m_testTimer(0) + , m_columnCount(20) +{ + m_chart->setBarSpecs(QPointF(2.0f, 0.5f), QPointF(0.0f, 0.0f), true); + m_chart->setupSampleSpace(QPoint(m_columnCount, m_columnCount*2)); +} + +ChartDataGenerator::~ChartDataGenerator() +{ + if (m_dataTimer) { + m_dataTimer->stop(); + delete m_dataTimer; + } + if (m_testTimer) { + m_testTimer->stop(); + delete m_testTimer; + } + delete m_chart; +} + +void ChartDataGenerator::start() +{ + m_dataTimer = new QTimer(); + m_dataTimer->setTimerType(Qt::CoarseTimer); + m_dataTimer->setInterval(100); + QObject::connect(m_dataTimer, &QTimer::timeout, this, &ChartDataGenerator::addBars); + m_dataTimer->start(100); + + // Uncomment this to enable style changing every 10 seconds +// m_testTimer = new QTimer(); +// m_testTimer->setTimerType(Qt::CoarseTimer); +// m_testTimer->setInterval(10000); +// QObject::connect(m_testTimer, &QTimer::timeout, this, &ChartDataGenerator::changeStyle); +// m_testTimer->start(10000); +} + +void ChartDataGenerator::addBars() +{ + QVector data; + for (int i = 0; i < m_columnCount; i++) { + data.append(((float)i / (float)m_columnCount) / 2.0f + (float)(rand() % 30) / 100); + } + m_chart->addDataSet(data); +} + +void ChartDataGenerator::changeStyle() +{ + static int model = 0; + switch (model) { + case 0: + m_chart->setBarType(QtDataVis3D::Q3DBars::Cylinders, false); + break; + case 1: + m_chart->setBarType(QtDataVis3D::Q3DBars::Cylinders, true); + break; + case 2: + m_chart->setBarType(QtDataVis3D::Q3DBars::Cones, false); + break; + case 3: + m_chart->setBarType(QtDataVis3D::Q3DBars::Cones, true); + break; + case 4: + m_chart->setBarType(QtDataVis3D::Q3DBars::Bars, false); + break; + case 5: + m_chart->setBarType(QtDataVis3D::Q3DBars::Bars, true); + break; + case 6: + m_chart->setBarType(QtDataVis3D::Q3DBars::Pyramids, false); + break; + case 7: + m_chart->setBarType(QtDataVis3D::Q3DBars::Pyramids, true); + break; + } + model++; + if (model > 7) + model = 0; +} + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QtDataVis3D::Q3DBars barchart; + barchart.resize(1024, 768); + barchart.show(); + + ChartDataGenerator *generator = new ChartDataGenerator(&barchart); + generator->start(); + + return app.exec(); +} diff --git a/examples/datavis3d/datavis3d.pro b/examples/datavis3d/datavis3d.pro new file mode 100644 index 00000000..0d8273fb --- /dev/null +++ b/examples/datavis3d/datavis3d.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS += barchart #\ + #spectrum diff --git a/examples/examples.pro b/examples/examples.pro new file mode 100644 index 00000000..b9b7be46 --- /dev/null +++ b/examples/examples.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += datavis3d -- cgit v1.2.3