From d879027ac73093e51d3470e9aea87aa5479a0ef1 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 3 Oct 2013 14:26:46 +0300 Subject: Replace 'chart' with 'graph' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-2369 Change-Id: Ic39bc03a0eee4fe75978e71af06ad7a655e958a9 Reviewed-by: Tomi Korpipää --- examples/audiolevels/audiolevels.cpp | 4 +- examples/audiolevels/audiolevels.h | 2 +- examples/audiolevels/audiolevels.pro | 4 + examples/barchart/barchart.pro | 9 - examples/barchart/doc/images/barchart-example.png | Bin 163146 -> 0 bytes examples/barchart/doc/src/barchart.qdoc | 28 -- examples/barchart/main.cpp | 254 -------------- examples/bars/bars.pro | 12 + examples/bars/doc/images/bars-example.png | Bin 0 -> 163146 bytes examples/bars/doc/src/bars.qdoc | 28 ++ examples/bars/main.cpp | 254 ++++++++++++++ examples/examples.pro | 7 +- examples/qmlbarchart/doc/src/qmlbarchart.qdoc | 29 -- examples/qmlbarchart/main.cpp | 45 --- examples/qmlbarchart/qml/qmlbarchart/axes.qml | 50 --- examples/qmlbarchart/qml/qmlbarchart/data.qml | 133 ------- examples/qmlbarchart/qml/qmlbarchart/main.qml | 157 --------- examples/qmlbarchart/qmlbarchart.desktop | 11 - examples/qmlbarchart/qmlbarchart.pro | 22 -- examples/qmlbarchart/qmlbarchart.qrc | 7 - examples/qmlbarchart/qmlbarchart64.png | Bin 3400 -> 0 bytes .../qtquick2applicationviewer.cpp | 81 ----- .../qtquick2applicationviewer.h | 33 -- .../qtquick2applicationviewer.pri | 170 --------- examples/qmlbars/doc/src/qmlbars.qdoc | 29 ++ examples/qmlbars/main.cpp | 45 +++ examples/qmlbars/qml/qmlbars/axes.qml | 50 +++ examples/qmlbars/qml/qmlbars/data.qml | 133 +++++++ examples/qmlbars/qml/qmlbars/main.qml | 157 +++++++++ examples/qmlbars/qmlbars.desktop | 11 + examples/qmlbars/qmlbars.pro | 25 ++ examples/qmlbars/qmlbars.qrc | 7 + examples/qmlbars/qmlbars64.png | Bin 0 -> 3400 bytes .../qtquick2applicationviewer.cpp | 81 +++++ .../qtquick2applicationviewer.h | 33 ++ .../qtquick2applicationviewer.pri | 170 +++++++++ examples/qmlscatter/doc/src/qmlscatter.qdoc | 2 +- examples/qmlscatter/qml/qmlscatter/main.qml | 4 +- examples/qmlscatter/qmlscatter.pro | 3 + examples/qmlsurface/qmlsurface.pro | 3 + examples/rainfall/doc/src/rainfall.qdoc | 2 +- examples/rainfall/main.cpp | 6 +- examples/rainfall/rainfall.pro | 8 +- examples/rainfall/rainfallchart.cpp | 138 -------- examples/rainfall/rainfallchart.h | 51 --- examples/rainfall/rainfallgraph.cpp | 138 ++++++++ examples/rainfall/rainfallgraph.h | 51 +++ examples/scatter/doc/src/scatter.qdoc | 29 ++ examples/scatter/main.cpp | 152 ++++++++ examples/scatter/scatter.pro | 13 + examples/scatter/scatterdatamodifier.cpp | 169 +++++++++ examples/scatter/scatterdatamodifier.h | 62 ++++ examples/scatterchart/doc/src/scatterchart.qdoc | 29 -- examples/scatterchart/main.cpp | 152 -------- examples/scatterchart/scatterchart.cpp | 167 --------- examples/scatterchart/scatterchart.h | 62 ---- examples/scatterchart/scatterchart.pro | 10 - examples/surfacechart/Heightmap.png | Bin 71764 -> 0 bytes examples/surfacechart/chartmodifier.cpp | 389 --------------------- examples/surfacechart/chartmodifier.h | 95 ----- examples/surfacechart/main.cpp | 256 -------------- examples/surfacechart/surface.qrc | 5 - examples/surfacechart/surfacechart.pro | 16 - examples/widget/chart.cpp | 217 ------------ examples/widget/chart.h | 79 ----- examples/widget/doc/src/widget.qdoc | 2 +- examples/widget/graphmodifier.cpp | 218 ++++++++++++ examples/widget/graphmodifier.h | 79 +++++ examples/widget/main.cpp | 34 +- examples/widget/widget.pro | 8 +- 70 files changed, 1998 insertions(+), 2732 deletions(-) delete mode 100644 examples/barchart/barchart.pro delete mode 100644 examples/barchart/doc/images/barchart-example.png delete mode 100644 examples/barchart/doc/src/barchart.qdoc delete mode 100644 examples/barchart/main.cpp create mode 100644 examples/bars/bars.pro create mode 100644 examples/bars/doc/images/bars-example.png create mode 100644 examples/bars/doc/src/bars.qdoc create mode 100644 examples/bars/main.cpp delete mode 100644 examples/qmlbarchart/doc/src/qmlbarchart.qdoc delete mode 100644 examples/qmlbarchart/main.cpp delete mode 100644 examples/qmlbarchart/qml/qmlbarchart/axes.qml delete mode 100644 examples/qmlbarchart/qml/qmlbarchart/data.qml delete mode 100644 examples/qmlbarchart/qml/qmlbarchart/main.qml delete mode 100644 examples/qmlbarchart/qmlbarchart.desktop delete mode 100644 examples/qmlbarchart/qmlbarchart.pro delete mode 100644 examples/qmlbarchart/qmlbarchart.qrc delete mode 100644 examples/qmlbarchart/qmlbarchart64.png delete mode 100644 examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.cpp delete mode 100644 examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.h delete mode 100644 examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.pri create mode 100644 examples/qmlbars/doc/src/qmlbars.qdoc create mode 100644 examples/qmlbars/main.cpp create mode 100644 examples/qmlbars/qml/qmlbars/axes.qml create mode 100644 examples/qmlbars/qml/qmlbars/data.qml create mode 100644 examples/qmlbars/qml/qmlbars/main.qml create mode 100644 examples/qmlbars/qmlbars.desktop create mode 100644 examples/qmlbars/qmlbars.pro create mode 100644 examples/qmlbars/qmlbars.qrc create mode 100644 examples/qmlbars/qmlbars64.png create mode 100644 examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.cpp create mode 100644 examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.h create mode 100644 examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.pri delete mode 100644 examples/rainfall/rainfallchart.cpp delete mode 100644 examples/rainfall/rainfallchart.h create mode 100644 examples/rainfall/rainfallgraph.cpp create mode 100644 examples/rainfall/rainfallgraph.h create mode 100644 examples/scatter/doc/src/scatter.qdoc create mode 100644 examples/scatter/main.cpp create mode 100644 examples/scatter/scatter.pro create mode 100644 examples/scatter/scatterdatamodifier.cpp create mode 100644 examples/scatter/scatterdatamodifier.h delete mode 100644 examples/scatterchart/doc/src/scatterchart.qdoc delete mode 100644 examples/scatterchart/main.cpp delete mode 100644 examples/scatterchart/scatterchart.cpp delete mode 100644 examples/scatterchart/scatterchart.h delete mode 100644 examples/scatterchart/scatterchart.pro delete mode 100644 examples/surfacechart/Heightmap.png delete mode 100644 examples/surfacechart/chartmodifier.cpp delete mode 100644 examples/surfacechart/chartmodifier.h delete mode 100644 examples/surfacechart/main.cpp delete mode 100644 examples/surfacechart/surface.qrc delete mode 100644 examples/surfacechart/surfacechart.pro delete mode 100644 examples/widget/chart.cpp delete mode 100644 examples/widget/chart.h create mode 100644 examples/widget/graphmodifier.cpp create mode 100644 examples/widget/graphmodifier.h (limited to 'examples') diff --git a/examples/audiolevels/audiolevels.cpp b/examples/audiolevels/audiolevels.cpp index bfa419b4..0d227a31 100644 --- a/examples/audiolevels/audiolevels.cpp +++ b/examples/audiolevels/audiolevels.cpp @@ -27,10 +27,10 @@ QT_DATAVISUALIZATION_USE_NAMESPACE -AudioLevels::AudioLevels(Q3DBars *chart, QObject *parent) +AudioLevels::AudioLevels(Q3DBars *graph, QObject *parent) : QObject(parent), m_device(0), - m_graph(chart), + m_graph(graph), m_audioInput(0) { // Set up the graph diff --git a/examples/audiolevels/audiolevels.h b/examples/audiolevels/audiolevels.h index eafb799e..90141850 100644 --- a/examples/audiolevels/audiolevels.h +++ b/examples/audiolevels/audiolevels.h @@ -31,7 +31,7 @@ class AudioLevels : public QObject Q_OBJECT public: - AudioLevels(Q3DBars *chart, QObject *parent = 0); + AudioLevels(Q3DBars *graph, QObject *parent = 0); ~AudioLevels(); private: diff --git a/examples/audiolevels/audiolevels.pro b/examples/audiolevels/audiolevels.pro index 79356f18..7df4379b 100644 --- a/examples/audiolevels/audiolevels.pro +++ b/examples/audiolevels/audiolevels.pro @@ -14,3 +14,7 @@ HEADERS += audiolevels.h \ audiolevelsiodevice.h INSTALLS += target + +OTHER_FILES += doc/src/* \ + doc/images/* + diff --git a/examples/barchart/barchart.pro b/examples/barchart/barchart.pro deleted file mode 100644 index 12b296c5..00000000 --- a/examples/barchart/barchart.pro +++ /dev/null @@ -1,9 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -SOURCES += main.cpp - -INSTALLS += target - -QT += widgets diff --git a/examples/barchart/doc/images/barchart-example.png b/examples/barchart/doc/images/barchart-example.png deleted file mode 100644 index 0f321c95..00000000 Binary files a/examples/barchart/doc/images/barchart-example.png and /dev/null differ diff --git a/examples/barchart/doc/src/barchart.qdoc b/examples/barchart/doc/src/barchart.qdoc deleted file mode 100644 index 0966bd29..00000000 --- a/examples/barchart/doc/src/barchart.qdoc +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -/*! - \example barchart - \title Barchart Example - - The barchart example shows how to make a simple 3D bar chart using Q3DBars. - - \image barchart-example.png - - TODO -*/ diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp deleted file mode 100644 index 5a69a5fb..00000000 --- a/examples/barchart/main.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define USE_STATIC_DATA - -using namespace QtDataVisualization; - -class ChartDataGenerator : public QObject -{ -public: - explicit ChartDataGenerator(Q3DBars *barchart, QTableWidget *tableWidget); - ~ChartDataGenerator(); - - void setupModel(); - void addRow(); - void changeStyle(); - void changePresetCamera(); - void changeTheme(); - void start(); - void selectFromTable(const QPoint &selection); - void selectedFromTable(int currentRow, int currentColumn, int previousRow, int previousColumn); - void fixTableSize(); - -private: - Q3DBars *m_chart; - QTimer *m_dataTimer; - QTimer *m_styleTimer; - QTimer *m_presetTimer; - QTimer *m_themeTimer; - int m_columnCount; - int m_rowCount; - QTableWidget *m_tableWidget; // not owned -}; - -ChartDataGenerator::ChartDataGenerator(Q3DBars *barchart, QTableWidget *tableWidget) - : m_chart(barchart), - m_dataTimer(0), - m_styleTimer(0), - m_presetTimer(0), - m_themeTimer(0), - m_columnCount(100), - m_rowCount(50), - m_tableWidget(tableWidget) -{ - // Set up bar specifications; make the bars as wide as they are deep, - // and add a small space between the bars - m_chart->setBarThickness(1.0); - m_chart->setBarSpacing(QSizeF(0.2, 0.2)); - - // Set bar type to flat pyramids - m_chart->setBarType(QDataVis::MeshStylePyramids, false); - -#ifndef USE_STATIC_DATA - // Set up sample space; make it as deep as it's wide - m_chart->setDataWindow(m_rowCount, m_columnCount); - m_tableWidget->setColumnCount(m_columnCount); - - // Set selection mode to full - m_chart->setSelectionMode(QDataVis::SelectionModeItemRowAndColumn); - - // Hide axis labels by explicitly setting one empty string as label list - m_chart->rowAxis()->setCategoryLabels(QStringList(QString())); - m_chart->columnAxis()->setCategoryLabels(QStringList(QString())); - - m_chart->activeDataProxy()->setItemLabelFormat(QStringLiteral("@valueLabel")); -#else - // Set selection mode to zoom row - m_chart->setSelectionMode(QDataVis::SelectionModeSliceRow); - m_chart->setFont(QFont("Impact", 20)); -#endif - - // Set theme - m_chart->setTheme(QDataVis::ThemeDigia); - - // Set preset camera position - m_chart->setCameraPreset(QDataVis::CameraPresetFront); -} - -ChartDataGenerator::~ChartDataGenerator() -{ - if (m_dataTimer) { - m_dataTimer->stop(); - delete m_dataTimer; - } - delete m_chart; -} - -void ChartDataGenerator::start() -{ -#ifndef USE_STATIC_DATA - m_dataTimer = new QTimer(); - m_dataTimer->setTimerType(Qt::CoarseTimer); - QObject::connect(m_dataTimer, &QTimer::timeout, this, &ChartDataGenerator::addRow); - m_dataTimer->start(0); - m_tableWidget->setFixedWidth(m_chart->width()); -#else - setupModel(); - // Table needs to be shown before the size of its headers can be accurately obtained, - // so we postpone it a bit - m_dataTimer = new QTimer(); - m_dataTimer->setSingleShot(true); - QObject::connect(m_dataTimer, &QTimer::timeout, this, &ChartDataGenerator::fixTableSize); - m_dataTimer->start(0); -#endif -} - -void ChartDataGenerator::setupModel() -{ - // Set up row and column names - QStringList days; - days << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday" << "Sunday"; - QStringList weeks; - weeks << "week 1" << "week 2" << "week 3" << "week 4" << "week 5"; - - // Set up data Mon Tue Wed Thu Fri Sat Sun - float hours[5][7] = {{2.0f, 1.0f, 3.0f, 0.2f, 1.0f, 5.0f, 10.0f}, // week 1 - {0.5f, 1.0f, 3.0f, 1.0f, 2.0f, 2.0f, 3.0f}, // week 2 - {1.0f, 1.0f, 2.0f, 1.0f, 4.0f, 4.0f, 4.0f}, // week 3 - {0.0f, 1.0f, 0.0f, 0.0f, 2.0f, 2.0f, 0.3f}, // week 4 - {3.0f, 3.0f, 6.0f, 2.0f, 2.0f, 1.0f, 1.0f}}; // week 5 - - // Add labels - m_chart->rowAxis()->setTitle("Week of year"); - m_chart->columnAxis()->setTitle("Day of week"); - m_chart->valueAxis()->setTitle("Hours playing banjo"); - m_chart->valueAxis()->setSegmentCount(5); - m_chart->valueAxis()->setLabelFormat("%.1f h"); - - m_tableWidget->setRowCount(5); - m_tableWidget->setColumnCount(7); - m_tableWidget->setHorizontalHeaderLabels(days); - m_tableWidget->setVerticalHeaderLabels(weeks); - m_tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_tableWidget->setCurrentCell(-1, -1); - - for (int week = 0; week < weeks.size(); week++) { - for (int day = 0; day < days.size(); day++) { - QModelIndex index = m_tableWidget->model()->index(week, day); - m_tableWidget->model()->setData(index, hours[week][day]); - } - } -} - -void ChartDataGenerator::addRow() -{ - m_tableWidget->model()->insertRow(0); - if (m_tableWidget->model()->rowCount() > m_rowCount) - m_tableWidget->model()->removeRow(m_rowCount); - for (int i = 0; i < m_columnCount; i++) { - QModelIndex index = m_tableWidget->model()->index(0, i); - m_tableWidget->model()->setData(index, - ((qreal)i / (qreal)m_columnCount) / 2.0 + (qreal)(rand() % 30) / 100.0); - } - m_tableWidget->resizeColumnsToContents(); -} - -void ChartDataGenerator::selectFromTable(const QPoint &selection) -{ - m_tableWidget->setFocus(); - m_tableWidget->setCurrentCell(selection.x(), selection.y()); -} - -void ChartDataGenerator::selectedFromTable(int currentRow, int currentColumn, - int previousRow, int previousColumn) -{ - Q_UNUSED(previousRow) - Q_UNUSED(previousColumn) - m_chart->setSelectedBarPos(QPoint(currentRow, currentColumn)); -} - -void ChartDataGenerator::fixTableSize() -{ - int width = m_tableWidget->horizontalHeader()->length(); - width += m_tableWidget->verticalHeader()->width(); - m_tableWidget->setFixedWidth(width + 2); - int height = m_tableWidget->verticalHeader()->length(); - height += m_tableWidget->horizontalHeader()->height(); - m_tableWidget->setFixedHeight(height + 2); -} - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - QWidget widget; - QVBoxLayout *layout = new QVBoxLayout(&widget); - - Q3DBars *chart = new Q3DBars(); - QSize screenSize = chart->screen()->size(); - - QWidget *container = QWidget::createWindowContainer(chart); - container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 2)); - container->setMaximumSize(screenSize); - container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - container->setFocusPolicy(Qt::StrongFocus); - - widget.setWindowTitle(QStringLiteral("Hours playing banjo")); - - QTableWidget *tableWidget = new QTableWidget(&widget); - tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - tableWidget->setAlternatingRowColors(true); - - layout->addWidget(container, 1); - layout->addWidget(tableWidget, 1, Qt::AlignHCenter); - - // Since we are dealing with QTableWidget, the model will already have data sorted properly - // in rows and columns, so create a custom mapping to utilize this. - QItemModelBarDataMapping *mapping = new QItemModelBarDataMapping; - mapping->setUseModelCategories(true); - QItemModelBarDataProxy *proxy = new QItemModelBarDataProxy(tableWidget->model(), mapping); - chart->setActiveDataProxy(proxy); - - ChartDataGenerator generator(chart, tableWidget); - - QObject::connect(chart, &Q3DBars::selectedBarPosChanged, &generator, - &ChartDataGenerator::selectFromTable); - QObject::connect(tableWidget, &QTableWidget::currentCellChanged, &generator, - &ChartDataGenerator::selectedFromTable); - - widget.show(); - generator.start(); - - return app.exec(); -} diff --git a/examples/bars/bars.pro b/examples/bars/bars.pro new file mode 100644 index 00000000..f319f690 --- /dev/null +++ b/examples/bars/bars.pro @@ -0,0 +1,12 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +SOURCES += main.cpp + +INSTALLS += target + +QT += widgets + +OTHER_FILES += doc/src/* \ + doc/images/* diff --git a/examples/bars/doc/images/bars-example.png b/examples/bars/doc/images/bars-example.png new file mode 100644 index 00000000..0f321c95 Binary files /dev/null and b/examples/bars/doc/images/bars-example.png differ diff --git a/examples/bars/doc/src/bars.qdoc b/examples/bars/doc/src/bars.qdoc new file mode 100644 index 00000000..8a9a4458 --- /dev/null +++ b/examples/bars/doc/src/bars.qdoc @@ -0,0 +1,28 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +/*! + \example bars + \title Bars Example + + The bars example shows how to make a simple 3D bar graph using Q3DBars. + + \image bars-example.png + + TODO +*/ diff --git a/examples/bars/main.cpp b/examples/bars/main.cpp new file mode 100644 index 00000000..42e7da57 --- /dev/null +++ b/examples/bars/main.cpp @@ -0,0 +1,254 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define USE_STATIC_DATA + +using namespace QtDataVisualization; + +class GraphDataGenerator : public QObject +{ +public: + explicit GraphDataGenerator(Q3DBars *bargraph, QTableWidget *tableWidget); + ~GraphDataGenerator(); + + void setupModel(); + void addRow(); + void changeStyle(); + void changePresetCamera(); + void changeTheme(); + void start(); + void selectFromTable(const QPoint &selection); + void selectedFromTable(int currentRow, int currentColumn, int previousRow, int previousColumn); + void fixTableSize(); + +private: + Q3DBars *m_graph; + QTimer *m_dataTimer; + QTimer *m_styleTimer; + QTimer *m_presetTimer; + QTimer *m_themeTimer; + int m_columnCount; + int m_rowCount; + QTableWidget *m_tableWidget; // not owned +}; + +GraphDataGenerator::GraphDataGenerator(Q3DBars *bargraph, QTableWidget *tableWidget) + : m_graph(bargraph), + m_dataTimer(0), + m_styleTimer(0), + m_presetTimer(0), + m_themeTimer(0), + m_columnCount(100), + m_rowCount(50), + m_tableWidget(tableWidget) +{ + // Set up bar specifications; make the bars as wide as they are deep, + // and add a small space between the bars + m_graph->setBarThickness(1.0); + m_graph->setBarSpacing(QSizeF(0.2, 0.2)); + + // Set bar type to flat pyramids + m_graph->setBarType(QDataVis::MeshStylePyramids, false); + +#ifndef USE_STATIC_DATA + // Set up sample space; make it as deep as it's wide + m_graph->setDataWindow(m_rowCount, m_columnCount); + m_tableWidget->setColumnCount(m_columnCount); + + // Set selection mode to full + m_graph->setSelectionMode(QDataVis::SelectionModeItemRowAndColumn); + + // Hide axis labels by explicitly setting one empty string as label list + m_graph->rowAxis()->setCategoryLabels(QStringList(QString())); + m_graph->columnAxis()->setCategoryLabels(QStringList(QString())); + + m_graph->activeDataProxy()->setItemLabelFormat(QStringLiteral("@valueLabel")); +#else + // Set selection mode to zoom row + m_graph->setSelectionMode(QDataVis::SelectionModeSliceRow); + m_graph->setFont(QFont("Impact", 20)); +#endif + + // Set theme + m_graph->setTheme(QDataVis::ThemeDigia); + + // Set preset camera position + m_graph->setCameraPreset(QDataVis::CameraPresetFront); +} + +GraphDataGenerator::~GraphDataGenerator() +{ + if (m_dataTimer) { + m_dataTimer->stop(); + delete m_dataTimer; + } + delete m_graph; +} + +void GraphDataGenerator::start() +{ +#ifndef USE_STATIC_DATA + m_dataTimer = new QTimer(); + m_dataTimer->setTimerType(Qt::CoarseTimer); + QObject::connect(m_dataTimer, &QTimer::timeout, this, &GraphDataGenerator::addRow); + m_dataTimer->start(0); + m_tableWidget->setFixedWidth(m_graph->width()); +#else + setupModel(); + // Table needs to be shown before the size of its headers can be accurately obtained, + // so we postpone it a bit + m_dataTimer = new QTimer(); + m_dataTimer->setSingleShot(true); + QObject::connect(m_dataTimer, &QTimer::timeout, this, &GraphDataGenerator::fixTableSize); + m_dataTimer->start(0); +#endif +} + +void GraphDataGenerator::setupModel() +{ + // Set up row and column names + QStringList days; + days << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday" << "Sunday"; + QStringList weeks; + weeks << "week 1" << "week 2" << "week 3" << "week 4" << "week 5"; + + // Set up data Mon Tue Wed Thu Fri Sat Sun + float hours[5][7] = {{2.0f, 1.0f, 3.0f, 0.2f, 1.0f, 5.0f, 10.0f}, // week 1 + {0.5f, 1.0f, 3.0f, 1.0f, 2.0f, 2.0f, 3.0f}, // week 2 + {1.0f, 1.0f, 2.0f, 1.0f, 4.0f, 4.0f, 4.0f}, // week 3 + {0.0f, 1.0f, 0.0f, 0.0f, 2.0f, 2.0f, 0.3f}, // week 4 + {3.0f, 3.0f, 6.0f, 2.0f, 2.0f, 1.0f, 1.0f}}; // week 5 + + // Add labels + m_graph->rowAxis()->setTitle("Week of year"); + m_graph->columnAxis()->setTitle("Day of week"); + m_graph->valueAxis()->setTitle("Hours playing banjo"); + m_graph->valueAxis()->setSegmentCount(5); + m_graph->valueAxis()->setLabelFormat("%.1f h"); + + m_tableWidget->setRowCount(5); + m_tableWidget->setColumnCount(7); + m_tableWidget->setHorizontalHeaderLabels(days); + m_tableWidget->setVerticalHeaderLabels(weeks); + m_tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_tableWidget->setCurrentCell(-1, -1); + + for (int week = 0; week < weeks.size(); week++) { + for (int day = 0; day < days.size(); day++) { + QModelIndex index = m_tableWidget->model()->index(week, day); + m_tableWidget->model()->setData(index, hours[week][day]); + } + } +} + +void GraphDataGenerator::addRow() +{ + m_tableWidget->model()->insertRow(0); + if (m_tableWidget->model()->rowCount() > m_rowCount) + m_tableWidget->model()->removeRow(m_rowCount); + for (int i = 0; i < m_columnCount; i++) { + QModelIndex index = m_tableWidget->model()->index(0, i); + m_tableWidget->model()->setData(index, + ((qreal)i / (qreal)m_columnCount) / 2.0 + (qreal)(rand() % 30) / 100.0); + } + m_tableWidget->resizeColumnsToContents(); +} + +void GraphDataGenerator::selectFromTable(const QPoint &selection) +{ + m_tableWidget->setFocus(); + m_tableWidget->setCurrentCell(selection.x(), selection.y()); +} + +void GraphDataGenerator::selectedFromTable(int currentRow, int currentColumn, + int previousRow, int previousColumn) +{ + Q_UNUSED(previousRow) + Q_UNUSED(previousColumn) + m_graph->setSelectedBarPos(QPoint(currentRow, currentColumn)); +} + +void GraphDataGenerator::fixTableSize() +{ + int width = m_tableWidget->horizontalHeader()->length(); + width += m_tableWidget->verticalHeader()->width(); + m_tableWidget->setFixedWidth(width + 2); + int height = m_tableWidget->verticalHeader()->length(); + height += m_tableWidget->horizontalHeader()->height(); + m_tableWidget->setFixedHeight(height + 2); +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QWidget widget; + QVBoxLayout *layout = new QVBoxLayout(&widget); + + Q3DBars *graph = new Q3DBars(); + QSize screenSize = graph->screen()->size(); + + QWidget *container = QWidget::createWindowContainer(graph); + container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 2)); + container->setMaximumSize(screenSize); + container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + container->setFocusPolicy(Qt::StrongFocus); + + widget.setWindowTitle(QStringLiteral("Hours playing banjo")); + + QTableWidget *tableWidget = new QTableWidget(&widget); + tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + tableWidget->setAlternatingRowColors(true); + + layout->addWidget(container, 1); + layout->addWidget(tableWidget, 1, Qt::AlignHCenter); + + // Since we are dealing with QTableWidget, the model will already have data sorted properly + // in rows and columns, so create a custom mapping to utilize this. + QItemModelBarDataMapping *mapping = new QItemModelBarDataMapping; + mapping->setUseModelCategories(true); + QItemModelBarDataProxy *proxy = new QItemModelBarDataProxy(tableWidget->model(), mapping); + graph->setActiveDataProxy(proxy); + + GraphDataGenerator generator(graph, tableWidget); + + QObject::connect(graph, &Q3DBars::selectedBarPosChanged, &generator, + &GraphDataGenerator::selectFromTable); + QObject::connect(tableWidget, &QTableWidget::currentCellChanged, &generator, + &GraphDataGenerator::selectedFromTable); + + widget.show(); + generator.start(); + + return app.exec(); +} diff --git a/examples/examples.pro b/examples/examples.pro index aa2512c2..a76b95a7 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,13 +1,12 @@ TEMPLATE = subdirs -SUBDIRS += qmlbarchart \ +SUBDIRS += qmlbars \ qmlscatter \ qmlsurface !android: { - SUBDIRS += barchart \ + SUBDIRS += bars \ rainfall \ widget \ - surfacechart \ - scatterchart + scatter } qtHaveModule(multimedia):!android: SUBDIRS += audiolevels diff --git a/examples/qmlbarchart/doc/src/qmlbarchart.qdoc b/examples/qmlbarchart/doc/src/qmlbarchart.qdoc deleted file mode 100644 index b7b84c0e..00000000 --- a/examples/qmlbarchart/doc/src/qmlbarchart.qdoc +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -/*! - \example qmlbarchart - \title Qt Quick 2 Barchart Example - - The Qt Quick 2 barchart example shows how to make a simple 3D bar chart using Q3DBars and Qt - Quick 2. - - \image qmlbarchart-example.png - - TODO -*/ diff --git a/examples/qmlbarchart/main.cpp b/examples/qmlbarchart/main.cpp deleted file mode 100644 index 1a3fcddc..00000000 --- a/examples/qmlbarchart/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -#include "qtquick2applicationviewer.h" -#ifdef Q_OS_ANDROID -#include -#include -#endif -#include - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - - QtQuick2ApplicationViewer viewer; -#ifdef Q_OS_ANDROID - viewer.addImportPath(QString::fromLatin1("assets:/qml")); - viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), - QString::fromLatin1("lib"))); -#else - viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), - QString::fromLatin1("qml"))); -#endif - viewer.setSource(QUrl("qrc:/qml/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/qmlbarchart/qml/qmlbarchart/axes.qml b/examples/qmlbarchart/qml/qmlbarchart/axes.qml deleted file mode 100644 index b0ba3eb2..00000000 --- a/examples/qmlbarchart/qml/qmlbarchart/axes.qml +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -import QtQuick 2.1 -import com.digia.QtDataVisualization 1.0 - -Item { - property alias column: columnAxis - property alias expenses: expensesAxis - property alias income: incomeAxis - - // For row labels we can use row labels from data proxy, so default axis - // suffices for rows. - - // Custom labels for columns, since the data contains abbreviated month names. - CategoryAxis3D { - id: columnAxis - categoryLabels: ["January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December"] - } - ValueAxis3D { - id: incomeAxis - min: 0 - max: 35 - labelFormat: "%.2f M\u20AC" - title: "Monthly income" - } - ValueAxis3D { - id: expensesAxis - min: 0 - max: 35 - labelFormat: "-%.2f M\u20AC" - title: "Monthly expenses" - } -} diff --git a/examples/qmlbarchart/qml/qmlbarchart/data.qml b/examples/qmlbarchart/qml/qmlbarchart/data.qml deleted file mode 100644 index fff568cc..00000000 --- a/examples/qmlbarchart/qml/qmlbarchart/data.qml +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -import QtQuick 2.1 -import com.digia.QtDataVisualization 1.0 - -Item { - property alias mapping: valueMapping - property alias model: dataModel - property alias proxy: modelProxy - - BarDataMapping { - id: valueMapping - rowRole: "year" - columnRole: "month" - valueRole: "expenses" - } - - ItemModelBarDataProxy { - id: modelProxy - activeMapping: valueMapping - itemModel: dataModel - } - - ListModel { - id: dataModel - ListElement{ year: "2006"; month: "Jan"; expenses: "4"; income: "5" } - ListElement{ year: "2006"; month: "Feb"; expenses: "5"; income: "6" } - ListElement{ year: "2006"; month: "Mar"; expenses: "7"; income: "4" } - ListElement{ year: "2006"; month: "Apr"; expenses: "3"; income: "2" } - ListElement{ year: "2006"; month: "May"; expenses: "4"; income: "1" } - ListElement{ year: "2006"; month: "Jun"; expenses: "2"; income: "2" } - ListElement{ year: "2006"; month: "Jul"; expenses: "1"; income: "3" } - ListElement{ year: "2006"; month: "Aug"; expenses: "5"; income: "1" } - ListElement{ year: "2006"; month: "Sep"; expenses: "2"; income: "3" } - ListElement{ year: "2006"; month: "Oct"; expenses: "5"; income: "2" } - ListElement{ year: "2006"; month: "Nov"; expenses: "8"; income: "5" } - ListElement{ year: "2006"; month: "Dec"; expenses: "3"; income: "3" } - - ListElement{ year: "2007"; month: "Jan"; expenses: "3"; income: "1" } - ListElement{ year: "2007"; month: "Feb"; expenses: "4"; income: "2" } - ListElement{ year: "2007"; month: "Mar"; expenses: "12"; income: "4" } - ListElement{ year: "2007"; month: "Apr"; expenses: "13"; income: "6" } - ListElement{ year: "2007"; month: "May"; expenses: "14"; income: "11" } - ListElement{ year: "2007"; month: "Jun"; expenses: "7"; income: "7" } - ListElement{ year: "2007"; month: "Jul"; expenses: "6"; income: "4" } - ListElement{ year: "2007"; month: "Aug"; expenses: "4"; income: "15" } - ListElement{ year: "2007"; month: "Sep"; expenses: "2"; income: "18" } - ListElement{ year: "2007"; month: "Oct"; expenses: "29"; income: "25" } - ListElement{ year: "2007"; month: "Nov"; expenses: "23"; income: "29" } - ListElement{ year: "2007"; month: "Dec"; expenses: "5"; income: "9" } - - ListElement{ year: "2008"; month: "Jan"; expenses: "3"; income: "8" } - ListElement{ year: "2008"; month: "Feb"; expenses: "8"; income: "14" } - ListElement{ year: "2008"; month: "Mar"; expenses: "10"; income: "20" } - ListElement{ year: "2008"; month: "Apr"; expenses: "12"; income: "24" } - ListElement{ year: "2008"; month: "May"; expenses: "10"; income: "19" } - ListElement{ year: "2008"; month: "Jun"; expenses: "5"; income: "8" } - ListElement{ year: "2008"; month: "Jul"; expenses: "1"; income: "4" } - ListElement{ year: "2008"; month: "Aug"; expenses: "7"; income: "12" } - ListElement{ year: "2008"; month: "Sep"; expenses: "4"; income: "16" } - ListElement{ year: "2008"; month: "Oct"; expenses: "22"; income: "33" } - ListElement{ year: "2008"; month: "Nov"; expenses: "16"; income: "25" } - ListElement{ year: "2008"; month: "Dec"; expenses: "2"; income: "7" } - - ListElement{ year: "2009"; month: "Jan"; expenses: "4"; income: "5" } - ListElement{ year: "2009"; month: "Feb"; expenses: "4"; income: "7" } - ListElement{ year: "2009"; month: "Mar"; expenses: "11"; income: "14" } - ListElement{ year: "2009"; month: "Apr"; expenses: "16"; income: "22" } - ListElement{ year: "2009"; month: "May"; expenses: "3"; income: "5" } - ListElement{ year: "2009"; month: "Jun"; expenses: "4"; income: "8" } - ListElement{ year: "2009"; month: "Jul"; expenses: "7"; income: "9" } - ListElement{ year: "2009"; month: "Aug"; expenses: "9"; income: "13" } - ListElement{ year: "2009"; month: "Sep"; expenses: "1"; income: "6" } - ListElement{ year: "2009"; month: "Oct"; expenses: "14"; income: "25" } - ListElement{ year: "2009"; month: "Nov"; expenses: "19"; income: "29" } - ListElement{ year: "2009"; month: "Dec"; expenses: "5"; income: "7" } - - ListElement{ year: "2010"; month: "Jan"; expenses: "14"; income: "22" } - ListElement{ year: "2010"; month: "Feb"; expenses: "5"; income: "7" } - ListElement{ year: "2010"; month: "Mar"; expenses: "1"; income: "9" } - ListElement{ year: "2010"; month: "Apr"; expenses: "1"; income: "12" } - ListElement{ year: "2010"; month: "May"; expenses: "5"; income: "9" } - ListElement{ year: "2010"; month: "Jun"; expenses: "5"; income: "8" } - ListElement{ year: "2010"; month: "Jul"; expenses: "3"; income: "7" } - ListElement{ year: "2010"; month: "Aug"; expenses: "1"; income: "5" } - ListElement{ year: "2010"; month: "Sep"; expenses: "2"; income: "4" } - ListElement{ year: "2010"; month: "Oct"; expenses: "10"; income: "13" } - ListElement{ year: "2010"; month: "Nov"; expenses: "12"; income: "17" } - ListElement{ year: "2010"; month: "Dec"; expenses: "6"; income: "9" } - - ListElement{ year: "2011"; month: "Jan"; expenses: "2"; income: "6" } - ListElement{ year: "2011"; month: "Feb"; expenses: "4"; income: "8" } - ListElement{ year: "2011"; month: "Mar"; expenses: "7"; income: "12" } - ListElement{ year: "2011"; month: "Apr"; expenses: "9"; income: "15" } - ListElement{ year: "2011"; month: "May"; expenses: "7"; income: "19" } - ListElement{ year: "2011"; month: "Jun"; expenses: "9"; income: "18" } - ListElement{ year: "2011"; month: "Jul"; expenses: "13"; income: "17" } - ListElement{ year: "2011"; month: "Aug"; expenses: "5"; income: "9" } - ListElement{ year: "2011"; month: "Sep"; expenses: "3"; income: "8" } - ListElement{ year: "2011"; month: "Oct"; expenses: "13"; income: "15" } - ListElement{ year: "2011"; month: "Nov"; expenses: "8"; income: "17" } - ListElement{ year: "2011"; month: "Dec"; expenses: "7"; income: "10" } - - ListElement{ year: "2012"; month: "Jan"; expenses: "12"; income: "16" } - ListElement{ year: "2012"; month: "Feb"; expenses: "24"; income: "28" } - ListElement{ year: "2012"; month: "Mar"; expenses: "27"; income: "22" } - ListElement{ year: "2012"; month: "Apr"; expenses: "29"; income: "25" } - ListElement{ year: "2012"; month: "May"; expenses: "27"; income: "29" } - ListElement{ year: "2012"; month: "Jun"; expenses: "19"; income: "18" } - ListElement{ year: "2012"; month: "Jul"; expenses: "13"; income: "17" } - ListElement{ year: "2012"; month: "Aug"; expenses: "15"; income: "19" } - ListElement{ year: "2012"; month: "Sep"; expenses: "3"; income: "8" } - ListElement{ year: "2012"; month: "Oct"; expenses: "3"; income: "6" } - ListElement{ year: "2012"; month: "Nov"; expenses: "4"; income: "8" } - ListElement{ year: "2012"; month: "Dec"; expenses: "5"; income: "9" } - } -} diff --git a/examples/qmlbarchart/qml/qmlbarchart/main.qml b/examples/qmlbarchart/qml/qmlbarchart/main.qml deleted file mode 100644 index a8bca564..00000000 --- a/examples/qmlbarchart/qml/qmlbarchart/main.qml +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -import QtQuick 2.1 -import QtQuick.Controls 1.0 -import com.digia.QtDataVisualization 1.0 -import "." - -Item { - id: mainview - width: 1280 - height: 1024 - visible: true - - Data { - id: chartData - } - - Axes { - id: chartAxes - } - - Item { - id: dataView - width: parent.width - tableView.width - height: parent.height - anchors.right: parent.right; - - Bars3D { - id: testChart - width: dataView.width - height: dataView.height - shadowQuality: Bars3D.ShadowQualityMedium - selectionMode: Bars3D.SelectionModeItem - font.pointSize: 35 - theme: Bars3D.ThemeRetro - labelStyle: Bars3D.LabelStyleFromTheme - dataProxy: chartData.proxy - barThickness: 0.5 - barSpacing: Qt.size(0.5, 0.5) - barSpacingRelative: false - cameraPreset: Bars3D.CameraPresetRight - columnAxis: chartAxes.column - valueAxis: chartAxes.expenses - itemLabelFormat: "@valueTitle for @colLabel, @rowLabel: @valueLabel" - - onSelectedBarPosChanged: { - // Set tableView current row to selected bar - var rowRole = chartData.proxy.rowLabels[position.x]; - var colRole = chartData.proxy.columnLabels[position.y]; - var currentRow = tableView.currentRow - if (currentRow === -1 || rowRole !== chartData.model.get(currentRow).year - || colRole !== chartData.model.get(currentRow).month) { - var totalRows = tableView.rowCount; - for (var i = 0; i < totalRows; i++) { - var currentRowRole = chartData.model.get(i).year - var currentColRole = chartData.model.get(i).month - if (currentRowRole === rowRole && currentColRole === colRole) { - tableView.currentRow = i - break - } - } - } - } - } - } - - Button { - id: mappingToggle - anchors.bottom: parent.bottom - width: tableView.width - height: 60 - text: "Show Income" - onClicked: { - if (chartData.mapping.valueRole === "expenses") { - chartData.mapping.valueRole = "income" - text = "Show Expenses" - testChart.valueAxis = chartAxes.income - } else { - chartData.mapping.valueRole = "expenses" - text = "Show Income" - testChart.valueAxis = chartAxes.expenses - } - } - } - - Button { - id: shadowToggle - anchors.bottom: mappingToggle.top - width: tableView.width - height: 60 - text: "Hide Shadows" - onClicked: { - if (testChart.shadowQuality == Bars3D.ShadowQualityNone) { - testChart.shadowQuality = Bars3D.ShadowQualityMedium; - text = "Hide Shadows" - } else { - testChart.shadowQuality = Bars3D.ShadowQualityNone; - text = "Show Shadows" - } - } - } - - Button { - id: dataToggle - anchors.bottom: shadowToggle.top - width: tableView.width - height: 60 - text: "Show 2010 - 2012" - onClicked: { - if (testChart.rowAxis.max !== 6) { - text = "Show 2010 - 2012" - chartData.mapping.autoRowCategories = true - } else { - text = "Show all years" - // Explicitly defining row categories, since we do not want to show data for - // all years in the model, just for the selected ones. - chartData.mapping.autoRowCategories = false - chartData.mapping.rowCategories = ["2010", "2011", "2012"] - } - } - } - - TableView { - id: tableView - x: 0 - y: 0 - width: 298 - height: parent.height - mappingToggle.height - shadowToggle.height - dataToggle.height - TableViewColumn{ role: "year" ; title: "Year" ; width: 80 } - TableViewColumn{ role: "month" ; title: "Month" ; width: 80 } - TableViewColumn{ role: "expenses" ; title: "Expenses" ; width: 60 } - TableViewColumn{ role: "income" ; title: "Income" ; width: 60 } - model: chartData.model - - onCurrentRowChanged: { - var rowIndex = chartData.proxy.activeMapping.rowCategoryIndex(chartData.model.get(currentRow).year) - var colIndex = chartData.proxy.activeMapping.columnCategoryIndex(chartData.model.get(currentRow).month) - testChart.selectedBarPos = Qt.point(rowIndex, colIndex) - } - } -} diff --git a/examples/qmlbarchart/qmlbarchart.desktop b/examples/qmlbarchart/qmlbarchart.desktop deleted file mode 100644 index c01705df..00000000 --- a/examples/qmlbarchart/qmlbarchart.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Version=1.0 -Type=Application -Terminal=false -Name=qmlbarchart -Exec=/opt/qmlbarchart/bin/qmlbarchart -Icon=qmlbarchart64 -X-Window-Icon= -X-HildonDesk-ShowInToolbar=true -X-Osso-Type=application/x-executable diff --git a/examples/qmlbarchart/qmlbarchart.pro b/examples/qmlbarchart/qmlbarchart.pro deleted file mode 100644 index b74b8558..00000000 --- a/examples/qmlbarchart/qmlbarchart.pro +++ /dev/null @@ -1,22 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -QT += widgets - -# Add more folders to ship with the application, here -folder_01.source = qml/qmlbarchart -folder_01.target = qml -DEPLOYMENTFOLDERS = folder_01 - -# Additional import path used to resolve QML modules in Creator's code model -QML_IMPORT_PATH = - -# The .cpp file which was generated for your project. Feel free to hack it. -SOURCES += main.cpp - -# Please do not modify the following two lines. Required for deployment. -include(qtquick2applicationviewer/qtquick2applicationviewer.pri) -qtcAddDeployment() - -RESOURCES += qmlbarchart.qrc diff --git a/examples/qmlbarchart/qmlbarchart.qrc b/examples/qmlbarchart/qmlbarchart.qrc deleted file mode 100644 index a2c7d75b..00000000 --- a/examples/qmlbarchart/qmlbarchart.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - qml/qmlbarchart/main.qml - qml/qmlbarchart/data.qml - qml/qmlbarchart/axes.qml - - diff --git a/examples/qmlbarchart/qmlbarchart64.png b/examples/qmlbarchart/qmlbarchart64.png deleted file mode 100644 index 707d5c4e..00000000 Binary files a/examples/qmlbarchart/qmlbarchart64.png and /dev/null differ diff --git a/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.cpp b/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.cpp deleted file mode 100644 index 10709d7a..00000000 --- a/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// checksum 0x4f6f version 0x90005 -/* - This file was generated by the Qt Quick 2 Application wizard of Qt Creator. - QtQuick2ApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#include "qtquick2applicationviewer.h" - -#include -#include -#include - -class QtQuick2ApplicationViewerPrivate -{ - QString mainQmlFile; - friend class QtQuick2ApplicationViewer; - static QString adjustPath(const QString &path); -}; - -QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path) -{ -#if defined(Q_OS_MAC) - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("%1/../Resources/%2") - .arg(QCoreApplication::applicationDirPath(), path); -#elif defined(Q_OS_BLACKBERRY) - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("app/native/%1").arg(path); -#elif !defined(Q_OS_ANDROID) - QString pathInInstallDir = - QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; - pathInInstallDir = - QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; -#endif - return path; -} - -QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent) - : QQuickView(parent) - , d(new QtQuick2ApplicationViewerPrivate()) -{ - connect(engine(), SIGNAL(quit()), SLOT(close())); - setResizeMode(QQuickView::SizeRootObjectToView); -} - -QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer() -{ - delete d; -} - -void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file) -{ - d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file); -#ifdef Q_OS_ANDROID - setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); -#else - setSource(QUrl::fromLocalFile(d->mainQmlFile)); -#endif -} - -void QtQuick2ApplicationViewer::addImportPath(const QString &path) -{ - engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path)); -} - -void QtQuick2ApplicationViewer::showExpanded() -{ -#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX) - showFullScreen(); -#else - show(); -#endif -} diff --git a/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.h b/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.h deleted file mode 100644 index cf66f140..00000000 --- a/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.h +++ /dev/null @@ -1,33 +0,0 @@ -// checksum 0xfde6 version 0x90005 -/* - This file was generated by the Qt Quick 2 Application wizard of Qt Creator. - QtQuick2ApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#ifndef QTQUICK2APPLICATIONVIEWER_H -#define QTQUICK2APPLICATIONVIEWER_H - -#include - -class QtQuick2ApplicationViewer : public QQuickView -{ - Q_OBJECT - -public: - explicit QtQuick2ApplicationViewer(QWindow *parent = 0); - virtual ~QtQuick2ApplicationViewer(); - - void setMainQmlFile(const QString &file); - void addImportPath(const QString &path); - - void showExpanded(); - -private: - class QtQuick2ApplicationViewerPrivate *d; -}; - -#endif // QTQUICK2APPLICATIONVIEWER_H diff --git a/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.pri b/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.pri deleted file mode 100644 index a071e63d..00000000 --- a/examples/qmlbarchart/qtquick2applicationviewer/qtquick2applicationviewer.pri +++ /dev/null @@ -1,170 +0,0 @@ -# checksum 0x7b0d version 0x90005 -# This file was generated by the Qt Quick 2 Application wizard of Qt Creator. -# The code below adds the QtQuick2ApplicationViewer to the project and handles -# the activation of QML debugging. -# It is recommended not to modify this file, since newer versions of Qt Creator -# may offer an updated version of it. - -QT += qml quick - -SOURCES += $$PWD/qtquick2applicationviewer.cpp -HEADERS += $$PWD/qtquick2applicationviewer.h -INCLUDEPATH += $$PWD -# This file was generated by an application wizard of Qt Creator. -# The code below handles deployment to Android and Maemo, aswell as copying -# of the application data to shadow build directories on desktop. -# It is recommended not to modify this file, since newer versions of Qt Creator -# may offer an updated version of it. - -defineTest(qtcAddDeployment) { -for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - greaterThan(QT_MAJOR_VERSION, 4) { - itemsources = $${item}.files - } else { - itemsources = $${item}.sources - } - $$itemsources = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath= $$eval($${deploymentfolder}.target) - export($$itemsources) - export($$itempath) - DEPLOYMENT += $$item -} - -MAINPROFILEPWD = $$PWD - -android-no-sdk { - for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - itemfiles = $${item}.files - $$itemfiles = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) - export($$itemfiles) - export($$itempath) - INSTALLS += $$item - } - - target.path = /data/user/qt - - export(target.path) - INSTALLS += target -} else:android { - for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - itemfiles = $${item}.files - $$itemfiles = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath = /assets/$$eval($${deploymentfolder}.target) - export($$itemfiles) - export($$itempath) - INSTALLS += $$item - } - INSTALLS += target -} else:win32 { - copyCommand = - for(deploymentfolder, DEPLOYMENTFOLDERS) { - source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) - source = $$replace(source, /, \\) - sourcePathSegments = $$split(source, \\) - target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) - target = $$replace(target, /, \\) - target ~= s,\\\\\\.?\\\\,\\, - !isEqual(source,$$target) { - !isEmpty(copyCommand):copyCommand += && - isEqual(QMAKE_DIR_SEP, \\) { - copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" - } else { - source = $$replace(source, \\\\, /) - target = $$OUT_PWD/$$eval($${deploymentfolder}.target) - target = $$replace(target, \\\\, /) - copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" - } - } - } - !isEmpty(copyCommand) { - copyCommand = @echo Copying application data... && $$copyCommand - copydeploymentfolders.commands = $$copyCommand - first.depends = $(first) copydeploymentfolders - export(first.depends) - export(copydeploymentfolders.commands) - QMAKE_EXTRA_TARGETS += first copydeploymentfolders - } -} else:unix { - maemo5 { - desktopfile.files = $${TARGET}.desktop - desktopfile.path = /usr/share/applications/hildon - icon.files = $${TARGET}64.png - icon.path = /usr/share/icons/hicolor/64x64/apps - } else:!isEmpty(MEEGO_VERSION_MAJOR) { - desktopfile.files = $${TARGET}_harmattan.desktop - desktopfile.path = /usr/share/applications - icon.files = $${TARGET}80.png - icon.path = /usr/share/icons/hicolor/80x80/apps - } else { # Assumed to be a Desktop Unix - copyCommand = - for(deploymentfolder, DEPLOYMENTFOLDERS) { - source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) - source = $$replace(source, \\\\, /) - macx { - target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) - } else { - target = $$OUT_PWD/$$eval($${deploymentfolder}.target) - } - target = $$replace(target, \\\\, /) - sourcePathSegments = $$split(source, /) - targetFullPath = $$target/$$last(sourcePathSegments) - targetFullPath ~= s,/\\.?/,/, - !isEqual(source,$$targetFullPath) { - !isEmpty(copyCommand):copyCommand += && - copyCommand += $(MKDIR) \"$$target\" - copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" - } - } - !isEmpty(copyCommand) { - copyCommand = @echo Copying application data... && $$copyCommand - copydeploymentfolders.commands = $$copyCommand - first.depends = $(first) copydeploymentfolders - export(first.depends) - export(copydeploymentfolders.commands) - QMAKE_EXTRA_TARGETS += first copydeploymentfolders - } - } - !isEmpty(target.path) { - installPrefix = $${target.path} - } else { - installPrefix = /opt/$${TARGET} - } - for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - itemfiles = $${item}.files - $$itemfiles = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) - export($$itemfiles) - export($$itempath) - INSTALLS += $$item - } - - !isEmpty(desktopfile.path) { - export(icon.files) - export(icon.path) - export(desktopfile.files) - export(desktopfile.path) - INSTALLS += icon desktopfile - } - - isEmpty(target.path) { - target.path = $${installPrefix}/bin - export(target.path) - } - INSTALLS += target -} - -export (ICON) -export (INSTALLS) -export (DEPLOYMENT) -export (LIBS) -export (QMAKE_EXTRA_TARGETS) -} diff --git a/examples/qmlbars/doc/src/qmlbars.qdoc b/examples/qmlbars/doc/src/qmlbars.qdoc new file mode 100644 index 00000000..e382bb6b --- /dev/null +++ b/examples/qmlbars/doc/src/qmlbars.qdoc @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +/*! + \example qmlbars + \title Qt Quick 2 Bars Example + + The Qt Quick 2 bars example shows how to make a simple 3D bar graph using Q3DBars and Qt + Quick 2. + + \image qmlbars-example.png + + TODO +*/ diff --git a/examples/qmlbars/main.cpp b/examples/qmlbars/main.cpp new file mode 100644 index 00000000..1a3fcddc --- /dev/null +++ b/examples/qmlbars/main.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +#include "qtquick2applicationviewer.h" +#ifdef Q_OS_ANDROID +#include +#include +#endif +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QtQuick2ApplicationViewer viewer; +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/qml")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), + QString::fromLatin1("lib"))); +#else + viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), + QString::fromLatin1("qml"))); +#endif + viewer.setSource(QUrl("qrc:/qml/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/qmlbars/qml/qmlbars/axes.qml b/examples/qmlbars/qml/qmlbars/axes.qml new file mode 100644 index 00000000..b0ba3eb2 --- /dev/null +++ b/examples/qmlbars/qml/qmlbars/axes.qml @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +import QtQuick 2.1 +import com.digia.QtDataVisualization 1.0 + +Item { + property alias column: columnAxis + property alias expenses: expensesAxis + property alias income: incomeAxis + + // For row labels we can use row labels from data proxy, so default axis + // suffices for rows. + + // Custom labels for columns, since the data contains abbreviated month names. + CategoryAxis3D { + id: columnAxis + categoryLabels: ["January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December"] + } + ValueAxis3D { + id: incomeAxis + min: 0 + max: 35 + labelFormat: "%.2f M\u20AC" + title: "Monthly income" + } + ValueAxis3D { + id: expensesAxis + min: 0 + max: 35 + labelFormat: "-%.2f M\u20AC" + title: "Monthly expenses" + } +} diff --git a/examples/qmlbars/qml/qmlbars/data.qml b/examples/qmlbars/qml/qmlbars/data.qml new file mode 100644 index 00000000..fff568cc --- /dev/null +++ b/examples/qmlbars/qml/qmlbars/data.qml @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +import QtQuick 2.1 +import com.digia.QtDataVisualization 1.0 + +Item { + property alias mapping: valueMapping + property alias model: dataModel + property alias proxy: modelProxy + + BarDataMapping { + id: valueMapping + rowRole: "year" + columnRole: "month" + valueRole: "expenses" + } + + ItemModelBarDataProxy { + id: modelProxy + activeMapping: valueMapping + itemModel: dataModel + } + + ListModel { + id: dataModel + ListElement{ year: "2006"; month: "Jan"; expenses: "4"; income: "5" } + ListElement{ year: "2006"; month: "Feb"; expenses: "5"; income: "6" } + ListElement{ year: "2006"; month: "Mar"; expenses: "7"; income: "4" } + ListElement{ year: "2006"; month: "Apr"; expenses: "3"; income: "2" } + ListElement{ year: "2006"; month: "May"; expenses: "4"; income: "1" } + ListElement{ year: "2006"; month: "Jun"; expenses: "2"; income: "2" } + ListElement{ year: "2006"; month: "Jul"; expenses: "1"; income: "3" } + ListElement{ year: "2006"; month: "Aug"; expenses: "5"; income: "1" } + ListElement{ year: "2006"; month: "Sep"; expenses: "2"; income: "3" } + ListElement{ year: "2006"; month: "Oct"; expenses: "5"; income: "2" } + ListElement{ year: "2006"; month: "Nov"; expenses: "8"; income: "5" } + ListElement{ year: "2006"; month: "Dec"; expenses: "3"; income: "3" } + + ListElement{ year: "2007"; month: "Jan"; expenses: "3"; income: "1" } + ListElement{ year: "2007"; month: "Feb"; expenses: "4"; income: "2" } + ListElement{ year: "2007"; month: "Mar"; expenses: "12"; income: "4" } + ListElement{ year: "2007"; month: "Apr"; expenses: "13"; income: "6" } + ListElement{ year: "2007"; month: "May"; expenses: "14"; income: "11" } + ListElement{ year: "2007"; month: "Jun"; expenses: "7"; income: "7" } + ListElement{ year: "2007"; month: "Jul"; expenses: "6"; income: "4" } + ListElement{ year: "2007"; month: "Aug"; expenses: "4"; income: "15" } + ListElement{ year: "2007"; month: "Sep"; expenses: "2"; income: "18" } + ListElement{ year: "2007"; month: "Oct"; expenses: "29"; income: "25" } + ListElement{ year: "2007"; month: "Nov"; expenses: "23"; income: "29" } + ListElement{ year: "2007"; month: "Dec"; expenses: "5"; income: "9" } + + ListElement{ year: "2008"; month: "Jan"; expenses: "3"; income: "8" } + ListElement{ year: "2008"; month: "Feb"; expenses: "8"; income: "14" } + ListElement{ year: "2008"; month: "Mar"; expenses: "10"; income: "20" } + ListElement{ year: "2008"; month: "Apr"; expenses: "12"; income: "24" } + ListElement{ year: "2008"; month: "May"; expenses: "10"; income: "19" } + ListElement{ year: "2008"; month: "Jun"; expenses: "5"; income: "8" } + ListElement{ year: "2008"; month: "Jul"; expenses: "1"; income: "4" } + ListElement{ year: "2008"; month: "Aug"; expenses: "7"; income: "12" } + ListElement{ year: "2008"; month: "Sep"; expenses: "4"; income: "16" } + ListElement{ year: "2008"; month: "Oct"; expenses: "22"; income: "33" } + ListElement{ year: "2008"; month: "Nov"; expenses: "16"; income: "25" } + ListElement{ year: "2008"; month: "Dec"; expenses: "2"; income: "7" } + + ListElement{ year: "2009"; month: "Jan"; expenses: "4"; income: "5" } + ListElement{ year: "2009"; month: "Feb"; expenses: "4"; income: "7" } + ListElement{ year: "2009"; month: "Mar"; expenses: "11"; income: "14" } + ListElement{ year: "2009"; month: "Apr"; expenses: "16"; income: "22" } + ListElement{ year: "2009"; month: "May"; expenses: "3"; income: "5" } + ListElement{ year: "2009"; month: "Jun"; expenses: "4"; income: "8" } + ListElement{ year: "2009"; month: "Jul"; expenses: "7"; income: "9" } + ListElement{ year: "2009"; month: "Aug"; expenses: "9"; income: "13" } + ListElement{ year: "2009"; month: "Sep"; expenses: "1"; income: "6" } + ListElement{ year: "2009"; month: "Oct"; expenses: "14"; income: "25" } + ListElement{ year: "2009"; month: "Nov"; expenses: "19"; income: "29" } + ListElement{ year: "2009"; month: "Dec"; expenses: "5"; income: "7" } + + ListElement{ year: "2010"; month: "Jan"; expenses: "14"; income: "22" } + ListElement{ year: "2010"; month: "Feb"; expenses: "5"; income: "7" } + ListElement{ year: "2010"; month: "Mar"; expenses: "1"; income: "9" } + ListElement{ year: "2010"; month: "Apr"; expenses: "1"; income: "12" } + ListElement{ year: "2010"; month: "May"; expenses: "5"; income: "9" } + ListElement{ year: "2010"; month: "Jun"; expenses: "5"; income: "8" } + ListElement{ year: "2010"; month: "Jul"; expenses: "3"; income: "7" } + ListElement{ year: "2010"; month: "Aug"; expenses: "1"; income: "5" } + ListElement{ year: "2010"; month: "Sep"; expenses: "2"; income: "4" } + ListElement{ year: "2010"; month: "Oct"; expenses: "10"; income: "13" } + ListElement{ year: "2010"; month: "Nov"; expenses: "12"; income: "17" } + ListElement{ year: "2010"; month: "Dec"; expenses: "6"; income: "9" } + + ListElement{ year: "2011"; month: "Jan"; expenses: "2"; income: "6" } + ListElement{ year: "2011"; month: "Feb"; expenses: "4"; income: "8" } + ListElement{ year: "2011"; month: "Mar"; expenses: "7"; income: "12" } + ListElement{ year: "2011"; month: "Apr"; expenses: "9"; income: "15" } + ListElement{ year: "2011"; month: "May"; expenses: "7"; income: "19" } + ListElement{ year: "2011"; month: "Jun"; expenses: "9"; income: "18" } + ListElement{ year: "2011"; month: "Jul"; expenses: "13"; income: "17" } + ListElement{ year: "2011"; month: "Aug"; expenses: "5"; income: "9" } + ListElement{ year: "2011"; month: "Sep"; expenses: "3"; income: "8" } + ListElement{ year: "2011"; month: "Oct"; expenses: "13"; income: "15" } + ListElement{ year: "2011"; month: "Nov"; expenses: "8"; income: "17" } + ListElement{ year: "2011"; month: "Dec"; expenses: "7"; income: "10" } + + ListElement{ year: "2012"; month: "Jan"; expenses: "12"; income: "16" } + ListElement{ year: "2012"; month: "Feb"; expenses: "24"; income: "28" } + ListElement{ year: "2012"; month: "Mar"; expenses: "27"; income: "22" } + ListElement{ year: "2012"; month: "Apr"; expenses: "29"; income: "25" } + ListElement{ year: "2012"; month: "May"; expenses: "27"; income: "29" } + ListElement{ year: "2012"; month: "Jun"; expenses: "19"; income: "18" } + ListElement{ year: "2012"; month: "Jul"; expenses: "13"; income: "17" } + ListElement{ year: "2012"; month: "Aug"; expenses: "15"; income: "19" } + ListElement{ year: "2012"; month: "Sep"; expenses: "3"; income: "8" } + ListElement{ year: "2012"; month: "Oct"; expenses: "3"; income: "6" } + ListElement{ year: "2012"; month: "Nov"; expenses: "4"; income: "8" } + ListElement{ year: "2012"; month: "Dec"; expenses: "5"; income: "9" } + } +} diff --git a/examples/qmlbars/qml/qmlbars/main.qml b/examples/qmlbars/qml/qmlbars/main.qml new file mode 100644 index 00000000..aec3188c --- /dev/null +++ b/examples/qmlbars/qml/qmlbars/main.qml @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import com.digia.QtDataVisualization 1.0 +import "." + +Item { + id: mainview + width: 1280 + height: 1024 + visible: true + + Data { + id: graphData + } + + Axes { + id: graphAxes + } + + Item { + id: dataView + width: parent.width - tableView.width + height: parent.height + anchors.right: parent.right; + + Bars3D { + id: testGraph + width: dataView.width + height: dataView.height + shadowQuality: Bars3D.ShadowQualityMedium + selectionMode: Bars3D.SelectionModeItem + font.pointSize: 35 + theme: Bars3D.ThemeRetro + labelStyle: Bars3D.LabelStyleFromTheme + dataProxy: graphData.proxy + barThickness: 0.5 + barSpacing: Qt.size(0.5, 0.5) + barSpacingRelative: false + cameraPreset: Bars3D.CameraPresetRight + columnAxis: graphAxes.column + valueAxis: graphAxes.expenses + itemLabelFormat: "@valueTitle for @colLabel, @rowLabel: @valueLabel" + + onSelectedBarPosChanged: { + // Set tableView current row to selected bar + var rowRole = graphData.proxy.rowLabels[position.x]; + var colRole = graphData.proxy.columnLabels[position.y]; + var currentRow = tableView.currentRow + if (currentRow === -1 || rowRole !== graphData.model.get(currentRow).year + || colRole !== graphData.model.get(currentRow).month) { + var totalRows = tableView.rowCount; + for (var i = 0; i < totalRows; i++) { + var currentRowRole = graphData.model.get(i).year + var currentColRole = graphData.model.get(i).month + if (currentRowRole === rowRole && currentColRole === colRole) { + tableView.currentRow = i + break + } + } + } + } + } + } + + Button { + id: mappingToggle + anchors.bottom: parent.bottom + width: tableView.width + height: 60 + text: "Show Income" + onClicked: { + if (graphData.mapping.valueRole === "expenses") { + graphData.mapping.valueRole = "income" + text = "Show Expenses" + testGraph.valueAxis = graphAxes.income + } else { + graphData.mapping.valueRole = "expenses" + text = "Show Income" + testGraph.valueAxis = graphAxes.expenses + } + } + } + + Button { + id: shadowToggle + anchors.bottom: mappingToggle.top + width: tableView.width + height: 60 + text: "Hide Shadows" + onClicked: { + if (testGraph.shadowQuality == Bars3D.ShadowQualityNone) { + testGraph.shadowQuality = Bars3D.ShadowQualityMedium; + text = "Hide Shadows" + } else { + testGraph.shadowQuality = Bars3D.ShadowQualityNone; + text = "Show Shadows" + } + } + } + + Button { + id: dataToggle + anchors.bottom: shadowToggle.top + width: tableView.width + height: 60 + text: "Show 2010 - 2012" + onClicked: { + if (testGraph.rowAxis.max !== 6) { + text = "Show 2010 - 2012" + graphData.mapping.autoRowCategories = true + } else { + text = "Show all years" + // Explicitly defining row categories, since we do not want to show data for + // all years in the model, just for the selected ones. + graphData.mapping.autoRowCategories = false + graphData.mapping.rowCategories = ["2010", "2011", "2012"] + } + } + } + + TableView { + id: tableView + x: 0 + y: 0 + width: 298 + height: parent.height - mappingToggle.height - shadowToggle.height - dataToggle.height + TableViewColumn{ role: "year" ; title: "Year" ; width: 80 } + TableViewColumn{ role: "month" ; title: "Month" ; width: 80 } + TableViewColumn{ role: "expenses" ; title: "Expenses" ; width: 60 } + TableViewColumn{ role: "income" ; title: "Income" ; width: 60 } + model: graphData.model + + onCurrentRowChanged: { + var rowIndex = graphData.proxy.activeMapping.rowCategoryIndex(graphData.model.get(currentRow).year) + var colIndex = graphData.proxy.activeMapping.columnCategoryIndex(graphData.model.get(currentRow).month) + testGraph.selectedBarPos = Qt.point(rowIndex, colIndex) + } + } +} diff --git a/examples/qmlbars/qmlbars.desktop b/examples/qmlbars/qmlbars.desktop new file mode 100644 index 00000000..cf59c6b8 --- /dev/null +++ b/examples/qmlbars/qmlbars.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=qmlbars +Exec=/opt/qmlbars/bin/qmlbars +Icon=qmlbars64 +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/qmlbars/qmlbars.pro b/examples/qmlbars/qmlbars.pro new file mode 100644 index 00000000..758e7b76 --- /dev/null +++ b/examples/qmlbars/qmlbars.pro @@ -0,0 +1,25 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += widgets + +# Add more folders to ship with the application, here +folder_01.source = qml/qmlbars +folder_01.target = qml +DEPLOYMENTFOLDERS = folder_01 + +# Additional import path used to resolve QML modules in Creator's code model +QML_IMPORT_PATH = + +# The .cpp file which was generated for your project. Feel free to hack it. +SOURCES += main.cpp + +# Please do not modify the following two lines. Required for deployment. +include(qtquick2applicationviewer/qtquick2applicationviewer.pri) +qtcAddDeployment() + +RESOURCES += qmlbars.qrc + +OTHER_FILES += doc/src/* \ + doc/images/* diff --git a/examples/qmlbars/qmlbars.qrc b/examples/qmlbars/qmlbars.qrc new file mode 100644 index 00000000..7c291fd3 --- /dev/null +++ b/examples/qmlbars/qmlbars.qrc @@ -0,0 +1,7 @@ + + + qml/qmlbars/axes.qml + qml/qmlbars/data.qml + qml/qmlbars/main.qml + + diff --git a/examples/qmlbars/qmlbars64.png b/examples/qmlbars/qmlbars64.png new file mode 100644 index 00000000..707d5c4e Binary files /dev/null and b/examples/qmlbars/qmlbars64.png differ diff --git a/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.cpp b/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.cpp new file mode 100644 index 00000000..10709d7a --- /dev/null +++ b/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.cpp @@ -0,0 +1,81 @@ +// checksum 0x4f6f version 0x90005 +/* + This file was generated by the Qt Quick 2 Application wizard of Qt Creator. + QtQuick2ApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#include "qtquick2applicationviewer.h" + +#include +#include +#include + +class QtQuick2ApplicationViewerPrivate +{ + QString mainQmlFile; + friend class QtQuick2ApplicationViewer; + static QString adjustPath(const QString &path); +}; + +QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path) +{ +#if defined(Q_OS_MAC) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("%1/../Resources/%2") + .arg(QCoreApplication::applicationDirPath(), path); +#elif defined(Q_OS_BLACKBERRY) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("app/native/%1").arg(path); +#elif !defined(Q_OS_ANDROID) + QString pathInInstallDir = + QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; + pathInInstallDir = + QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#endif + return path; +} + +QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent) + : QQuickView(parent) + , d(new QtQuick2ApplicationViewerPrivate()) +{ + connect(engine(), SIGNAL(quit()), SLOT(close())); + setResizeMode(QQuickView::SizeRootObjectToView); +} + +QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer() +{ + delete d; +} + +void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file) +{ + d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file); +#ifdef Q_OS_ANDROID + setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); +#else + setSource(QUrl::fromLocalFile(d->mainQmlFile)); +#endif +} + +void QtQuick2ApplicationViewer::addImportPath(const QString &path) +{ + engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path)); +} + +void QtQuick2ApplicationViewer::showExpanded() +{ +#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX) + showFullScreen(); +#else + show(); +#endif +} diff --git a/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.h b/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.h new file mode 100644 index 00000000..cf66f140 --- /dev/null +++ b/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.h @@ -0,0 +1,33 @@ +// checksum 0xfde6 version 0x90005 +/* + This file was generated by the Qt Quick 2 Application wizard of Qt Creator. + QtQuick2ApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#ifndef QTQUICK2APPLICATIONVIEWER_H +#define QTQUICK2APPLICATIONVIEWER_H + +#include + +class QtQuick2ApplicationViewer : public QQuickView +{ + Q_OBJECT + +public: + explicit QtQuick2ApplicationViewer(QWindow *parent = 0); + virtual ~QtQuick2ApplicationViewer(); + + void setMainQmlFile(const QString &file); + void addImportPath(const QString &path); + + void showExpanded(); + +private: + class QtQuick2ApplicationViewerPrivate *d; +}; + +#endif // QTQUICK2APPLICATIONVIEWER_H diff --git a/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.pri b/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.pri new file mode 100644 index 00000000..a071e63d --- /dev/null +++ b/examples/qmlbars/qtquick2applicationviewer/qtquick2applicationviewer.pri @@ -0,0 +1,170 @@ +# checksum 0x7b0d version 0x90005 +# This file was generated by the Qt Quick 2 Application wizard of Qt Creator. +# The code below adds the QtQuick2ApplicationViewer to the project and handles +# the activation of QML debugging. +# It is recommended not to modify this file, since newer versions of Qt Creator +# may offer an updated version of it. + +QT += qml quick + +SOURCES += $$PWD/qtquick2applicationviewer.cpp +HEADERS += $$PWD/qtquick2applicationviewer.h +INCLUDEPATH += $$PWD +# This file was generated by an application wizard of Qt Creator. +# The code below handles deployment to Android and Maemo, aswell as copying +# of the application data to shadow build directories on desktop. +# It is recommended not to modify this file, since newer versions of Qt Creator +# may offer an updated version of it. + +defineTest(qtcAddDeployment) { +for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + greaterThan(QT_MAJOR_VERSION, 4) { + itemsources = $${item}.files + } else { + itemsources = $${item}.sources + } + $$itemsources = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath= $$eval($${deploymentfolder}.target) + export($$itemsources) + export($$itempath) + DEPLOYMENT += $$item +} + +MAINPROFILEPWD = $$PWD + +android-no-sdk { + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + + target.path = /data/user/qt + + export(target.path) + INSTALLS += target +} else:android { + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = /assets/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + INSTALLS += target +} else:win32 { + copyCommand = + for(deploymentfolder, DEPLOYMENTFOLDERS) { + source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) + source = $$replace(source, /, \\) + sourcePathSegments = $$split(source, \\) + target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) + target = $$replace(target, /, \\) + target ~= s,\\\\\\.?\\\\,\\, + !isEqual(source,$$target) { + !isEmpty(copyCommand):copyCommand += && + isEqual(QMAKE_DIR_SEP, \\) { + copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" + } else { + source = $$replace(source, \\\\, /) + target = $$OUT_PWD/$$eval($${deploymentfolder}.target) + target = $$replace(target, \\\\, /) + copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" + } + } + } + !isEmpty(copyCommand) { + copyCommand = @echo Copying application data... && $$copyCommand + copydeploymentfolders.commands = $$copyCommand + first.depends = $(first) copydeploymentfolders + export(first.depends) + export(copydeploymentfolders.commands) + QMAKE_EXTRA_TARGETS += first copydeploymentfolders + } +} else:unix { + maemo5 { + desktopfile.files = $${TARGET}.desktop + desktopfile.path = /usr/share/applications/hildon + icon.files = $${TARGET}64.png + icon.path = /usr/share/icons/hicolor/64x64/apps + } else:!isEmpty(MEEGO_VERSION_MAJOR) { + desktopfile.files = $${TARGET}_harmattan.desktop + desktopfile.path = /usr/share/applications + icon.files = $${TARGET}80.png + icon.path = /usr/share/icons/hicolor/80x80/apps + } else { # Assumed to be a Desktop Unix + copyCommand = + for(deploymentfolder, DEPLOYMENTFOLDERS) { + source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) + source = $$replace(source, \\\\, /) + macx { + target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) + } else { + target = $$OUT_PWD/$$eval($${deploymentfolder}.target) + } + target = $$replace(target, \\\\, /) + sourcePathSegments = $$split(source, /) + targetFullPath = $$target/$$last(sourcePathSegments) + targetFullPath ~= s,/\\.?/,/, + !isEqual(source,$$targetFullPath) { + !isEmpty(copyCommand):copyCommand += && + copyCommand += $(MKDIR) \"$$target\" + copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" + } + } + !isEmpty(copyCommand) { + copyCommand = @echo Copying application data... && $$copyCommand + copydeploymentfolders.commands = $$copyCommand + first.depends = $(first) copydeploymentfolders + export(first.depends) + export(copydeploymentfolders.commands) + QMAKE_EXTRA_TARGETS += first copydeploymentfolders + } + } + !isEmpty(target.path) { + installPrefix = $${target.path} + } else { + installPrefix = /opt/$${TARGET} + } + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + + !isEmpty(desktopfile.path) { + export(icon.files) + export(icon.path) + export(desktopfile.files) + export(desktopfile.path) + INSTALLS += icon desktopfile + } + + isEmpty(target.path) { + target.path = $${installPrefix}/bin + export(target.path) + } + INSTALLS += target +} + +export (ICON) +export (INSTALLS) +export (DEPLOYMENT) +export (LIBS) +export (QMAKE_EXTRA_TARGETS) +} diff --git a/examples/qmlscatter/doc/src/qmlscatter.qdoc b/examples/qmlscatter/doc/src/qmlscatter.qdoc index a014874e..590b9a30 100644 --- a/examples/qmlscatter/doc/src/qmlscatter.qdoc +++ b/examples/qmlscatter/doc/src/qmlscatter.qdoc @@ -20,7 +20,7 @@ \example qmlscatter \title Qt Quick 2 Scatter Example - The Qt Quick 2 scatter example shows how to make a simple scatter chart visualization using + The Qt Quick 2 scatter example shows how to make a simple scatter graph visualization using Q3DScatter and Qt Quick 2. \image qmlscatter-example.png diff --git a/examples/qmlscatter/qml/qmlscatter/main.qml b/examples/qmlscatter/qml/qmlscatter/main.qml index 9a600867..333dfadd 100644 --- a/examples/qmlscatter/qml/qmlscatter/main.qml +++ b/examples/qmlscatter/qml/qmlscatter/main.qml @@ -25,7 +25,7 @@ Item { visible: true Data { - id: chartData + id: graphData } Item { @@ -40,7 +40,7 @@ Item { height: dataView.height font.family: "Lucida Handwriting" font.pointSize: 40 - dataProxy: chartData.proxy + dataProxy: graphData.proxy theme: Scatter3D.ThemeIsabelle shadowQuality: Scatter3D.ShadowQualitySoftLow selectionMode: Scatter3D.SelectionModeItem diff --git a/examples/qmlscatter/qmlscatter.pro b/examples/qmlscatter/qmlscatter.pro index b42fd239..0c66c5ae 100644 --- a/examples/qmlscatter/qmlscatter.pro +++ b/examples/qmlscatter/qmlscatter.pro @@ -20,3 +20,6 @@ include(qtquick2applicationviewer/qtquick2applicationviewer.pri) qtcAddDeployment() RESOURCES += qmlscatter.qrc + +OTHER_FILES += doc/src/* \ + doc/images/* diff --git a/examples/qmlsurface/qmlsurface.pro b/examples/qmlsurface/qmlsurface.pro index 251619cf..64c72cf7 100644 --- a/examples/qmlsurface/qmlsurface.pro +++ b/examples/qmlsurface/qmlsurface.pro @@ -20,3 +20,6 @@ include(qtquick2applicationviewer/qtquick2applicationviewer.pri) qtcAddDeployment() RESOURCES += qmlsurface.qrc + +OTHER_FILES += doc/src/* \ + doc/images/* diff --git a/examples/rainfall/doc/src/rainfall.qdoc b/examples/rainfall/doc/src/rainfall.qdoc index 95050dff..c28029a4 100644 --- a/examples/rainfall/doc/src/rainfall.qdoc +++ b/examples/rainfall/doc/src/rainfall.qdoc @@ -20,7 +20,7 @@ \example rainfall \title Rainfall Example - The barchart example shows how to make a simple 3D bar chart using Q3DBars. + The bars example shows how to make a simple 3D bar graph using Q3DBars. \image rainfall-example.png diff --git a/examples/rainfall/main.cpp b/examples/rainfall/main.cpp index 638fb842..54ea63e9 100644 --- a/examples/rainfall/main.cpp +++ b/examples/rainfall/main.cpp @@ -16,7 +16,7 @@ ** ****************************************************************************/ -#include "rainfallchart.h" +#include "rainfallgraph.h" #include using namespace QtDataVisualization; @@ -30,8 +30,8 @@ int main(int argc, char **argv) rainfall->setPosition(QPoint(10, 30)); rainfall->show(); - RainfallChart rainfallchart(rainfall); - rainfallchart.start(); + RainfallGraph rainfallgraph(rainfall); + rainfallgraph.start(); return app.exec(); } diff --git a/examples/rainfall/rainfall.pro b/examples/rainfall/rainfall.pro index af7f963b..0a2e1498 100644 --- a/examples/rainfall/rainfall.pro +++ b/examples/rainfall/rainfall.pro @@ -3,13 +3,13 @@ } SOURCES += main.cpp \ - rainfallchart.cpp \ + rainfallgraph.cpp \ variantdataset.cpp \ variantbardataproxy.cpp \ variantbardatamapping.cpp \ HEADERS += \ - rainfallchart.h \ + rainfallgraph.h \ variantdataset.h \ variantbardataproxy.h \ variantbardatamapping.h @@ -19,5 +19,7 @@ INSTALLS += target RESOURCES += \ rainfall.qrc -OTHER_FILES += data/raindata.txt +OTHER_FILES += data/raindata.txt \ + doc/src/* \ + doc/images/* diff --git a/examples/rainfall/rainfallchart.cpp b/examples/rainfall/rainfallchart.cpp deleted file mode 100644 index 45e252bc..00000000 --- a/examples/rainfall/rainfallchart.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "rainfallchart.h" -#include -#include -#include -#include -#include -#include -#include - -using namespace QtDataVisualization; - -RainfallChart::RainfallChart(Q3DBars *rainfall) - : m_chart(rainfall) -{ - // In data file the months are in numeric format, so create custom list - for (int i = 1; i <= 12; i++) - m_numericMonths << QString::number(i); - - m_columnCount = m_numericMonths.size(); - - m_proxy = new VariantBarDataProxy; - m_chart->setActiveDataProxy(m_proxy); - - updateYearsList(2000, 2012); - - // Set up bar specifications; make the bars as wide as they are deep, - // and add a small space between the bars - m_chart->setBarThickness(1.0); - m_chart->setBarSpacing(QSizeF(0.2, 0.2)); - - // Set axis labels and titles - QStringList months; - months << "January" << "February" << "March" << "April" << "May" << "June" << "July" << "August" << "September" << "October" << "November" << "December"; - m_chart->rowAxis()->setTitle("Year"); - m_chart->columnAxis()->setTitle("Month"); - m_chart->valueAxis()->setTitle("rainfall"); - m_chart->valueAxis()->setLabelFormat("%d mm"); - m_chart->rowAxis()->setCategoryLabels(m_years); - m_chart->columnAxis()->setCategoryLabels(months); - - // Set bar type to cylinder - m_chart->setBarType(QDataVis::MeshStyleCylinders, false); - - // Set shadows to medium - m_chart->setShadowQuality(QDataVis::ShadowQualityMedium); - - // Set font - m_chart->setFont(QFont("Century Gothic", 30)); - - // Set selection mode to bar and column - m_chart->setSelectionMode(QDataVis::SelectionModeSliceColumn); - - // Set theme - m_chart->setTheme(QDataVis::ThemeArmyBlue); - - // Set preset camera position - m_chart->setCameraPreset(QDataVis::CameraPresetIsometricRightHigh); - - // Disable grid - m_chart->setGridVisible(false); - - // Set window title - m_chart->setTitle(QStringLiteral("Monthly rainfall in Northern Finland")); -} - -RainfallChart::~RainfallChart() -{ - delete m_mapping; - delete m_dataSet; - delete m_chart; -} - -void RainfallChart::start() -{ - addDataSet(); -} - -void RainfallChart::updateYearsList(int start, int end) -{ - m_years.clear(); - for (int i = start; i <= end; i++) - m_years << QString::number(i); - - m_rowCount = m_years.size(); -} - -void RainfallChart::addDataSet() -{ - m_dataSet = new VariantDataSet; - VariantDataItemList *itemList = new VariantDataItemList; - QTextStream stream; - QFile dataFile(":/data/raindata.txt"); - if (dataFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - stream.setDevice(&dataFile); - while (!stream.atEnd()) { - QString line = stream.readLine(); - if (line.startsWith("#")) - continue; - QStringList strList = line.split(",", QString::SkipEmptyParts); - if (strList.size() < 3) { - qWarning() << "Invalid row read from data:" << line; - continue; - } - VariantDataItem *newItem = new VariantDataItem; - for (int i = 0; i < 2; i++) - newItem->append(strList.at(i).trimmed()); - newItem->append(strList.at(2).trimmed().toDouble()); - itemList->append(newItem); - } - } else { - qWarning() << "Unable to open data file:" << dataFile.fileName(); - } - - m_dataSet->addItems(itemList); - - m_proxy->setDataSet(m_dataSet); - - m_mapping = new VariantBarDataMapping(0, 1, 2, m_years, m_numericMonths); - m_proxy->setMapping(m_mapping); -} diff --git a/examples/rainfall/rainfallchart.h b/examples/rainfall/rainfallchart.h deleted file mode 100644 index 2c596f5c..00000000 --- a/examples/rainfall/rainfallchart.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 RAINFALLCHART_H -#define RAINFALLCHART_H - -#include "variantbardataproxy.h" -#include - -using namespace QtDataVisualization; - -class RainfallChart : public QObject -{ - Q_OBJECT -public: - explicit RainfallChart(Q3DBars *rainfall); - ~RainfallChart(); - - void addDataSet(); - void start(); - -private: - - void updateYearsList(int start, int end); - Q3DBars *m_chart; - int m_columnCount; - int m_rowCount; - QStringList m_years; - QStringList m_numericMonths; - VariantBarDataProxy *m_proxy; - VariantBarDataMapping *m_mapping; - VariantDataSet *m_dataSet; -}; - - -#endif // RAINFALLCHART_H diff --git a/examples/rainfall/rainfallgraph.cpp b/examples/rainfall/rainfallgraph.cpp new file mode 100644 index 00000000..5cd70710 --- /dev/null +++ b/examples/rainfall/rainfallgraph.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 "rainfallgraph.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace QtDataVisualization; + +RainfallGraph::RainfallGraph(Q3DBars *rainfall) + : m_graph(rainfall) +{ + // In data file the months are in numeric format, so create custom list + for (int i = 1; i <= 12; i++) + m_numericMonths << QString::number(i); + + m_columnCount = m_numericMonths.size(); + + m_proxy = new VariantBarDataProxy; + m_graph->setActiveDataProxy(m_proxy); + + updateYearsList(2000, 2012); + + // Set up bar specifications; make the bars as wide as they are deep, + // and add a small space between the bars + m_graph->setBarThickness(1.0); + m_graph->setBarSpacing(QSizeF(0.2, 0.2)); + + // Set axis labels and titles + QStringList months; + months << "January" << "February" << "March" << "April" << "May" << "June" << "July" << "August" << "September" << "October" << "November" << "December"; + m_graph->rowAxis()->setTitle("Year"); + m_graph->columnAxis()->setTitle("Month"); + m_graph->valueAxis()->setTitle("rainfall"); + m_graph->valueAxis()->setLabelFormat("%d mm"); + m_graph->rowAxis()->setCategoryLabels(m_years); + m_graph->columnAxis()->setCategoryLabels(months); + + // Set bar type to cylinder + m_graph->setBarType(QDataVis::MeshStyleCylinders, false); + + // Set shadows to medium + m_graph->setShadowQuality(QDataVis::ShadowQualityMedium); + + // Set font + m_graph->setFont(QFont("Century Gothic", 30)); + + // Set selection mode to bar and column + m_graph->setSelectionMode(QDataVis::SelectionModeSliceColumn); + + // Set theme + m_graph->setTheme(QDataVis::ThemeArmyBlue); + + // Set preset camera position + m_graph->setCameraPreset(QDataVis::CameraPresetIsometricRightHigh); + + // Disable grid + m_graph->setGridVisible(false); + + // Set window title + m_graph->setTitle(QStringLiteral("Monthly rainfall in Northern Finland")); +} + +RainfallGraph::~RainfallGraph() +{ + delete m_mapping; + delete m_dataSet; + delete m_graph; +} + +void RainfallGraph::start() +{ + addDataSet(); +} + +void RainfallGraph::updateYearsList(int start, int end) +{ + m_years.clear(); + for (int i = start; i <= end; i++) + m_years << QString::number(i); + + m_rowCount = m_years.size(); +} + +void RainfallGraph::addDataSet() +{ + m_dataSet = new VariantDataSet; + VariantDataItemList *itemList = new VariantDataItemList; + QTextStream stream; + QFile dataFile(":/data/raindata.txt"); + if (dataFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + stream.setDevice(&dataFile); + while (!stream.atEnd()) { + QString line = stream.readLine(); + if (line.startsWith("#")) + continue; + QStringList strList = line.split(",", QString::SkipEmptyParts); + if (strList.size() < 3) { + qWarning() << "Invalid row read from data:" << line; + continue; + } + VariantDataItem *newItem = new VariantDataItem; + for (int i = 0; i < 2; i++) + newItem->append(strList.at(i).trimmed()); + newItem->append(strList.at(2).trimmed().toDouble()); + itemList->append(newItem); + } + } else { + qWarning() << "Unable to open data file:" << dataFile.fileName(); + } + + m_dataSet->addItems(itemList); + + m_proxy->setDataSet(m_dataSet); + + m_mapping = new VariantBarDataMapping(0, 1, 2, m_years, m_numericMonths); + m_proxy->setMapping(m_mapping); +} diff --git a/examples/rainfall/rainfallgraph.h b/examples/rainfall/rainfallgraph.h new file mode 100644 index 00000000..6317ab71 --- /dev/null +++ b/examples/rainfall/rainfallgraph.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 RAINFALLGRAPH_H +#define RAINFALLGRAPH_H + +#include "variantbardataproxy.h" +#include + +using namespace QtDataVisualization; + +class RainfallGraph : public QObject +{ + Q_OBJECT +public: + explicit RainfallGraph(Q3DBars *rainfall); + ~RainfallGraph(); + + void addDataSet(); + void start(); + +private: + + void updateYearsList(int start, int end); + Q3DBars *m_graph; + int m_columnCount; + int m_rowCount; + QStringList m_years; + QStringList m_numericMonths; + VariantBarDataProxy *m_proxy; + VariantBarDataMapping *m_mapping; + VariantDataSet *m_dataSet; +}; + + +#endif diff --git a/examples/scatter/doc/src/scatter.qdoc b/examples/scatter/doc/src/scatter.qdoc new file mode 100644 index 00000000..7f4bda38 --- /dev/null +++ b/examples/scatter/doc/src/scatter.qdoc @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +/*! + \example scatter + \title Scatter Example + + The scatter example shows how to make a simple 3D scatter graph using Q3DScatter and + combining the use of widgets for adjusting several adjustable qualities. + + \image scatter-example.png + + TODO +*/ diff --git a/examples/scatter/main.cpp b/examples/scatter/main.cpp new file mode 100644 index 00000000..961ed3db --- /dev/null +++ b/examples/scatter/main.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 "scatterdatamodifier.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QWidget *widget = new QWidget; + QHBoxLayout *hLayout = new QHBoxLayout(widget); + QVBoxLayout *vLayout = new QVBoxLayout(); + + Q3DScatter *graph = new Q3DScatter(); + QSize screenSize = graph->screen()->size(); + + QWidget *container = QWidget::createWindowContainer(graph); + container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); + container->setMaximumSize(screenSize); + container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + container->setFocusPolicy(Qt::StrongFocus); + + widget->setWindowTitle(QStringLiteral("values of some things in something")); + + hLayout->addWidget(container, 1); + hLayout->addLayout(vLayout); + + QComboBox *themeList = new QComboBox(widget); + themeList->addItem(QStringLiteral("Qt")); + themeList->addItem(QStringLiteral("Primary Colors")); + themeList->addItem(QStringLiteral("Digia")); + themeList->addItem(QStringLiteral("Stone Moss")); + themeList->addItem(QStringLiteral("Army Blue")); + themeList->addItem(QStringLiteral("Retro")); + themeList->addItem(QStringLiteral("Ebony")); + themeList->addItem(QStringLiteral("Isabelle")); + themeList->setCurrentIndex(6); + + QPushButton *labelButton = new QPushButton(widget); + labelButton->setText(QStringLiteral("Change label style")); + + QCheckBox *smoothCheckBox = new QCheckBox(widget); + smoothCheckBox->setText(QStringLiteral("Smooth dots")); + smoothCheckBox->setChecked(true); + + QComboBox *barStyleList = new QComboBox(widget); + barStyleList->addItem(QStringLiteral("Sphere")); + barStyleList->addItem(QStringLiteral("Tetrahedron")); + barStyleList->setCurrentIndex(0); + + QPushButton *cameraButton = new QPushButton(widget); + cameraButton->setText(QStringLiteral("Change camera preset")); + + QCheckBox *backgroundCheckBox = new QCheckBox(widget); + backgroundCheckBox->setText(QStringLiteral("Show background")); + backgroundCheckBox->setChecked(true); + + QCheckBox *gridCheckBox = new QCheckBox(widget); + gridCheckBox->setText(QStringLiteral("Show grid")); + gridCheckBox->setChecked(true); + + QComboBox *shadowQuality = new QComboBox(widget); + shadowQuality->addItem(QStringLiteral("None")); + shadowQuality->addItem(QStringLiteral("Low")); + shadowQuality->addItem(QStringLiteral("Medium")); + shadowQuality->addItem(QStringLiteral("High")); + shadowQuality->addItem(QStringLiteral("Low Soft")); + shadowQuality->addItem(QStringLiteral("Medium Soft")); + shadowQuality->addItem(QStringLiteral("High Soft")); + shadowQuality->setCurrentIndex(3); + + QFontComboBox *fontList = new QFontComboBox(widget); + fontList->setCurrentFont(QFont("Arial")); + + vLayout->addWidget(labelButton, 0, Qt::AlignTop); + vLayout->addWidget(cameraButton, 0, Qt::AlignTop); + vLayout->addWidget(backgroundCheckBox); + vLayout->addWidget(gridCheckBox); + vLayout->addWidget(smoothCheckBox, 0, Qt::AlignTop); + vLayout->addWidget(new QLabel(QStringLiteral("Change dot style"))); + vLayout->addWidget(barStyleList); + vLayout->addWidget(new QLabel(QStringLiteral("Change theme"))); + vLayout->addWidget(themeList); + vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality"))); + vLayout->addWidget(shadowQuality); + vLayout->addWidget(new QLabel(QStringLiteral("Change font"))); + vLayout->addWidget(fontList, 1, Qt::AlignTop); + + widget->show(); + + ScatterDataModifier *modifier = new ScatterDataModifier(graph); + + QObject::connect(cameraButton, &QPushButton::clicked, modifier, + &ScatterDataModifier::changePresetCamera); + QObject::connect(labelButton, &QPushButton::clicked, modifier, + &ScatterDataModifier::changeLabelStyle); + + QObject::connect(backgroundCheckBox, &QCheckBox::stateChanged, modifier, + &ScatterDataModifier::setBackgroundEnabled); + QObject::connect(gridCheckBox, &QCheckBox::stateChanged, modifier, + &ScatterDataModifier::setGridEnabled); + QObject::connect(smoothCheckBox, &QCheckBox::stateChanged, modifier, + &ScatterDataModifier::setSmoothDots); + + QObject::connect(barStyleList, SIGNAL(currentIndexChanged(int)), modifier, + SLOT(changeStyle(int))); + + QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), modifier, + SLOT(changeTheme(int))); + + QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), modifier, + SLOT(changeShadowQuality(int))); + + QObject::connect(modifier, &ScatterDataModifier::shadowQualityChanged, shadowQuality, + &QComboBox::setCurrentIndex); + QObject::connect(graph, &Q3DScatter::shadowQualityChanged, modifier, + &ScatterDataModifier::shadowQualityUpdatedByVisual); + + QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier, + &ScatterDataModifier::changeFont); + + modifier->start(); + + return app.exec(); +} diff --git a/examples/scatter/scatter.pro b/examples/scatter/scatter.pro new file mode 100644 index 00000000..beff2164 --- /dev/null +++ b/examples/scatter/scatter.pro @@ -0,0 +1,13 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +SOURCES += main.cpp scatterdatamodifier.cpp +HEADERS += scatterdatamodifier.h + +QT += widgets + +INSTALLS += target + +OTHER_FILES += doc/src/* \ + doc/images/* diff --git a/examples/scatter/scatterdatamodifier.cpp b/examples/scatter/scatterdatamodifier.cpp new file mode 100644 index 00000000..cf3296bb --- /dev/null +++ b/examples/scatter/scatterdatamodifier.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 "scatterdatamodifier.h" +#include +#include +#include +using namespace QtDataVisualization; + +//#define RANDOM_SCATTER // Uncomment this to switch to random scatter + +const int numberOfItems = 10000; + +ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter) + : m_graph(scatter), + m_fontSize(40.0f), + m_style(QDataVis::MeshStyleSpheres), + m_smooth(true) +{ + QFont font = m_graph->font(); + font.setPointSize(m_fontSize); + m_graph->setFont(font); + m_graph->setObjectType(QDataVis::MeshStyleSpheres, true); + m_graph->setTheme(QDataVis::ThemeEbony); + m_graph->setShadowQuality(QDataVis::ShadowQualityHigh); + m_graph->setCameraPreset(QDataVis::CameraPresetFront); + m_graph->setAxisX(new Q3DValueAxis); + m_graph->setAxisY(new Q3DValueAxis); + m_graph->setAxisZ(new Q3DValueAxis); + + QScatterDataProxy *proxy = new QScatterDataProxy; + proxy->setItemLabelFormat("@xTitle: @xLabel @yTitle: @yLabel @zTitle: @zLabel"); + m_graph->setActiveDataProxy(proxy); + + changeLabelStyle(); +} + +ScatterDataModifier::~ScatterDataModifier() +{ + delete m_graph; +} + +void ScatterDataModifier::start() +{ + addData(); +} + +void ScatterDataModifier::addData() +{ + // Add labels + m_graph->axisX()->setTitle("X"); + m_graph->axisY()->setTitle("Y"); + m_graph->axisZ()->setTitle("Z"); + m_graph->axisX()->setRange(-50.0, 50.0); + m_graph->axisY()->setRange(-1.0, 1.0); + m_graph->axisZ()->setRange(-50.0, 50.0); + + QScatterDataArray *dataArray = new QScatterDataArray; + dataArray->resize(numberOfItems); + QScatterDataItem *ptrToDataArray = &dataArray->first(); + +#ifdef RANDOM_SCATTER + for (int i = 0; i < numberOfItems; i++) { + ptrToDataArray->setPosition(randVector()); + ptrToDataArray++; + } +#else + float limit = qSqrt(numberOfItems) / 2.0f; + for (float i = -limit; i < limit; i++) { + for (float j = -limit; j < limit; j++) { + ptrToDataArray->setPosition(QVector3D(i, qCos(qDegreesToRadians((i * j) / 7.5)), j)); + ptrToDataArray++; + } + } +#endif + + static_cast(m_graph->activeDataProxy())->resetArray(dataArray); +} + +void ScatterDataModifier::changeStyle(int style) +{ + m_style = QDataVis::MeshStyle(style + 5); // skip unsupported mesh types + m_graph->setObjectType(m_style, m_smooth); +} + +void ScatterDataModifier::setSmoothDots(int smooth) +{ + m_smooth = bool(smooth); + m_graph->setObjectType(m_style, m_smooth); +} + +void ScatterDataModifier::changeTheme(int theme) +{ + m_graph->setTheme((QDataVis::Theme)theme); +} + +void ScatterDataModifier::changePresetCamera() +{ + static int preset = QDataVis::CameraPresetFrontLow; + + m_graph->setCameraPreset((QDataVis::CameraPreset)preset); + + if (++preset > QDataVis::CameraPresetDirectlyAboveCCW45) + preset = QDataVis::CameraPresetFrontLow; +} + +void ScatterDataModifier::changeLabelStyle() +{ + static int style = QDataVis::LabelStyleFromTheme; + + m_graph->setLabelStyle((QDataVis::LabelStyle)style); + + if (++style > QDataVis::LabelStyleTransparent) + style = QDataVis::LabelStyleOpaque; +} + +void ScatterDataModifier::changeFont(const QFont &font) +{ + QFont newFont = font; + newFont.setPointSizeF(m_fontSize); + m_graph->setFont(newFont); +} + +void ScatterDataModifier::shadowQualityUpdatedByVisual(QDataVis::ShadowQuality sq) +{ + int quality = int(sq); + // Updates the UI component to show correct shadow quality + emit shadowQualityChanged(quality); +} + +void ScatterDataModifier::changeShadowQuality(int quality) +{ + QDataVis::ShadowQuality sq = QDataVis::ShadowQuality(quality); + m_graph->setShadowQuality(sq); + emit shadowQualityChanged(quality); +} + +void ScatterDataModifier::setBackgroundEnabled(int enabled) +{ + m_graph->setBackgroundVisible((bool)enabled); +} + +void ScatterDataModifier::setGridEnabled(int enabled) +{ + m_graph->setGridVisible((bool)enabled); +} + +QVector3D ScatterDataModifier::randVector() +{ + return QVector3D( + (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f, + (float)(rand() % 100) / 100.0f - (float)(rand() % 100) / 100.0f, + (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f); +} diff --git a/examples/scatter/scatterdatamodifier.h b/examples/scatter/scatterdatamodifier.h new file mode 100644 index 00000000..5cc9348b --- /dev/null +++ b/examples/scatter/scatterdatamodifier.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 SCATTERDATAMODIFIER_H +#define SCATTERDATAMODIFIER_H + +#include +#include + +using namespace QtDataVisualization; + +class ScatterDataModifier : public QObject +{ + Q_OBJECT +public: + explicit ScatterDataModifier(Q3DScatter *scatter); + ~ScatterDataModifier(); + + void addData(); + void changeStyle(); + void changePresetCamera(); + void changeLabelStyle(); + void changeFont(const QFont &font); + void changeFontSize(int fontsize); + void setBackgroundEnabled(int enabled); + void setGridEnabled(int enabled); + void setSmoothDots(int smooth); + void start(); + +public slots: + void changeStyle(int style); + void changeTheme(int theme); + void changeShadowQuality(int quality); + void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality); + +signals: + void shadowQualityChanged(int quality); + +private: + QVector3D randVector(); + Q3DScatter *m_graph; + int m_fontSize; + QDataVis::MeshStyle m_style; + bool m_smooth; +}; + +#endif diff --git a/examples/scatterchart/doc/src/scatterchart.qdoc b/examples/scatterchart/doc/src/scatterchart.qdoc deleted file mode 100644 index d6878ff9..00000000 --- a/examples/scatterchart/doc/src/scatterchart.qdoc +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -/*! - \example scatterchart - \title Scatter Chart Example - - The scatterchart example shows how to make a simple 3D scatter chart using Q3DScatter and - combining the use of widgets for adjusting several adjustable qualities. - - \image scatterchart-example.png - - TODO -*/ diff --git a/examples/scatterchart/main.cpp b/examples/scatterchart/main.cpp deleted file mode 100644 index 9d66a9b9..00000000 --- a/examples/scatterchart/main.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "scatterchart.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - QWidget *widget = new QWidget; - QHBoxLayout *hLayout = new QHBoxLayout(widget); - QVBoxLayout *vLayout = new QVBoxLayout(); - - Q3DScatter *chart = new Q3DScatter(); - QSize screenSize = chart->screen()->size(); - - QWidget *container = QWidget::createWindowContainer(chart); - container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); - container->setMaximumSize(screenSize); - container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - container->setFocusPolicy(Qt::StrongFocus); - - widget->setWindowTitle(QStringLiteral("values of some things in something")); - - hLayout->addWidget(container, 1); - hLayout->addLayout(vLayout); - - QComboBox *themeList = new QComboBox(widget); - themeList->addItem(QStringLiteral("Qt")); - themeList->addItem(QStringLiteral("Primary Colors")); - themeList->addItem(QStringLiteral("Digia")); - themeList->addItem(QStringLiteral("Stone Moss")); - themeList->addItem(QStringLiteral("Army Blue")); - themeList->addItem(QStringLiteral("Retro")); - themeList->addItem(QStringLiteral("Ebony")); - themeList->addItem(QStringLiteral("Isabelle")); - themeList->setCurrentIndex(6); - - QPushButton *labelButton = new QPushButton(widget); - labelButton->setText(QStringLiteral("Change label style")); - - QCheckBox *smoothCheckBox = new QCheckBox(widget); - smoothCheckBox->setText(QStringLiteral("Smooth dots")); - smoothCheckBox->setChecked(true); - - QComboBox *barStyleList = new QComboBox(widget); - barStyleList->addItem(QStringLiteral("Sphere")); - barStyleList->addItem(QStringLiteral("Tetrahedron")); - barStyleList->setCurrentIndex(0); - - QPushButton *cameraButton = new QPushButton(widget); - cameraButton->setText(QStringLiteral("Change camera preset")); - - QCheckBox *backgroundCheckBox = new QCheckBox(widget); - backgroundCheckBox->setText(QStringLiteral("Show background")); - backgroundCheckBox->setChecked(true); - - QCheckBox *gridCheckBox = new QCheckBox(widget); - gridCheckBox->setText(QStringLiteral("Show grid")); - gridCheckBox->setChecked(true); - - QComboBox *shadowQuality = new QComboBox(widget); - shadowQuality->addItem(QStringLiteral("None")); - shadowQuality->addItem(QStringLiteral("Low")); - shadowQuality->addItem(QStringLiteral("Medium")); - shadowQuality->addItem(QStringLiteral("High")); - shadowQuality->addItem(QStringLiteral("Low Soft")); - shadowQuality->addItem(QStringLiteral("Medium Soft")); - shadowQuality->addItem(QStringLiteral("High Soft")); - shadowQuality->setCurrentIndex(3); - - QFontComboBox *fontList = new QFontComboBox(widget); - fontList->setCurrentFont(QFont("Arial")); - - vLayout->addWidget(labelButton, 0, Qt::AlignTop); - vLayout->addWidget(cameraButton, 0, Qt::AlignTop); - vLayout->addWidget(backgroundCheckBox); - vLayout->addWidget(gridCheckBox); - vLayout->addWidget(smoothCheckBox, 0, Qt::AlignTop); - vLayout->addWidget(new QLabel(QStringLiteral("Change dot style"))); - vLayout->addWidget(barStyleList); - vLayout->addWidget(new QLabel(QStringLiteral("Change theme"))); - vLayout->addWidget(themeList); - vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality"))); - vLayout->addWidget(shadowQuality); - vLayout->addWidget(new QLabel(QStringLiteral("Change font"))); - vLayout->addWidget(fontList, 1, Qt::AlignTop); - - widget->show(); - - ScatterDataModifier *modifier = new ScatterDataModifier(chart); - - QObject::connect(cameraButton, &QPushButton::clicked, modifier, - &ScatterDataModifier::changePresetCamera); - QObject::connect(labelButton, &QPushButton::clicked, modifier, - &ScatterDataModifier::changeLabelStyle); - - QObject::connect(backgroundCheckBox, &QCheckBox::stateChanged, modifier, - &ScatterDataModifier::setBackgroundEnabled); - QObject::connect(gridCheckBox, &QCheckBox::stateChanged, modifier, - &ScatterDataModifier::setGridEnabled); - QObject::connect(smoothCheckBox, &QCheckBox::stateChanged, modifier, - &ScatterDataModifier::setSmoothDots); - - QObject::connect(barStyleList, SIGNAL(currentIndexChanged(int)), modifier, - SLOT(changeStyle(int))); - - QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), modifier, - SLOT(changeTheme(int))); - - QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), modifier, - SLOT(changeShadowQuality(int))); - - QObject::connect(modifier, &ScatterDataModifier::shadowQualityChanged, shadowQuality, - &QComboBox::setCurrentIndex); - QObject::connect(chart, &Q3DScatter::shadowQualityChanged, modifier, - &ScatterDataModifier::shadowQualityUpdatedByVisual); - - QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier, - &ScatterDataModifier::changeFont); - - modifier->start(); - - return app.exec(); -} diff --git a/examples/scatterchart/scatterchart.cpp b/examples/scatterchart/scatterchart.cpp deleted file mode 100644 index 879d8471..00000000 --- a/examples/scatterchart/scatterchart.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "scatterchart.h" -#include -#include -#include -using namespace QtDataVisualization; - -//#define RANDOM_SCATTER // Uncomment this to switch to random scatter - -const int numberOfItems = 10000; - -ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter) - : m_chart(scatter), - m_fontSize(40.0f), - m_style(QDataVis::MeshStyleSpheres), - m_smooth(true) -{ - QFont font = m_chart->font(); - font.setPointSize(m_fontSize); - m_chart->setFont(font); - m_chart->setObjectType(QDataVis::MeshStyleSpheres, true); - m_chart->setTheme(QDataVis::ThemeEbony); - m_chart->setShadowQuality(QDataVis::ShadowQualityHigh); - m_chart->setCameraPreset(QDataVis::CameraPresetFront); - m_chart->setAxisX(new Q3DValueAxis); - m_chart->setAxisY(new Q3DValueAxis); - m_chart->setAxisZ(new Q3DValueAxis); - - QScatterDataProxy *proxy = new QScatterDataProxy; - proxy->setItemLabelFormat("@xTitle: @xLabel @yTitle: @yLabel @zTitle: @zLabel"); - m_chart->setActiveDataProxy(proxy); -} - -ScatterDataModifier::~ScatterDataModifier() -{ - delete m_chart; -} - -void ScatterDataModifier::start() -{ - addData(); -} - -void ScatterDataModifier::addData() -{ - // Add labels - m_chart->axisX()->setTitle("X"); - m_chart->axisY()->setTitle("Y"); - m_chart->axisZ()->setTitle("Z"); - m_chart->axisX()->setRange(-50.0, 50.0); - m_chart->axisY()->setRange(-1.0, 1.0); - m_chart->axisZ()->setRange(-50.0, 50.0); - - QScatterDataArray *dataArray = new QScatterDataArray; - dataArray->resize(numberOfItems); - QScatterDataItem *ptrToDataArray = &dataArray->first(); - -#ifdef RANDOM_SCATTER - for (int i = 0; i < numberOfItems; i++) { - ptrToDataArray->setPosition(randVector()); - ptrToDataArray++; - } -#else - float limit = qSqrt(numberOfItems) / 2.0f; - for (float i = -limit; i < limit; i++) { - for (float j = -limit; j < limit; j++) { - ptrToDataArray->setPosition(QVector3D(i, qCos(qDegreesToRadians((i * j) / 7.5)), j)); - ptrToDataArray++; - } - } -#endif - - static_cast(m_chart->activeDataProxy())->resetArray(dataArray); -} - -void ScatterDataModifier::changeStyle(int style) -{ - m_style = QDataVis::MeshStyle(style + 5); // skip unsupported mesh types - m_chart->setObjectType(m_style, m_smooth); -} - -void ScatterDataModifier::setSmoothDots(int smooth) -{ - m_smooth = bool(smooth); - m_chart->setObjectType(m_style, m_smooth); -} - -void ScatterDataModifier::changeTheme(int theme) -{ - m_chart->setTheme((QDataVis::Theme)theme); -} - -void ScatterDataModifier::changePresetCamera() -{ - static int preset = QDataVis::CameraPresetFrontLow; - - m_chart->setCameraPreset((QDataVis::CameraPreset)preset); - - if (++preset > QDataVis::CameraPresetDirectlyAboveCCW45) - preset = QDataVis::CameraPresetFrontLow; -} - -void ScatterDataModifier::changeLabelStyle() -{ - static int style = QDataVis::LabelStyleOpaque; - - m_chart->setLabelStyle((QDataVis::LabelStyle)style); - - if (++style > QDataVis::LabelStyleTransparent) - style = QDataVis::LabelStyleOpaque; -} - -void ScatterDataModifier::changeFont(const QFont &font) -{ - QFont newFont = font; - newFont.setPointSizeF(m_fontSize); - m_chart->setFont(newFont); -} - -void ScatterDataModifier::shadowQualityUpdatedByVisual(QDataVis::ShadowQuality sq) -{ - int quality = int(sq); - // Updates the UI component to show correct shadow quality - emit shadowQualityChanged(quality); -} - -void ScatterDataModifier::changeShadowQuality(int quality) -{ - QDataVis::ShadowQuality sq = QDataVis::ShadowQuality(quality); - m_chart->setShadowQuality(sq); - emit shadowQualityChanged(quality); -} - -void ScatterDataModifier::setBackgroundEnabled(int enabled) -{ - m_chart->setBackgroundVisible((bool)enabled); -} - -void ScatterDataModifier::setGridEnabled(int enabled) -{ - m_chart->setGridVisible((bool)enabled); -} - -QVector3D ScatterDataModifier::randVector() -{ - return QVector3D( - (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f, - (float)(rand() % 100) / 100.0f - (float)(rand() % 100) / 100.0f, - (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f); -} diff --git a/examples/scatterchart/scatterchart.h b/examples/scatterchart/scatterchart.h deleted file mode 100644 index f67a0e88..00000000 --- a/examples/scatterchart/scatterchart.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 SCATTERDATAMODIFIER_H -#define SCATTERDATAMODIFIER_H - -#include -#include - -using namespace QtDataVisualization; - -class ScatterDataModifier : public QObject -{ - Q_OBJECT -public: - explicit ScatterDataModifier(Q3DScatter *scatter); - ~ScatterDataModifier(); - - void addData(); - void changeStyle(); - void changePresetCamera(); - void changeLabelStyle(); - void changeFont(const QFont &font); - void changeFontSize(int fontsize); - void setBackgroundEnabled(int enabled); - void setGridEnabled(int enabled); - void setSmoothDots(int smooth); - void start(); - -public slots: - void changeStyle(int style); - void changeTheme(int theme); - void changeShadowQuality(int quality); - void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality); - -signals: - void shadowQualityChanged(int quality); - -private: - QVector3D randVector(); - Q3DScatter *m_chart; - int m_fontSize; - QDataVis::MeshStyle m_style; - bool m_smooth; -}; - -#endif diff --git a/examples/scatterchart/scatterchart.pro b/examples/scatterchart/scatterchart.pro deleted file mode 100644 index 5dee59fd..00000000 --- a/examples/scatterchart/scatterchart.pro +++ /dev/null @@ -1,10 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -SOURCES += main.cpp scatterchart.cpp -HEADERS += scatterchart.h - -QT += widgets - -INSTALLS += target diff --git a/examples/surfacechart/Heightmap.png b/examples/surfacechart/Heightmap.png deleted file mode 100644 index 2a860111..00000000 Binary files a/examples/surfacechart/Heightmap.png and /dev/null differ diff --git a/examples/surfacechart/chartmodifier.cpp b/examples/surfacechart/chartmodifier.cpp deleted file mode 100644 index b0115fd3..00000000 --- a/examples/surfacechart/chartmodifier.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "chartmodifier.h" -#include -#include - -#include -#include -#include - -QT_DATAVISUALIZATION_USE_NAMESPACE - -//#define JITTER_PLANE -//#define WONKY_PLANE - -ChartModifier::ChartModifier(Q3DSurface *chart) - : m_chart(chart), - m_gridSliderX(0), - m_gridSliderZ(0), - m_axisRangeSliderX(0), - m_axisRangeSliderZ(0), - m_axisMinSliderX(0), - m_axisMinSliderZ(0), - m_xCount(50), - m_zCount(50), - m_activeSample(0), - m_fontSize(40), - m_rangeX(16.0), - m_rangeZ(16.0), - m_minX(-8.0), - m_minZ(-8.0), - m_planeArray(0) -{ - m_chart->setAxisX(new Q3DValueAxis); - m_chart->setAxisY(new Q3DValueAxis); - m_chart->setAxisZ(new Q3DValueAxis); - m_chart->axisX()->setRange(m_minX, m_minX + m_rangeX); - m_chart->axisZ()->setRange(m_minZ, m_minZ + m_rangeZ); - changeStyle(); - - connect(&m_timer, &QTimer::timeout, this, &ChartModifier::timeout); -} - -ChartModifier::~ChartModifier() -{ - delete m_chart; -} - -void ChartModifier::toggleSmooth(bool enabled) -{ - qDebug() << "ChartModifier::toggleSmooth " << enabled; - m_chart->setSmoothSurfaceEnabled(enabled); -} - -void ChartModifier::toggleSurfaceGrid(bool enable) -{ - qDebug() << "ChartModifier::toggleSurfaceGrid" << enable; - m_chart->setSurfaceGridEnabled(enable); -} - -void ChartModifier::toggleSqrtSin(bool enable) -{ - if (enable) { - qDebug() << "Create Sqrt&Sin surface, (" << m_xCount << ", " << m_zCount << ")"; - - float minX = -10.0; - float maxX = 10.0; - float minZ = -10.0; - float maxZ = 10.0; - float stepX = (maxX - minX) / float(m_xCount - 1); - float stepZ = (maxZ - minZ) / float(m_zCount - 1); - - QSurfaceDataArray *dataArray = new QSurfaceDataArray; - dataArray->reserve(m_zCount); - for (float i = 0; i < m_zCount; i++) { - QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); - for (float j = 0; j < m_xCount; j++) { - float x = j * stepX + minX; - float z = i * stepZ + minZ; - float R = qSqrt(x * x + z * z) + 0.01f; - float y = (qSin(R) / R + 0.24f) * 1.61f + 1.0f; - (*newRow)[j].setPosition(QVector3D(x, y, z)); - qDebug() << x << y << z; - } - *dataArray << newRow; - } - - m_chart->axisY()->setRange(1.0, 3.0); - m_chart->axisX()->setLabelFormat("%.2f"); - m_chart->axisZ()->setLabelFormat("%.2f"); - - resetArrayAndSliders(dataArray, minZ, maxZ, minX, maxX); - - m_activeSample = ChartModifier::SqrtSin; - } else { - qDebug() << "Remove surface"; - } -} - -void ChartModifier::togglePlane(bool enable) -{ - qDebug() << "ChartModifier::togglePlane " << enable; - - if (enable) { - m_planeArray = new QSurfaceDataArray; - -#ifdef JITTER_PLANE - m_timer.start(0); -#endif - m_chart->axisY()->setRange(0.0, 1.0); - m_chart->axisX()->setLabelFormat("%.2f"); - m_chart->axisZ()->setLabelFormat("%.2f"); - - m_planeArray->reserve(m_zCount); - float minX = -10.0; - float maxX = 20.0; - float minZ = -10.0; - float maxZ = 10.0; - float stepX = (maxX - minX) / float(m_xCount - 1); - float stepZ = (maxZ - minZ) / float(m_zCount - 1); -#ifdef WONKY_PLANE - float halfZ = m_zCount / 2; - float wonkyFactor = 0.01f; - float maxStepX = 0.0f; - for (float i = 0; i < m_zCount; i++) { - QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); - if (i < halfZ) { - stepX += wonkyFactor; - maxStepX = stepX; - } else { - stepX -= wonkyFactor; - } - for (float j = 0; j < m_xCount; j++) { - (*newRow)[j].setPosition(QVector3D(j * stepX + minX, -0.04f, - i * stepZ + minZ)); - - } - *m_planeArray << newRow; - } - - resetArrayAndSliders(m_planeArray, minZ, maxZ, minX, m_xCount * maxStepX + minZ); -#else - for (float i = 0; i < m_zCount; i++) { - QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); - for (float j = 0; j < m_xCount; j++) - (*newRow)[j].setPosition(QVector3D(j * stepX + minX, -0.04f, i * stepZ + minZ)); - - *m_planeArray << newRow; - } - - resetArrayAndSliders(m_planeArray, minZ, maxZ, minX, maxX); -#endif - - m_activeSample = ChartModifier::Plane; - } -#ifdef JITTER_PLANE - else { - m_timer.stop(); - } -#endif -} - -void ChartModifier::setHeightMapData(bool enable) -{ - if (enable) { - // Do the height map the hard way. - // Easier alternative would be to use the QHeightMapSurfaceDataProxy. - QImage image(":/maps/map"); - - QSurfaceDataArray *dataArray = new QSurfaceDataArray; - uchar *bits = image.bits(); - - int p = image.width() * 4 * (image.height() - 1); - dataArray->reserve(image.height()); - float minX = 34.0; - float maxX = 40.0; - float minZ = 18.0; - float maxZ = 24.0; - float xMul = (maxX - minX) / float(image.width() - 1); - float zMul = (maxZ - minZ) / float(image.height() - 1); - for (int i = 0; i < image.height(); i++, p -= image.width() * 4) { - QSurfaceDataRow *newRow = new QSurfaceDataRow(image.width()); - for (int j = 0; j < image.width(); j++) { - (*newRow)[j].setPosition(QVector3D((float(j) * xMul) + minX, - (float(bits[p + (j * 4)]) + 1.0f) / 1.0f, - (float(i) * zMul) + minZ)); - } - *dataArray << newRow; - } - - m_chart->axisY()->setAutoAdjustRange(true); - m_chart->axisX()->setLabelFormat("%.1f N"); - m_chart->axisZ()->setLabelFormat("%.1f E"); - - resetArrayAndSliders(dataArray, minZ, maxZ, minX, maxX); - - m_activeSample = ChartModifier::Map; - } -} - -void ChartModifier::toggleGridSliderLock(bool enable) -{ - m_gridSlidersLocked = enable; - if (m_gridSlidersLocked) { - m_gridSliderZ->setEnabled(false); - m_gridSliderZ->setValue(m_gridSliderX->value()); - } else { - m_gridSliderZ->setEnabled(true); - } -} - -void ChartModifier::adjustXCount(int count) -{ - m_xCount = count; - if (m_gridSlidersLocked) - m_gridSliderZ->setValue(count); - - updateSamples(); - - qDebug() << "X count =" << count; -} - -void ChartModifier::adjustZCount(int count) -{ - m_zCount = count; - - updateSamples(); - - qDebug() << "Z count =" << count; -} - -void ChartModifier::adjustXRange(int range) -{ - m_rangeX = range; - m_chart->axisX()->setRange(m_minX, m_minX + m_rangeX); - - qDebug() << "X Range =" << range; -} - -void ChartModifier::adjustZRange(int range) -{ - m_rangeZ = range; - m_chart->axisZ()->setRange(m_minZ, m_minZ + m_rangeZ); - - qDebug() << "Z Range =" << range; -} - -void ChartModifier::adjustXMin(int min) -{ - m_minX = min; - m_chart->axisX()->setRange(m_minX, m_minX + m_rangeX); - - qDebug() << "X Minimum =" << min; -} - -void ChartModifier::adjustZMin(int min) -{ - m_minZ = min; - m_chart->axisZ()->setRange(m_minZ, m_minZ + m_rangeZ); - - qDebug() << "Z Minimum =" << min; -} - -void ChartModifier::gradientPressed() -{ - QLinearGradient gradient; - gradient.setColorAt(0.0, Qt::black); - gradient.setColorAt(0.33, Qt::blue); - gradient.setColorAt(0.67, Qt::red); - gradient.setColorAt(1.0, Qt::yellow); - m_chart->setGradient(gradient); -} - -void ChartModifier::changeFont(const QFont &font) -{ - QFont newFont = font; - newFont.setPointSizeF(m_fontSize); - m_chart->setFont(newFont); -} - -void ChartModifier::changeStyle() -{ - static int style = QDataVis::LabelStyleFromTheme; - - m_chart->setLabelStyle((QDataVis::LabelStyle)style); - - if (++style > QDataVis::LabelStyleTransparent) - style = QDataVis::LabelStyleOpaque; -} - -void ChartModifier::changeTheme(int theme) -{ - m_chart->setTheme((QDataVis::Theme)theme); -} - -void ChartModifier::timeout() -{ - int rows = m_planeArray->size(); - int columns = m_planeArray->at(0)->size(); - - // Induce minor random jitter to the existing plane array - for (int i = 0; i < rows; i++) { - for (int j = 0; j < columns; j++) { - (*m_planeArray->at(i))[j].setX(m_planeArray->at(i)->at(j).x() - * ((float((rand() % 10) + 5.0f) / 10000.0f) + 0.999f)); - (*m_planeArray->at(i))[j].setY(m_planeArray->at(i)->at(j).y() - * ((float((rand() % 10) + 5.0f) / 1000.0f) + 0.99f) + 0.0001f); - (*m_planeArray->at(i))[j].setZ(m_planeArray->at(i)->at(j).z() - * ((float((rand() % 10) + 5.0f) / 10000.0f) + 0.999f)); - } - } - - // Reset same array to make it redraw - m_chart->activeDataProxy()->resetArray(m_planeArray); -} - -void ChartModifier::resetArrayAndSliders(QSurfaceDataArray *array, qreal minZ, qreal maxZ, qreal minX, qreal maxX) -{ - m_axisMinSliderX->setValue(minX); - m_axisMinSliderZ->setValue(minZ); - m_axisRangeSliderX->setValue(maxX - minX); - m_axisRangeSliderZ->setValue(maxZ - minZ); - - m_chart->activeDataProxy()->resetArray(array); -} - -void ChartModifier::changeShadowQuality(int quality) -{ - QDataVis::ShadowQuality sq = QDataVis::ShadowQuality(quality); - m_chart->setShadowQuality(sq); -} - -void ChartModifier::changeSelectionMode(int mode) -{ - switch (mode) { - case 0: - qDebug() << "QDataVis::SelectionModeNone"; - m_chart->setSelectionMode(QDataVis::SelectionModeNone); - break; - case 1: - qDebug() << "QDataVis::SelectionModeItem"; - m_chart->setSelectionMode(QDataVis::SelectionModeItem); - break; - case 2: - qDebug() << "QDataVis::SelectionModeSliceRow"; - m_chart->setSelectionMode(QDataVis::SelectionModeSliceRow); - break; - case 3: - qDebug() << "QDataVis::SelectionModeSliceColumn"; - m_chart->setSelectionMode(QDataVis::SelectionModeSliceColumn); - break; - default: - qDebug() << __FUNCTION__ << " Unsupported selection mode."; - break; - } -} - -void ChartModifier::updateSamples() -{ - switch (m_activeSample) { - case SqrtSin: - toggleSqrtSin(true); - break; - - case Plane: - togglePlane(true); - break; - - default: - break; - } -} - diff --git a/examples/surfacechart/chartmodifier.h b/examples/surfacechart/chartmodifier.h deleted file mode 100644 index 083ceff7..00000000 --- a/examples/surfacechart/chartmodifier.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 CHARTMODIFIER_H -#define CHARTMODIFIER_H - -#include -#include -#include -#include - -using namespace QtDataVisualization; - -class ChartModifier : public QObject -{ - Q_OBJECT -public: - enum Samples { - SqrtSin = 1, - Plane, - Map - }; - - explicit ChartModifier(Q3DSurface *chart); - ~ChartModifier(); - - void toggleSmooth(bool enabled); - void toggleSurfaceGrid(bool enable); - void toggleSqrtSin(bool enable); - void togglePlane(bool enable); - void setHeightMapData(bool enable); - void toggleGridSliderLock(bool enable); - void setGridSliderX(QSlider *slider) { m_gridSliderX = slider; } - void setGridSliderZ(QSlider *slider) { m_gridSliderZ = slider; } - void setAxisRangeSliderX(QSlider *slider) { m_axisRangeSliderX = slider; } - void setAxisRangeSliderZ(QSlider *slider) { m_axisRangeSliderZ = slider; } - void setAxisMinSliderX(QSlider *slider) { m_axisMinSliderX = slider; } - void setAxisMinSliderZ(QSlider *slider) { m_axisMinSliderZ = slider; } - void adjustXCount(int count); - void adjustZCount(int count); - void adjustXRange(int range); - void adjustZRange(int range); - void adjustXMin(int min); - void adjustZMin(int min); - void updateSamples(); - void gradientPressed(); - void changeFont(const QFont &font); - void changeStyle(); - -public slots: - void changeShadowQuality(int quality); - void changeTheme(int theme); - void changeSelectionMode(int mode); - void timeout(); - -private: - void resetArrayAndSliders(QSurfaceDataArray *array, qreal minZ, qreal maxZ, qreal minX, - qreal maxX); - - Q3DSurface *m_chart; - QSlider *m_gridSliderX; - QSlider *m_gridSliderZ; - QSlider *m_axisRangeSliderX; - QSlider *m_axisRangeSliderZ; - QSlider *m_axisMinSliderX; - QSlider *m_axisMinSliderZ; - bool m_gridSlidersLocked; - int m_xCount; - int m_zCount; - int m_activeSample; - int m_fontSize; - qreal m_rangeX; - qreal m_rangeZ; - qreal m_minX; - qreal m_minZ; - QTimer m_timer; - QSurfaceDataArray *m_planeArray; -}; - -#endif // CHARTMODIFIER_H diff --git a/examples/surfacechart/main.cpp b/examples/surfacechart/main.cpp deleted file mode 100644 index 256f4e2d..00000000 --- a/examples/surfacechart/main.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "chartmodifier.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace QtDataVisualization; - -const int initialTheme = 4; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QWidget *widget = new QWidget; - QHBoxLayout *hLayout = new QHBoxLayout(widget); - QVBoxLayout *vLayout = new QVBoxLayout(); - vLayout->setAlignment(Qt::AlignTop); - - Q3DSurface *surfaceChart = new Q3DSurface(); - QSize screenSize = surfaceChart->screen()->size(); - - // Set to default, should be same as the initial on themeList - surfaceChart->setTheme(QDataVis::Theme(initialTheme)); - - QWidget *container = QWidget::createWindowContainer(surfaceChart); - container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 2)); - container->setMaximumSize(screenSize); - container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - container->setFocusPolicy(Qt::StrongFocus); - - widget->setWindowTitle(QStringLiteral("Surface tester")); - - hLayout->addWidget(container, 1); - hLayout->addLayout(vLayout); - - QCheckBox *smoothCB = new QCheckBox(widget); - smoothCB->setText(QStringLiteral("Smooth ")); - smoothCB->setChecked(surfaceChart->isSmoothSurfaceEnabled()); - - QCheckBox *surfaceGridCB = new QCheckBox(widget); - surfaceGridCB->setText(QStringLiteral("Surface Grid")); - surfaceGridCB->setChecked(true); - - //QCheckBox *sqrtSinCB = new QCheckBox(widget); - QRadioButton *sqrtSinCB = new QRadioButton(widget); - sqrtSinCB->setText(QStringLiteral("Sqrt & Sin")); - sqrtSinCB->setChecked(false); - - QRadioButton *planeCB = new QRadioButton(widget); - planeCB->setText(QStringLiteral("Plane")); - planeCB->setChecked(false); - - QRadioButton *heightMapCB = new QRadioButton(widget); - heightMapCB->setText(QStringLiteral("Height map")); - heightMapCB->setChecked(false); - - QCheckBox *gridSlidersLockCB = new QCheckBox(widget); - gridSlidersLockCB->setText(QStringLiteral("Lock")); - gridSlidersLockCB->setChecked(false); - - QSlider *gridSliderX = new QSlider(Qt::Horizontal, widget); - gridSliderX->setTickInterval(1); - gridSliderX->setMinimum(2); - gridSliderX->setValue(30); - gridSliderX->setMaximum(200); - gridSliderX->setEnabled(true); - QSlider *gridSliderZ = new QSlider(Qt::Horizontal, widget); - gridSliderZ->setTickInterval(1); - gridSliderZ->setMinimum(2); - gridSliderZ->setValue(30); - gridSliderZ->setMaximum(200); - gridSliderZ->setEnabled(true); - - QSlider *axisRangeSliderX = new QSlider(Qt::Horizontal, widget); - axisRangeSliderX->setTickInterval(1); - axisRangeSliderX->setMinimum(2); - axisRangeSliderX->setValue(16); - axisRangeSliderX->setMaximum(100); - axisRangeSliderX->setEnabled(true); - QSlider *axisRangeSliderZ = new QSlider(Qt::Horizontal, widget); - axisRangeSliderZ->setTickInterval(1); - axisRangeSliderZ->setMinimum(2); - axisRangeSliderZ->setValue(16); - axisRangeSliderZ->setMaximum(100); - axisRangeSliderZ->setEnabled(true); - - QSlider *axisMinSliderX = new QSlider(Qt::Horizontal, widget); - axisMinSliderX->setTickInterval(1); - axisMinSliderX->setMinimum(-50); - axisMinSliderX->setValue(-8); - axisMinSliderX->setMaximum(50); - axisMinSliderX->setEnabled(true); - QSlider *axisMinSliderZ = new QSlider(Qt::Horizontal, widget); - axisMinSliderZ->setTickInterval(1); - axisMinSliderZ->setMinimum(-50); - axisMinSliderZ->setValue(-8); - axisMinSliderZ->setMaximum(50); - axisMinSliderZ->setEnabled(true); - - QLinearGradient gr(0, 0, 100, 1); - gr.setColorAt(0.0, Qt::black); - gr.setColorAt(0.33, Qt::blue); - gr.setColorAt(0.67, Qt::red); - gr.setColorAt(1.0, Qt::yellow); - QPixmap pm(100, 24); - QPainter pmp(&pm); - pmp.setBrush(QBrush(gr)); - pmp.setPen(Qt::NoPen); - pmp.drawRect(0, 0, 100, 24); - QPushButton *colorPB = new QPushButton(); - colorPB->setIcon(QIcon(pm)); - colorPB->setIconSize(QSize(100, 24)); - - QFontComboBox *fontList = new QFontComboBox(widget); - fontList->setCurrentFont(QFont("Arial")); - - QPushButton *labelButton = new QPushButton(widget); - labelButton->setText(QStringLiteral("Change label style")); - - QComboBox *themeList = new QComboBox(widget); - themeList->addItem(QStringLiteral("Qt")); - themeList->addItem(QStringLiteral("Primary Colors")); - themeList->addItem(QStringLiteral("Digia")); - themeList->addItem(QStringLiteral("Stone Moss")); - themeList->addItem(QStringLiteral("Army Blue")); - themeList->addItem(QStringLiteral("Retro")); - themeList->addItem(QStringLiteral("Ebony")); - themeList->addItem(QStringLiteral("Isabelle")); - themeList->setCurrentIndex(initialTheme); - -// QComboBox *shadowQuality = new QComboBox(widget); -// shadowQuality->addItem(QStringLiteral("None")); -// shadowQuality->addItem(QStringLiteral("Low")); -// shadowQuality->addItem(QStringLiteral("Medium")); -// shadowQuality->addItem(QStringLiteral("High")); -// shadowQuality->addItem(QStringLiteral("Low Soft")); -// shadowQuality->addItem(QStringLiteral("Medium Soft")); -// shadowQuality->addItem(QStringLiteral("High Soft")); -// shadowQuality->setCurrentIndex(3); - QComboBox *selectionMode = new QComboBox(widget); - selectionMode->addItem(QStringLiteral("SelectionModeNone")); - selectionMode->addItem(QStringLiteral("SelectionModeItem")); - selectionMode->addItem(QStringLiteral("SelectionModeSliceRow")); - selectionMode->addItem(QStringLiteral("SelectionModeSliceColumn")); - selectionMode->setCurrentIndex(1); - - // Add controls to the layout - vLayout->addWidget(smoothCB); - vLayout->addWidget(surfaceGridCB); - vLayout->addWidget(new QLabel(QStringLiteral("Select surface sample"))); - vLayout->addWidget(sqrtSinCB); - vLayout->addWidget(planeCB); - vLayout->addWidget(heightMapCB); - vLayout->addWidget(new QLabel(QStringLiteral("Adjust sample count"))); - vLayout->addWidget(gridSlidersLockCB); - vLayout->addWidget(gridSliderX); - vLayout->addWidget(gridSliderZ); - vLayout->addWidget(new QLabel(QStringLiteral("Adjust axis range"))); - vLayout->addWidget(axisRangeSliderX); - vLayout->addWidget(axisRangeSliderZ); - vLayout->addWidget(new QLabel(QStringLiteral("Adjust axis minimum"))); - vLayout->addWidget(axisMinSliderX); - vLayout->addWidget(axisMinSliderZ); - vLayout->addWidget(colorPB); - vLayout->addWidget(new QLabel(QStringLiteral("Change font"))); - vLayout->addWidget(fontList); - vLayout->addWidget(labelButton); - vLayout->addWidget(new QLabel(QStringLiteral("Change theme"))); - vLayout->addWidget(themeList); -// vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality"))); -// vLayout->addWidget(shadowQuality); - vLayout->addWidget(new QLabel(QStringLiteral("Selection Mode"))); - vLayout->addWidget(selectionMode); - - widget->show(); - - ChartModifier *modifier = new ChartModifier(surfaceChart); - - // Connect controls to slots on modifier - QObject::connect(smoothCB, &QCheckBox::stateChanged, - modifier, &ChartModifier::toggleSmooth); - QObject::connect(surfaceGridCB, &QCheckBox::stateChanged, - modifier, &ChartModifier::toggleSurfaceGrid); - QObject::connect(sqrtSinCB, &QRadioButton::toggled, - modifier, &ChartModifier::toggleSqrtSin); - QObject::connect(planeCB, &QCheckBox::toggled, - modifier, &ChartModifier::togglePlane); - QObject::connect(heightMapCB, &QCheckBox::toggled, - modifier, &ChartModifier::setHeightMapData); - QObject::connect(gridSlidersLockCB, &QCheckBox::stateChanged, - modifier, &ChartModifier::toggleGridSliderLock); - QObject::connect(gridSliderX, &QSlider::valueChanged, - modifier, &ChartModifier::adjustXCount); - QObject::connect(gridSliderZ, &QSlider::valueChanged, - modifier, &ChartModifier::adjustZCount); - QObject::connect(axisRangeSliderX, &QSlider::valueChanged, - modifier, &ChartModifier::adjustXRange); - QObject::connect(axisRangeSliderZ, &QSlider::valueChanged, - modifier, &ChartModifier::adjustZRange); - QObject::connect(axisMinSliderX, &QSlider::valueChanged, - modifier, &ChartModifier::adjustXMin); - QObject::connect(axisMinSliderZ, &QSlider::valueChanged, - modifier, &ChartModifier::adjustZMin); - QObject::connect(colorPB, &QPushButton::pressed, - modifier, &ChartModifier::gradientPressed); - QObject::connect(fontList, &QFontComboBox::currentFontChanged, - modifier, &ChartModifier::changeFont); - QObject::connect(labelButton, &QPushButton::clicked, - modifier, &ChartModifier::changeStyle); - QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), - modifier, SLOT(changeTheme(int))); -// QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), -// modifier, SLOT(changeShadowQuality(int))); - QObject::connect(selectionMode, SIGNAL(currentIndexChanged(int)), - modifier, SLOT(changeSelectionMode(int))); - - modifier->setGridSliderZ(gridSliderZ); - modifier->setGridSliderX(gridSliderX); - modifier->setAxisRangeSliderX(axisRangeSliderX); - modifier->setAxisRangeSliderZ(axisRangeSliderZ); - modifier->setAxisMinSliderX(axisMinSliderX); - modifier->setAxisMinSliderZ(axisMinSliderZ); - modifier->toggleGridSliderLock(gridSlidersLockCB->checkState()); - sqrtSinCB->setChecked(true); - - return app.exec(); -} diff --git a/examples/surfacechart/surface.qrc b/examples/surfacechart/surface.qrc deleted file mode 100644 index c18da2c4..00000000 --- a/examples/surfacechart/surface.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - Heightmap.png - - diff --git a/examples/surfacechart/surfacechart.pro b/examples/surfacechart/surfacechart.pro deleted file mode 100644 index 2ebc90da..00000000 --- a/examples/surfacechart/surfacechart.pro +++ /dev/null @@ -1,16 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -SOURCES += main.cpp \ - chartmodifier.cpp - -QT += widgets - -INSTALLS += target - -HEADERS += \ - chartmodifier.h - -RESOURCES += \ - surface.qrc diff --git a/examples/widget/chart.cpp b/examples/widget/chart.cpp deleted file mode 100644 index 50f2535a..00000000 --- a/examples/widget/chart.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "chart.h" -#include -#include -#include -#include - -QT_DATAVISUALIZATION_USE_NAMESPACE - -const QString celsiusString = QString(QChar(0xB0)) + "C"; - -ChartModifier::ChartModifier(Q3DBars *barchart) - : m_chart(barchart), - m_xRotation(0.0), - m_yRotation(0.0), - m_fontSize(20), - m_segments(4), - m_subSegments(3), - m_minval(-20.0), // TODO Barchart Y-axis currently only properly supports zero-centered ranges - m_maxval(20.0), - m_temperatureAxis(new Q3DValueAxis), - m_yearAxis(new Q3DCategoryAxis), - m_monthAxis(new Q3DCategoryAxis), - m_temperatureData(new QBarDataProxy), - m_style(QDataVis::MeshStyleBevelBars), - m_smooth(false) -{ - m_months << "January" << "February" << "March" << "April" << "May" << "June" << "July" << "August" << "September" << "October" << "November" << "December"; - m_years << "2006" << "2007" << "2008" << "2009" << "2010" << "2011" << "2012"; - - m_chart->setBackgroundVisible(false); - - m_temperatureAxis->setTitle("Average temperature"); - m_temperatureAxis->setSegmentCount(m_segments); - m_temperatureAxis->setSubSegmentCount(m_subSegments); - m_temperatureAxis->setRange(m_minval, m_maxval); - m_temperatureAxis->setLabelFormat(QString(QStringLiteral("%d ") + celsiusString)); - - m_yearAxis->setTitle("Year"); - - m_monthAxis->setTitle("Month"); - - m_chart->addAxis(m_temperatureAxis); - m_chart->addAxis(m_yearAxis); - m_chart->addAxis(m_monthAxis); - - m_chart->setShadowQuality(QDataVis::ShadowQualitySoftMedium); - - m_temperatureData->setItemLabelFormat(QStringLiteral("@valueTitle for @colLabel @rowLabel: @valueLabel")); - - m_chart->addDataProxy(m_temperatureData); - - m_chart->setFont(QFont("Times Roman", 20)); - - m_chart->setSelectionMode(QDataVis::SelectionModeItem); - - resetTemperatureData(); -} - -ChartModifier::~ChartModifier() -{ - delete m_chart; -} - -void ChartModifier::start() -{ - m_chart->setActiveDataProxy(m_temperatureData); - - m_chart->setTitle(QStringLiteral("Average temperatures in Oulu, Finland (2006-2012)")); - - m_chart->setValueAxis(m_temperatureAxis); - m_chart->setRowAxis(m_yearAxis); - m_chart->setColumnAxis(m_monthAxis); -} - -void ChartModifier::resetTemperatureData() -{ - // Set up data - static const qreal temp[7][12] = { - {-6.7, -11.7, -9.7, 3.3, 9.2, 14.0, 16.3, 17.8, 10.2, 2.1, -2.6, -0.3}, // 2006 - {-6.8, -13.3, 0.2, 1.5, 7.9, 13.4, 16.1, 15.5, 8.2, 5.4, -2.6, -0.8}, // 2007 - {-4.2, -4.0, -4.6, 1.9, 7.3, 12.5, 15.0, 12.8, 7.6, 5.1, -0.9, -1.3}, // 2008 - {-7.8, -8.8, -4.2, 0.7, 9.3, 13.2, 15.8, 15.5, 11.2, 0.6, 0.7, -8.4}, // 2009 - {-14.4, -12.1, -7.0, 2.3, 11.0, 12.6, 18.8, 13.8, 9.4, 3.9, -5.6, -13.0}, // 2010 - {-9.0, -15.2, -3.8, 2.6, 8.3, 15.9, 18.6, 14.9, 11.1, 5.3, 1.8, -0.2}, // 2011 - {-8.7, -11.3, -2.3, 0.4, 7.5, 12.2, 16.4, 14.1, 9.2, 3.1, 0.3, -12.1} // 2012 - }; - - // Create data rows - QBarDataArray *dataSet = new QBarDataArray; - QBarDataRow *dataRow; - - dataSet->reserve(m_years.size()); - for (int year = 0; year < m_years.size(); year++) { - dataRow = new QBarDataRow(m_months.size()); - // Create data items - for (int month = 0; month < m_months.size(); month++) { - // Add data to rows - (*dataRow)[month].setValue(temp[year][month]); - } - // Add row to set - dataSet->append(dataRow); - } - - // Add data to chart (chart assumes ownership) - m_temperatureData->resetArray(dataSet, m_years, m_months); -} - -void ChartModifier::changeStyle(int style) -{ - m_style = QDataVis::MeshStyle(style); - m_chart->setBarType(m_style, m_smooth); -} - -void ChartModifier::changePresetCamera() -{ - static int preset = QDataVis::CameraPresetFrontLow; - - m_chart->setCameraPreset((QDataVis::CameraPreset)preset); - - if (++preset > QDataVis::CameraPresetDirectlyBelow) - preset = QDataVis::CameraPresetFrontLow; -} - -void ChartModifier::changeTheme(int theme) -{ - m_chart->setTheme((QDataVis::Theme)theme); -} - -void ChartModifier::changeLabelStyle() -{ - static int style = QDataVis::LabelStyleOpaque; - - m_chart->setLabelStyle((QDataVis::LabelStyle)style); - - if (++style > QDataVis::LabelStyleTransparent) - style = QDataVis::LabelStyleOpaque; -} - -void ChartModifier::changeSelectionMode(int selectionMode) -{ - m_chart->setSelectionMode((QDataVis::SelectionMode)selectionMode); -} - -void ChartModifier::changeFont(const QFont &font) -{ - QFont newFont = font; - newFont.setPointSize(m_fontSize); - m_chart->setFont(newFont); -} - -void ChartModifier::changeFontSize(int fontsize) -{ - m_fontSize = fontsize; - QFont font = m_chart->font(); - font.setPointSize(m_fontSize); - m_chart->setFont(font); -} - -void ChartModifier::shadowQualityUpdatedByVisual(QDataVis::ShadowQuality sq) -{ - int quality = int(sq); - // Updates the UI component to show correct shadow quality - emit shadowQualityChanged(quality); -} - -void ChartModifier::changeShadowQuality(int quality) -{ - QDataVis::ShadowQuality sq = QDataVis::ShadowQuality(quality); - m_chart->setShadowQuality(sq); - emit shadowQualityChanged(quality); -} - -void ChartModifier::rotateX(int rotation) -{ - m_xRotation = rotation; - m_chart->setCameraPosition(m_xRotation, m_yRotation); -} - -void ChartModifier::rotateY(int rotation) -{ - m_yRotation = rotation; - m_chart->setCameraPosition(m_xRotation, m_yRotation); -} - -void ChartModifier::setBackgroundEnabled(int enabled) -{ - m_chart->setBackgroundVisible((bool)enabled); -} - -void ChartModifier::setGridEnabled(int enabled) -{ - m_chart->setGridVisible((bool)enabled); -} - -void ChartModifier::setSmoothBars(int smooth) -{ - m_smooth = bool(smooth); - m_chart->setBarType(m_style, m_smooth); -} diff --git a/examples/widget/chart.h b/examples/widget/chart.h deleted file mode 100644 index 51a8d5e0..00000000 --- a/examples/widget/chart.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 CHARTMODIFIER_H -#define CHARTMODIFIER_H - -#include - -#include -#include -#include -#include - -using namespace QtDataVisualization; - -class ChartModifier : public QObject -{ - Q_OBJECT -public: - explicit ChartModifier(Q3DBars *barchart); - ~ChartModifier(); - - void resetTemperatureData(); - void changePresetCamera(); - void changeLabelStyle(); - void changeFont(const QFont &font); - void changeFontSize(int fontsize); - void rotateX(int rotation); - void rotateY(int rotation); - void setBackgroundEnabled(int enabled); - void setGridEnabled(int enabled); - void setSmoothBars(int smooth); - void start(); - -public slots: - void changeStyle(int style); - void changeSelectionMode(int selectionMode); - void changeTheme(int theme); - void changeShadowQuality(int quality); - void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality); - -signals: - void shadowQualityChanged(int quality); - -private: - Q3DBars *m_chart; - qreal m_xRotation; - qreal m_yRotation; - int m_fontSize; - int m_segments; - int m_subSegments; - qreal m_minval; - qreal m_maxval; - QStringList m_months; - QStringList m_years; - Q3DValueAxis *m_temperatureAxis; - Q3DCategoryAxis *m_yearAxis; - Q3DCategoryAxis *m_monthAxis; - QBarDataProxy *m_temperatureData; - QDataVis::MeshStyle m_style; - bool m_smooth; -}; - -#endif diff --git a/examples/widget/doc/src/widget.qdoc b/examples/widget/doc/src/widget.qdoc index d76df2b5..e0c0f14b 100644 --- a/examples/widget/doc/src/widget.qdoc +++ b/examples/widget/doc/src/widget.qdoc @@ -20,7 +20,7 @@ \example widget \title Widget Example - The widget example shows how to make a 3D bar chart using Q3DBars and combining the use of + The widget example shows how to make a 3D bar graph using Q3DBars and combining the use of widgets for adjusting several adjustable qualities. \image widget-example.png diff --git a/examples/widget/graphmodifier.cpp b/examples/widget/graphmodifier.cpp new file mode 100644 index 00000000..7da3000b --- /dev/null +++ b/examples/widget/graphmodifier.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 "graphmodifier.h" +#include +#include +#include +#include + +QT_DATAVISUALIZATION_USE_NAMESPACE + +const QString celsiusString = QString(QChar(0xB0)) + "C"; + +GraphModifier::GraphModifier(Q3DBars *bargraph) + : m_graph(bargraph), + m_xRotation(0.0), + m_yRotation(0.0), + m_fontSize(20), + m_segments(4), + m_subSegments(3), + m_minval(-20.0), // TODO Bargraph Y-axis currently only properly supports zero-centered ranges + m_maxval(20.0), + m_temperatureAxis(new Q3DValueAxis), + m_yearAxis(new Q3DCategoryAxis), + m_monthAxis(new Q3DCategoryAxis), + m_temperatureData(new QBarDataProxy), + m_style(QDataVis::MeshStyleBevelBars), + m_smooth(false) +{ + m_months << "January" << "February" << "March" << "April" << "May" << "June" << "July" << "August" << "September" << "October" << "November" << "December"; + m_years << "2006" << "2007" << "2008" << "2009" << "2010" << "2011" << "2012"; + + m_graph->setBackgroundVisible(false); + + m_temperatureAxis->setTitle("Average temperature"); + m_temperatureAxis->setSegmentCount(m_segments); + m_temperatureAxis->setSubSegmentCount(m_subSegments); + m_temperatureAxis->setRange(m_minval, m_maxval); + m_temperatureAxis->setLabelFormat(QString(QStringLiteral("%d ") + celsiusString)); + + m_yearAxis->setTitle("Year"); + + m_monthAxis->setTitle("Month"); + + m_graph->addAxis(m_temperatureAxis); + m_graph->addAxis(m_yearAxis); + m_graph->addAxis(m_monthAxis); + + m_graph->setShadowQuality(QDataVis::ShadowQualitySoftMedium); + + m_temperatureData->setItemLabelFormat(QStringLiteral("@valueTitle for @colLabel @rowLabel: @valueLabel")); + + m_graph->addDataProxy(m_temperatureData); + + m_graph->setFont(QFont("Times Roman", 20)); + + m_graph->setSelectionMode(QDataVis::SelectionModeItem); + + resetTemperatureData(); + changeLabelStyle(); +} + +GraphModifier::~GraphModifier() +{ + delete m_graph; +} + +void GraphModifier::start() +{ + m_graph->setActiveDataProxy(m_temperatureData); + + m_graph->setTitle(QStringLiteral("Average temperatures in Oulu, Finland (2006-2012)")); + + m_graph->setValueAxis(m_temperatureAxis); + m_graph->setRowAxis(m_yearAxis); + m_graph->setColumnAxis(m_monthAxis); +} + +void GraphModifier::resetTemperatureData() +{ + // Set up data + static const qreal temp[7][12] = { + {-6.7, -11.7, -9.7, 3.3, 9.2, 14.0, 16.3, 17.8, 10.2, 2.1, -2.6, -0.3}, // 2006 + {-6.8, -13.3, 0.2, 1.5, 7.9, 13.4, 16.1, 15.5, 8.2, 5.4, -2.6, -0.8}, // 2007 + {-4.2, -4.0, -4.6, 1.9, 7.3, 12.5, 15.0, 12.8, 7.6, 5.1, -0.9, -1.3}, // 2008 + {-7.8, -8.8, -4.2, 0.7, 9.3, 13.2, 15.8, 15.5, 11.2, 0.6, 0.7, -8.4}, // 2009 + {-14.4, -12.1, -7.0, 2.3, 11.0, 12.6, 18.8, 13.8, 9.4, 3.9, -5.6, -13.0}, // 2010 + {-9.0, -15.2, -3.8, 2.6, 8.3, 15.9, 18.6, 14.9, 11.1, 5.3, 1.8, -0.2}, // 2011 + {-8.7, -11.3, -2.3, 0.4, 7.5, 12.2, 16.4, 14.1, 9.2, 3.1, 0.3, -12.1} // 2012 + }; + + // Create data rows + QBarDataArray *dataSet = new QBarDataArray; + QBarDataRow *dataRow; + + dataSet->reserve(m_years.size()); + for (int year = 0; year < m_years.size(); year++) { + dataRow = new QBarDataRow(m_months.size()); + // Create data items + for (int month = 0; month < m_months.size(); month++) { + // Add data to rows + (*dataRow)[month].setValue(temp[year][month]); + } + // Add row to set + dataSet->append(dataRow); + } + + // Add data to the graph (the graph assumes ownership) + m_temperatureData->resetArray(dataSet, m_years, m_months); +} + +void GraphModifier::changeStyle(int style) +{ + m_style = QDataVis::MeshStyle(style); + m_graph->setBarType(m_style, m_smooth); +} + +void GraphModifier::changePresetCamera() +{ + static int preset = QDataVis::CameraPresetFrontLow; + + m_graph->setCameraPreset((QDataVis::CameraPreset)preset); + + if (++preset > QDataVis::CameraPresetDirectlyBelow) + preset = QDataVis::CameraPresetFrontLow; +} + +void GraphModifier::changeTheme(int theme) +{ + m_graph->setTheme((QDataVis::Theme)theme); +} + +void GraphModifier::changeLabelStyle() +{ + static int style = QDataVis::LabelStyleFromTheme; + + m_graph->setLabelStyle((QDataVis::LabelStyle)style); + + if (++style > QDataVis::LabelStyleTransparent) + style = QDataVis::LabelStyleOpaque; +} + +void GraphModifier::changeSelectionMode(int selectionMode) +{ + m_graph->setSelectionMode((QDataVis::SelectionMode)selectionMode); +} + +void GraphModifier::changeFont(const QFont &font) +{ + QFont newFont = font; + newFont.setPointSize(m_fontSize); + m_graph->setFont(newFont); +} + +void GraphModifier::changeFontSize(int fontsize) +{ + m_fontSize = fontsize; + QFont font = m_graph->font(); + font.setPointSize(m_fontSize); + m_graph->setFont(font); +} + +void GraphModifier::shadowQualityUpdatedByVisual(QDataVis::ShadowQuality sq) +{ + int quality = int(sq); + // Updates the UI component to show correct shadow quality + emit shadowQualityChanged(quality); +} + +void GraphModifier::changeShadowQuality(int quality) +{ + QDataVis::ShadowQuality sq = QDataVis::ShadowQuality(quality); + m_graph->setShadowQuality(sq); + emit shadowQualityChanged(quality); +} + +void GraphModifier::rotateX(int rotation) +{ + m_xRotation = rotation; + m_graph->setCameraPosition(m_xRotation, m_yRotation); +} + +void GraphModifier::rotateY(int rotation) +{ + m_yRotation = rotation; + m_graph->setCameraPosition(m_xRotation, m_yRotation); +} + +void GraphModifier::setBackgroundEnabled(int enabled) +{ + m_graph->setBackgroundVisible((bool)enabled); +} + +void GraphModifier::setGridEnabled(int enabled) +{ + m_graph->setGridVisible((bool)enabled); +} + +void GraphModifier::setSmoothBars(int smooth) +{ + m_smooth = bool(smooth); + m_graph->setBarType(m_style, m_smooth); +} diff --git a/examples/widget/graphmodifier.h b/examples/widget/graphmodifier.h new file mode 100644 index 00000000..2e18ffd2 --- /dev/null +++ b/examples/widget/graphmodifier.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 GRAPHMODIFIER_H +#define GRAPHMODIFIER_H + +#include + +#include +#include +#include +#include + +using namespace QtDataVisualization; + +class GraphModifier : public QObject +{ + Q_OBJECT +public: + explicit GraphModifier(Q3DBars *bargraph); + ~GraphModifier(); + + void resetTemperatureData(); + void changePresetCamera(); + void changeLabelStyle(); + void changeFont(const QFont &font); + void changeFontSize(int fontsize); + void rotateX(int rotation); + void rotateY(int rotation); + void setBackgroundEnabled(int enabled); + void setGridEnabled(int enabled); + void setSmoothBars(int smooth); + void start(); + +public slots: + void changeStyle(int style); + void changeSelectionMode(int selectionMode); + void changeTheme(int theme); + void changeShadowQuality(int quality); + void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality); + +signals: + void shadowQualityChanged(int quality); + +private: + Q3DBars *m_graph; + qreal m_xRotation; + qreal m_yRotation; + int m_fontSize; + int m_segments; + int m_subSegments; + qreal m_minval; + qreal m_maxval; + QStringList m_months; + QStringList m_years; + Q3DValueAxis *m_temperatureAxis; + Q3DCategoryAxis *m_yearAxis; + Q3DCategoryAxis *m_monthAxis; + QBarDataProxy *m_temperatureData; + QDataVis::MeshStyle m_style; + bool m_smooth; +}; + +#endif diff --git a/examples/widget/main.cpp b/examples/widget/main.cpp index 1a1645e5..c1bee4e5 100644 --- a/examples/widget/main.cpp +++ b/examples/widget/main.cpp @@ -16,7 +16,7 @@ ** ****************************************************************************/ -#include "chart.h" +#include "graphmodifier.h" #include #include @@ -38,10 +38,10 @@ int main(int argc, char **argv) QHBoxLayout *hLayout = new QHBoxLayout(widget); QVBoxLayout *vLayout = new QVBoxLayout(); - Q3DBars *widgetchart = new Q3DBars(); - QSize screenSize = widgetchart->screen()->size(); + Q3DBars *widgetgraph = new Q3DBars(); + QSize screenSize = widgetgraph->screen()->size(); - QWidget *container = QWidget::createWindowContainer(widgetchart); + QWidget *container = QWidget::createWindowContainer(widgetgraph); container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); container->setMaximumSize(screenSize); container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -153,22 +153,22 @@ int main(int argc, char **argv) widget->show(); - ChartModifier *modifier = new ChartModifier(widgetchart); + GraphModifier *modifier = new GraphModifier(widgetgraph); - QObject::connect(rotationSliderX, &QSlider::valueChanged, modifier, &ChartModifier::rotateX); - QObject::connect(rotationSliderY, &QSlider::valueChanged, modifier, &ChartModifier::rotateY); + QObject::connect(rotationSliderX, &QSlider::valueChanged, modifier, &GraphModifier::rotateX); + QObject::connect(rotationSliderY, &QSlider::valueChanged, modifier, &GraphModifier::rotateY); QObject::connect(labelButton, &QPushButton::clicked, modifier, - &ChartModifier::changeLabelStyle); + &GraphModifier::changeLabelStyle); QObject::connect(cameraButton, &QPushButton::clicked, modifier, - &ChartModifier::changePresetCamera); + &GraphModifier::changePresetCamera); QObject::connect(backgroundCheckBox, &QCheckBox::stateChanged, modifier, - &ChartModifier::setBackgroundEnabled); + &GraphModifier::setBackgroundEnabled); QObject::connect(gridCheckBox, &QCheckBox::stateChanged, modifier, - &ChartModifier::setGridEnabled); + &GraphModifier::setGridEnabled); QObject::connect(smoothCheckBox, &QCheckBox::stateChanged, modifier, - &ChartModifier::setSmoothBars); + &GraphModifier::setSmoothBars); QObject::connect(barStyleList, SIGNAL(currentIndexChanged(int)), modifier, SLOT(changeStyle(int))); @@ -182,15 +182,15 @@ int main(int argc, char **argv) QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), modifier, SLOT(changeShadowQuality(int))); - QObject::connect(modifier, &ChartModifier::shadowQualityChanged, shadowQuality, + QObject::connect(modifier, &GraphModifier::shadowQualityChanged, shadowQuality, &QComboBox::setCurrentIndex); - QObject::connect(widgetchart, &Q3DBars::shadowQualityChanged, modifier, - &ChartModifier::shadowQualityUpdatedByVisual); + QObject::connect(widgetgraph, &Q3DBars::shadowQualityChanged, modifier, + &GraphModifier::shadowQualityUpdatedByVisual); QObject::connect(fontSizeSlider, &QSlider::valueChanged, modifier, - &ChartModifier::changeFontSize); + &GraphModifier::changeFontSize); QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier, - &ChartModifier::changeFont); + &GraphModifier::changeFont); modifier->start(); diff --git a/examples/widget/widget.pro b/examples/widget/widget.pro index 2b4078a4..c9feb187 100644 --- a/examples/widget/widget.pro +++ b/examples/widget/widget.pro @@ -2,9 +2,13 @@ error( "Couldn't find the examples.pri file!" ) } -SOURCES += main.cpp chart.cpp -HEADERS += chart.h +SOURCES += main.cpp graphmodifier.cpp +HEADERS += graphmodifier.h QT += widgets INSTALLS += target + +OTHER_FILES += doc/src/* \ + doc/images/* + -- cgit v1.2.3