##// END OF EJS Templates
Switched the z-order of axis to be below series...
Tero Ahola -
r1790:9e99014de1f1
parent child
Show More
@@ -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 CURRENTLY_BUILDING_COMPONENTS = "demos"
1 CURRENTLY_BUILDING_COMPONENTS = "demos"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += chartthemes \
7 SUBDIRS += chartthemes \
8 piechartcustomization \
8 piechartcustomization \
9 dynamicspline \
9 dynamicspline \
10 qmlchart \
10 qmlchart \
11 qmlweather \
11 qmlweather \
12 qmlf1legends \
12 qmlf1legends \
13 qmlcustomizations \
13 qmlcustomizations \
14 qmlcustommodel \
14 qmlcustommodel \
15 qmloscilloscope \
15 qmloscilloscope \
16 chartviewer
16 chartviewer \
17 chartinteractions
@@ -1,143 +1,143
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 QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47
47
48 public:
48 public:
49
49
50 enum AxisType {
50 enum AxisType {
51 AxisTypeNoAxis = 0x0,
51 AxisTypeNoAxis = 0x0,
52 AxisTypeValues = 0x1,
52 AxisTypeValues = 0x1,
53 AxisTypeCategories = 0x2,
53 AxisTypeCategories = 0x2,
54 AxisTypeIntervals = 0x3,
54 AxisTypeIntervals = 0x3,
55 AxisTypeDateTime = 0x4
55 AxisTypeDateTime = 0x4
56 };
56 };
57
57
58 Q_DECLARE_FLAGS(AxisTypes, AxisType)
58 Q_DECLARE_FLAGS(AxisTypes, AxisType)
59
59
60 protected:
60 protected:
61 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
61 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
62
62
63 public:
63 public:
64 ~QAbstractAxis();
64 ~QAbstractAxis();
65
65
66 virtual AxisType type() const = 0;
66 virtual AxisType type() const = 0;
67
67
68 //visibilty hadnling
68 //visibilty hadnling
69 bool isVisible() const;
69 bool isVisible() const;
70 void setVisible(bool visible = true);
70 void setVisible(bool visible = true);
71
71
72
72
73 //axis handling
73 //axis handling
74 bool isArrowVisible() const;
74 bool isArrowVisible() const;
75 void setArrowVisible(bool visible = true);
75 void setArrowVisible(bool visible = true);
76 void setAxisPen(const QPen &pen);
76 void setAxisPen(const QPen &pen);
77 QPen axisPen() const;
77 QPen axisPen() const;
78 void setAxisPenColor(QColor color);
78 void setAxisPenColor(QColor color);
79 QColor axisPenColor() const;
79 QColor axisPenColor() const;
80
80
81 //grid handling
81 //grid handling
82 bool isGridLineVisible() const;
82 bool isGridLineVisible() const;
83 void setGridLineVisible(bool visible = true);
83 void setGridLineVisible(bool visible = true);
84 void setGridLinePen(const QPen &pen);
84 void setGridLinePen(const QPen &pen);
85 QPen gridLinePen() const;
85 QPen gridLinePen() const;
86
86
87 //labels handling
87 //labels handling
88 bool labelsVisible() const;
88 bool labelsVisible() const;
89 void setLabelsVisible(bool visible = true);
89 void setLabelsVisible(bool visible = true);
90 void setLabelsPen(const QPen &pen);
90 void setLabelsPen(const QPen &pen);
91 QPen labelsPen() const;
91 QPen labelsPen() const;
92 void setLabelsBrush(const QBrush &brush);
92 void setLabelsBrush(const QBrush &brush);
93 QBrush labelsBrush() const;
93 QBrush labelsBrush() const;
94 void setLabelsFont(const QFont &font);
94 void setLabelsFont(const QFont &font);
95 QFont labelsFont() const;
95 QFont labelsFont() const;
96 void setLabelsAngle(int angle);
96 void setLabelsAngle(int angle);
97 int labelsAngle() const;
97 int labelsAngle() const;
98 void setLabelsColor(QColor color);
98 void setLabelsColor(QColor color);
99 QColor labelsColor() const;
99 QColor labelsColor() const;
100
100
101 //shades handling
101 //shades handling
102 bool shadesVisible() const;
102 bool shadesVisible() const;
103 void setShadesVisible(bool visible = true);
103 void setShadesVisible(bool visible = true);
104 void setShadesPen(const QPen &pen);
104 void setShadesPen(const QPen &pen);
105 QPen shadesPen() const;
105 QPen shadesPen() const;
106 void setShadesBrush(const QBrush &brush);
106 void setShadesBrush(const QBrush &brush);
107 QBrush shadesBrush() const;
107 QBrush shadesBrush() const;
108 void setShadesColor(QColor color);
108 void setShadesColor(QColor color);
109 QColor shadesColor() const;
109 QColor shadesColor() const;
110 void setShadesBorderColor(QColor color);
110 void setShadesBorderColor(QColor color);
111 QColor shadesBorderColor() const;
111 QColor shadesBorderColor() const;
112
112
113 Qt::Orientation orientation();
113 Qt::Orientation orientation();
114
114
115 //range handling
115 //range handling
116 void setMin(const QVariant &min);
116 void setMin(const QVariant &min);
117 void setMax(const QVariant &max);
117 void setMax(const QVariant &max);
118 void setRange(const QVariant &min, const QVariant &max);
118 void setRange(const QVariant &min, const QVariant &max);
119
119
120 void show();
120 void show();
121 void hide();
121 void hide();
122
122
123 Q_SIGNALS:
123 Q_SIGNALS:
124 void visibleChanged(bool visible);
124 void visibleChanged(bool visible);
125 void arrowVisibleChanged(bool visible);
125 void arrowVisibleChanged(bool visible);
126 void labelsVisibleChanged(bool visible);
126 void labelsVisibleChanged(bool visible);
127 void gridVisibleChanged(bool visible);
127 void gridVisibleChanged(bool visible);
128 void colorChanged(QColor color);
128 void colorChanged(QColor color);
129 void labelsColorChanged(QColor color);
129 void labelsColorChanged(QColor color);
130 void shadesVisibleChanged(bool visible);
130 void shadesVisibleChanged(bool visible);
131 void shadesColorChanged(QColor color);
131 void shadesColorChanged(QColor color);
132 void shadesBorderColorChanged(QColor color);
132 void shadesBorderColorChanged(QColor color);
133
133
134 protected:
134 protected:
135 QScopedPointer<QAbstractAxisPrivate> d_ptr;
135 QScopedPointer<QAbstractAxisPrivate> d_ptr;
136 Q_DISABLE_COPY(QAbstractAxis);
136 Q_DISABLE_COPY(QAbstractAxis)
137 friend class ChartDataSet;
137 friend class ChartDataSet;
138 friend class ChartAxis;
138 friend class ChartAxis;
139 friend class ChartPresenter;
139 friend class ChartPresenter;
140 };
140 };
141
141
142 QTCOMMERCIALCHART_END_NAMESPACE
142 QTCOMMERCIALCHART_END_NAMESPACE
143 #endif
143 #endif
@@ -1,176 +1,176
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTPRESENTER_H
30 #ifndef CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
35 #include <QRectF>
35 #include <QRectF>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class ChartElement;
39 class ChartElement;
40 class QAbstractSeries;
40 class QAbstractSeries;
41 class ChartDataSet;
41 class ChartDataSet;
42 class Domain;
42 class Domain;
43 class ChartAxis;
43 class ChartAxis;
44 class ChartTheme;
44 class ChartTheme;
45 class ChartAnimator;
45 class ChartAnimator;
46 class ChartBackground;
46 class ChartBackground;
47 class ChartAnimation;
47 class ChartAnimation;
48 class ChartLayout;
48 class ChartLayout;
49
49
50 class ChartPresenter: public QObject
50 class ChartPresenter: public QObject
51 {
51 {
52 Q_OBJECT
52 Q_OBJECT
53 public:
53 public:
54 enum ZValues {
54 enum ZValues {
55 BackgroundZValue = -1,
55 BackgroundZValue = -1,
56 ShadesZValue ,
56 ShadesZValue ,
57 GridZValue,
57 GridZValue,
58 AxisZValue,
58 SeriesZValue,
59 SeriesZValue,
59 LineChartZValue = SeriesZValue,
60 LineChartZValue = SeriesZValue,
60 SplineChartZValue = SeriesZValue,
61 SplineChartZValue = SeriesZValue,
61 BarSeriesZValue = SeriesZValue,
62 BarSeriesZValue = SeriesZValue,
62 ScatterSeriesZValue = SeriesZValue,
63 ScatterSeriesZValue = SeriesZValue,
63 PieSeriesZValue = SeriesZValue,
64 PieSeriesZValue = SeriesZValue,
64 AxisZValue,
65 LegendZValue,
65 LegendZValue,
66 TopMostZValue
66 TopMostZValue
67 };
67 };
68
68
69 enum State {
69 enum State {
70 ShowState,
70 ShowState,
71 ScrollUpState,
71 ScrollUpState,
72 ScrollDownState,
72 ScrollDownState,
73 ScrollLeftState,
73 ScrollLeftState,
74 ScrollRightState,
74 ScrollRightState,
75 ZoomInState,
75 ZoomInState,
76 ZoomOutState
76 ZoomOutState
77 };
77 };
78
78
79 ChartPresenter(QChart* chart,ChartDataSet *dataset);
79 ChartPresenter(QChart* chart,ChartDataSet *dataset);
80 virtual ~ChartPresenter();
80 virtual ~ChartPresenter();
81
81
82 ChartTheme *chartTheme() const { return m_chartTheme; }
82 ChartTheme *chartTheme() const { return m_chartTheme; }
83 ChartDataSet *dataSet() const { return m_dataset; }
83 ChartDataSet *dataSet() const { return m_dataset; }
84 QGraphicsItem* rootItem() const { return m_chart; }
84 QGraphicsItem* rootItem() const { return m_chart; }
85 QGraphicsRectItem* backgroundItem();
85 QGraphicsRectItem* backgroundItem();
86 QGraphicsItem* titleItem();
86 QGraphicsItem* titleItem();
87 QList<ChartAxis*> axisItems() const;
87 QList<ChartAxis*> axisItems() const;
88
88
89 QLegend* legend();
89 QLegend* legend();
90
90
91 void setBackgroundBrush(const QBrush& brush);
91 void setBackgroundBrush(const QBrush& brush);
92 QBrush backgroundBrush() const;
92 QBrush backgroundBrush() const;
93
93
94 void setBackgroundPen(const QPen& pen);
94 void setBackgroundPen(const QPen& pen);
95 QPen backgroundPen() const;
95 QPen backgroundPen() const;
96
96
97 void setTitle(const QString& title);
97 void setTitle(const QString& title);
98 QString title() const;
98 QString title() const;
99
99
100 void setTitleFont(const QFont& font);
100 void setTitleFont(const QFont& font);
101 QFont titleFont() const;
101 QFont titleFont() const;
102
102
103 void setTitleBrush(const QBrush &brush);
103 void setTitleBrush(const QBrush &brush);
104 QBrush titleBrush() const;
104 QBrush titleBrush() const;
105
105
106 void setBackgroundVisible(bool visible);
106 void setBackgroundVisible(bool visible);
107 bool isBackgroundVisible() const;
107 bool isBackgroundVisible() const;
108
108
109 void setBackgroundDropShadowEnabled(bool enabled);
109 void setBackgroundDropShadowEnabled(bool enabled);
110 bool isBackgroundDropShadowEnabled() const;
110 bool isBackgroundDropShadowEnabled() const;
111
111
112 void setVisible(bool visible);
112 void setVisible(bool visible);
113
113
114 void setTheme(QChart::ChartTheme theme,bool force = true);
114 void setTheme(QChart::ChartTheme theme,bool force = true);
115 QChart::ChartTheme theme();
115 QChart::ChartTheme theme();
116
116
117 void setAnimationOptions(QChart::AnimationOptions options);
117 void setAnimationOptions(QChart::AnimationOptions options);
118 QChart::AnimationOptions animationOptions() const;
118 QChart::AnimationOptions animationOptions() const;
119
119
120 void zoomIn(qreal factor);
120 void zoomIn(qreal factor);
121 void zoomIn(const QRectF& rect);
121 void zoomIn(const QRectF& rect);
122 void zoomOut(qreal factor);
122 void zoomOut(qreal factor);
123 void scroll(qreal dx,qreal dy);
123 void scroll(qreal dx,qreal dy);
124
124
125 void setGeometry(const QRectF& rect);
125 void setGeometry(const QRectF& rect);
126 QRectF geometry() { return m_rect; }
126 QRectF geometry() { return m_rect; }
127
127
128 void startAnimation(ChartAnimation* animation);
128 void startAnimation(ChartAnimation* animation);
129 State state() const { return m_state; }
129 State state() const { return m_state; }
130 QPointF statePoint() const { return m_statePoint; }
130 QPointF statePoint() const { return m_statePoint; }
131
131
132 void resetAllElements();
132 void resetAllElements();
133
133
134 void setMarginsMinimum(const QRectF& margins);
134 void setMarginsMinimum(const QRectF& margins);
135 QRectF margins() const;
135 QRectF margins() const;
136 QGraphicsLayout* layout();
136 QGraphicsLayout* layout();
137
137
138 private:
138 private:
139 void createBackgroundItem();
139 void createBackgroundItem();
140 void createTitleItem();
140 void createTitleItem();
141 void selectVisibleAxis();
141 void selectVisibleAxis();
142
142
143 public Q_SLOTS:
143 public Q_SLOTS:
144 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
144 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
145 void handleSeriesRemoved(QAbstractSeries* series);
145 void handleSeriesRemoved(QAbstractSeries* series);
146 void handleAxisAdded(QAbstractAxis* axis,Domain* domain);
146 void handleAxisAdded(QAbstractAxis* axis,Domain* domain);
147 void handleAxisRemoved(QAbstractAxis* axis);
147 void handleAxisRemoved(QAbstractAxis* axis);
148 void handleAxisVisibleChanged(bool visible);
148 void handleAxisVisibleChanged(bool visible);
149
149
150 private Q_SLOTS:
150 private Q_SLOTS:
151 void handleAnimationFinished();
151 void handleAnimationFinished();
152
152
153 Q_SIGNALS:
153 Q_SIGNALS:
154 void geometryChanged(const QRectF& rect);
154 void geometryChanged(const QRectF& rect);
155 void animationsFinished();
155 void animationsFinished();
156 void marginsChanged(QRectF margins);
156 void marginsChanged(QRectF margins);
157
157
158 private:
158 private:
159 QChart* m_chart;
159 QChart* m_chart;
160 ChartDataSet* m_dataset;
160 ChartDataSet* m_dataset;
161 ChartTheme *m_chartTheme;
161 ChartTheme *m_chartTheme;
162 QMap<QAbstractSeries*, ChartElement*> m_chartItems;
162 QMap<QAbstractSeries*, ChartElement*> m_chartItems;
163 QMap<QAbstractAxis*, ChartAxis*> m_axisItems;
163 QMap<QAbstractAxis*, ChartAxis*> m_axisItems;
164 QRectF m_rect;
164 QRectF m_rect;
165 QChart::AnimationOptions m_options;
165 QChart::AnimationOptions m_options;
166 State m_state;
166 State m_state;
167 QPointF m_statePoint;
167 QPointF m_statePoint;
168 QList<ChartAnimation*> m_animations;
168 QList<ChartAnimation*> m_animations;
169 ChartLayout* m_layout;
169 ChartLayout* m_layout;
170 ChartBackground* m_backgroundItem;
170 ChartBackground* m_backgroundItem;
171 QGraphicsSimpleTextItem* m_titleItem;
171 QGraphicsSimpleTextItem* m_titleItem;
172 };
172 };
173
173
174 QTCOMMERCIALCHART_END_NAMESPACE
174 QTCOMMERCIALCHART_END_NAMESPACE
175
175
176 #endif /* CHARTPRESENTER_H_ */
176 #endif /* CHARTPRESENTER_H_ */
General Comments 0
You need to be logged in to leave comments. Login now