@@ -1,93 +1,95 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise 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 <QDebug> |
|
25 | #include <QDebug> | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
30 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
|
31 | Q_DECLARE_METATYPE(QAbstractAxis *) | |||
31 |
|
32 | |||
32 | DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) : |
|
33 | DataSource::DataSource(QDeclarativeView *appViewer, QObject *parent) : | |
33 | QObject(parent), |
|
34 | QObject(parent), | |
34 | m_appViewer(appViewer), |
|
35 | m_appViewer(appViewer), | |
35 | m_index(-1) |
|
36 | m_index(-1) | |
36 | { |
|
37 | { | |
37 | qRegisterMetaType<QAbstractSeries*>(); |
|
38 | qRegisterMetaType<QAbstractSeries*>(); | |
|
39 | qRegisterMetaType<QAbstractAxis*>(); | |||
38 |
|
40 | |||
39 | generateData(0, 5, 1024); |
|
41 | generateData(0, 5, 1024); | |
40 | } |
|
42 | } | |
41 |
|
43 | |||
42 | void DataSource::update(QAbstractSeries *series) |
|
44 | void DataSource::update(QAbstractSeries *series) | |
43 | { |
|
45 | { | |
44 | if (series) { |
|
46 | if (series) { | |
45 | QXYSeries *xySeries = static_cast<QXYSeries *>(series); |
|
47 | QXYSeries *xySeries = static_cast<QXYSeries *>(series); | |
46 | m_index++; |
|
48 | m_index++; | |
47 | if (m_index > m_data.count() - 1) |
|
49 | if (m_index > m_data.count() - 1) | |
48 | m_index = 0; |
|
50 | m_index = 0; | |
49 |
|
51 | |||
50 | QList<QPointF> points = m_data.at(m_index); |
|
52 | QList<QPointF> points = m_data.at(m_index); | |
51 | // Use replace instead of clear + append, it's optimized for performance |
|
53 | // Use replace instead of clear + append, it's optimized for performance | |
52 | xySeries->replace(points); |
|
54 | xySeries->replace(points); | |
53 | } |
|
55 | } | |
54 | } |
|
56 | } | |
55 |
|
57 | |||
56 | void DataSource::generateData(int type, int rowCount, int colCount) |
|
58 | void DataSource::generateData(int type, int rowCount, int colCount) | |
57 | { |
|
59 | { | |
58 | // Remove previous data |
|
60 | // Remove previous data | |
59 | foreach (QList<QPointF> row, m_data) |
|
61 | foreach (QList<QPointF> row, m_data) | |
60 | row.clear(); |
|
62 | row.clear(); | |
61 | m_data.clear(); |
|
63 | m_data.clear(); | |
62 |
|
64 | |||
63 | // Append the new data depending on the type |
|
65 | // Append the new data depending on the type | |
64 | for (int i(0); i < rowCount; i++) { |
|
66 | for (int i(0); i < rowCount; i++) { | |
65 | QList<QPointF> points; |
|
67 | QList<QPointF> points; | |
66 | for (int j(0); j < colCount; j++) { |
|
68 | for (int j(0); j < colCount; j++) { | |
67 | qreal x(0); |
|
69 | qreal x(0); | |
68 | qreal y(0); |
|
70 | qreal y(0); | |
69 | switch (type) { |
|
71 | switch (type) { | |
70 | case 0: |
|
72 | case 0: | |
71 | // data with sin + random component |
|
73 | // data with sin + random component | |
72 | y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; |
|
74 | y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; | |
73 | x = j; |
|
75 | x = j; | |
74 | break; |
|
76 | break; | |
75 | case 1: |
|
77 | case 1: | |
76 | // linear data |
|
78 | // linear data | |
77 | x = j; |
|
79 | x = j; | |
78 | y = (qreal) i / 10; |
|
80 | y = (qreal) i / 10; | |
79 | break; |
|
81 | break; | |
80 | default: |
|
82 | default: | |
81 | // unknown, do nothing |
|
83 | // unknown, do nothing | |
82 | break; |
|
84 | break; | |
83 | } |
|
85 | } | |
84 | points.append(QPointF(x, y)); |
|
86 | points.append(QPointF(x, y)); | |
85 | } |
|
87 | } | |
86 | m_data.append(points); |
|
88 | m_data.append(points); | |
87 | } |
|
89 | } | |
88 | } |
|
90 | } | |
89 |
|
91 | |||
90 | void DataSource::setAntialiasing(bool enabled) |
|
92 | void DataSource::setAntialiasing(bool enabled) | |
91 | { |
|
93 | { | |
92 | m_appViewer->setRenderHint(QPainter::Antialiasing, enabled); |
|
94 | m_appViewer->setRenderHint(QPainter::Antialiasing, enabled); | |
93 | } |
|
95 | } |
@@ -1,89 +1,91 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise 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 <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
31 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
|
32 | Q_DECLARE_METATYPE(QAbstractAxis *) | |||
32 |
|
33 | |||
33 | DataSource::DataSource(QQuickView *appViewer, QObject *parent) : |
|
34 | DataSource::DataSource(QQuickView *appViewer, QObject *parent) : | |
34 | QObject(parent), |
|
35 | QObject(parent), | |
35 | m_appViewer(appViewer), |
|
36 | m_appViewer(appViewer), | |
36 | m_index(-1) |
|
37 | m_index(-1) | |
37 | { |
|
38 | { | |
38 | qRegisterMetaType<QAbstractSeries*>(); |
|
39 | qRegisterMetaType<QAbstractSeries*>(); | |
|
40 | qRegisterMetaType<QAbstractAxis*>(); | |||
39 |
|
41 | |||
40 | generateData(0, 5, 1024); |
|
42 | generateData(0, 5, 1024); | |
41 | } |
|
43 | } | |
42 |
|
44 | |||
43 | void DataSource::update(QAbstractSeries *series) |
|
45 | void DataSource::update(QAbstractSeries *series) | |
44 | { |
|
46 | { | |
45 | if (series) { |
|
47 | if (series) { | |
46 | QXYSeries *xySeries = static_cast<QXYSeries *>(series); |
|
48 | QXYSeries *xySeries = static_cast<QXYSeries *>(series); | |
47 | m_index++; |
|
49 | m_index++; | |
48 | if (m_index > m_data.count() - 1) |
|
50 | if (m_index > m_data.count() - 1) | |
49 | m_index = 0; |
|
51 | m_index = 0; | |
50 |
|
52 | |||
51 | QList<QPointF> points = m_data.at(m_index); |
|
53 | QList<QPointF> points = m_data.at(m_index); | |
52 | // Use replace instead of clear + append, it's optimized for performance |
|
54 | // Use replace instead of clear + append, it's optimized for performance | |
53 | xySeries->replace(points); |
|
55 | xySeries->replace(points); | |
54 | } |
|
56 | } | |
55 | } |
|
57 | } | |
56 |
|
58 | |||
57 | void DataSource::generateData(int type, int rowCount, int colCount) |
|
59 | void DataSource::generateData(int type, int rowCount, int colCount) | |
58 | { |
|
60 | { | |
59 | // Remove previous data |
|
61 | // Remove previous data | |
60 | foreach (QList<QPointF> row, m_data) |
|
62 | foreach (QList<QPointF> row, m_data) | |
61 | row.clear(); |
|
63 | row.clear(); | |
62 | m_data.clear(); |
|
64 | m_data.clear(); | |
63 |
|
65 | |||
64 | // Append the new data depending on the type |
|
66 | // Append the new data depending on the type | |
65 | for (int i(0); i < rowCount; i++) { |
|
67 | for (int i(0); i < rowCount; i++) { | |
66 | QList<QPointF> points; |
|
68 | QList<QPointF> points; | |
67 | for (int j(0); j < colCount; j++) { |
|
69 | for (int j(0); j < colCount; j++) { | |
68 | qreal x(0); |
|
70 | qreal x(0); | |
69 | qreal y(0); |
|
71 | qreal y(0); | |
70 | switch (type) { |
|
72 | switch (type) { | |
71 | case 0: |
|
73 | case 0: | |
72 | // data with sin + random component |
|
74 | // data with sin + random component | |
73 | y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; |
|
75 | y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; | |
74 | x = j; |
|
76 | x = j; | |
75 | break; |
|
77 | break; | |
76 | case 1: |
|
78 | case 1: | |
77 | // linear data |
|
79 | // linear data | |
78 | x = j; |
|
80 | x = j; | |
79 | y = (qreal) i / 10; |
|
81 | y = (qreal) i / 10; | |
80 | break; |
|
82 | break; | |
81 | default: |
|
83 | default: | |
82 | // unknown, do nothing |
|
84 | // unknown, do nothing | |
83 | break; |
|
85 | break; | |
84 | } |
|
86 | } | |
85 | points.append(QPointF(x, y)); |
|
87 | points.append(QPointF(x, y)); | |
86 | } |
|
88 | } | |
87 | m_data.append(points); |
|
89 | m_data.append(points); | |
88 | } |
|
90 | } | |
89 | } |
|
91 | } |
General Comments 0
You need to be logged in to leave comments.
Login now