##// END OF EJS Templates
Merge remote-tracking branch 'origin/5.7' into dev...
Merge remote-tracking branch 'origin/5.7' into dev Change-Id: I86dec1064d79704214e885681449ca347b193d66

File last commit:

r2854:46147b040d06
r2895:e9a2e2a5e9c0 merge
Show More
datasource.cpp
101 lines | 3.2 KiB | text/x-c | CppLexer
Miikka Heikkinen
Updated license...
r2854 /****************************************************************************
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
Miikka Heikkinen
Updated license...
r2854 ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
Miikka Heikkinen
Updated license...
r2854 ** This file is part of the Qt Charts module of the Qt Toolkit.
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
Miikka Heikkinen
Updated license...
r2854 ** $QT_BEGIN_LICENSE:GPL$
Titta Heikkala
Updated license headers...
r2845 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
Miikka Heikkinen
Updated license...
r2854 ** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Miikka Heikkinen
Generate charts plugin for QtQuick2 as well as QtQuick1...
r2488 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
Miikka Heikkinen
Updated license...
r2854 ****************************************************************************/
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);
}
}