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