@@ -1,103 +1,101 | |||||
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 "chart.h" | |||
21 | #include <QValueAxis> |
|
22 | #include <QValueAxis> | |
22 | #include <QAbstractAxis> |
|
23 | #include <QAbstractAxis> | |
23 | #include <cmath> |
|
24 | #include <cmath> | |
24 | #include <QDebug> |
|
|||
25 |
|
||||
26 | #include "chart.h" |
|
|||
27 |
|
25 | |||
28 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) |
|
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) | |
29 | : QChart(parent, wFlags), m_series(series) |
|
27 | : QChart(parent, wFlags), m_series(series) | |
30 | { |
|
28 | { | |
31 | m_clicked = false; |
|
29 | m_clicked = false; | |
32 | } |
|
30 | } | |
33 |
|
31 | |||
34 | Chart::~Chart() |
|
32 | Chart::~Chart() | |
35 | { |
|
33 | { | |
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 | void Chart::clickPoint(const QPointF &point) |
|
36 | void Chart::clickPoint(const QPointF &point) | |
39 | { |
|
37 | { | |
40 | // Find the closes data point |
|
38 | // Find the closes data point | |
41 | m_movingPoint = QPoint(); |
|
39 | m_movingPoint = QPoint(); | |
42 | m_clicked = false; |
|
40 | m_clicked = false; | |
43 | foreach (QPointF p, m_series->points()) { |
|
41 | foreach (QPointF p, m_series->points()) { | |
44 | if (distance(p, point) < distance(m_movingPoint, point)) { |
|
42 | if (distance(p, point) < distance(m_movingPoint, point)) { | |
45 | m_movingPoint = p; |
|
43 | m_movingPoint = p; | |
46 | m_clicked = true; |
|
44 | m_clicked = true; | |
47 | } |
|
45 | } | |
48 | } |
|
46 | } | |
49 | } |
|
47 | } | |
50 |
|
48 | |||
51 | qreal Chart::distance(const QPointF &p1, const QPointF &p2) |
|
49 | qreal Chart::distance(const QPointF &p1, const QPointF &p2) | |
52 | { |
|
50 | { | |
53 | return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) |
|
51 | return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) | |
54 | + (p1.y() - p2.y()) * (p1.y() - p2.y())); |
|
52 | + (p1.y() - p2.y()) * (p1.y() - p2.y())); | |
55 | } |
|
53 | } | |
56 |
|
54 | |||
57 | void Chart::setPointClicked(bool clicked) |
|
55 | void Chart::setPointClicked(bool clicked) | |
58 | { |
|
56 | { | |
59 | m_clicked = clicked; |
|
57 | m_clicked = clicked; | |
60 | } |
|
58 | } | |
61 |
|
59 | |||
62 | void Chart::handlePointMove(const QPoint &point) |
|
60 | void Chart::handlePointMove(const QPoint &point) | |
63 | { |
|
61 | { | |
64 | if (m_clicked) { |
|
62 | if (m_clicked) { | |
65 | //Map the point clicked from the ChartView |
|
63 | //Map the point clicked from the ChartView | |
66 | //to the area occupied by the chart. |
|
64 | //to the area occupied by the chart. | |
67 | QPoint mappedPoint = point; |
|
65 | QPoint mappedPoint = point; | |
68 | mappedPoint.setX(point.x()-this->plotArea().x()); |
|
66 | mappedPoint.setX(point.x()-this->plotArea().x()); | |
69 | mappedPoint.setY(point.y()-this->plotArea().y()); |
|
67 | mappedPoint.setY(point.y()-this->plotArea().y()); | |
70 |
|
68 | |||
71 | //Get the x- and y axis to be able to convert the mapped |
|
69 | //Get the x- and y axis to be able to convert the mapped | |
72 | //coordinate point to the charts scale. |
|
70 | //coordinate point to the charts scale. | |
73 | QAbstractAxis * axisx = this->axisX(); |
|
71 | QAbstractAxis * axisx = this->axisX(); | |
74 | QValueAxis* haxis = 0; |
|
72 | QValueAxis* haxis = 0; | |
75 | if (axisx->type() == QAbstractAxis::AxisTypeValue) |
|
73 | if (axisx->type() == QAbstractAxis::AxisTypeValue) | |
76 | haxis = qobject_cast<QValueAxis*>(axisx); |
|
74 | haxis = qobject_cast<QValueAxis*>(axisx); | |
77 |
|
75 | |||
78 | QAbstractAxis * axisy = this->axisY(); |
|
76 | QAbstractAxis * axisy = this->axisY(); | |
79 | QValueAxis* vaxis = 0; |
|
77 | QValueAxis* vaxis = 0; | |
80 | if (axisy->type() == QAbstractAxis::AxisTypeValue) |
|
78 | if (axisy->type() == QAbstractAxis::AxisTypeValue) | |
81 | vaxis = qobject_cast<QValueAxis*>(axisy); |
|
79 | vaxis = qobject_cast<QValueAxis*>(axisy); | |
82 |
|
80 | |||
83 | if (haxis && vaxis) { |
|
81 | if (haxis && vaxis) { | |
84 | //Calculate the "unit" between points on the x |
|
82 | //Calculate the "unit" between points on the x | |
85 | //y axis. |
|
83 | //y axis. | |
86 | double xUnit = this->plotArea().width()/haxis->max(); |
|
84 | double xUnit = this->plotArea().width()/haxis->max(); | |
87 | double yUnit = this->plotArea().height()/vaxis->max(); |
|
85 | double yUnit = this->plotArea().height()/vaxis->max(); | |
88 |
|
86 | |||
89 | //Convert the mappedPoint to the actual chart scale. |
|
87 | //Convert the mappedPoint to the actual chart scale. | |
90 | double x = mappedPoint.x()/xUnit; |
|
88 | double x = mappedPoint.x()/xUnit; | |
91 | double y = vaxis->max() - mappedPoint.y()/yUnit; |
|
89 | double y = vaxis->max() - mappedPoint.y()/yUnit; | |
92 |
|
90 | |||
93 | //Replace the old point with the new one. |
|
91 | //Replace the old point with the new one. | |
94 | m_series->replace(m_movingPoint, QPointF(x, y)); |
|
92 | m_series->replace(m_movingPoint, QPointF(x, y)); | |
95 |
|
93 | |||
96 | //Update the m_movingPoint so we are able to |
|
94 | //Update the m_movingPoint so we are able to | |
97 | //do the replace also during mousemoveEvent. |
|
95 | //do the replace also during mousemoveEvent. | |
98 | m_movingPoint.setX(x); |
|
96 | m_movingPoint.setX(x); | |
99 | m_movingPoint.setY(y); |
|
97 | m_movingPoint.setY(y); | |
100 | } |
|
98 | } | |
101 | } |
|
99 | } | |
102 | } |
|
100 | } | |
103 |
|
101 |
@@ -1,50 +1,50 | |||||
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 <QMouseEvent> |
|
|||
22 | #include "chartview.h" |
|
21 | #include "chartview.h" | |
|
22 | #include <QMouseEvent> | |||
23 | #include "chart.h" |
|
23 | #include "chart.h" | |
24 |
|
24 | |||
25 | ChartView::ChartView(Chart *chart, QWidget *parent) : |
|
25 | ChartView::ChartView(Chart *chart, QWidget *parent) : | |
26 | QChartView(chart, parent) |
|
26 | QChartView(chart, parent) | |
27 | { |
|
27 | { | |
28 | m_chart = chart; |
|
28 | m_chart = chart; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | void ChartView::mousePressEvent(QMouseEvent *event) |
|
31 | void ChartView::mousePressEvent(QMouseEvent *event) | |
32 | { |
|
32 | { | |
33 | m_mousePos = event->pos(); |
|
33 | m_mousePos = event->pos(); | |
34 | QChartView::mousePressEvent(event); |
|
34 | QChartView::mousePressEvent(event); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | void ChartView::mouseMoveEvent(QMouseEvent *event) |
|
37 | void ChartView::mouseMoveEvent(QMouseEvent *event) | |
38 | { |
|
38 | { | |
39 | m_chart->handlePointMove(event->pos()); |
|
39 | m_chart->handlePointMove(event->pos()); | |
40 | QChartView::mouseMoveEvent(event); |
|
40 | QChartView::mouseMoveEvent(event); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartView::mouseReleaseEvent(QMouseEvent *event) |
|
43 | void ChartView::mouseReleaseEvent(QMouseEvent *event) | |
44 | { |
|
44 | { | |
45 | if (event->pos() != m_mousePos) { |
|
45 | if (event->pos() != m_mousePos) { | |
46 | m_chart->handlePointMove(event->pos()); |
|
46 | m_chart->handlePointMove(event->pos()); | |
47 | m_chart->setPointClicked(false); |
|
47 | m_chart->setPointClicked(false); | |
48 | } |
|
48 | } | |
49 | QChartView::mouseReleaseEvent(event); |
|
49 | QChartView::mouseReleaseEvent(event); | |
50 | } |
|
50 | } |
@@ -1,76 +1,77 | |||||
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 |
#ifndef THEMEWI |
|
21 | #ifndef THEMEWIDGET_H | |
22 |
#define THEMEWI |
|
22 | #define THEMEWIDGET_H | |
|
23 | ||||
23 | #include <QWidget> |
|
24 | #include <QWidget> | |
24 | #include <QChartGlobal> |
|
25 | #include <QChartGlobal> | |
25 |
|
26 | |||
26 | class QComboBox; |
|
27 | class QComboBox; | |
27 | class QCheckBox; |
|
28 | class QCheckBox; | |
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | class QChartView; |
|
31 | class QChartView; | |
31 | class QChart; |
|
32 | class QChart; | |
32 | QTCOMMERCIALCHART_END_NAMESPACE |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE | |
33 |
|
34 | |||
34 | typedef QPair<QPointF, QString> Data; |
|
35 | typedef QPair<QPointF, QString> Data; | |
35 | typedef QList<Data> DataList; |
|
36 | typedef QList<Data> DataList; | |
36 | typedef QList<DataList> DataTable; |
|
37 | typedef QList<DataList> DataTable; | |
37 |
|
38 | |||
38 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
39 | QTCOMMERCIALCHART_USE_NAMESPACE | |
39 |
|
40 | |||
40 | class ThemeWidget: public QWidget |
|
41 | class ThemeWidget: public QWidget | |
41 | { |
|
42 | { | |
42 | Q_OBJECT |
|
43 | Q_OBJECT | |
43 | public: |
|
44 | public: | |
44 | explicit ThemeWidget(QWidget *parent = 0); |
|
45 | explicit ThemeWidget(QWidget *parent = 0); | |
45 | ~ThemeWidget(); |
|
46 | ~ThemeWidget(); | |
46 |
|
47 | |||
47 | private Q_SLOTS: |
|
48 | private Q_SLOTS: | |
48 | void updateUI(); |
|
49 | void updateUI(); | |
49 |
|
50 | |||
50 | private: |
|
51 | private: | |
51 | DataTable generateRandomData(int listCount,int valueMax,int valueCount) const; |
|
52 | DataTable generateRandomData(int listCount,int valueMax,int valueCount) const; | |
52 | QComboBox* createThemeBox() const; |
|
53 | QComboBox* createThemeBox() const; | |
53 | QComboBox* createAnimationBox() const; |
|
54 | QComboBox* createAnimationBox() const; | |
54 | QComboBox* createLegendBox() const; |
|
55 | QComboBox* createLegendBox() const; | |
55 | void connectSignals(); |
|
56 | void connectSignals(); | |
56 | QChart* createAreaChart() const; |
|
57 | QChart* createAreaChart() const; | |
57 | QChart* createBarChart(int valueCount) const; |
|
58 | QChart* createBarChart(int valueCount) const; | |
58 | QChart* createPieChart() const; |
|
59 | QChart* createPieChart() const; | |
59 | QChart* createLineChart() const; |
|
60 | QChart* createLineChart() const; | |
60 | QChart* createSplineChart() const; |
|
61 | QChart* createSplineChart() const; | |
61 | QChart* createScatterChart() const; |
|
62 | QChart* createScatterChart() const; | |
62 |
|
63 | |||
63 | private: |
|
64 | private: | |
64 | int m_listCount; |
|
65 | int m_listCount; | |
65 | int m_valueMax; |
|
66 | int m_valueMax; | |
66 | int m_valueCount; |
|
67 | int m_valueCount; | |
67 | QList<QChartView*> m_charts; |
|
68 | QList<QChartView*> m_charts; | |
68 | DataTable m_dataTable; |
|
69 | DataTable m_dataTable; | |
69 |
|
70 | |||
70 | QComboBox *m_themeComboBox; |
|
71 | QComboBox *m_themeComboBox; | |
71 | QCheckBox *m_antialiasCheckBox; |
|
72 | QCheckBox *m_antialiasCheckBox; | |
72 | QComboBox *m_animatedComboBox; |
|
73 | QComboBox *m_animatedComboBox; | |
73 | QComboBox *m_legendComboBox; |
|
74 | QComboBox *m_legendComboBox; | |
74 | }; |
|
75 | }; | |
75 |
|
76 | |||
76 |
#endif /* THEMEWI |
|
77 | #endif /* THEMEWIDGET_H */ |
@@ -1,51 +1,51 | |||||
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 |
#ifndef |
|
21 | #ifndef CUSTOMTABLEMODEL_H | |
22 |
#define |
|
22 | #define CUSTOMTABLEMODEL_H | |
23 |
|
23 | |||
24 | #include <QAbstractTableModel> |
|
24 | #include <QAbstractTableModel> | |
25 | #include <QHash> |
|
25 | #include <QHash> | |
26 | #include <QRect> |
|
26 | #include <QRect> | |
27 |
|
27 | |||
28 | class CustomTableModel : public QAbstractTableModel |
|
28 | class CustomTableModel : public QAbstractTableModel | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | public: |
|
31 | public: | |
32 | explicit CustomTableModel(QObject *parent = 0); |
|
32 | explicit CustomTableModel(QObject *parent = 0); | |
33 |
|
33 | |||
34 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
34 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; | |
35 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
35 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; | |
36 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
|
36 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | |
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
38 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
|
38 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); | |
39 | Qt::ItemFlags flags ( const QModelIndex & index ) const; |
|
39 | Qt::ItemFlags flags ( const QModelIndex & index ) const; | |
40 |
|
40 | |||
41 | void addMapping(QString color, QRect area); |
|
41 | void addMapping(QString color, QRect area); | |
42 | void clearMapping() { m_mapping.clear(); } |
|
42 | void clearMapping() { m_mapping.clear(); } | |
43 |
|
43 | |||
44 | private: |
|
44 | private: | |
45 | QList<QVector<qreal> * > m_data; |
|
45 | QList<QVector<qreal> * > m_data; | |
46 | QHash<QString, QRect> m_mapping; |
|
46 | QHash<QString, QRect> m_mapping; | |
47 | int m_columnCount; |
|
47 | int m_columnCount; | |
48 | int m_rowCount; |
|
48 | int m_rowCount; | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 |
#endif // |
|
51 | #endif // CUSTOMTABLEMODEL_H |
@@ -1,51 +1,51 | |||||
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 |
#ifndef |
|
21 | #ifndef CUSTOMTABLEMODEL_H | |
22 |
#define |
|
22 | #define CUSTOMTABLEMODEL_H | |
23 |
|
23 | |||
24 | #include <QAbstractTableModel> |
|
24 | #include <QAbstractTableModel> | |
25 | #include <QHash> |
|
25 | #include <QHash> | |
26 | #include <QRect> |
|
26 | #include <QRect> | |
27 |
|
27 | |||
28 | class CustomTableModel : public QAbstractTableModel |
|
28 | class CustomTableModel : public QAbstractTableModel | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | public: |
|
31 | public: | |
32 | explicit CustomTableModel(QObject *parent = 0); |
|
32 | explicit CustomTableModel(QObject *parent = 0); | |
33 |
|
33 | |||
34 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
34 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; | |
35 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
35 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; | |
36 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
|
36 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | |
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
38 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
|
38 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); | |
39 | Qt::ItemFlags flags ( const QModelIndex & index ) const; |
|
39 | Qt::ItemFlags flags ( const QModelIndex & index ) const; | |
40 |
|
40 | |||
41 | void addMapping(QString color, QRect area); |
|
41 | void addMapping(QString color, QRect area); | |
42 | void clearMapping() { m_mapping.clear(); } |
|
42 | void clearMapping() { m_mapping.clear(); } | |
43 |
|
43 | |||
44 | private: |
|
44 | private: | |
45 | QList<QVector<qreal> * > m_data; |
|
45 | QList<QVector<qreal> * > m_data; | |
46 | QHash<QString, QRect> m_mapping; |
|
46 | QHash<QString, QRect> m_mapping; | |
47 | int m_columnCount; |
|
47 | int m_columnCount; | |
48 | int m_rowCount; |
|
48 | int m_rowCount; | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 |
#endif // |
|
51 | #endif // CUSTOMTABLEMODEL_H |
@@ -1,46 +1,46 | |||||
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 |
#ifndef |
|
21 | #ifndef CHARTVIEW_H | |
22 |
#define |
|
22 | #define CHARTVIEW_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QChartView> |
|
25 | #include <QChartView> | |
26 | #include <QScatterSeries> |
|
26 | #include <QScatterSeries> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | class ChartView : public QChartView |
|
30 | class ChartView : public QChartView | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | ChartView(QWidget *parent = 0); |
|
35 | ChartView(QWidget *parent = 0); | |
36 | ~ChartView(); |
|
36 | ~ChartView(); | |
37 |
|
37 | |||
38 | private Q_SLOTS: |
|
38 | private Q_SLOTS: | |
39 | void handleClickedPoint(const QPointF& point); |
|
39 | void handleClickedPoint(const QPointF& point); | |
40 |
|
40 | |||
41 | private: |
|
41 | private: | |
42 | QScatterSeries *m_scatter; |
|
42 | QScatterSeries *m_scatter; | |
43 | QScatterSeries *m_scatter2; |
|
43 | QScatterSeries *m_scatter2; | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 |
#endif // |
|
46 | #endif // CHARTVIEW_H |
@@ -1,98 +1,98 | |||||
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 |
#ifndef TST_QABSTRACT |
|
21 | #ifndef TST_QABSTRACTAXIS_H | |
22 |
#define TST_QABSTRACT |
|
22 | #define TST_QABSTRACTAXIS_H | |
23 |
|
23 | |||
24 | #include <QtTest/QtTest> |
|
24 | #include <QtTest/QtTest> | |
25 | #include <tst_definitions.h> |
|
25 | #include <tst_definitions.h> | |
26 | #include <qabstractaxis.h> |
|
26 | #include <qabstractaxis.h> | |
27 | #include <qchartview.h> |
|
27 | #include <qchartview.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | class tst_QAbstractAxis : public QObject |
|
31 | class tst_QAbstractAxis : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public slots: |
|
35 | public slots: | |
36 | virtual void initTestCase(); |
|
36 | virtual void initTestCase(); | |
37 | virtual void cleanupTestCase(); |
|
37 | virtual void cleanupTestCase(); | |
38 | virtual void init(QAbstractAxis* axis,QAbstractSeries* series); |
|
38 | virtual void init(QAbstractAxis* axis,QAbstractSeries* series); | |
39 | virtual void cleanup(); |
|
39 | virtual void cleanup(); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void axisPen_data(); |
|
42 | void axisPen_data(); | |
43 | void axisPen(); |
|
43 | void axisPen(); | |
44 | void axisPenColor_data(); |
|
44 | void axisPenColor_data(); | |
45 | void axisPenColor(); |
|
45 | void axisPenColor(); | |
46 | void gridLinePen_data(); |
|
46 | void gridLinePen_data(); | |
47 | void gridLinePen(); |
|
47 | void gridLinePen(); | |
48 | void lineVisible_data(); |
|
48 | void lineVisible_data(); | |
49 | void lineVisible(); |
|
49 | void lineVisible(); | |
50 | void gridLineVisible_data(); |
|
50 | void gridLineVisible_data(); | |
51 | void gridLineVisible(); |
|
51 | void gridLineVisible(); | |
52 | void visible_data(); |
|
52 | void visible_data(); | |
53 | void visible(); |
|
53 | void visible(); | |
54 | void labelsAngle_data(); |
|
54 | void labelsAngle_data(); | |
55 | void labelsAngle(); |
|
55 | void labelsAngle(); | |
56 | void labelsBrush_data(); |
|
56 | void labelsBrush_data(); | |
57 | void labelsBrush(); |
|
57 | void labelsBrush(); | |
58 | void labelsColor_data(); |
|
58 | void labelsColor_data(); | |
59 | void labelsColor(); |
|
59 | void labelsColor(); | |
60 | void labelsFont_data(); |
|
60 | void labelsFont_data(); | |
61 | void labelsFont(); |
|
61 | void labelsFont(); | |
62 | void labelsPen_data(); |
|
62 | void labelsPen_data(); | |
63 | void labelsPen(); |
|
63 | void labelsPen(); | |
64 | void labelsVisible_data(); |
|
64 | void labelsVisible_data(); | |
65 | void labelsVisible(); |
|
65 | void labelsVisible(); | |
66 | void orientation_data(); |
|
66 | void orientation_data(); | |
67 | void orientation(); |
|
67 | void orientation(); | |
68 | void setMax_data(); |
|
68 | void setMax_data(); | |
69 | void setMax(); |
|
69 | void setMax(); | |
70 | void setMin_data(); |
|
70 | void setMin_data(); | |
71 | void setMin(); |
|
71 | void setMin(); | |
72 | void setRange_data(); |
|
72 | void setRange_data(); | |
73 | void setRange(); |
|
73 | void setRange(); | |
74 | void shadesBorderColor_data(); |
|
74 | void shadesBorderColor_data(); | |
75 | void shadesBorderColor(); |
|
75 | void shadesBorderColor(); | |
76 | void shadesBrush_data(); |
|
76 | void shadesBrush_data(); | |
77 | void shadesBrush(); |
|
77 | void shadesBrush(); | |
78 | void shadesColor_data(); |
|
78 | void shadesColor_data(); | |
79 | void shadesColor(); |
|
79 | void shadesColor(); | |
80 | void shadesPen_data(); |
|
80 | void shadesPen_data(); | |
81 | void shadesPen(); |
|
81 | void shadesPen(); | |
82 | void shadesVisible_data(); |
|
82 | void shadesVisible_data(); | |
83 | void shadesVisible(); |
|
83 | void shadesVisible(); | |
84 | void show_data(); |
|
84 | void show_data(); | |
85 | void show(); |
|
85 | void show(); | |
86 | void hide_data(); |
|
86 | void hide_data(); | |
87 | void hide(); |
|
87 | void hide(); | |
88 |
|
88 | |||
89 | protected: |
|
89 | protected: | |
90 | void qabstractaxis(); |
|
90 | void qabstractaxis(); | |
91 | protected: |
|
91 | protected: | |
92 | QChartView* m_view; |
|
92 | QChartView* m_view; | |
93 | QChart* m_chart; |
|
93 | QChart* m_chart; | |
94 | QAbstractAxis* m_axis; |
|
94 | QAbstractAxis* m_axis; | |
95 | QAbstractSeries* m_series; |
|
95 | QAbstractSeries* m_series; | |
96 | }; |
|
96 | }; | |
97 |
|
97 | |||
98 | #endif |
|
98 | #endif |
@@ -1,76 +1,76 | |||||
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 |
#ifndef ENGINE_H |
|
21 | #ifndef ENGINE_H | |
22 |
#define ENGINE_H |
|
22 | #define ENGINE_H | |
23 |
|
23 | |||
24 | #include <QObject> |
|
24 | #include <QObject> | |
25 | #include <QAbstractSeries> |
|
25 | #include <QAbstractSeries> | |
26 | #include <QModelIndex> |
|
26 | #include <QModelIndex> | |
27 |
|
27 | |||
28 | class QStandardItemModel; |
|
28 | class QStandardItemModel; | |
29 | class QItemSelectionModel; |
|
29 | class QItemSelectionModel; | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 | class QChart; |
|
33 | class QChart; | |
34 | class QXYSeries; |
|
34 | class QXYSeries; | |
35 | class QAbstractBarSeries; |
|
35 | class QAbstractBarSeries; | |
36 | class QPieSeries; |
|
36 | class QPieSeries; | |
37 | class QAreaSeries; |
|
37 | class QAreaSeries; | |
38 | QTCOMMERCIALCHART_END_NAMESPACE |
|
38 | QTCOMMERCIALCHART_END_NAMESPACE | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
40 | QTCOMMERCIALCHART_USE_NAMESPACE | |
41 |
|
41 | |||
42 | class Engine : public QObject |
|
42 | class Engine : public QObject | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | explicit Engine(QObject *parent = 0); |
|
46 | explicit Engine(QObject *parent = 0); | |
47 | ~Engine(); |
|
47 | ~Engine(); | |
48 |
|
48 | |||
49 | int modelCount() { return m_count; } |
|
49 | int modelCount() { return m_count; } | |
50 | QStandardItemModel *model() const { return m_model; } |
|
50 | QStandardItemModel *model() const { return m_model; } | |
51 | QItemSelectionModel *selectionModel() const { return m_selection; } |
|
51 | QItemSelectionModel *selectionModel() const { return m_selection; } | |
52 | QChart* chart() const { return m_chart; } |
|
52 | QChart* chart() const { return m_chart; } | |
53 | void clearModels(); |
|
53 | void clearModels(); | |
54 | QList<QAbstractSeries*> addSeries(QAbstractSeries::SeriesType type); |
|
54 | QList<QAbstractSeries*> addSeries(QAbstractSeries::SeriesType type); | |
55 | void removeSeries(QAbstractSeries* series); |
|
55 | void removeSeries(QAbstractSeries* series); | |
56 | bool save(const QString &filename) const; |
|
56 | bool save(const QString &filename) const; | |
57 | bool load(const QString &filename); |
|
57 | bool load(const QString &filename); | |
58 | signals: |
|
58 | signals: | |
59 | void selected(); |
|
59 | void selected(); | |
60 |
|
60 | |||
61 | private: |
|
61 | private: | |
62 | void createModels(); |
|
62 | void createModels(); | |
63 | void setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow); |
|
63 | void setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow); | |
64 | void setupBarSeries(QAbstractBarSeries *series, const QList<int>& columns, int minRow, int maxRow); |
|
64 | void setupBarSeries(QAbstractBarSeries *series, const QList<int>& columns, int minRow, int maxRow); | |
65 | void setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow); |
|
65 | void setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow); | |
66 | void setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow); |
|
66 | void setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow); | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
69 | int m_count; |
|
69 | int m_count; | |
70 | QChart *m_chart; |
|
70 | QChart *m_chart; | |
71 | QStandardItemModel *m_model; |
|
71 | QStandardItemModel *m_model; | |
72 | QItemSelectionModel *m_selection; |
|
72 | QItemSelectionModel *m_selection; | |
73 | QMap<QAbstractSeries*, QList<QModelIndex> > m_seriesModelIndex; |
|
73 | QMap<QAbstractSeries*, QList<QModelIndex> > m_seriesModelIndex; | |
74 | }; |
|
74 | }; | |
75 |
|
75 | |||
76 |
#endif /* ENGINE_H |
|
76 | #endif /* ENGINE_H */ |
@@ -1,71 +1,69 | |||||
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 "wavechart.h" |
|
21 | #include "wavechart.h" | |
22 | #include <cmath> |
|
22 | #include <cmath> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
25 | |||
26 | #define PI 3.14159265358979 |
|
26 | #define PI 3.14159265358979 | |
27 | static const int numPoints =100; |
|
27 | static const int numPoints =100; | |
28 |
|
28 | |||
29 | WaveChart::WaveChart(QChart* chart, QWidget* parent) : |
|
29 | WaveChart::WaveChart(QChart* chart, QWidget* parent) : | |
30 | QChartView(chart, parent), |
|
30 | QChartView(chart, parent), | |
31 | m_series(new QLineSeries()), |
|
31 | m_series(new QLineSeries()), | |
32 | m_wave(0), |
|
32 | m_wave(0), | |
33 | m_step(2 * PI / numPoints) |
|
33 | m_step(2 * PI / numPoints) | |
34 | { |
|
34 | { | |
35 | QPen blue(Qt::blue); |
|
35 | QPen blue(Qt::blue); | |
36 | blue.setWidth(3); |
|
36 | blue.setWidth(3); | |
37 | m_series->setPen(blue); |
|
37 | m_series->setPen(blue); | |
38 |
|
38 | |||
39 | chart->legend()->setVisible(false); |
|
39 | chart->legend()->setVisible(false); | |
40 |
|
40 | |||
41 | QTime now = QTime::currentTime(); |
|
41 | QTime now = QTime::currentTime(); | |
42 | qsrand((uint) now.msec()); |
|
42 | qsrand((uint) now.msec()); | |
43 |
|
43 | |||
44 | int fluctuate = 100; |
|
44 | int fluctuate = 100; | |
45 |
|
45 | |||
46 | for (qreal x = 0; x <= 2 * PI; x += m_step) { |
|
46 | for (qreal x = 0; x <= 2 * PI; x += m_step) { | |
47 | m_series->append(x, fabs(sin(x) * fluctuate)); |
|
47 | m_series->append(x, fabs(sin(x) * fluctuate)); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | chart->addSeries(m_series); |
|
50 | chart->addSeries(m_series); | |
51 | chart->createDefaultAxes(); |
|
51 | chart->createDefaultAxes(); | |
52 |
|
52 | |||
53 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(update())); |
|
53 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(update())); | |
54 | m_timer.setInterval(5000); |
|
54 | m_timer.setInterval(5000); | |
55 | m_timer.start(); |
|
55 | m_timer.start(); | |
56 |
|
||||
57 | } |
|
56 | } | |
58 | ; |
|
|||
59 |
|
57 | |||
60 | void WaveChart::update() |
|
58 | void WaveChart::update() | |
61 | { |
|
59 | { | |
62 |
|
60 | |||
63 | int fluctuate; |
|
61 | int fluctuate; | |
64 | const QList<QPointF>& points = m_series->points(); |
|
62 | const QList<QPointF>& points = m_series->points(); | |
65 | for (qreal i = 0, x = 0; x <= 2 * PI; x += m_step, i++) { |
|
63 | for (qreal i = 0, x = 0; x <= 2 * PI; x += m_step, i++) { | |
66 | fluctuate = qrand() % 100; |
|
64 | fluctuate = qrand() % 100; | |
67 | m_series->replace(x,points[i].y(),x,fabs(sin(x) * fluctuate)); |
|
65 | m_series->replace(x,points[i].y(),x,fabs(sin(x) * fluctuate)); | |
68 |
|
66 | |||
69 | } |
|
67 | } | |
70 |
|
68 | |||
71 | } |
|
69 | } |
@@ -1,44 +1,49 | |||||
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 | #ifndef WAVECHART_H | |||
|
22 | #define WAVECHART_H | |||
|
23 | ||||
21 | #include <QTimer> |
|
24 | #include <QTimer> | |
22 | #include <QTime> |
|
25 | #include <QTime> | |
23 | #include <QObject> |
|
26 | #include <QObject> | |
24 | #include <QLineSeries> |
|
27 | #include <QLineSeries> | |
25 | #include <QChartView> |
|
28 | #include <QChartView> | |
26 |
|
29 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
31 | |||
29 | class WaveChart: public QChartView |
|
32 | class WaveChart: public QChartView | |
30 | { |
|
33 | { | |
31 | Q_OBJECT |
|
34 | Q_OBJECT | |
32 |
|
35 | |||
33 | public: |
|
36 | public: | |
34 | WaveChart(QChart* chart, QWidget* parent); |
|
37 | WaveChart(QChart* chart, QWidget* parent); | |
35 |
|
38 | |||
36 | private slots: |
|
39 | private slots: | |
37 | void update(); |
|
40 | void update(); | |
38 |
|
41 | |||
39 | private: |
|
42 | private: | |
40 | QLineSeries* m_series; |
|
43 | QLineSeries* m_series; | |
41 | int m_wave; |
|
44 | int m_wave; | |
42 | qreal m_step; |
|
45 | qreal m_step; | |
43 | QTimer m_timer; |
|
46 | QTimer m_timer; | |
44 | }; |
|
47 | }; | |
|
48 | ||||
|
49 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now