##// END OF EJS Templates
Fix oscilloscope demos on android...
Heikkinen Miikka -
r2526:383eb97e1450
parent child
Show More
@@ -1,93 +1,93
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "datasource.h"
22 22 #include <QXYSeries>
23 23 #include <QAreaSeries>
24 24 #include <QDeclarativeView>
25 25 #include <QDebug>
26 26 #include <cmath>
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QAbstractSeries *)
31 31
32 32 DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) :
33 33 QObject(parent),
34 34 m_appViewer(appViewer),
35 35 m_index(-1)
36 36 {
37 37 qRegisterMetaType<QAbstractSeries*>();
38 38
39 39 generateData(0, 5, 1024);
40 40 }
41 41
42 42 void DataSource::update(QAbstractSeries *series)
43 43 {
44 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
45 Q_ASSERT(xySeries);
44 if (series) {
45 QXYSeries *xySeries = static_cast<QXYSeries *>(series);
46 m_index++;
47 if (m_index > m_data.count() - 1)
48 m_index = 0;
46 49
47 m_index++;
48 if (m_index > m_data.count() - 1)
49 m_index = 0;
50
51 QList<QPointF> points = m_data.at(m_index);
52 // Use replace instead of clear + append, it's optimized for performance
53 xySeries->replace(points);
50 QList<QPointF> points = m_data.at(m_index);
51 // Use replace instead of clear + append, it's optimized for performance
52 xySeries->replace(points);
53 }
54 54 }
55 55
56 56 void DataSource::generateData(int type, int rowCount, int colCount)
57 57 {
58 58 // Remove previous data
59 59 foreach (QList<QPointF> row, m_data)
60 60 row.clear();
61 61 m_data.clear();
62 62
63 63 // Append the new data depending on the type
64 64 for (int i(0); i < rowCount; i++) {
65 65 QList<QPointF> points;
66 66 for (int j(0); j < colCount; j++) {
67 67 qreal x(0);
68 68 qreal y(0);
69 69 switch (type) {
70 70 case 0:
71 71 // data with sin + random component
72 72 y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
73 73 x = j;
74 74 break;
75 75 case 1:
76 76 // linear data
77 77 x = j;
78 78 y = (qreal) i / 10;
79 79 break;
80 80 default:
81 81 // unknown, do nothing
82 82 break;
83 83 }
84 84 points.append(QPointF(x, y));
85 85 }
86 86 m_data.append(points);
87 87 }
88 88 }
89 89
90 90 void DataSource::setAntialiasing(bool enabled)
91 91 {
92 92 m_appViewer->setRenderHint(QPainter::Antialiasing, enabled);
93 93 }
@@ -1,89 +1,89
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "datasource.h"
22 22 #include <QXYSeries>
23 23 #include <QAreaSeries>
24 24 #include <QtQuick/QQuickView>
25 25 #include <QtQuick/QQuickItem>
26 26 #include <QDebug>
27 27 #include <cmath>
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 Q_DECLARE_METATYPE(QAbstractSeries *)
32 32
33 33 DataSource::DataSource(QQuickView *appViewer, QObject *parent) :
34 34 QObject(parent),
35 35 m_appViewer(appViewer),
36 36 m_index(-1)
37 37 {
38 38 qRegisterMetaType<QAbstractSeries*>();
39 39
40 40 generateData(0, 5, 1024);
41 41 }
42 42
43 43 void DataSource::update(QAbstractSeries *series)
44 44 {
45 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
46 Q_ASSERT(xySeries);
45 if (series) {
46 QXYSeries *xySeries = static_cast<QXYSeries *>(series);
47 m_index++;
48 if (m_index > m_data.count() - 1)
49 m_index = 0;
47 50
48 m_index++;
49 if (m_index > m_data.count() - 1)
50 m_index = 0;
51
52 QList<QPointF> points = m_data.at(m_index);
53 // Use replace instead of clear + append, it's optimized for performance
54 xySeries->replace(points);
51 QList<QPointF> points = m_data.at(m_index);
52 // Use replace instead of clear + append, it's optimized for performance
53 xySeries->replace(points);
54 }
55 55 }
56 56
57 57 void DataSource::generateData(int type, int rowCount, int colCount)
58 58 {
59 59 // Remove previous data
60 60 foreach (QList<QPointF> row, m_data)
61 61 row.clear();
62 62 m_data.clear();
63 63
64 64 // Append the new data depending on the type
65 65 for (int i(0); i < rowCount; i++) {
66 66 QList<QPointF> points;
67 67 for (int j(0); j < colCount; j++) {
68 68 qreal x(0);
69 69 qreal y(0);
70 70 switch (type) {
71 71 case 0:
72 72 // data with sin + random component
73 73 y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
74 74 x = j;
75 75 break;
76 76 case 1:
77 77 // linear data
78 78 x = j;
79 79 y = (qreal) i / 10;
80 80 break;
81 81 default:
82 82 // unknown, do nothing
83 83 break;
84 84 }
85 85 points.append(QPointF(x, y));
86 86 }
87 87 m_data.append(points);
88 88 }
89 89 }
General Comments 0
You need to be logged in to leave comments. Login now