##// END OF EJS Templates
Remove opengl dependency from oscilloscope demos....
Miikka Heikkinen -
r2525:5407eb4cd85a
parent child
Show More
@@ -1,37 +1,32
1 CURRENTLY_BUILDING_COMPONENTS = "demos"
1 CURRENTLY_BUILDING_COMPONENTS = "demos"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += piechartcustomization \
7 SUBDIRS += piechartcustomization \
8 dynamicspline \
8 dynamicspline \
9 nesteddonuts \
9 nesteddonuts \
10 qmlchart \
10 qmlchart \
11 qmlweather \
11 qmlweather \
12 qmlf1legends \
12 qmlf1legends \
13 qmlcustomizations \
13 qmlcustomizations \
14 qmlcustommodel \
14 qmlcustommodel \
15 chartinteractions \
15 chartinteractions \
16 qmlaxes \
16 qmlaxes \
17 qmlcustomlegend \
17 qmlcustomlegend \
18 callout \
18 callout \
19 qmlpolarchart
19 qmlpolarchart \
20
20 qmloscilloscope \
21 contains(QT_CONFIG, opengl) {
21 chartthemes
22 SUBDIRS += chartthemes \
23 qmloscilloscope
24 } else {
25 message("OpenGL not available. Some demos are disabled")
26 }
27
22
28 contains(QT_CONFIG, multimedia) {
23 contains(QT_CONFIG, multimedia) {
29 SUBDIRS += audio
24 SUBDIRS += audio
30 } else {
25 } else {
31 message("QtMultimedia library not available. Some demos are disabled")
26 message("QtMultimedia library not available. Some demos are disabled")
32 }
27 }
33
28
34 contains(QT_VERSION, ^5\\..*\\..*$):qtHaveModule(quick) {
29 contains(QT_VERSION, ^5\\..*\\..*$):qtHaveModule(quick) {
35 SUBDIRS += quick2chart \
30 SUBDIRS += quick2chart \
36 quick2oscilloscope
31 quick2oscilloscope
37 }
32 }
@@ -1,94 +1,93
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 <QDeclarativeView>
24 #include <QDeclarativeView>
25 #include <QGLWidget>
26 #include <QDebug>
25 #include <QDebug>
27 #include <cmath>
26 #include <cmath>
28
27
29 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
30
29
31 Q_DECLARE_METATYPE(QAbstractSeries *)
30 Q_DECLARE_METATYPE(QAbstractSeries *)
32
31
33 DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) :
32 DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) :
34 QObject(parent),
33 QObject(parent),
35 m_appViewer(appViewer),
34 m_appViewer(appViewer),
36 m_index(-1)
35 m_index(-1)
37 {
36 {
38 qRegisterMetaType<QAbstractSeries*>();
37 qRegisterMetaType<QAbstractSeries*>();
39
38
40 generateData(0, 5, 1024);
39 generateData(0, 5, 1024);
41 }
40 }
42
41
43 void DataSource::update(QAbstractSeries *series)
42 void DataSource::update(QAbstractSeries *series)
44 {
43 {
45 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
44 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
46 Q_ASSERT(xySeries);
45 Q_ASSERT(xySeries);
47
46
48 m_index++;
47 m_index++;
49 if (m_index > m_data.count() - 1)
48 if (m_index > m_data.count() - 1)
50 m_index = 0;
49 m_index = 0;
51
50
52 QList<QPointF> points = m_data.at(m_index);
51 QList<QPointF> points = m_data.at(m_index);
53 // Use replace instead of clear + append, it's optimized for performance
52 // Use replace instead of clear + append, it's optimized for performance
54 xySeries->replace(points);
53 xySeries->replace(points);
55 }
54 }
56
55
57 void DataSource::generateData(int type, int rowCount, int colCount)
56 void DataSource::generateData(int type, int rowCount, int colCount)
58 {
57 {
59 // Remove previous data
58 // Remove previous data
60 foreach (QList<QPointF> row, m_data)
59 foreach (QList<QPointF> row, m_data)
61 row.clear();
60 row.clear();
62 m_data.clear();
61 m_data.clear();
63
62
64 // Append the new data depending on the type
63 // Append the new data depending on the type
65 for (int i(0); i < rowCount; i++) {
64 for (int i(0); i < rowCount; i++) {
66 QList<QPointF> points;
65 QList<QPointF> points;
67 for (int j(0); j < colCount; j++) {
66 for (int j(0); j < colCount; j++) {
68 qreal x(0);
67 qreal x(0);
69 qreal y(0);
68 qreal y(0);
70 switch (type) {
69 switch (type) {
71 case 0:
70 case 0:
72 // data with sin + random component
71 // data with sin + random component
73 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;
74 x = j;
73 x = j;
75 break;
74 break;
76 case 1:
75 case 1:
77 // linear data
76 // linear data
78 x = j;
77 x = j;
79 y = (qreal) i / 10;
78 y = (qreal) i / 10;
80 break;
79 break;
81 default:
80 default:
82 // unknown, do nothing
81 // unknown, do nothing
83 break;
82 break;
84 }
83 }
85 points.append(QPointF(x, y));
84 points.append(QPointF(x, y));
86 }
85 }
87 m_data.append(points);
86 m_data.append(points);
88 }
87 }
89 }
88 }
90
89
91 void DataSource::setAntialiasing(bool enabled)
90 void DataSource::setAntialiasing(bool enabled)
92 {
91 {
93 m_appViewer->setRenderHint(QPainter::Antialiasing, enabled);
92 m_appViewer->setRenderHint(QPainter::Antialiasing, enabled);
94 }
93 }
@@ -1,14 +1,13
1 !include( ../demos.pri ) {
1 !include( ../demos.pri ) {
2 error( "Couldn't find the demos.pri file!" )
2 error( "Couldn't find the demos.pri file!" )
3 }
3 }
4
4
5 QT += opengl
6 RESOURCES += resources.qrc
5 RESOURCES += resources.qrc
7 SOURCES += main.cpp \
6 SOURCES += main.cpp \
8 datasource.cpp
7 datasource.cpp
9 OTHER_FILES += qml/qmloscilloscope/*
8 OTHER_FILES += qml/qmloscilloscope/*
10
9
11 include(qmlapplicationviewer/qmlapplicationviewer.pri)
10 include(qmlapplicationviewer/qmlapplicationviewer.pri)
12
11
13 HEADERS += \
12 HEADERS += \
14 datasource.h
13 datasource.h
@@ -1,90 +1,89
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 <QtQuick/QQuickView>
24 #include <QtQuick/QQuickView>
25 #include <QtQuick/QQuickItem>
25 #include <QtQuick/QQuickItem>
26 #include <QGLWidget>
27 #include <QDebug>
26 #include <QDebug>
28 #include <cmath>
27 #include <cmath>
29
28
30 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
31
30
32 Q_DECLARE_METATYPE(QAbstractSeries *)
31 Q_DECLARE_METATYPE(QAbstractSeries *)
33
32
34 DataSource::DataSource(QQuickView *appViewer, QObject *parent) :
33 DataSource::DataSource(QQuickView *appViewer, QObject *parent) :
35 QObject(parent),
34 QObject(parent),
36 m_appViewer(appViewer),
35 m_appViewer(appViewer),
37 m_index(-1)
36 m_index(-1)
38 {
37 {
39 qRegisterMetaType<QAbstractSeries*>();
38 qRegisterMetaType<QAbstractSeries*>();
40
39
41 generateData(0, 5, 1024);
40 generateData(0, 5, 1024);
42 }
41 }
43
42
44 void DataSource::update(QAbstractSeries *series)
43 void DataSource::update(QAbstractSeries *series)
45 {
44 {
46 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
45 QXYSeries *xySeries = qobject_cast<QXYSeries *>(series);
47 Q_ASSERT(xySeries);
46 Q_ASSERT(xySeries);
48
47
49 m_index++;
48 m_index++;
50 if (m_index > m_data.count() - 1)
49 if (m_index > m_data.count() - 1)
51 m_index = 0;
50 m_index = 0;
52
51
53 QList<QPointF> points = m_data.at(m_index);
52 QList<QPointF> points = m_data.at(m_index);
54 // Use replace instead of clear + append, it's optimized for performance
53 // Use replace instead of clear + append, it's optimized for performance
55 xySeries->replace(points);
54 xySeries->replace(points);
56 }
55 }
57
56
58 void DataSource::generateData(int type, int rowCount, int colCount)
57 void DataSource::generateData(int type, int rowCount, int colCount)
59 {
58 {
60 // Remove previous data
59 // Remove previous data
61 foreach (QList<QPointF> row, m_data)
60 foreach (QList<QPointF> row, m_data)
62 row.clear();
61 row.clear();
63 m_data.clear();
62 m_data.clear();
64
63
65 // Append the new data depending on the type
64 // Append the new data depending on the type
66 for (int i(0); i < rowCount; i++) {
65 for (int i(0); i < rowCount; i++) {
67 QList<QPointF> points;
66 QList<QPointF> points;
68 for (int j(0); j < colCount; j++) {
67 for (int j(0); j < colCount; j++) {
69 qreal x(0);
68 qreal x(0);
70 qreal y(0);
69 qreal y(0);
71 switch (type) {
70 switch (type) {
72 case 0:
71 case 0:
73 // data with sin + random component
72 // data with sin + random component
74 y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
73 y = sin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
75 x = j;
74 x = j;
76 break;
75 break;
77 case 1:
76 case 1:
78 // linear data
77 // linear data
79 x = j;
78 x = j;
80 y = (qreal) i / 10;
79 y = (qreal) i / 10;
81 break;
80 break;
82 default:
81 default:
83 // unknown, do nothing
82 // unknown, do nothing
84 break;
83 break;
85 }
84 }
86 points.append(QPointF(x, y));
85 points.append(QPointF(x, y));
87 }
86 }
88 m_data.append(points);
87 m_data.append(points);
89 }
88 }
90 }
89 }
@@ -1,14 +1,13
1 !include( ../demos.pri ) {
1 !include( ../demos.pri ) {
2 error( "Couldn't find the demos.pri file!" )
2 error( "Couldn't find the demos.pri file!" )
3 }
3 }
4
4
5 QT += opengl
6 RESOURCES += resources.qrc
5 RESOURCES += resources.qrc
7 SOURCES += main.cpp \
6 SOURCES += main.cpp \
8 datasource.cpp
7 datasource.cpp
9 OTHER_FILES += qml/quick2oscilloscope/*
8 OTHER_FILES += qml/quick2oscilloscope/*
10
9
11 include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
10 include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
12
11
13 HEADERS += \
12 HEADERS += \
14 datasource.h
13 datasource.h
General Comments 0
You need to be logged in to leave comments. Login now