@@ -0,0 +1,101 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QValuesAxis> | |
|
22 | #include <QAbstractAxis> | |
|
23 | #include <QDebug> | |
|
24 | ||
|
25 | #include "chart.h" | |
|
26 | ||
|
27 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) | |
|
28 | : QChart(parent, wFlags), m_series(series) | |
|
29 | { | |
|
30 | m_clicked = false; | |
|
31 | } | |
|
32 | ||
|
33 | Chart::~Chart() | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | void Chart::clickPoint(const QPointF &point) | |
|
38 | { | |
|
39 | //Get all points from the series. | |
|
40 | QList<QPointF> points = m_series->points(); | |
|
41 | //Construct a small rectangle around the clicked point | |
|
42 | //to identify the real point clicked from the series. | |
|
43 | QRectF clickRect(point.x() - 0.5, point.y() - 0.5, 1.0, 1.0); | |
|
44 | ||
|
45 | //Find the clicked point to be moved. | |
|
46 | foreach (QPointF p, points) { | |
|
47 | if (clickRect.contains(p)) { | |
|
48 | m_movingPoint = p; | |
|
49 | m_clicked = true; | |
|
50 | return; | |
|
51 | } | |
|
52 | } | |
|
53 | } | |
|
54 | ||
|
55 | void Chart::setPointClicked(bool clicked) | |
|
56 | { | |
|
57 | m_clicked = clicked; | |
|
58 | } | |
|
59 | ||
|
60 | void Chart::handlePointMove(const QPoint &point) | |
|
61 | { | |
|
62 | if (m_clicked) { | |
|
63 | //Map the point clicked from the ChartView | |
|
64 | //to the area occupied by the chart. | |
|
65 | QPoint mappedPoint = point; | |
|
66 | mappedPoint.setX(point.x()-this->plotArea().x()); | |
|
67 | mappedPoint.setY(point.y()-this->plotArea().y()); | |
|
68 | ||
|
69 | //Get the x- and y axis to be able to convert the mapped | |
|
70 | //coordinate point to the charts scale. | |
|
71 | QAbstractAxis * axisx = this->axisX(); | |
|
72 | QValuesAxis* haxis = 0; | |
|
73 | if (axisx->type() == QAbstractAxis::AxisTypeValues) | |
|
74 | haxis = qobject_cast<QValuesAxis*>(axisx); | |
|
75 | ||
|
76 | QAbstractAxis * axisy = this->axisY(); | |
|
77 | QValuesAxis* vaxis = 0; | |
|
78 | if (axisy->type() == QAbstractAxis::AxisTypeValues) | |
|
79 | vaxis = qobject_cast<QValuesAxis*>(axisy); | |
|
80 | ||
|
81 | if (haxis && vaxis) { | |
|
82 | //Calculate the "unit" between points on the x | |
|
83 | //y axis. | |
|
84 | double xUnit = this->plotArea().width()/haxis->max(); | |
|
85 | double yUnit = this->plotArea().height()/vaxis->max(); | |
|
86 | ||
|
87 | //Convert the mappedPoint to the actual chart scale. | |
|
88 | double x = mappedPoint.x()/xUnit; | |
|
89 | double y = vaxis->max() - mappedPoint.y()/yUnit; | |
|
90 | ||
|
91 | //Replace the old point with the new one. | |
|
92 | m_series->replace(m_movingPoint, QPointF(x, y)); | |
|
93 | ||
|
94 | //Update the m_movingPoint so we are able to | |
|
95 | //do the replace also during mousemoveEvent. | |
|
96 | m_movingPoint.setX(x); | |
|
97 | m_movingPoint.setY(y); | |
|
98 | } | |
|
99 | } | |
|
100 | } | |
|
101 |
@@ -0,0 +1,52 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #ifndef CHART_H | |
|
22 | #define CHART_H | |
|
23 | ||
|
24 | #include <QChart> | |
|
25 | #include <QLineSeries> | |
|
26 | ||
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
28 | ||
|
29 | class Chart : public QChart | |
|
30 | { | |
|
31 | Q_OBJECT | |
|
32 | public: | |
|
33 | explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0, QLineSeries *series = 0); | |
|
34 | ~Chart(); | |
|
35 | ||
|
36 | public slots: | |
|
37 | void clickPoint(const QPointF &point); | |
|
38 | ||
|
39 | public: | |
|
40 | void handlePointMove(const QPoint &point); | |
|
41 | void setPointClicked(bool clicked); | |
|
42 | ||
|
43 | private: | |
|
44 | QLineSeries *m_series; | |
|
45 | QPointF m_movingPoint; | |
|
46 | ||
|
47 | //Boolean value to determine if an actual point in the | |
|
48 | //series is clicked. | |
|
49 | bool m_clicked; | |
|
50 | }; | |
|
51 | ||
|
52 | #endif // CHART_H |
@@ -0,0 +1,9 | |||
|
1 | !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" ) | |
|
2 | ||
|
3 | QT += core gui | |
|
4 | ||
|
5 | TARGET = chartinteractions | |
|
6 | TEMPLATE = app | |
|
7 | ||
|
8 | HEADERS += chart.h chartview.h | |
|
9 | SOURCES += main.cpp chart.cpp chartview.cpp |
@@ -0,0 +1,50 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QMouseEvent> | |
|
22 | #include "chartview.h" | |
|
23 | #include "chart.h" | |
|
24 | ||
|
25 | ChartView::ChartView(Chart *chart, QWidget *parent) : | |
|
26 | QChartView(chart, parent) | |
|
27 | { | |
|
28 | m_chart = chart; | |
|
29 | } | |
|
30 | ||
|
31 | void ChartView::mousePressEvent(QMouseEvent *event) | |
|
32 | { | |
|
33 | m_mousePos = event->pos(); | |
|
34 | QChartView::mousePressEvent(event); | |
|
35 | } | |
|
36 | ||
|
37 | void ChartView::mouseMoveEvent(QMouseEvent *event) | |
|
38 | { | |
|
39 | m_chart->handlePointMove(event->pos()); | |
|
40 | QChartView::mouseMoveEvent(event); | |
|
41 | } | |
|
42 | ||
|
43 | void ChartView::mouseReleaseEvent(QMouseEvent *event) | |
|
44 | { | |
|
45 | if (event->pos() != m_mousePos) { | |
|
46 | m_chart->handlePointMove(event->pos()); | |
|
47 | m_chart->setPointClicked(false); | |
|
48 | } | |
|
49 | QChartView::mouseReleaseEvent(event); | |
|
50 | } |
@@ -0,0 +1,45 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #ifndef CHARTVIEW_H | |
|
22 | #define CHARTVIEW_H | |
|
23 | ||
|
24 | #include <QChartView> | |
|
25 | ||
|
26 | class Chart; | |
|
27 | ||
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
29 | ||
|
30 | class ChartView : public QChartView | |
|
31 | { | |
|
32 | public: | |
|
33 | ChartView(Chart *chart, QWidget *parent = 0); | |
|
34 | ||
|
35 | protected: | |
|
36 | void mousePressEvent(QMouseEvent *event); | |
|
37 | void mouseMoveEvent(QMouseEvent *event); | |
|
38 | void mouseReleaseEvent(QMouseEvent *event); | |
|
39 | ||
|
40 | private: | |
|
41 | Chart *m_chart; | |
|
42 | QPoint m_mousePos; | |
|
43 | }; | |
|
44 | ||
|
45 | #endif |
@@ -0,0 +1,71 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QApplication> | |
|
22 | #include <QMainWindow> | |
|
23 | #include <QLineSeries> | |
|
24 | ||
|
25 | #include <QValuesAxis> | |
|
26 | ||
|
27 | #include "chart.h" | |
|
28 | #include "chartview.h" | |
|
29 | ||
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
31 | ||
|
32 | int main(int argc, char *argv[]) | |
|
33 | { | |
|
34 | QApplication a(argc, argv); | |
|
35 | ||
|
36 | QLineSeries* series = new QLineSeries(); | |
|
37 | ||
|
38 | series->append(0, 6); | |
|
39 | series->append(1, 3); | |
|
40 | series->append(2, 4); | |
|
41 | series->append(3, 8); | |
|
42 | series->append(7, 13); | |
|
43 | series->append(10, 5); | |
|
44 | *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); | |
|
45 | ||
|
46 | Chart* chart = new Chart(0, 0, series); | |
|
47 | chart->legend()->hide(); | |
|
48 | chart->addSeries(series); | |
|
49 | chart->createDefaultAxes(); | |
|
50 | chart->setTitle("Drag'n drop to move data points"); | |
|
51 | ||
|
52 | QValuesAxis *axisX = new QValuesAxis(); | |
|
53 | chart->setAxisX(axisX, series); | |
|
54 | axisX->setRange(0, 20); | |
|
55 | ||
|
56 | QValuesAxis *axisY = new QValuesAxis(); | |
|
57 | chart->setAxisY(axisY, series); | |
|
58 | axisY->setRange(0, 13); | |
|
59 | ||
|
60 | QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF))); | |
|
61 | ||
|
62 | ChartView* chartView = new ChartView(chart); | |
|
63 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
64 | ||
|
65 | QMainWindow window; | |
|
66 | window.setCentralWidget(chartView); | |
|
67 | window.resize(400, 300); | |
|
68 | window.show(); | |
|
69 | ||
|
70 | return a.exec(); | |
|
71 | } |
@@ -1,16 +1,17 | |||
|
1 | 1 | CURRENTLY_BUILDING_COMPONENTS = "demos" |
|
2 | 2 | !include( ../config.pri ) { |
|
3 | 3 | error( "Couldn't find the config.pri file!" ) |
|
4 | 4 | } |
|
5 | 5 | |
|
6 | 6 | TEMPLATE = subdirs |
|
7 | 7 | SUBDIRS += chartthemes \ |
|
8 | 8 | piechartcustomization \ |
|
9 | 9 | dynamicspline \ |
|
10 | 10 | qmlchart \ |
|
11 | 11 | qmlweather \ |
|
12 | 12 | qmlf1legends \ |
|
13 | 13 | qmlcustomizations \ |
|
14 | 14 | qmlcustommodel \ |
|
15 | 15 | qmloscilloscope \ |
|
16 | chartviewer | |
|
16 | chartviewer \ | |
|
17 | chartinteractions |
@@ -1,143 +1,143 | |||
|
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 | #ifndef QABSTRACTAXIS_H |
|
22 | 22 | #define QABSTRACTAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QFont> |
|
27 | 27 | #include <QVariant> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractAxisPrivate; |
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
37 | 37 | Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged) |
|
38 | 38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) |
|
39 | 39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
40 | 40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
41 | 41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
42 | 42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
43 | 43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
44 | 44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
45 | 45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
46 | 46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
47 | 47 | |
|
48 | 48 | public: |
|
49 | 49 | |
|
50 | 50 | enum AxisType { |
|
51 | 51 | AxisTypeNoAxis = 0x0, |
|
52 | 52 | AxisTypeValues = 0x1, |
|
53 | 53 | AxisTypeCategories = 0x2, |
|
54 | 54 | AxisTypeIntervals = 0x3, |
|
55 | 55 | AxisTypeDateTime = 0x4 |
|
56 | 56 | }; |
|
57 | 57 | |
|
58 | 58 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
59 | 59 | |
|
60 | 60 | protected: |
|
61 | 61 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); |
|
62 | 62 | |
|
63 | 63 | public: |
|
64 | 64 | ~QAbstractAxis(); |
|
65 | 65 | |
|
66 | 66 | virtual AxisType type() const = 0; |
|
67 | 67 | |
|
68 | 68 | //visibilty hadnling |
|
69 | 69 | bool isVisible() const; |
|
70 | 70 | void setVisible(bool visible = true); |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | //axis handling |
|
74 | 74 | bool isArrowVisible() const; |
|
75 | 75 | void setArrowVisible(bool visible = true); |
|
76 | 76 | void setAxisPen(const QPen &pen); |
|
77 | 77 | QPen axisPen() const; |
|
78 | 78 | void setAxisPenColor(QColor color); |
|
79 | 79 | QColor axisPenColor() const; |
|
80 | 80 | |
|
81 | 81 | //grid handling |
|
82 | 82 | bool isGridLineVisible() const; |
|
83 | 83 | void setGridLineVisible(bool visible = true); |
|
84 | 84 | void setGridLinePen(const QPen &pen); |
|
85 | 85 | QPen gridLinePen() const; |
|
86 | 86 | |
|
87 | 87 | //labels handling |
|
88 | 88 | bool labelsVisible() const; |
|
89 | 89 | void setLabelsVisible(bool visible = true); |
|
90 | 90 | void setLabelsPen(const QPen &pen); |
|
91 | 91 | QPen labelsPen() const; |
|
92 | 92 | void setLabelsBrush(const QBrush &brush); |
|
93 | 93 | QBrush labelsBrush() const; |
|
94 | 94 | void setLabelsFont(const QFont &font); |
|
95 | 95 | QFont labelsFont() const; |
|
96 | 96 | void setLabelsAngle(int angle); |
|
97 | 97 | int labelsAngle() const; |
|
98 | 98 | void setLabelsColor(QColor color); |
|
99 | 99 | QColor labelsColor() const; |
|
100 | 100 | |
|
101 | 101 | //shades handling |
|
102 | 102 | bool shadesVisible() const; |
|
103 | 103 | void setShadesVisible(bool visible = true); |
|
104 | 104 | void setShadesPen(const QPen &pen); |
|
105 | 105 | QPen shadesPen() const; |
|
106 | 106 | void setShadesBrush(const QBrush &brush); |
|
107 | 107 | QBrush shadesBrush() const; |
|
108 | 108 | void setShadesColor(QColor color); |
|
109 | 109 | QColor shadesColor() const; |
|
110 | 110 | void setShadesBorderColor(QColor color); |
|
111 | 111 | QColor shadesBorderColor() const; |
|
112 | 112 | |
|
113 | 113 | Qt::Orientation orientation(); |
|
114 | 114 | |
|
115 | 115 | //range handling |
|
116 | 116 | void setMin(const QVariant &min); |
|
117 | 117 | void setMax(const QVariant &max); |
|
118 | 118 | void setRange(const QVariant &min, const QVariant &max); |
|
119 | 119 | |
|
120 | 120 | void show(); |
|
121 | 121 | void hide(); |
|
122 | 122 | |
|
123 | 123 | Q_SIGNALS: |
|
124 | 124 | void visibleChanged(bool visible); |
|
125 | 125 | void arrowVisibleChanged(bool visible); |
|
126 | 126 | void labelsVisibleChanged(bool visible); |
|
127 | 127 | void gridVisibleChanged(bool visible); |
|
128 | 128 | void colorChanged(QColor color); |
|
129 | 129 | void labelsColorChanged(QColor color); |
|
130 | 130 | void shadesVisibleChanged(bool visible); |
|
131 | 131 | void shadesColorChanged(QColor color); |
|
132 | 132 | void shadesBorderColorChanged(QColor color); |
|
133 | 133 | |
|
134 | 134 | protected: |
|
135 | 135 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
136 |
Q_DISABLE_COPY(QAbstractAxis) |
|
|
136 | Q_DISABLE_COPY(QAbstractAxis) | |
|
137 | 137 | friend class ChartDataSet; |
|
138 | 138 | friend class ChartAxis; |
|
139 | 139 | friend class ChartPresenter; |
|
140 | 140 | }; |
|
141 | 141 | |
|
142 | 142 | QTCOMMERCIALCHART_END_NAMESPACE |
|
143 | 143 | #endif |
@@ -1,176 +1,176 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTPRESENTER_H |
|
31 | 31 | #define CHARTPRESENTER_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
35 | 35 | #include <QRectF> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class ChartElement; |
|
40 | 40 | class QAbstractSeries; |
|
41 | 41 | class ChartDataSet; |
|
42 | 42 | class Domain; |
|
43 | 43 | class ChartAxis; |
|
44 | 44 | class ChartTheme; |
|
45 | 45 | class ChartAnimator; |
|
46 | 46 | class ChartBackground; |
|
47 | 47 | class ChartAnimation; |
|
48 | 48 | class ChartLayout; |
|
49 | 49 | |
|
50 | 50 | class ChartPresenter: public QObject |
|
51 | 51 | { |
|
52 | 52 | Q_OBJECT |
|
53 | 53 | public: |
|
54 | 54 | enum ZValues { |
|
55 | 55 | BackgroundZValue = -1, |
|
56 | 56 | ShadesZValue , |
|
57 | 57 | GridZValue, |
|
58 | AxisZValue, | |
|
58 | 59 | SeriesZValue, |
|
59 | 60 | LineChartZValue = SeriesZValue, |
|
60 | 61 | SplineChartZValue = SeriesZValue, |
|
61 | 62 | BarSeriesZValue = SeriesZValue, |
|
62 | 63 | ScatterSeriesZValue = SeriesZValue, |
|
63 | 64 | PieSeriesZValue = SeriesZValue, |
|
64 | AxisZValue, | |
|
65 | 65 | LegendZValue, |
|
66 | 66 | TopMostZValue |
|
67 | 67 | }; |
|
68 | 68 | |
|
69 | 69 | enum State { |
|
70 | 70 | ShowState, |
|
71 | 71 | ScrollUpState, |
|
72 | 72 | ScrollDownState, |
|
73 | 73 | ScrollLeftState, |
|
74 | 74 | ScrollRightState, |
|
75 | 75 | ZoomInState, |
|
76 | 76 | ZoomOutState |
|
77 | 77 | }; |
|
78 | 78 | |
|
79 | 79 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
80 | 80 | virtual ~ChartPresenter(); |
|
81 | 81 | |
|
82 | 82 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
83 | 83 | ChartDataSet *dataSet() const { return m_dataset; } |
|
84 | 84 | QGraphicsItem* rootItem() const { return m_chart; } |
|
85 | 85 | QGraphicsRectItem* backgroundItem(); |
|
86 | 86 | QGraphicsItem* titleItem(); |
|
87 | 87 | QList<ChartAxis*> axisItems() const; |
|
88 | 88 | |
|
89 | 89 | QLegend* legend(); |
|
90 | 90 | |
|
91 | 91 | void setBackgroundBrush(const QBrush& brush); |
|
92 | 92 | QBrush backgroundBrush() const; |
|
93 | 93 | |
|
94 | 94 | void setBackgroundPen(const QPen& pen); |
|
95 | 95 | QPen backgroundPen() const; |
|
96 | 96 | |
|
97 | 97 | void setTitle(const QString& title); |
|
98 | 98 | QString title() const; |
|
99 | 99 | |
|
100 | 100 | void setTitleFont(const QFont& font); |
|
101 | 101 | QFont titleFont() const; |
|
102 | 102 | |
|
103 | 103 | void setTitleBrush(const QBrush &brush); |
|
104 | 104 | QBrush titleBrush() const; |
|
105 | 105 | |
|
106 | 106 | void setBackgroundVisible(bool visible); |
|
107 | 107 | bool isBackgroundVisible() const; |
|
108 | 108 | |
|
109 | 109 | void setBackgroundDropShadowEnabled(bool enabled); |
|
110 | 110 | bool isBackgroundDropShadowEnabled() const; |
|
111 | 111 | |
|
112 | 112 | void setVisible(bool visible); |
|
113 | 113 | |
|
114 | 114 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
115 | 115 | QChart::ChartTheme theme(); |
|
116 | 116 | |
|
117 | 117 | void setAnimationOptions(QChart::AnimationOptions options); |
|
118 | 118 | QChart::AnimationOptions animationOptions() const; |
|
119 | 119 | |
|
120 | 120 | void zoomIn(qreal factor); |
|
121 | 121 | void zoomIn(const QRectF& rect); |
|
122 | 122 | void zoomOut(qreal factor); |
|
123 | 123 | void scroll(qreal dx,qreal dy); |
|
124 | 124 | |
|
125 | 125 | void setGeometry(const QRectF& rect); |
|
126 | 126 | QRectF geometry() { return m_rect; } |
|
127 | 127 | |
|
128 | 128 | void startAnimation(ChartAnimation* animation); |
|
129 | 129 | State state() const { return m_state; } |
|
130 | 130 | QPointF statePoint() const { return m_statePoint; } |
|
131 | 131 | |
|
132 | 132 | void resetAllElements(); |
|
133 | 133 | |
|
134 | 134 | void setMarginsMinimum(const QRectF& margins); |
|
135 | 135 | QRectF margins() const; |
|
136 | 136 | QGraphicsLayout* layout(); |
|
137 | 137 | |
|
138 | 138 | private: |
|
139 | 139 | void createBackgroundItem(); |
|
140 | 140 | void createTitleItem(); |
|
141 | 141 | void selectVisibleAxis(); |
|
142 | 142 | |
|
143 | 143 | public Q_SLOTS: |
|
144 | 144 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); |
|
145 | 145 | void handleSeriesRemoved(QAbstractSeries* series); |
|
146 | 146 | void handleAxisAdded(QAbstractAxis* axis,Domain* domain); |
|
147 | 147 | void handleAxisRemoved(QAbstractAxis* axis); |
|
148 | 148 | void handleAxisVisibleChanged(bool visible); |
|
149 | 149 | |
|
150 | 150 | private Q_SLOTS: |
|
151 | 151 | void handleAnimationFinished(); |
|
152 | 152 | |
|
153 | 153 | Q_SIGNALS: |
|
154 | 154 | void geometryChanged(const QRectF& rect); |
|
155 | 155 | void animationsFinished(); |
|
156 | 156 | void marginsChanged(QRectF margins); |
|
157 | 157 | |
|
158 | 158 | private: |
|
159 | 159 | QChart* m_chart; |
|
160 | 160 | ChartDataSet* m_dataset; |
|
161 | 161 | ChartTheme *m_chartTheme; |
|
162 | 162 | QMap<QAbstractSeries*, ChartElement*> m_chartItems; |
|
163 | 163 | QMap<QAbstractAxis*, ChartAxis*> m_axisItems; |
|
164 | 164 | QRectF m_rect; |
|
165 | 165 | QChart::AnimationOptions m_options; |
|
166 | 166 | State m_state; |
|
167 | 167 | QPointF m_statePoint; |
|
168 | 168 | QList<ChartAnimation*> m_animations; |
|
169 | 169 | ChartLayout* m_layout; |
|
170 | 170 | ChartBackground* m_backgroundItem; |
|
171 | 171 | QGraphicsSimpleTextItem* m_titleItem; |
|
172 | 172 | }; |
|
173 | 173 | |
|
174 | 174 | QTCOMMERCIALCHART_END_NAMESPACE |
|
175 | 175 | |
|
176 | 176 | #endif /* CHARTPRESENTER_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now