@@ -1,95 +1,96 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "datasource.h" |
|
21 | #include "datasource.h" | |
22 | #include <QXYSeries> |
|
22 | #include <QXYSeries> | |
23 | #include <QAreaSeries> |
|
23 | #include <QAreaSeries> | |
24 | #include <QAbstractScrollArea> |
|
24 | #include <QAbstractScrollArea> | |
25 | #include <QGLWidget> |
|
25 | #include <QGLWidget> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
|
27 | #include <cmath> | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
30 | |||
30 | DataSource::DataSource(QAbstractScrollArea *appViewer, QObject *parent) : |
|
31 | DataSource::DataSource(QAbstractScrollArea *appViewer, QObject *parent) : | |
31 | m_appViewer(appViewer), |
|
|||
32 | QObject(parent), |
|
32 | QObject(parent), | |
|
33 | m_appViewer(appViewer), | |||
33 | m_index(-1) |
|
34 | m_index(-1) | |
34 | { |
|
35 | { | |
35 | // generate |
|
36 | // generate | |
36 | generateData(0, 5, 1024); |
|
37 | generateData(0, 5, 1024); | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | void DataSource::update(QAbstractSeries *series) |
|
40 | void DataSource::update(QAbstractSeries *series) | |
40 | { |
|
41 | { | |
41 | QXYSeries *xySeries = qobject_cast<QXYSeries *>(series); |
|
42 | QXYSeries *xySeries = qobject_cast<QXYSeries *>(series); | |
42 | Q_ASSERT(xySeries); |
|
43 | Q_ASSERT(xySeries); | |
43 |
|
44 | |||
44 | m_index++; |
|
45 | m_index++; | |
45 | if (m_index > m_data.count() - 1) |
|
46 | if (m_index > m_data.count() - 1) | |
46 | m_index = 0; |
|
47 | m_index = 0; | |
47 |
|
48 | |||
48 | QList<QPointF> points = m_data.at(m_index); |
|
49 | QList<QPointF> points = m_data.at(m_index); | |
49 | // Use replace instead of clear + append, it's optimized for performance |
|
50 | // Use replace instead of clear + append, it's optimized for performance | |
50 | xySeries->replace(points); |
|
51 | xySeries->replace(points); | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | void DataSource::generateData(int type, int rowCount, int colCount) |
|
54 | void DataSource::generateData(int type, int rowCount, int colCount) | |
54 | { |
|
55 | { | |
55 | qDebug() << "DataSource::generateData:" << type << rowCount << colCount; |
|
56 | qDebug() << "DataSource::generateData:" << type << rowCount << colCount; | |
56 |
|
57 | |||
57 | // Remove previous data |
|
58 | // Remove previous data | |
58 | foreach (QList<QPointF> row, m_data) |
|
59 | foreach (QList<QPointF> row, m_data) | |
59 | row.clear(); |
|
60 | row.clear(); | |
60 | m_data.clear(); |
|
61 | m_data.clear(); | |
61 |
|
62 | |||
62 | // Append the new data depending on the type |
|
63 | // Append the new data depending on the type | |
63 | for (int i(0); i < rowCount; i++) { |
|
64 | for (int i(0); i < rowCount; i++) { | |
64 | QList<QPointF> points; |
|
65 | QList<QPointF> points; | |
65 | for (int j(0); j < colCount; j++) { |
|
66 | for (int j(0); j < colCount; j++) { | |
66 | qreal x(0); |
|
67 | qreal x(0); | |
67 | qreal y(0); |
|
68 | qreal y(0); | |
68 | switch (type) { |
|
69 | switch (type) { | |
69 | case 0: |
|
70 | case 0: | |
70 | // data with sin + random component |
|
71 | // data with sin + random component | |
71 | y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; |
|
72 | y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; | |
72 | x = j; |
|
73 | x = j; | |
73 | break; |
|
74 | break; | |
74 | case 1: |
|
75 | case 1: | |
75 | // linear data |
|
76 | // linear data | |
76 | x = j; |
|
77 | x = j; | |
77 | y = (qreal) i / 10; |
|
78 | y = (qreal) i / 10; | |
78 | break; |
|
79 | break; | |
79 | default: |
|
80 | default: | |
80 | // unknown, do nothing |
|
81 | // unknown, do nothing | |
81 | break; |
|
82 | break; | |
82 | } |
|
83 | } | |
83 | points.append(QPointF(x, y)); |
|
84 | points.append(QPointF(x, y)); | |
84 | } |
|
85 | } | |
85 | m_data.append(points); |
|
86 | m_data.append(points); | |
86 | } |
|
87 | } | |
87 | } |
|
88 | } | |
88 |
|
89 | |||
89 | void DataSource::setOpenGL(bool enabled) |
|
90 | void DataSource::setOpenGL(bool enabled) | |
90 | { |
|
91 | { | |
91 | if (enabled) |
|
92 | if (enabled) | |
92 | m_appViewer->setViewport(new QGLWidget()); |
|
93 | m_appViewer->setViewport(new QGLWidget()); | |
93 | else |
|
94 | else | |
94 | m_appViewer->setViewport(0); |
|
95 | m_appViewer->setViewport(0); | |
95 | } |
|
96 | } |
@@ -1,85 +1,85 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 |
|
22 | |||
23 | Column { |
|
23 | Column { | |
24 | spacing: 5 |
|
24 | spacing: 5 | |
25 | signal openGLEnabled(bool enabled) |
|
25 | signal openGLEnabled(bool enabled) | |
26 | signal animationsEnabled(bool enabled) |
|
26 | signal animationsEnabled(bool enabled) | |
27 | signal seriesTypeChanged(string type) |
|
27 | signal seriesTypeChanged(string type) | |
28 | signal refreshRateChanged(variant rate); |
|
28 | signal refreshRateChanged(variant rate); | |
29 | signal signalSourceChanged(string source, int signalCount, int sampleCount); |
|
29 | signal signalSourceChanged(string source, int signalCount, int sampleCount); | |
30 |
|
30 | |||
31 | Text { |
|
31 | Text { | |
32 | text: "Oscilloscope" |
|
32 | text: "Oscilloscope" | |
33 | font.pointSize: 18 |
|
33 | font.pointSize: 18 | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | MultiButton { |
|
36 | MultiButton { | |
|
37 | text: "Graph: " | |||
|
38 | items: ["line", "spline", "scatter"] | |||
|
39 | currentSelection: 0 | |||
|
40 | onSelectionChanged: seriesTypeChanged(items[currentSelection]); | |||
|
41 | } | |||
|
42 | ||||
|
43 | MultiButton { | |||
37 | id: signalSourceButton |
|
44 | id: signalSourceButton | |
38 |
text: "S |
|
45 | text: "Source: " | |
39 | items: ["sin", "linear"] |
|
46 | items: ["sin", "linear"] | |
40 | currentSelection: 0 |
|
47 | currentSelection: 0 | |
41 | onSelectionChanged: signalSourceChanged( |
|
48 | onSelectionChanged: signalSourceChanged( | |
42 | selection, |
|
49 | selection, | |
43 | 5, |
|
50 | 5, | |
44 | sampleCountButton.items[sampleCountButton.currentSelection]); |
|
51 | sampleCountButton.items[sampleCountButton.currentSelection]); | |
45 | } |
|
52 | } | |
46 |
|
53 | |||
47 | MultiButton { |
|
54 | MultiButton { | |
48 | id: sampleCountButton |
|
55 | id: sampleCountButton | |
49 | text: "Samples: " |
|
56 | text: "Samples: " | |
50 | items: [6, 128, 1024, 10000] |
|
57 | items: [6, 128, 1024, 10000] | |
51 | currentSelection: 2 |
|
58 | currentSelection: 2 | |
52 | onSelectionChanged: signalSourceChanged( |
|
59 | onSelectionChanged: signalSourceChanged( | |
53 | signalSourceButton.items[signalSourceButton.currentSelection], |
|
60 | signalSourceButton.items[signalSourceButton.currentSelection], | |
54 | 5, |
|
61 | 5, | |
55 | selection); |
|
62 | selection); | |
56 | } |
|
63 | } | |
57 |
|
64 | |||
58 | MultiButton { |
|
65 | MultiButton { | |
59 | text: "Graph: " |
|
|||
60 | items: ["line", "spline", "scatter"] |
|
|||
61 | currentSelection: 0 |
|
|||
62 | onSelectionChanged: seriesTypeChanged(items[currentSelection]); |
|
|||
63 | } |
|
|||
64 |
|
||||
65 | MultiButton { |
|
|||
66 | text: "Refresh rate: " |
|
66 | text: "Refresh rate: " | |
67 | items: [1, 24, 60, 100] |
|
67 | items: [1, 24, 60, 100] | |
68 | currentSelection: 2 |
|
68 | currentSelection: 2 | |
69 | onSelectionChanged: refreshRateChanged(items[currentSelection]); |
|
69 | onSelectionChanged: refreshRateChanged(items[currentSelection]); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | MultiButton { |
|
72 | MultiButton { | |
73 | text: "OpenGL: " |
|
73 | text: "OpenGL: " | |
74 | items: ["OFF", "ON"] |
|
74 | items: ["OFF", "ON"] | |
75 | currentSelection: 0 |
|
75 | currentSelection: 0 | |
76 | onSelectionChanged: openGLEnabled(currentSelection == 1); |
|
76 | onSelectionChanged: openGLEnabled(currentSelection == 1); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | MultiButton { |
|
79 | MultiButton { | |
80 | text: "Animations: " |
|
80 | text: "Animations: " | |
81 | items: ["OFF", "ON"] |
|
81 | items: ["OFF", "ON"] | |
82 | currentSelection: 0 |
|
82 | currentSelection: 0 | |
83 | onSelectionChanged: animationsEnabled(currentSelection == 1); |
|
83 | onSelectionChanged: animationsEnabled(currentSelection == 1); | |
84 | } |
|
84 | } | |
85 | } |
|
85 | } |
@@ -1,47 +1,47 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 |
|
22 | |||
23 | Rectangle { |
|
23 | Rectangle { | |
24 | id: button |
|
24 | id: button | |
25 |
width: 10 |
|
25 | width: 120 | |
26 |
height: 3 |
|
26 | height: 35 | |
27 | border.color: "gray" |
|
27 | border.color: "gray" | |
28 |
radius: |
|
28 | radius: 7 | |
29 | property string text: "Option: " |
|
29 | property string text: "Option: " | |
30 | property variant items: ["first"] |
|
30 | property variant items: ["first"] | |
31 | property int currentSelection: 0 |
|
31 | property int currentSelection: 0 | |
32 | signal selectionChanged(variant selection) |
|
32 | signal selectionChanged(variant selection) | |
33 |
|
33 | |||
34 | Text { |
|
34 | Text { | |
35 | id: buttonText |
|
35 | id: buttonText | |
36 | anchors.centerIn: parent |
|
36 | anchors.centerIn: parent | |
37 | text: button.text + button.items[currentSelection] |
|
37 | text: button.text + button.items[currentSelection] | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | MouseArea { |
|
40 | MouseArea { | |
41 | anchors.fill: parent |
|
41 | anchors.fill: parent | |
42 | onClicked: { |
|
42 | onClicked: { | |
43 | currentSelection = (currentSelection + 1) % items.length; |
|
43 | currentSelection = (currentSelection + 1) % items.length; | |
44 | selectionChanged(button.items[currentSelection]); |
|
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