diff options
author | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2015-09-29 16:49:21 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2015-10-01 07:51:24 +0000 |
commit | 77545ecc2ba87e0b870f3f838727983210e6b236 (patch) | |
tree | 4bf54c907e8b474e98e18cb8a98792e3e6b83c9d /tests/manual | |
parent | e0808a4007f567c644ab0a87815c98e8985fcadc (diff) |
Added a manual test application for OpenGL series
Change-Id: I9e6a1b970a05ce550247fe6023fca11570fcf0f2
Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/manual.pro | 3 | ||||
-rw-r--r-- | tests/manual/openglseriestest/chartview.cpp | 54 | ||||
-rw-r--r-- | tests/manual/openglseriestest/chartview.h | 35 | ||||
-rw-r--r-- | tests/manual/openglseriestest/datasource.cpp | 112 | ||||
-rw-r--r-- | tests/manual/openglseriestest/datasource.h | 55 | ||||
-rw-r--r-- | tests/manual/openglseriestest/main.cpp | 29 | ||||
-rw-r--r-- | tests/manual/openglseriestest/mainwindow.cpp | 515 | ||||
-rw-r--r-- | tests/manual/openglseriestest/mainwindow.h | 106 | ||||
-rw-r--r-- | tests/manual/openglseriestest/mainwindow.ui | 582 | ||||
-rw-r--r-- | tests/manual/openglseriestest/openglseriestest.pro | 19 |
10 files changed, 1509 insertions, 1 deletions
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 5f2b85b1..25545aeb 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -7,7 +7,8 @@ SUBDIRS += \ contains(QT_CONFIG, opengl) { SUBDIRS += chartwidgettest \ wavechart \ - chartviewer + chartviewer \ + openglseriestest } else { message("OpenGL not available. Some test apps are disabled") } diff --git a/tests/manual/openglseriestest/chartview.cpp b/tests/manual/openglseriestest/chartview.cpp new file mode 100644 index 00000000..578d1b34 --- /dev/null +++ b/tests/manual/openglseriestest/chartview.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#include "chartview.h" +#include <QtGui/QMouseEvent> + +QT_CHARTS_USE_NAMESPACE + +ChartView::ChartView(QWidget *parent) : + QChartView(parent) +{ +} + +void ChartView::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Plus: + chart()->zoomIn(); + break; + case Qt::Key_Minus: + chart()->zoomOut(); + break; + case Qt::Key_Left: + chart()->scroll(-1.0, 0); + break; + case Qt::Key_Right: + chart()->scroll(1.0, 0); + break; + case Qt::Key_Up: + chart()->scroll(0, 1.0); + break; + case Qt::Key_Down: + chart()->scroll(0, -1.0); + break; + default: + QGraphicsView::keyPressEvent(event); + break; + } +} diff --git a/tests/manual/openglseriestest/chartview.h b/tests/manual/openglseriestest/chartview.h new file mode 100644 index 00000000..d3594a90 --- /dev/null +++ b/tests/manual/openglseriestest/chartview.h @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#ifndef CHARTVIEW_H +#define CHARTVIEW_H + +#include <QtCharts/QChartView> + +QT_CHARTS_USE_NAMESPACE + +class ChartView : public QChartView +{ +public: + ChartView(QWidget *parent = 0); + +protected: + void keyPressEvent(QKeyEvent *event); +}; + +#endif diff --git a/tests/manual/openglseriestest/datasource.cpp b/tests/manual/openglseriestest/datasource.cpp new file mode 100644 index 00000000..46ab8aff --- /dev/null +++ b/tests/manual/openglseriestest/datasource.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#include "datasource.h" +#include <QtCore/QtMath> + +QT_CHARTS_USE_NAMESPACE + +DataSource::DataSource(QObject *parent) : + QObject(parent), + m_index(-1) +{ +} + +void DataSource::update(QXYSeries *series, int seriesIndex) +{ + if (series) { + const QVector<QVector<QPointF> > &seriesData = m_data.at(seriesIndex); + if (seriesIndex == 0) + m_index++; + if (m_index > seriesData.count() - 1) + m_index = 0; + + QVector<QPointF> points = seriesData.at(m_index); + // Use replace instead of clear + append, it's optimized for performance + series->replace(points); + } +} + +void DataSource::handleSceneChanged() +{ + m_dataUpdater.start(); +} + +void DataSource::updateAllSeries() +{ + static int frameCount = 0; + static QString labelText = QStringLiteral("FPS: %1"); + + for (int i = 0; i < m_seriesList->size(); i++) + update(m_seriesList->value(i), i); + + frameCount++; + int elapsed = m_fpsTimer.elapsed(); + if (elapsed >= 1000) { + elapsed = m_fpsTimer.restart(); + qreal fps = qreal(0.1 * int(10000.0 * (qreal(frameCount) / qreal(elapsed)))); + m_fpsLabel->setText(labelText.arg(QString::number(fps, 'f', 1))); + m_fpsLabel->adjustSize(); + frameCount = 0; + } +} + +void DataSource::startUpdates(QList<QXYSeries *> &seriesList, QLabel *fpsLabel) +{ + m_seriesList = &seriesList; + m_fpsLabel = fpsLabel; + + m_dataUpdater.setInterval(0); + m_dataUpdater.setSingleShot(true); + QObject::connect(&m_dataUpdater, &QTimer::timeout, + this, &DataSource::updateAllSeries); + + m_fpsTimer.start(); + + m_data.resize(maxSeriesCount); + updateAllSeries(); +} + +void DataSource::generateData(int seriesIndex, int rowCount, int colCount) +{ + // Remove previous data + QVector<QVector<QPointF> > &seriesData = m_data[seriesIndex]; + seriesData.clear(); + seriesData.reserve(rowCount); + + qreal xAdjustment = 20.0 / (colCount * rowCount); + qreal yMultiplier = 3.0 / qreal(maxSeriesCount); + + // Append the new data depending on the type + qreal height = qreal(seriesIndex) * (10.0 / qreal(maxSeriesCount)) + 0.3; + for (int i(0); i < rowCount; i++) { + QVector<QPointF> points; + points.reserve(colCount); + for (int j(0); j < colCount; j++) { + qreal x(0); + qreal y(0); + // data with sin + random component + y = height + (yMultiplier * qSin(3.14159265358979 / 50 * j) + + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX)); + // 0.000001 added to make values logaxis compatible + x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i)); + points.append(QPointF(x, y)); + } + seriesData.append(points); + } +} diff --git a/tests/manual/openglseriestest/datasource.h b/tests/manual/openglseriestest/datasource.h new file mode 100644 index 00000000..d9c5463b --- /dev/null +++ b/tests/manual/openglseriestest/datasource.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#ifndef DATASOURCE_H +#define DATASOURCE_H + +#include <QtCore/QObject> +#include <QtCharts/QXYSeries> +#include <QtWidgets/QLabel> +#include <QtCore/QElapsedTimer> +#include <QtCore/QTimer> + +QT_CHARTS_USE_NAMESPACE + +const int maxSeriesCount = 10; + +class DataSource : public QObject +{ + Q_OBJECT +public: + explicit DataSource(QObject *parent = 0); + + void startUpdates(QList<QXYSeries *> &seriesList, QLabel *fpsLabel); + +public slots: + void generateData(int seriesIndex, int rowCount, int colCount); + void update(QXYSeries *series, int seriesIndex); + void handleSceneChanged(); + void updateAllSeries(); + +private: + QVector<QVector<QVector<QPointF> > > m_data; + int m_index; + QList<QXYSeries *> *m_seriesList; + QLabel *m_fpsLabel; + QElapsedTimer m_fpsTimer; + QTimer m_dataUpdater; +}; + +#endif // DATASOURCE_H diff --git a/tests/manual/openglseriestest/main.cpp b/tests/manual/openglseriestest/main.cpp new file mode 100644 index 00000000..7413eab5 --- /dev/null +++ b/tests/manual/openglseriestest/main.cpp @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#include "mainwindow.h" +#include <QtWidgets/QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/tests/manual/openglseriestest/mainwindow.cpp b/tests/manual/openglseriestest/mainwindow.cpp new file mode 100644 index 00000000..e48c895b --- /dev/null +++ b/tests/manual/openglseriestest/mainwindow.cpp @@ -0,0 +1,515 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#include "mainwindow.h" +#include "chartview.h" +#include <QtCharts/QScatterSeries> +#include <QtCharts/QLineSeries> +#include <QtCharts/QValueAxis> +#include <QtCharts/QLogValueAxis> +#include <QtCharts/QDateTimeAxis> +#include <QtCharts/QCategoryAxis> +#include <QtCharts/QChart> +#include <QtCore/QDebug> +#include <QtCore/QDateTime> + +QT_CHARTS_USE_NAMESPACE +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + m_xMin(0.0), + m_xMax(20.0), + m_yMin(0.0), + m_yMax(10.0), + m_backgroundBrush(new QBrush(Qt::white)), + m_plotAreaBackgroundBrush(new QBrush(Qt::NoBrush)), + m_backgroundPen(new QPen(Qt::NoPen)), + m_plotAreaBackgroundPen(new QPen(Qt::NoPen)), + m_animationOptions(QChart::NoAnimation), + m_chart(0), + m_xAxis(0), + m_yAxis(0), + m_xAxisMode(AxisModeValue), + m_yAxisMode(AxisModeValue), + m_pointCount(100) +{ + ui->setupUi(this); + + ui->yMinSpin->setValue(m_yMin); + ui->yMaxSpin->setValue(m_yMax); + ui->xMinSpin->setValue(m_xMin); + ui->xMaxSpin->setValue(m_xMax); + + initXYValueChart(); + setXAxis(AxisModeValue); + setYAxis(AxisModeValue); + + connect(ui->yMinSpin, SIGNAL(valueChanged(double)), + this, SLOT(yMinChanged(double))); + connect(ui->yMaxSpin, SIGNAL(valueChanged(double)), + this, SLOT(yMaxChanged(double))); + connect(ui->xMinSpin, SIGNAL(valueChanged(double)), + this, SLOT(xMinChanged(double))); + connect(ui->xMaxSpin, SIGNAL(valueChanged(double)), + this, SLOT(xMaxChanged(double))); + connect(ui->animationsComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(animationIndexChanged(int))); + connect(ui->xAxisComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(xAxisIndexChanged(int))); + connect(ui->yAxisComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(yAxisIndexChanged(int))); + connect(ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(backgroundIndexChanged(int))); + connect(ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(plotAreaIndexChanged(int))); + connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(themeIndexChanged(int))); + connect(ui->addSeriesButton, SIGNAL(clicked(bool)), + this, SLOT(addSeriesClicked())); + connect(ui->addGLSeriesButton, SIGNAL(clicked(bool)), + this, SLOT(addGLSeriesClicked())); + connect(ui->removeSeriesButton, SIGNAL(clicked(bool)), + this, SLOT(removeSeriesClicked())); + connect(ui->countComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(countIndexChanged(int))); + connect(ui->colorsComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(colorIndexChanged(int))); + connect(ui->widthComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(widthIndexChanged(int))); + + ui->chartView->setChart(m_chart); + ui->chartView->setRenderHint(QPainter::Antialiasing); + + QObject::connect(m_chart->scene(), &QGraphicsScene::changed, + &m_dataSource, &DataSource::handleSceneChanged); + + m_dataSource.startUpdates(m_seriesList, ui->fpsLabel); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::initXYValueChart() +{ + m_chart = new QChart(); + m_chart->setTitle("Use arrow keys to scroll and +/- to zoom"); + m_chart->setAnimationOptions(m_animationOptions); + m_chart->setBackgroundBrush(*m_backgroundBrush); + m_chart->setBackgroundPen(*m_backgroundPen); + m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush); + m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen); +} + +void MainWindow::setXAxis(MainWindow::AxisMode mode) +{ + if (m_xAxis) { + m_chart->removeAxis(m_xAxis); + delete m_xAxis; + m_xAxis = 0; + } + + m_xAxisMode = mode; + + switch (m_xAxisMode) { + case AxisModeNone: + return; + case AxisModeValue: + m_xAxis = new QValueAxis(); + break; + case AxisModeLogValue: + m_xAxis = new QLogValueAxis(); + break; + case AxisModeDateTime: + m_xAxis = new QDateTimeAxis(); + break; + case AxisModeCategory: + m_xAxis = new QCategoryAxis(); + applyCategories(); + break; + default: + qWarning() << "Unsupported AxisMode"; + return; + } + + m_chart->addAxis(m_xAxis, Qt::AlignBottom); + + foreach (QAbstractSeries *series, m_seriesList) + series->attachAxis(m_xAxis); + + applyRanges(); +} + +void MainWindow::setYAxis(MainWindow::AxisMode mode) +{ + if (m_yAxis) { + m_chart->removeAxis(m_yAxis); + delete m_yAxis; + m_yAxis = 0; + } + + m_yAxisMode = mode; + + switch (m_yAxisMode) { + case AxisModeNone: + return; + case AxisModeValue: + m_yAxis = new QValueAxis(); + break; + case AxisModeLogValue: + m_yAxis = new QLogValueAxis(); + break; + case AxisModeDateTime: + m_yAxis = new QDateTimeAxis(); + break; + case AxisModeCategory: + m_yAxis = new QCategoryAxis(); + applyCategories(); + break; + default: + qWarning() << "Unsupported AxisMode"; + return; + } + + m_chart->addAxis(m_yAxis, Qt::AlignLeft); + + foreach (QAbstractSeries *series, m_seriesList) + series->attachAxis(m_yAxis); + + applyRanges(); +} + +void MainWindow::applyRanges() +{ + if (m_xAxis) { + if (m_xAxisMode == AxisModeLogValue) { + if (m_xMin <= 0) + m_xMin = 1.0; + if (m_xMax <= m_xMin) + m_xMax = m_xMin + 1.0; + } + if (m_xAxisMode == AxisModeDateTime) { + QDateTime dateTimeMin; + QDateTime dateTimeMax; + dateTimeMin.setMSecsSinceEpoch(qint64(m_xMin)); + dateTimeMax.setMSecsSinceEpoch(qint64(m_xMax)); + m_xAxis->setRange(dateTimeMin, dateTimeMax); + } else { + m_xAxis->setRange(m_xMin, m_xMax); + } + ui->xMinSpin->setValue(m_xMin); + ui->xMaxSpin->setValue(m_xMax); + } + if (m_yAxis) { + if (m_yAxisMode == AxisModeLogValue) { + if (m_yMin <= 0) + m_yMin = 1.0; + if (m_yMax <= m_yMin) + m_yMax = m_yMin + 1.0; + } + if (m_yAxisMode == AxisModeDateTime) { + QDateTime dateTimeMin; + QDateTime dateTimeMax; + dateTimeMin.setMSecsSinceEpoch(qint64(m_yMin)); + dateTimeMax.setMSecsSinceEpoch(qint64(m_yMax)); + m_yAxis->setRange(dateTimeMin, dateTimeMax); + } else { + m_yAxis->setRange(m_yMin, m_yMax); + } + ui->yMinSpin->setValue(m_yMin); + ui->yMaxSpin->setValue(m_yMax); + } +} + +void MainWindow::xMinChanged(double value) +{ + m_xMin = value; + applyRanges(); +} + +void MainWindow::xMaxChanged(double value) +{ + m_xMax = value; + applyRanges(); +} + +void MainWindow::yMinChanged(double value) +{ + m_yMin = value; + applyRanges(); +} + +void MainWindow::yMaxChanged(double value) +{ + m_yMax = value; + applyRanges(); +} + +void MainWindow::animationIndexChanged(int index) +{ + switch (index) { + case 0: + m_animationOptions = QChart::NoAnimation; + break; + case 1: + m_animationOptions = QChart::SeriesAnimations; + break; + case 2: + m_animationOptions = QChart::GridAxisAnimations; + break; + case 3: + m_animationOptions = QChart::AllAnimations; + break; + default: + break; + } + + m_chart->setAnimationOptions(m_animationOptions); +} + +void MainWindow::xRangeChanged(qreal min, qreal max) +{ + if (!qFuzzyCompare(qreal(ui->xMinSpin->value()), min)) + ui->xMinSpin->setValue(min); + if (!qFuzzyCompare(qreal(ui->xMaxSpin->value()), max)) + ui->xMaxSpin->setValue(max); +} + +void MainWindow::yRangeChanged(qreal min, qreal max) +{ + if (!qFuzzyCompare(qreal(ui->yMinSpin->value()), min)) + ui->yMinSpin->setValue(min); + if (!qFuzzyCompare(qreal(ui->yMaxSpin->value()), max)) + ui->yMaxSpin->setValue(max); +} + +void MainWindow::xAxisIndexChanged(int index) +{ + switch (index) { + case 0: + setXAxis(AxisModeNone); + break; + case 1: + setXAxis(AxisModeValue); + break; + case 2: + setXAxis(AxisModeLogValue); + break; + case 3: + setXAxis(AxisModeDateTime); + break; + case 4: + setXAxis(AxisModeCategory); + break; + default: + qWarning("Invalid Index!"); + } +} + +void MainWindow::yAxisIndexChanged(int index) +{ + switch (index) { + case 0: + setYAxis(AxisModeNone); + break; + case 1: + setYAxis(AxisModeValue); + break; + case 2: + setYAxis(AxisModeLogValue); + break; + case 3: + setYAxis(AxisModeDateTime); + break; + case 4: + setYAxis(AxisModeCategory); + break; + default: + qWarning("Invalid Index!"); + } +} + +void MainWindow::themeIndexChanged(int index) +{ + m_chart->setTheme(QChart::ChartTheme(index)); +} + +void MainWindow::addSeriesClicked() +{ + addSeries(false); +} + +void MainWindow::removeSeriesClicked() +{ + if (m_seriesList.size()) { + QXYSeries *series = m_seriesList.takeAt(m_seriesList.size() - 1); + m_chart->removeSeries(series); + delete series; + } +} + +void MainWindow::addGLSeriesClicked() +{ + addSeries(true); +} + +void MainWindow::countIndexChanged(int index) +{ + m_pointCount = ui->countComboBox->itemText(index).toInt(); + for (int i = 0; i < m_seriesList.size(); i++) { + m_dataSource.generateData(i, 2, m_pointCount); + } +} + +void MainWindow::colorIndexChanged(int index) +{ + QColor color = QColor(ui->colorsComboBox->itemText(index).toLower()); + foreach (QXYSeries *series, m_seriesList) { + if (series->type() == QAbstractSeries::SeriesTypeScatter) { + QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); + scatterSeries->setBorderColor(color); + scatterSeries->setColor(color); + } else { + series->setColor(color); + } + } +} + +void MainWindow::widthIndexChanged(int index) +{ + int width = ui->widthComboBox->itemText(index).toInt(); + foreach (QXYSeries *series, m_seriesList) { + if (series->type() == QAbstractSeries::SeriesTypeScatter) { + QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); + scatterSeries->setMarkerSize(width); + } else { + QColor color = QColor(ui->colorsComboBox->itemText( + ui->colorsComboBox->currentIndex()).toLower()); + series->setPen(QPen(QBrush(color), width)); + } + } +} + +void MainWindow::backgroundIndexChanged(int index) +{ + delete m_backgroundBrush; + delete m_backgroundPen; + + switch (index) { + case 0: + m_backgroundBrush = new QBrush(Qt::white); + m_backgroundPen = new QPen(Qt::NoPen); + break; + case 1: + m_backgroundBrush = new QBrush(Qt::blue); + m_backgroundPen = new QPen(Qt::NoPen); + break; + case 2: + m_backgroundBrush = new QBrush(Qt::yellow); + m_backgroundPen = new QPen(Qt::black, 2); + break; + default: + break; + } + m_chart->setBackgroundBrush(*m_backgroundBrush); + m_chart->setBackgroundPen(*m_backgroundPen); +} + +void MainWindow::plotAreaIndexChanged(int index) +{ + delete m_plotAreaBackgroundBrush; + delete m_plotAreaBackgroundPen; + + switch (index) { + case 0: + m_plotAreaBackgroundBrush = new QBrush(Qt::green); + m_plotAreaBackgroundPen = new QPen(Qt::green); + m_chart->setPlotAreaBackgroundVisible(false); + break; + case 1: + m_plotAreaBackgroundBrush = new QBrush(Qt::magenta); + m_plotAreaBackgroundPen = new QPen(Qt::NoPen); + m_chart->setPlotAreaBackgroundVisible(true); + break; + case 2: + m_plotAreaBackgroundBrush = new QBrush(Qt::lightGray); + m_plotAreaBackgroundPen = new QPen(Qt::red, 6); + m_chart->setPlotAreaBackgroundVisible(true); + break; + default: + break; + } + m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush); + m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen); +} + +void MainWindow::applyCategories() +{ + // Basic layout is three categories, extended has five + if (m_xAxisMode == AxisModeCategory) { + QCategoryAxis *angCatAxis = static_cast<QCategoryAxis *>(m_xAxis); + if (angCatAxis->count() == 0) { + angCatAxis->setStartValue(2); + angCatAxis->append("Category A", 6); + angCatAxis->append("Category B", 12); + angCatAxis->append("Category C", 18); + } + } + + if (m_yAxisMode == AxisModeCategory) { + QCategoryAxis *radCatAxis = static_cast<QCategoryAxis *>(m_yAxis); + if (radCatAxis->count() == 0) { + radCatAxis->setStartValue(1); + radCatAxis->append("Category 1", 3); + radCatAxis->append("Category 2", 4); + radCatAxis->append("Category 3", 8); + } + } +} + +void MainWindow::addSeries(bool gl) +{ + QColor color = QColor(ui->colorsComboBox->itemText(ui->colorsComboBox->currentIndex()).toLower()); + int width = ui->widthComboBox->itemText(ui->widthComboBox->currentIndex()).toInt(); + + if (m_seriesList.size() < maxSeriesCount) { + QXYSeries *series; + if (qrand() % 2) { + series = new QLineSeries; + series->setPen(QPen(QBrush(color), width)); + } else { + QScatterSeries *scatterSeries = new QScatterSeries; + scatterSeries->setMarkerSize(width); + scatterSeries->setBorderColor(color); + scatterSeries->setBrush(QBrush(color)); + series = scatterSeries; + } + series->setUseOpenGL(gl); + m_dataSource.generateData(m_seriesList.size(), 2, m_pointCount); + m_seriesList.append(series); + m_chart->addSeries(series); + if (m_xAxis) + series->attachAxis(m_xAxis); + if (m_yAxis) + series->attachAxis(m_yAxis); + applyRanges(); + } +} diff --git a/tests/manual/openglseriestest/mainwindow.h b/tests/manual/openglseriestest/mainwindow.h new file mode 100644 index 00000000..46c119b0 --- /dev/null +++ b/tests/manual/openglseriestest/mainwindow.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include "datasource.h" +#include <QtWidgets/QMainWindow> +#include <QtCharts/QChart> + +QT_BEGIN_NAMESPACE +class QBrush; +class QPen; + +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + + +QT_CHARTS_USE_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +public slots: + void xMinChanged(double value); + void xMaxChanged(double value); + void yMinChanged(double value); + void yMaxChanged(double value); + void animationIndexChanged(int index); + void xRangeChanged(qreal min, qreal max); + void yRangeChanged(qreal min, qreal max); + void xAxisIndexChanged(int index); + void yAxisIndexChanged(int index); + void backgroundIndexChanged(int index); + void plotAreaIndexChanged(int index); + void themeIndexChanged(int index); + void addSeriesClicked(); + void removeSeriesClicked(); + void addGLSeriesClicked(); + void countIndexChanged(int index); + void colorIndexChanged(int index); + void widthIndexChanged(int index); + +private: + enum AxisMode { + AxisModeNone, + AxisModeValue, + AxisModeLogValue, + AxisModeDateTime, + AxisModeCategory + }; + + void initXYValueChart(); + void setXAxis(AxisMode mode); + void setYAxis(AxisMode mode); + + void applyRanges(); + void applyCategories(); + void addSeries(bool gl); + + Ui::MainWindow *ui; + + qreal m_xMin; + qreal m_xMax; + qreal m_yMin; + qreal m_yMax; + QBrush *m_backgroundBrush; + QBrush *m_plotAreaBackgroundBrush; + QPen *m_backgroundPen; + QPen *m_plotAreaBackgroundPen; + QChart::AnimationOptions m_animationOptions; + + QChart *m_chart; + QAbstractAxis *m_xAxis; + QAbstractAxis *m_yAxis; + AxisMode m_xAxisMode; + AxisMode m_yAxisMode; + + QList<QXYSeries *> m_seriesList; + DataSource m_dataSource; + int m_pointCount; +}; + +#endif // MAINWINDOW_H diff --git a/tests/manual/openglseriestest/mainwindow.ui b/tests/manual/openglseriestest/mainwindow.ui new file mode 100644 index 00000000..e5ca1514 --- /dev/null +++ b/tests/manual/openglseriestest/mainwindow.ui @@ -0,0 +1,582 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1047</width> + <height>643</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="ChartView" name="chartView"/> + </item> + <item> + <widget class="QGroupBox" name="settingsBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>200</width> + <height>0</height> + </size> + </property> + <property name="title"> + <string>Settings</string> + </property> + <widget class="QComboBox" name="animationsComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>170</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <item> + <property name="text"> + <string>No animations</string> + </property> + </item> + <item> + <property name="text"> + <string>Series animation</string> + </property> + </item> + <item> + <property name="text"> + <string>Grid animation</string> + </property> + </item> + <item> + <property name="text"> + <string>All animations</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="xAxisComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>23</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <property name="editable"> + <bool>false</bool> + </property> + <property name="currentText"> + <string>X Value Axis</string> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>No X Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>X Value Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>X Log Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>X DateTime Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>X Category Axis</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="yAxisComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>49</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <property name="editable"> + <bool>false</bool> + </property> + <property name="currentText"> + <string>Y Value Axis</string> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>No Y Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Y Value Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Y Log Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Y DateTime Axis</string> + </property> + </item> + <item> + <property name="text"> + <string>Y Category Axis</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="backgroundComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>190</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>Background: White</string> + </property> + </item> + <item> + <property name="text"> + <string>Background: Blue</string> + </property> + </item> + <item> + <property name="text"> + <string>Background: Yellow + Black Border</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="plotAreaComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>210</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>PlotArea: Transparent</string> + </property> + </item> + <item> + <property name="text"> + <string>PlotArea: Magenta</string> + </property> + </item> + <item> + <property name="text"> + <string>PlotArea: Gray + Red Border</string> + </property> + </item> + </widget> + <widget class="QWidget" name="layoutWidget"> + <property name="geometry"> + <rect> + <x>10</x> + <y>70</y> + <width>185</width> + <height>100</height> + </rect> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="yMinSpin"> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>1.000000000000000</double> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Y max</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_12"> + <property name="text"> + <string>Y min</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>X max</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QDoubleSpinBox" name="xMinSpin"> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>1.000000000000000</double> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>X min</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QDoubleSpinBox" name="yMaxSpin"> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>1.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="xMaxSpin"> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-999999999.000000000000000</double> + </property> + <property name="maximum"> + <double>999999999.000000000000000</double> + </property> + <property name="singleStep"> + <double>1.000000000000000</double> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QComboBox" name="themeComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>230</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>Theme: Light</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Blue Cerulean</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Dark</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Brown Sand</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Blue Ncs</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: High Contrast</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Blue Icy</string> + </property> + </item> + <item> + <property name="text"> + <string>Theme: Qt</string> + </property> + </item> + </widget> + <widget class="QPushButton" name="addSeriesButton"> + <property name="geometry"> + <rect> + <x>100</x> + <y>280</y> + <width>91</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Add Series</string> + </property> + </widget> + <widget class="QPushButton" name="removeSeriesButton"> + <property name="geometry"> + <rect> + <x>50</x> + <y>300</y> + <width>91</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Remove Series</string> + </property> + </widget> + <widget class="QComboBox" name="countComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>250</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <property name="editable"> + <bool>false</bool> + </property> + <property name="currentText"> + <string>100</string> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>100</string> + </property> + </item> + <item> + <property name="text"> + <string>1000</string> + </property> + </item> + <item> + <property name="text"> + <string>10000</string> + </property> + </item> + <item> + <property name="text"> + <string>100000</string> + </property> + </item> + <item> + <property name="text"> + <string>1000000</string> + </property> + </item> + <item> + <property name="text"> + <string>10000000</string> + </property> + </item> + </widget> + <widget class="QLabel" name="fpsLabel"> + <property name="geometry"> + <rect> + <x>10</x> + <y>550</y> + <width>47</width> + <height>13</height> + </rect> + </property> + <property name="text"> + <string>FPS:</string> + </property> + </widget> + <widget class="QPushButton" name="addGLSeriesButton"> + <property name="geometry"> + <rect> + <x>10</x> + <y>280</y> + <width>91</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Add GL Series</string> + </property> + </widget> + <widget class="QComboBox" name="colorsComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>330</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <item> + <property name="text"> + <string>Black</string> + </property> + </item> + <item> + <property name="text"> + <string>Red</string> + </property> + </item> + <item> + <property name="text"> + <string>Green</string> + </property> + </item> + <item> + <property name="text"> + <string>Blue</string> + </property> + </item> + </widget> + <widget class="QComboBox" name="widthComboBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>350</y> + <width>181</width> + <height>20</height> + </rect> + </property> + <item> + <property name="text"> + <string>1</string> + </property> + </item> + <item> + <property name="text"> + <string>2</string> + </property> + </item> + <item> + <property name="text"> + <string>3</string> + </property> + </item> + <item> + <property name="text"> + <string>4</string> + </property> + </item> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1047</width> + <height>21</height> + </rect> + </property> + </widget> + <widget class="QToolBar" name="mainToolBar"> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <customwidgets> + <customwidget> + <class>ChartView</class> + <extends>QGraphicsView</extends> + <header>chartview.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/openglseriestest/openglseriestest.pro b/tests/manual/openglseriestest/openglseriestest.pro new file mode 100644 index 00000000..b874fd33 --- /dev/null +++ b/tests/manual/openglseriestest/openglseriestest.pro @@ -0,0 +1,19 @@ +!include( ../../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +QT += core gui widgets + +TARGET = openglseriestest +TEMPLATE = app + +SOURCES += main.cpp \ + mainwindow.cpp \ + chartview.cpp \ + datasource.cpp + +HEADERS += mainwindow.h \ + chartview.h \ + datasource.h + +FORMS += mainwindow.ui |