diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 5f2b85b..25545ae 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 0000000..578d1b3 --- /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 + +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 0000000..d3594a9 --- /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 + +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 0000000..46ab8af --- /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 + +QT_CHARTS_USE_NAMESPACE + +DataSource::DataSource(QObject *parent) : + QObject(parent), + m_index(-1) +{ +} + +void DataSource::update(QXYSeries *series, int seriesIndex) +{ + if (series) { + const QVector > &seriesData = m_data.at(seriesIndex); + if (seriesIndex == 0) + m_index++; + if (m_index > seriesData.count() - 1) + m_index = 0; + + QVector 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 &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 > &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 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 0000000..d9c5463 --- /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 +#include +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + +const int maxSeriesCount = 10; + +class DataSource : public QObject +{ + Q_OBJECT +public: + explicit DataSource(QObject *parent = 0); + + void startUpdates(QList &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 > > m_data; + int m_index; + QList *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 0000000..7413eab --- /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 + +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 0000000..e48c895 --- /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 +#include +#include +#include +#include +#include +#include +#include +#include + +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(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(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(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(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 0000000..46c119b --- /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 +#include + +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 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 0000000..e5ca151 --- /dev/null +++ b/tests/manual/openglseriestest/mainwindow.ui @@ -0,0 +1,582 @@ + + + MainWindow + + + + 0 + 0 + 1047 + 643 + + + + MainWindow + + + + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + Settings + + + + + 10 + 170 + 181 + 20 + + + + + No animations + + + + + Series animation + + + + + Grid animation + + + + + All animations + + + + + + + 10 + 23 + 181 + 20 + + + + false + + + X Value Axis + + + 1 + + + + No X Axis + + + + + X Value Axis + + + + + X Log Axis + + + + + X DateTime Axis + + + + + X Category Axis + + + + + + + 10 + 49 + 181 + 20 + + + + false + + + Y Value Axis + + + 1 + + + + No Y Axis + + + + + Y Value Axis + + + + + Y Log Axis + + + + + Y DateTime Axis + + + + + Y Category Axis + + + + + + + 10 + 190 + 181 + 20 + + + + + 0 + 0 + + + + 0 + + + + Background: White + + + + + Background: Blue + + + + + Background: Yellow + Black Border + + + + + + + 10 + 210 + 181 + 20 + + + + + 0 + 0 + + + + 0 + + + + PlotArea: Transparent + + + + + PlotArea: Magenta + + + + + PlotArea: Gray + Red Border + + + + + + + 10 + 70 + 185 + 100 + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 1.000000000000000 + + + + + + + Y max + + + + + + + Y min + + + + + + + X max + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 1.000000000000000 + + + + + + + X min + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 1.000000000000000 + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 1.000000000000000 + + + + + + + + + 10 + 230 + 181 + 20 + + + + + 0 + 0 + + + + 0 + + + + Theme: Light + + + + + Theme: Blue Cerulean + + + + + Theme: Dark + + + + + Theme: Brown Sand + + + + + Theme: Blue Ncs + + + + + Theme: High Contrast + + + + + Theme: Blue Icy + + + + + Theme: Qt + + + + + + + 100 + 280 + 91 + 23 + + + + Add Series + + + + + + 50 + 300 + 91 + 23 + + + + Remove Series + + + + + + 10 + 250 + 181 + 20 + + + + false + + + 100 + + + 0 + + + + 100 + + + + + 1000 + + + + + 10000 + + + + + 100000 + + + + + 1000000 + + + + + 10000000 + + + + + + + 10 + 550 + 47 + 13 + + + + FPS: + + + + + + 10 + 280 + 91 + 23 + + + + Add GL Series + + + + + + 10 + 330 + 181 + 20 + + + + + Black + + + + + Red + + + + + Green + + + + + Blue + + + + + + + 10 + 350 + 181 + 20 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + + + + + + + 0 + 0 + 1047 + 21 + + + + + + TopToolBarArea + + + false + + + + + + + + ChartView + QGraphicsView +
chartview.h
+
+
+ + +
diff --git a/tests/manual/openglseriestest/openglseriestest.pro b/tests/manual/openglseriestest/openglseriestest.pro new file mode 100644 index 0000000..b874fd3 --- /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