@@ -1,93 +1,91 | |||
|
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 | 31 | DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) : |
|
32 | 32 | QObject(parent), |
|
33 | 33 | m_appViewer(appViewer), |
|
34 | 34 | m_index(-1) |
|
35 | 35 | { |
|
36 | 36 | // generate |
|
37 | 37 | generateData(0, 5, 1024); |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | void DataSource::update(QAbstractSeries *series) |
|
41 | 41 | { |
|
42 | 42 | QXYSeries *xySeries = qobject_cast<QXYSeries *>(series); |
|
43 | 43 | Q_ASSERT(xySeries); |
|
44 | 44 | |
|
45 | 45 | m_index++; |
|
46 | 46 | if (m_index > m_data.count() - 1) |
|
47 | 47 | m_index = 0; |
|
48 | 48 | |
|
49 | 49 | QList<QPointF> points = m_data.at(m_index); |
|
50 | 50 | // Use replace instead of clear + append, it's optimized for performance |
|
51 | 51 | xySeries->replace(points); |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | void DataSource::generateData(int type, int rowCount, int colCount) |
|
55 | 55 | { |
|
56 | qDebug() << "DataSource::generateData:" << type << rowCount << colCount; | |
|
57 | ||
|
58 | 56 | // Remove previous data |
|
59 | 57 | foreach (QList<QPointF> row, m_data) |
|
60 | 58 | row.clear(); |
|
61 | 59 | m_data.clear(); |
|
62 | 60 | |
|
63 | 61 | // Append the new data depending on the type |
|
64 | 62 | for (int i(0); i < rowCount; i++) { |
|
65 | 63 | QList<QPointF> points; |
|
66 | 64 | for (int j(0); j < colCount; j++) { |
|
67 | 65 | qreal x(0); |
|
68 | 66 | qreal y(0); |
|
69 | 67 | switch (type) { |
|
70 | 68 | case 0: |
|
71 | 69 | // data with sin + random component |
|
72 | 70 | y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; |
|
73 | 71 | x = j; |
|
74 | 72 | break; |
|
75 | 73 | case 1: |
|
76 | 74 | // linear data |
|
77 | 75 | x = j; |
|
78 | 76 | y = (qreal) i / 10; |
|
79 | 77 | break; |
|
80 | 78 | default: |
|
81 | 79 | // unknown, do nothing |
|
82 | 80 | break; |
|
83 | 81 | } |
|
84 | 82 | points.append(QPointF(x, y)); |
|
85 | 83 | } |
|
86 | 84 | m_data.append(points); |
|
87 | 85 | } |
|
88 | 86 | } |
|
89 | 87 | |
|
90 | 88 | void DataSource::setAntialiasing(bool enabled) |
|
91 | 89 | { |
|
92 | 90 | m_appViewer->setRenderHint(QPainter::Antialiasing, enabled); |
|
93 | 91 | } |
@@ -1,85 +1,86 | |||
|
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 |
spacing: |
|
|
24 | spacing: 8 | |
|
25 | 25 | signal animationsEnabled(bool enabled) |
|
26 | 26 | signal seriesTypeChanged(string type) |
|
27 | 27 | signal refreshRateChanged(variant rate); |
|
28 | 28 | signal signalSourceChanged(string source, int signalCount, int sampleCount); |
|
29 | 29 | signal antialiasingEnabled(bool enabled) |
|
30 | 30 | |
|
31 | 31 | Text { |
|
32 |
text: " |
|
|
32 | text: "Scope-PAS2" | |
|
33 | 33 | font.pointSize: 18 |
|
34 | color: "white" | |
|
34 | 35 | } |
|
35 | 36 | |
|
36 | 37 | MultiButton { |
|
37 | 38 | text: "Graph: " |
|
38 | 39 | items: ["line", "spline", "scatter"] |
|
39 | 40 | currentSelection: 0 |
|
40 | 41 | onSelectionChanged: seriesTypeChanged(items[currentSelection]); |
|
41 | 42 | } |
|
42 | 43 | |
|
43 | 44 | MultiButton { |
|
44 | 45 | id: signalSourceButton |
|
45 | 46 | text: "Source: " |
|
46 | 47 | items: ["sin", "linear"] |
|
47 | 48 | currentSelection: 0 |
|
48 | 49 | onSelectionChanged: signalSourceChanged( |
|
49 | 50 | selection, |
|
50 | 51 | 5, |
|
51 | 52 | sampleCountButton.items[sampleCountButton.currentSelection]); |
|
52 | 53 | } |
|
53 | 54 | |
|
54 | 55 | MultiButton { |
|
55 | 56 | id: sampleCountButton |
|
56 | 57 | text: "Samples: " |
|
57 | 58 | items: [6, 128, 1024, 10000] |
|
58 | 59 | currentSelection: 2 |
|
59 | 60 | onSelectionChanged: signalSourceChanged( |
|
60 | 61 | signalSourceButton.items[signalSourceButton.currentSelection], |
|
61 | 62 | 5, |
|
62 | 63 | selection); |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | MultiButton { |
|
66 | 67 | text: "Refresh rate: " |
|
67 | 68 | items: [1, 24, 60, 100] |
|
68 | 69 | currentSelection: 2 |
|
69 | 70 | onSelectionChanged: refreshRateChanged(items[currentSelection]); |
|
70 | 71 | } |
|
71 | 72 | |
|
72 | 73 | MultiButton { |
|
73 | 74 | text: "Animations: " |
|
74 | 75 | items: ["OFF", "ON"] |
|
75 | 76 | currentSelection: 0 |
|
76 | 77 | onSelectionChanged: animationsEnabled(currentSelection == 1); |
|
77 | 78 | } |
|
78 | 79 | |
|
79 | 80 | MultiButton { |
|
80 | 81 | text: "Antialias: " |
|
81 | 82 | items: ["OFF", "ON"] |
|
82 | 83 | currentSelection: 0 |
|
83 | 84 | onSelectionChanged: antialiasingEnabled(currentSelection == 1); |
|
84 | 85 | } |
|
85 | 86 | } |
@@ -1,47 +1,54 | |||
|
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: 1 |
|
|
26 |
height: 3 |
|
|
27 | border.color: "gray" | |
|
25 | width: 115 | |
|
26 | height: 31 | |
|
27 | gradient: Gradient { | |
|
28 | GradientStop { position: mouseArea.pressed ? 1.0 : 0.0; color: "#A09090" } | |
|
29 | GradientStop { position: mouseArea.pressed ? 0.0 : 1.0; color: "#505050" } | |
|
30 | } | |
|
31 | smooth: true | |
|
32 | ||
|
28 | 33 | radius: 7 |
|
29 | 34 | property string text: "Option: " |
|
30 | 35 | property variant items: ["first"] |
|
31 | 36 | property int currentSelection: 0 |
|
32 | 37 | signal selectionChanged(variant selection) |
|
33 | 38 | |
|
34 | 39 | Text { |
|
35 | 40 | id: buttonText |
|
36 | 41 | anchors.centerIn: parent |
|
42 | color: "#FFFFFF" | |
|
37 | 43 | text: button.text + button.items[currentSelection] |
|
38 | 44 | } |
|
39 | 45 | |
|
40 | 46 | MouseArea { |
|
47 | id: mouseArea | |
|
41 | 48 | anchors.fill: parent |
|
42 | 49 | onClicked: { |
|
43 | 50 | currentSelection = (currentSelection + 1) % items.length; |
|
44 | 51 | selectionChanged(button.items[currentSelection]); |
|
45 | 52 | } |
|
46 | 53 | } |
|
47 | 54 | } |
@@ -1,116 +1,116 | |||
|
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 |
import QtCommercial.Chart 1. |
|
|
22 | import QtCommercial.Chart 1.2 | |
|
23 | 23 | |
|
24 | 24 | //![1] |
|
25 | 25 | ChartView { |
|
26 | 26 | id: chartView |
|
27 | 27 | animationOptions: ChartView.NoAnimation |
|
28 | 28 | theme: ChartView.ChartThemeDark |
|
29 | 29 | |
|
30 | 30 | ValueAxis { |
|
31 | 31 | id: axisY1 |
|
32 | 32 | min: -1 |
|
33 | 33 | max: 4 |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | ValueAxis { |
|
37 | 37 | id: axisY2 |
|
38 | 38 | min: -10 |
|
39 | 39 | max: 5 |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | ValueAxis { |
|
43 | 43 | id: axisX |
|
44 | 44 | min: 0 |
|
45 | 45 | max: 1000 |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | LineSeries { |
|
49 | 49 | id: lineSeries1 |
|
50 | 50 | name: "signal 1" |
|
51 | 51 | axisX: axisX |
|
52 | 52 | axisY: axisY1 |
|
53 | 53 | } |
|
54 | 54 | LineSeries { |
|
55 | 55 | id: lineSeries2 |
|
56 | 56 | name: "signal 2" |
|
57 | 57 | axisX: axisX |
|
58 | axisY: axisY2 | |
|
58 | axisYRight: axisY2 | |
|
59 | 59 | } |
|
60 | 60 | // ... |
|
61 | 61 | //![1] |
|
62 | 62 | |
|
63 | 63 | //![2] |
|
64 | 64 | Timer { |
|
65 | 65 | id: refreshTimer |
|
66 | 66 | interval: 1 / 60 * 1000 // 60 Hz |
|
67 | 67 | running: true |
|
68 | 68 | repeat: true |
|
69 | 69 | onTriggered: { |
|
70 | 70 | dataSource.update(chartView.series(0)); |
|
71 | 71 | dataSource.update(chartView.series(1)); |
|
72 | 72 | } |
|
73 | 73 | } |
|
74 | 74 | //![2] |
|
75 | 75 | |
|
76 | 76 | //![3] |
|
77 | 77 | function changeSeriesType(type) { |
|
78 | 78 | chartView.removeAllSeries(); |
|
79 | 79 | |
|
80 | 80 | // Create two new series of the correct type. Axis x is the same for both of the series, |
|
81 | 81 | // but the series have their own y-axes to make it possible to control the y-offset |
|
82 | 82 | // of the "signal sources". |
|
83 | 83 | if (type == "line") { |
|
84 | 84 | scopeView.createSeries(ChartView.SeriesTypeLine, "signal 1", axisX, axisY1); |
|
85 | 85 | scopeView.createSeries(ChartView.SeriesTypeLine, "signal 2", axisX, axisY2); |
|
86 | 86 | } else if (type == "spline") { |
|
87 | 87 | scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 1", axisX, axisY1); |
|
88 | 88 | scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 2", axisX, axisY2); |
|
89 | 89 | } else { |
|
90 | 90 | var series1 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 1", axisX, axisY1); |
|
91 | 91 | series1.markerSize = 3; |
|
92 | 92 | series1.borderColor = "transparent"; |
|
93 | 93 | var series2 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 2", axisX, axisY2); |
|
94 | 94 | series2.markerSize = 3; |
|
95 | 95 | series2.borderColor = "transparent"; |
|
96 | 96 | } |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | function createAxis(min, max) { |
|
100 | 100 | // The following creates a ValueAxis object that can be then set as a x or y axis for a series |
|
101 | 101 | return Qt.createQmlObject("import QtQuick 1.1; import QtCommercial.Chart 1.1; ValueAxis { min: " |
|
102 | 102 | + min + "; max: " + max + " }", chartView); |
|
103 | 103 | } |
|
104 | 104 | //![3] |
|
105 | 105 | |
|
106 | 106 | function setAnimations(enabled) { |
|
107 | 107 | if (enabled) |
|
108 | 108 | scopeView.animationOptions = ChartView.SeriesAnimations; |
|
109 | 109 | else |
|
110 | 110 | scopeView.animationOptions = ChartView.NoAnimation; |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | function changeRefreshRate(rate) { |
|
114 | 114 | refreshTimer.interval = 1 / Number(rate) * 1000; |
|
115 | 115 | } |
|
116 | 116 | } |
@@ -1,61 +1,62 | |||
|
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 | //![1] |
|
24 | 24 | Rectangle { |
|
25 | 25 | id: main |
|
26 | 26 | width: 400 |
|
27 | 27 | height: 300 |
|
28 | color: "#404040" | |
|
28 | 29 | |
|
29 | 30 | ControlPanel { |
|
30 | 31 | id: controlPanel |
|
31 | 32 | anchors.top: parent.top |
|
32 | 33 | anchors.topMargin: 10 |
|
33 | 34 | anchors.bottom: parent.bottom |
|
34 | 35 | anchors.left: parent.left |
|
35 | 36 | anchors.leftMargin: 10 |
|
36 | 37 | // ... |
|
37 | 38 | //![1] |
|
38 | 39 | |
|
39 | 40 | onSignalSourceChanged: { |
|
40 | 41 | if (source == "sin") |
|
41 | 42 | dataSource.generateData(0, signalCount, sampleCount); |
|
42 | 43 | else |
|
43 | 44 | dataSource.generateData(1, signalCount, sampleCount); |
|
44 | 45 | } |
|
45 | 46 | onAnimationsEnabled: scopeView.setAnimations(enabled); |
|
46 | 47 | onSeriesTypeChanged: scopeView.changeSeriesType(type); |
|
47 | 48 | onRefreshRateChanged: scopeView.changeRefreshRate(rate); |
|
48 | 49 | onAntialiasingEnabled: dataSource.setAntialiasing(enabled); |
|
49 | 50 | } |
|
50 | 51 | |
|
51 | 52 | //![2] |
|
52 | 53 | ScopeView { |
|
53 | 54 | id: scopeView |
|
54 | 55 | anchors.top: parent.top |
|
55 | 56 | anchors.bottom: parent.bottom |
|
56 | 57 | anchors.right: parent.right |
|
57 | 58 | anchors.left: controlPanel.right |
|
58 | 59 | height: main.height |
|
59 | 60 | } |
|
60 | 61 | //![2] |
|
61 | 62 | } |
General Comments 0
You need to be logged in to leave comments.
Login now