##// END OF EJS Templates
Made Qml Oscilloscope example little more sensible...
Miikka Heikkinen -
r2832:faab188cb2e7
parent child
Show More
@@ -1,96 +1,92
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2015 The Qt Company Ltd
4 4 ** All rights reserved.
5 5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and The Qt Company.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 import QtQuick 2.1
20 20 import QtQuick.Layouts 1.0
21 21
22 22 ColumnLayout {
23 23 property alias openGLButton: openGLButton
24 property alias antialiasButton: antialiasButton
24 25 spacing: 8
25 26 Layout.fillHeight: true
26 27 signal animationsEnabled(bool enabled)
27 28 signal seriesTypeChanged(string type)
28 29 signal refreshRateChanged(variant rate);
29 30 signal signalSourceChanged(string source, int signalCount, int sampleCount);
30 31 signal antialiasingEnabled(bool enabled)
31 32 signal openGlChanged(bool enabled)
32 33
33 34 Text {
34 35 text: "Scope"
35 36 font.pointSize: 18
36 37 color: "white"
37 38 }
38 39
39 40 MultiButton {
40 41 id: openGLButton
41 42 text: "OpenGL: "
42 43 items: ["false", "true"]
43 currentSelection: 0
44 currentSelection: 1
44 45 onSelectionChanged: openGlChanged(currentSelection == 1);
45 46 }
46 47
47 48 MultiButton {
48 49 text: "Graph: "
49 items: ["line", "spline", "scatter"]
50 items: ["line", "scatter"]
50 51 currentSelection: 0
51 52 onSelectionChanged: seriesTypeChanged(items[currentSelection]);
52 53 }
53 54
54 55 MultiButton {
55 56 id: signalSourceButton
56 57 text: "Source: "
57 58 items: ["sin", "linear"]
58 59 currentSelection: 0
59 60 onSelectionChanged: signalSourceChanged(
60 61 selection,
61 62 5,
62 63 sampleCountButton.items[sampleCountButton.currentSelection]);
63 64 }
64 65
65 66 MultiButton {
66 67 id: sampleCountButton
67 68 text: "Samples: "
68 69 items: ["6", "128", "1024", "10000"]
69 70 currentSelection: 2
70 71 onSelectionChanged: signalSourceChanged(
71 72 signalSourceButton.items[signalSourceButton.currentSelection],
72 73 5,
73 74 selection);
74 75 }
75 76
76 77 MultiButton {
77 78 text: "Refresh rate: "
78 79 items: ["1", "24", "60"]
79 80 currentSelection: 2
80 81 onSelectionChanged: refreshRateChanged(items[currentSelection]);
81 82 }
82 83
83 84 MultiButton {
84 text: "Animations: "
85 items: ["OFF", "ON"]
86 currentSelection: 0
87 onSelectionChanged: animationsEnabled(currentSelection == 1);
88 }
89
90 MultiButton {
85 id: antialiasButton
91 86 text: "Antialias: "
92 87 items: ["OFF", "ON"]
88 enabled: false
93 89 currentSelection: 0
94 90 onSelectionChanged: antialiasingEnabled(currentSelection == 1);
95 91 }
96 92 }
@@ -1,130 +1,127
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2015 The Qt Company Ltd
4 4 ** All rights reserved.
5 5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and The Qt Company.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 import QtQuick 2.0
20 20 import QtCharts 2.1
21 21
22 22 //![1]
23 23 ChartView {
24 24 id: chartView
25 25 animationOptions: ChartView.NoAnimation
26 26 theme: ChartView.ChartThemeDark
27 property bool openGL: false
27 property bool openGL: true
28 28 onOpenGLChanged: {
29 29 series("signal 1").useOpenGL = openGL;
30 30 series("signal 2").useOpenGL = openGL;
31 31 }
32 32
33 33 ValueAxis {
34 34 id: axisY1
35 35 min: -1
36 36 max: 4
37 37 }
38 38
39 39 ValueAxis {
40 40 id: axisY2
41 41 min: -10
42 42 max: 5
43 43 }
44 44
45 45 ValueAxis {
46 46 id: axisX
47 47 min: 0
48 48 max: 1024
49 49 }
50 50
51 51 LineSeries {
52 52 id: lineSeries1
53 53 name: "signal 1"
54 54 axisX: axisX
55 55 axisY: axisY1
56 56 useOpenGL: chartView.openGL
57 57 }
58 58 LineSeries {
59 59 id: lineSeries2
60 60 name: "signal 2"
61 61 axisX: axisX
62 62 axisYRight: axisY2
63 63 useOpenGL: chartView.openGL
64 64 }
65 65 //![1]
66 66
67 67 //![2]
68 68 Timer {
69 69 id: refreshTimer
70 70 interval: 1 / 60 * 1000 // 60 Hz
71 71 running: true
72 72 repeat: true
73 73 onTriggered: {
74 74 dataSource.update(chartView.series(0));
75 75 dataSource.update(chartView.series(1));
76 76 }
77 77 }
78 78 //![2]
79 79
80 80 //![3]
81 81 function changeSeriesType(type) {
82 82 chartView.removeAllSeries();
83 83
84 84 // Create two new series of the correct type. Axis x is the same for both of the series,
85 85 // but the series have their own y-axes to make it possible to control the y-offset
86 86 // of the "signal sources".
87 87 if (type == "line") {
88 88 var series1 = chartView.createSeries(ChartView.SeriesTypeLine, "signal 1",
89 89 axisX, axisY1);
90 90 series1.useOpenGL = chartView.openGL
91 91
92 92 var series2 = chartView.createSeries(ChartView.SeriesTypeLine, "signal 2",
93 93 axisX, axisY2);
94 94 series2.useOpenGL = chartView.openGL
95 } else if (type == "spline") {
96 chartView.createSeries(ChartView.SeriesTypeSpline, "signal 1", axisX, axisY1);
97 chartView.createSeries(ChartView.SeriesTypeSpline, "signal 2", axisX, axisY2);
98 95 } else {
99 96 var series1 = chartView.createSeries(ChartView.SeriesTypeScatter, "signal 1",
100 97 axisX, axisY1);
101 series1.markerSize = 3;
98 series1.markerSize = 2;
102 99 series1.borderColor = "transparent";
103 100 series1.useOpenGL = chartView.openGL
104 101
105 102 var series2 = chartView.createSeries(ChartView.SeriesTypeScatter, "signal 2",
106 103 axisX, axisY2);
107 series2.markerSize = 3;
104 series2.markerSize = 2;
108 105 series2.borderColor = "transparent";
109 106 series2.useOpenGL = chartView.openGL
110 107 }
111 108 }
112 109
113 110 function createAxis(min, max) {
114 111 // The following creates a ValueAxis object that can be then set as a x or y axis for a series
115 112 return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: "
116 113 + min + "; max: " + max + " }", chartView);
117 114 }
118 115 //![3]
119 116
120 117 function setAnimations(enabled) {
121 118 if (enabled)
122 119 chartView.animationOptions = ChartView.SeriesAnimations;
123 120 else
124 121 chartView.animationOptions = ChartView.NoAnimation;
125 122 }
126 123
127 124 function changeRefreshRate(rate) {
128 125 refreshTimer.interval = 1 / Number(rate) * 1000;
129 126 }
130 127 }
@@ -1,71 +1,65
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2015 The Qt Company Ltd
4 4 ** All rights reserved.
5 5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and The Qt Company.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 import QtQuick 2.0
20 20
21 21 //![1]
22 22 Rectangle {
23 23 id: main
24 24 width: 600
25 25 height: 400
26 26 color: "#404040"
27 27
28 28 ControlPanel {
29 29 id: controlPanel
30 30 anchors.top: parent.top
31 31 anchors.topMargin: 10
32 32 anchors.bottom: parent.bottom
33 33 anchors.left: parent.left
34 34 anchors.leftMargin: 10
35 35 //![1]
36 36
37 37 onSignalSourceChanged: {
38 38 if (source == "sin")
39 39 dataSource.generateData(0, signalCount, sampleCount);
40 40 else
41 41 dataSource.generateData(1, signalCount, sampleCount);
42 42 scopeView.axisX().max = sampleCount;
43 43 }
44 onAnimationsEnabled: scopeView.setAnimations(enabled);
45 onSeriesTypeChanged: {
46 scopeView.changeSeriesType(type);
47 if (type === "spline") {
48 controlPanel.openGLButton.currentSelection = 0;
49 controlPanel.openGLButton.enabled = false;
50 scopeView.openGL = false;
51 } else {
52 controlPanel.openGLButton.enabled = true;
53 }
54 }
44 onSeriesTypeChanged: scopeView.changeSeriesType(type);
55 45 onRefreshRateChanged: scopeView.changeRefreshRate(rate);
56 46 onAntialiasingEnabled: scopeView.antialiasing = enabled;
57 onOpenGlChanged: scopeView.openGL = enabled;
47 onOpenGlChanged: {
48 scopeView.openGL = enabled;
49 antialiasButton.enabled = !enabled;
50 antialiasButton.currentSelection = 0;
51 }
58 52 }
59 53
60 54 //![2]
61 55 ScopeView {
62 56 id: scopeView
63 57 anchors.top: parent.top
64 58 anchors.bottom: parent.bottom
65 59 anchors.right: parent.right
66 60 anchors.left: controlPanel.right
67 61 height: main.height
68 62 }
69 63 //![2]
70 64
71 65 }
@@ -1,57 +1,57
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2015 The Qt Company Ltd
4 4 ** All rights reserved.
5 5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and The Qt Company.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example qmloscilloscope
21 \title QML Oscilloscope
21 \title Qml Oscilloscope
22 22 \ingroup qtcharts_examples
23 23
24 24 \image examples_qmloscilloscope.png
25 25
26 26 \brief The example shows how to implement application with strict performance requirements
27 27 using the Qt Charts QML API.
28 28
29 29 The oscilloscope application demonstrates how to use the Qt Charts QML API to implement an
30 30 application with strict performance requirements. The application uses generated data with
31 31 configurable characteristics to mimic a simple oscilloscope user interface.
32 32
33 33 To get information about actual rendering speed shown in the application output console, you can
34 34 set QSG_RENDER_TIMING = 1 to your run environment settings. To do so go to Projects - Run -
35 35 Run environment in Qt Creator and select Add. Then you can experiment with the different
36 36 configurable options of the example application to find the configuration that gives you the
37 37 best performance in your environment.
38 38
39 39 The application window is shared by control and scope views:
40 40 \snippet qmloscilloscope/qml/qmloscilloscope/main.qml 1
41 41 \dots
42 42 \snippet qmloscilloscope/qml/qmloscilloscope/main.qml 2
43 43
44 44 ControlView implements the buttons used for configuring. ScopeView uses a ChartView to show
45 45 a chart with two line series:
46 46 \snippet qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 1
47 47 \dots
48 48
49 49 The data of the line series is updated with a QML timer. In a real life application the
50 50 updating could be triggered with a signal from Qt C++ code.
51 51 \snippet qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 2
52 52
53 53 The oscilloscope also allows you to switch the type of the series used for visualizing the
54 54 signal sources. This is implemented by dynamically destroying and creating series:
55 55 \snippet qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 3
56 56
57 57 */
General Comments 0
You need to be logged in to leave comments. Login now