##// END OF EJS Templates
Fix build on OSX: Added missing cmath include
Tero Ahola -
r1786:808d1ae6a39e
parent child
Show More
@@ -1,95 +1,96
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 <QAbstractScrollArea>
25 25 #include <QGLWidget>
26 26 #include <QDebug>
27 #include <cmath>
27 28
28 29 QTCOMMERCIALCHART_USE_NAMESPACE
29 30
30 31 DataSource::DataSource(QAbstractScrollArea *appViewer, QObject *parent) :
31 m_appViewer(appViewer),
32 32 QObject(parent),
33 m_appViewer(appViewer),
33 34 m_index(-1)
34 35 {
35 36 // generate
36 37 generateData(0, 5, 1024);
37 38 }
38 39
39 40 void DataSource::update(QAbstractSeries *series)
40 41 {
41 42 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
42 43 Q_ASSERT(xySeries);
43 44
44 45 m_index++;
45 46 if (m_index > m_data.count() - 1)
46 47 m_index = 0;
47 48
48 49 QList<QPointF> points = m_data.at(m_index);
49 50 // Use replace instead of clear + append, it's optimized for performance
50 51 xySeries->replace(points);
51 52 }
52 53
53 54 void DataSource::generateData(int type, int rowCount, int colCount)
54 55 {
55 56 qDebug() << "DataSource::generateData:" << type << rowCount << colCount;
56 57
57 58 // Remove previous data
58 59 foreach (QList<QPointF> row, m_data)
59 60 row.clear();
60 61 m_data.clear();
61 62
62 63 // Append the new data depending on the type
63 64 for (int i(0); i < rowCount; i++) {
64 65 QList<QPointF> points;
65 66 for (int j(0); j < colCount; j++) {
66 67 qreal x(0);
67 68 qreal y(0);
68 69 switch (type) {
69 70 case 0:
70 71 // data with sin + random component
71 72 y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
72 73 x = j;
73 74 break;
74 75 case 1:
75 76 // linear data
76 77 x = j;
77 78 y = (qreal) i / 10;
78 79 break;
79 80 default:
80 81 // unknown, do nothing
81 82 break;
82 83 }
83 84 points.append(QPointF(x, y));
84 85 }
85 86 m_data.append(points);
86 87 }
87 88 }
88 89
89 90 void DataSource::setOpenGL(bool enabled)
90 91 {
91 92 if (enabled)
92 93 m_appViewer->setViewport(new QGLWidget());
93 94 else
94 95 m_appViewer->setViewport(0);
95 96 }
@@ -1,85 +1,85
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 import QtQuick 1.0
22 22
23 23 Column {
24 24 spacing: 5
25 25 signal openGLEnabled(bool enabled)
26 26 signal animationsEnabled(bool enabled)
27 27 signal seriesTypeChanged(string type)
28 28 signal refreshRateChanged(variant rate);
29 29 signal signalSourceChanged(string source, int signalCount, int sampleCount);
30 30
31 31 Text {
32 32 text: "Oscilloscope"
33 33 font.pointSize: 18
34 34 }
35 35
36 36 MultiButton {
37 text: "Graph: "
38 items: ["line", "spline", "scatter"]
39 currentSelection: 0
40 onSelectionChanged: seriesTypeChanged(items[currentSelection]);
41 }
42
43 MultiButton {
37 44 id: signalSourceButton
38 text: "Signal source: "
45 text: "Source: "
39 46 items: ["sin", "linear"]
40 47 currentSelection: 0
41 48 onSelectionChanged: signalSourceChanged(
42 49 selection,
43 50 5,
44 51 sampleCountButton.items[sampleCountButton.currentSelection]);
45 52 }
46 53
47 54 MultiButton {
48 55 id: sampleCountButton
49 56 text: "Samples: "
50 57 items: [6, 128, 1024, 10000]
51 58 currentSelection: 2
52 59 onSelectionChanged: signalSourceChanged(
53 60 signalSourceButton.items[signalSourceButton.currentSelection],
54 61 5,
55 62 selection);
56 63 }
57 64
58 65 MultiButton {
59 text: "Graph: "
60 items: ["line", "spline", "scatter"]
61 currentSelection: 0
62 onSelectionChanged: seriesTypeChanged(items[currentSelection]);
63 }
64
65 MultiButton {
66 66 text: "Refresh rate: "
67 67 items: [1, 24, 60, 100]
68 68 currentSelection: 2
69 69 onSelectionChanged: refreshRateChanged(items[currentSelection]);
70 70 }
71 71
72 72 MultiButton {
73 73 text: "OpenGL: "
74 74 items: ["OFF", "ON"]
75 75 currentSelection: 0
76 76 onSelectionChanged: openGLEnabled(currentSelection == 1);
77 77 }
78 78
79 79 MultiButton {
80 80 text: "Animations: "
81 81 items: ["OFF", "ON"]
82 82 currentSelection: 0
83 83 onSelectionChanged: animationsEnabled(currentSelection == 1);
84 84 }
85 85 }
@@ -1,47 +1,47
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 import QtQuick 1.0
22 22
23 23 Rectangle {
24 24 id: button
25 width: 105
26 height: 33
25 width: 120
26 height: 35
27 27 border.color: "gray"
28 radius: 5
28 radius: 7
29 29 property string text: "Option: "
30 30 property variant items: ["first"]
31 31 property int currentSelection: 0
32 32 signal selectionChanged(variant selection)
33 33
34 34 Text {
35 35 id: buttonText
36 36 anchors.centerIn: parent
37 37 text: button.text + button.items[currentSelection]
38 38 }
39 39
40 40 MouseArea {
41 41 anchors.fill: parent
42 42 onClicked: {
43 43 currentSelection = (currentSelection + 1) % items.length;
44 44 selectionChanged(button.items[currentSelection]);
45 45 }
46 46 }
47 47 }
General Comments 0
You need to be logged in to leave comments. Login now