##// END OF EJS Templates
Add QXYSeries::replace(QVector<QPointF> points) overload....
Add QXYSeries::replace(QVector<QPointF> points) overload. Task-number: QTRD-3384 Change-Id: Ic7dcdfeadd3f5c7ba66191f8c427a0d65796895d Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>

File last commit:

r2798:412d1b6b2a80
r2798:412d1b6b2a80
Show More
datasource.cpp
90 lines | 2.6 KiB | text/x-c | CppLexer
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 /****************************************************************************
**
Titta Heikkala
Copyright header changes...
r2776 ** Copyright (C) 2015 The Qt Company Ltd
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 ** All rights reserved.
Titta Heikkala
Copyright header changes...
r2776 ** For any questions to The Qt Company, please use contact form at http://qt.io
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
Titta Heikkala
Updated license headers...
r2740 ** This file is part of the Qt Charts module.
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
Titta Heikkala
Updated license headers...
r2740 ** 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
Titta Heikkala
Copyright header changes...
r2776 ** agreement between you and The Qt Company.
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
** If you have questions regarding the use of this file, please use
Titta Heikkala
Updated license headers...
r2740 ** contact form at http://qt.io
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
****************************************************************************/
#include "datasource.h"
Titta Heikkala
Fix include syntax...
r2714 #include <QtCharts/QXYSeries>
#include <QtCharts/QAreaSeries>
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 #include <QtQuick/QQuickView>
#include <QtQuick/QQuickItem>
Titta Heikkala
Fix include syntax...
r2714 #include <QtCore/QDebug>
#include <QtCore/QtMath>
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_USE_NAMESPACE
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488
Q_DECLARE_METATYPE(QAbstractSeries *)
Titta Heikkala
Fix axes issues with oscilloscope demos...
r2694 Q_DECLARE_METATYPE(QAbstractAxis *)
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488
DataSource::DataSource(QQuickView *appViewer, QObject *parent) :
QObject(parent),
m_appViewer(appViewer),
m_index(-1)
{
qRegisterMetaType<QAbstractSeries*>();
Titta Heikkala
Fix axes issues with oscilloscope demos...
r2694 qRegisterMetaType<QAbstractAxis*>();
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488
generateData(0, 5, 1024);
}
void DataSource::update(QAbstractSeries *series)
{
Heikkinen Miikka
Fix oscilloscope demos on android...
r2526 if (series) {
QXYSeries *xySeries = static_cast<QXYSeries *>(series);
m_index++;
if (m_index > m_data.count() - 1)
m_index = 0;
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488
Miikka Heikkinen
Add QXYSeries::replace(QVector<QPointF> points) overload....
r2798 QVector<QPointF> points = m_data.at(m_index);
Heikkinen Miikka
Fix oscilloscope demos on android...
r2526 // Use replace instead of clear + append, it's optimized for performance
xySeries->replace(points);
}
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 }
void DataSource::generateData(int type, int rowCount, int colCount)
{
// Remove previous data
Miikka Heikkinen
Add QXYSeries::replace(QVector<QPointF> points) overload....
r2798 foreach (QVector<QPointF> row, m_data)
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 row.clear();
m_data.clear();
// Append the new data depending on the type
for (int i(0); i < rowCount; i++) {
Miikka Heikkinen
Add QXYSeries::replace(QVector<QPointF> points) overload....
r2798 QVector<QPointF> points;
points.reserve(colCount);
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 for (int j(0); j < colCount; j++) {
qreal x(0);
qreal y(0);
switch (type) {
case 0:
// data with sin + random component
Titta Heikkala
Fix Chart build on Solaris...
r2613 y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 x = j;
break;
case 1:
// linear data
x = j;
y = (qreal) i / 10;
break;
default:
// unknown, do nothing
break;
}
points.append(QPointF(x, y));
}
m_data.append(points);
}
}