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