##// END OF EJS Templates
Fix axes issues with oscilloscope demos...
Titta Heikkala -
r2694:638297e957ee
parent child
Show More
@@ -1,93 +1,95
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 11 ** accordance with the Qt Enterprise 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 <qmath.h>
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QAbstractSeries *)
31 Q_DECLARE_METATYPE(QAbstractAxis *)
31 32
32 33 DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) :
33 34 QObject(parent),
34 35 m_appViewer(appViewer),
35 36 m_index(-1)
36 37 {
37 38 qRegisterMetaType<QAbstractSeries*>();
39 qRegisterMetaType<QAbstractAxis*>();
38 40
39 41 generateData(0, 5, 1024);
40 42 }
41 43
42 44 void DataSource::update(QAbstractSeries *series)
43 45 {
44 46 if (series) {
45 47 QXYSeries *xySeries = static_cast<QXYSeries *>(series);
46 48 m_index++;
47 49 if (m_index > m_data.count() - 1)
48 50 m_index = 0;
49 51
50 52 QList<QPointF> points = m_data.at(m_index);
51 53 // Use replace instead of clear + append, it's optimized for performance
52 54 xySeries->replace(points);
53 55 }
54 56 }
55 57
56 58 void DataSource::generateData(int type, int rowCount, int colCount)
57 59 {
58 60 // Remove previous data
59 61 foreach (QList<QPointF> row, m_data)
60 62 row.clear();
61 63 m_data.clear();
62 64
63 65 // Append the new data depending on the type
64 66 for (int i(0); i < rowCount; i++) {
65 67 QList<QPointF> points;
66 68 for (int j(0); j < colCount; j++) {
67 69 qreal x(0);
68 70 qreal y(0);
69 71 switch (type) {
70 72 case 0:
71 73 // data with sin + random component
72 74 y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
73 75 x = j;
74 76 break;
75 77 case 1:
76 78 // linear data
77 79 x = j;
78 80 y = (qreal) i / 10;
79 81 break;
80 82 default:
81 83 // unknown, do nothing
82 84 break;
83 85 }
84 86 points.append(QPointF(x, y));
85 87 }
86 88 m_data.append(points);
87 89 }
88 90 }
89 91
90 92 void DataSource::setAntialiasing(bool enabled)
91 93 {
92 94 m_appViewer->setRenderHint(QPainter::Antialiasing, enabled);
93 95 }
@@ -1,89 +1,91
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 11 ** accordance with the Qt Enterprise 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 <qmath.h>
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 Q_DECLARE_METATYPE(QAbstractSeries *)
32 Q_DECLARE_METATYPE(QAbstractAxis *)
32 33
33 34 DataSource::DataSource(QQuickView *appViewer, QObject *parent) :
34 35 QObject(parent),
35 36 m_appViewer(appViewer),
36 37 m_index(-1)
37 38 {
38 39 qRegisterMetaType<QAbstractSeries*>();
40 qRegisterMetaType<QAbstractAxis*>();
39 41
40 42 generateData(0, 5, 1024);
41 43 }
42 44
43 45 void DataSource::update(QAbstractSeries *series)
44 46 {
45 47 if (series) {
46 48 QXYSeries *xySeries = static_cast<QXYSeries *>(series);
47 49 m_index++;
48 50 if (m_index > m_data.count() - 1)
49 51 m_index = 0;
50 52
51 53 QList<QPointF> points = m_data.at(m_index);
52 54 // Use replace instead of clear + append, it's optimized for performance
53 55 xySeries->replace(points);
54 56 }
55 57 }
56 58
57 59 void DataSource::generateData(int type, int rowCount, int colCount)
58 60 {
59 61 // Remove previous data
60 62 foreach (QList<QPointF> row, m_data)
61 63 row.clear();
62 64 m_data.clear();
63 65
64 66 // Append the new data depending on the type
65 67 for (int i(0); i < rowCount; i++) {
66 68 QList<QPointF> points;
67 69 for (int j(0); j < colCount; j++) {
68 70 qreal x(0);
69 71 qreal y(0);
70 72 switch (type) {
71 73 case 0:
72 74 // data with sin + random component
73 75 y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
74 76 x = j;
75 77 break;
76 78 case 1:
77 79 // linear data
78 80 x = j;
79 81 y = (qreal) i / 10;
80 82 break;
81 83 default:
82 84 // unknown, do nothing
83 85 break;
84 86 }
85 87 points.append(QPointF(x, y));
86 88 }
87 89 m_data.append(points);
88 90 }
89 91 }
General Comments 0
You need to be logged in to leave comments. Login now