##// END OF EJS Templates
Fixed Qt5 specific issue with meta types in QML oscilloscope demo
Tero Ahola -
r2394:297768d995b8
parent child
Show More
@@ -1,91 +1,94
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 <QGLWidget>
26 26 #include <QDebug>
27 27 #include <cmath>
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 Q_DECLARE_METATYPE(QAbstractSeries *)
32
31 33 DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) :
32 34 QObject(parent),
33 35 m_appViewer(appViewer),
34 36 m_index(-1)
35 37 {
36 // generate
38 qRegisterMetaType<QAbstractSeries*>();
39
37 40 generateData(0, 5, 1024);
38 41 }
39 42
40 43 void DataSource::update(QAbstractSeries *series)
41 44 {
42 45 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
43 46 Q_ASSERT(xySeries);
44 47
45 48 m_index++;
46 49 if (m_index > m_data.count() - 1)
47 50 m_index = 0;
48 51
49 52 QList<QPointF> points = m_data.at(m_index);
50 53 // Use replace instead of clear + append, it's optimized for performance
51 54 xySeries->replace(points);
52 55 }
53 56
54 57 void DataSource::generateData(int type, int rowCount, int colCount)
55 58 {
56 59 // Remove previous data
57 60 foreach (QList<QPointF> row, m_data)
58 61 row.clear();
59 62 m_data.clear();
60 63
61 64 // Append the new data depending on the type
62 65 for (int i(0); i < rowCount; i++) {
63 66 QList<QPointF> points;
64 67 for (int j(0); j < colCount; j++) {
65 68 qreal x(0);
66 69 qreal y(0);
67 70 switch (type) {
68 71 case 0:
69 72 // data with sin + random component
70 73 y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
71 74 x = j;
72 75 break;
73 76 case 1:
74 77 // linear data
75 78 x = j;
76 79 y = (qreal) i / 10;
77 80 break;
78 81 default:
79 82 // unknown, do nothing
80 83 break;
81 84 }
82 85 points.append(QPointF(x, y));
83 86 }
84 87 m_data.append(points);
85 88 }
86 89 }
87 90
88 91 void DataSource::setAntialiasing(bool enabled)
89 92 {
90 93 m_appViewer->setRenderHint(QPainter::Antialiasing, enabled);
91 94 }
General Comments 0
You need to be logged in to leave comments. Login now