@@ -1,183 +1,173 | |||||
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 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 | import QmlCustomModel 1.0 |
|
23 | import QmlCustomModel 1.0 | |
24 |
|
24 | |||
25 | Rectangle { |
|
25 | Rectangle { | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 |
|
27 | |||
28 | //![1] |
|
28 | //![1] | |
29 | ChartView { |
|
29 | ChartView { | |
30 | id: chartView |
|
30 | id: chartView | |
31 | title: "Top-5 car brand shares in Finland" |
|
31 | title: "Top-5 car brand shares in Finland" | |
32 | anchors.fill: parent |
|
32 | anchors.fill: parent | |
33 | animationOptions: ChartView.SeriesAnimations |
|
33 | animationOptions: ChartView.SeriesAnimations | |
34 |
|
34 | |||
35 | BarCategoriesAxis { |
|
35 | BarCategoriesAxis { | |
36 | id: categoryAxis |
|
36 | id: categoryAxis | |
37 | categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] |
|
37 | categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | ValuesAxis { |
|
40 | ValuesAxis { | |
41 | id: yAxis |
|
41 | id: yAxis | |
42 | min: 0 |
|
42 | min: 0 | |
43 | max: 60 |
|
43 | max: 60 | |
44 | } |
|
44 | } | |
45 | // ... |
|
45 | // ... | |
46 | //![1] |
|
46 | //![1] | |
47 |
|
47 | |||
48 | //![2] |
|
48 | //![2] | |
49 | CustomModel { |
|
49 | CustomModel { | |
50 | id: customModel |
|
50 | id: customModel | |
51 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] |
|
51 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] | |
52 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
52 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
53 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } |
|
53 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } | |
54 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } |
|
54 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } | |
55 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } |
|
55 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } | |
56 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } |
|
56 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } | |
57 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
57 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } | |
58 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
58 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } | |
59 | } |
|
59 | } | |
60 | //![2] |
|
60 | //![2] | |
61 |
|
61 | |||
62 | //![5] |
|
62 | //![5] | |
63 | BarSeries { |
|
63 | BarSeries { | |
64 | id: myBarSeries |
|
64 | id: myBarSeries | |
65 | name: "Others" |
|
65 | name: "Others" | |
66 | barWidth: 0.9 |
|
66 | barWidth: 0.9 | |
67 | visible: false |
|
67 | visible: false | |
68 | HBarModelMapper { |
|
68 | HBarModelMapper { | |
69 | model: customModel |
|
69 | model: customModel | |
70 | firstBarSetRow: 6 |
|
70 | firstBarSetRow: 6 | |
71 | lastBarSetRow: 6 |
|
71 | lastBarSetRow: 6 | |
72 | firstColumn: 2 |
|
72 | firstColumn: 2 | |
73 | } |
|
73 | } | |
74 | } |
|
74 | } | |
75 | //![5] |
|
75 | //![5] | |
76 |
|
76 | |||
77 | //![4] |
|
77 | //![4] | |
78 | LineSeries { |
|
78 | LineSeries { | |
79 | id: lineSeries1 |
|
79 | id: lineSeries1 | |
80 | name: "Volkswagen" |
|
80 | name: "Volkswagen" | |
81 | visible: false |
|
81 | visible: false | |
82 | HXYModelMapper { |
|
82 | HXYModelMapper { | |
83 | model: customModel |
|
83 | model: customModel | |
84 | xRow: 0 |
|
84 | xRow: 0 | |
85 | yRow: 1 |
|
85 | yRow: 1 | |
86 | firstColumn: 2 |
|
86 | firstColumn: 2 | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 | //![4] |
|
89 | //![4] | |
90 |
|
90 | |||
91 | LineSeries { |
|
91 | LineSeries { | |
92 | id: lineSeries2 |
|
92 | id: lineSeries2 | |
93 | name: "Toyota" |
|
93 | name: "Toyota" | |
94 | visible: false |
|
94 | visible: false | |
95 | HXYModelMapper { |
|
95 | HXYModelMapper { | |
96 | model: customModel |
|
96 | model: customModel | |
97 | xRow: 0 |
|
97 | xRow: 0 | |
98 | yRow: 2 |
|
98 | yRow: 2 | |
99 | firstColumn: 2 |
|
99 | firstColumn: 2 | |
100 | } |
|
100 | } | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | LineSeries { |
|
103 | LineSeries { | |
104 | id: lineSeries3 |
|
104 | id: lineSeries3 | |
105 | name: "Ford" |
|
105 | name: "Ford" | |
106 | visible: false |
|
106 | visible: false | |
107 | HXYModelMapper { |
|
107 | HXYModelMapper { | |
108 | model: customModel |
|
108 | model: customModel | |
109 | xRow: 0 |
|
109 | xRow: 0 | |
110 | yRow: 3 |
|
110 | yRow: 3 | |
111 | firstColumn: 2 |
|
111 | firstColumn: 2 | |
112 | } |
|
112 | } | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | LineSeries { |
|
115 | LineSeries { | |
116 | id: lineSeries4 |
|
116 | id: lineSeries4 | |
117 | name: "Skoda" |
|
117 | name: "Skoda" | |
118 | visible: false |
|
118 | visible: false | |
119 | HXYModelMapper { |
|
119 | HXYModelMapper { | |
120 | model: customModel |
|
120 | model: customModel | |
121 | xRow: 0 |
|
121 | xRow: 0 | |
122 | yRow: 4 |
|
122 | yRow: 4 | |
123 | firstColumn: 2 |
|
123 | firstColumn: 2 | |
124 | } |
|
124 | } | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | LineSeries { |
|
127 | LineSeries { | |
128 | id: lineSeries5 |
|
128 | id: lineSeries5 | |
129 | name: "Volvo" |
|
129 | name: "Volvo" | |
130 | visible: false |
|
130 | visible: false | |
131 | HXYModelMapper { |
|
131 | HXYModelMapper { | |
132 | model: customModel |
|
132 | model: customModel | |
133 | xRow: 0 |
|
133 | xRow: 0 | |
134 | yRow: 5 |
|
134 | yRow: 5 | |
135 | firstColumn: 2 |
|
135 | firstColumn: 2 | |
136 | } |
|
136 | } | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | //![3] |
|
139 | //![3] | |
140 | PieSeries { |
|
140 | PieSeries { | |
141 | id: pieSeries |
|
141 | id: pieSeries | |
142 | size: 0.4 |
|
142 | size: 0.4 | |
143 | horizontalPosition: 0.85 |
|
143 | horizontalPosition: 0.85 | |
144 | verticalPosition: 0.4 |
|
144 | verticalPosition: 0.4 | |
145 | onClicked: { |
|
145 | onClicked: { | |
146 | // Show the selection by exploding the slice |
|
146 | // Show the selection by exploding the slice | |
147 | slice.exploded = !slice.exploded; |
|
147 | slice.exploded = !slice.exploded; | |
148 |
|
148 | |||
149 | // Update the line series to show the yearly data for this slice |
|
149 | // Update the line series to show the yearly data for this slice | |
150 | for (var i = 0; i < chartView.count; i++) { |
|
150 | for (var i = 0; i < chartView.count; i++) { | |
151 | if (chartView.series(i).name == slice.label) { |
|
151 | if (chartView.series(i).name == slice.label) { | |
152 | chartView.series(i).visible = slice.exploded; |
|
152 | chartView.series(i).visible = slice.exploded; | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | VPieModelMapper { |
|
157 | VPieModelMapper { | |
158 | model: customModel |
|
158 | model: customModel | |
159 | labelsColumn: 1 |
|
159 | labelsColumn: 1 | |
160 | valuesColumn: 2 |
|
160 | valuesColumn: 2 | |
161 | firstRow: 1 |
|
161 | firstRow: 1 | |
162 | } |
|
162 | } | |
163 | } |
|
163 | } | |
164 | //![3] |
|
164 | //![3] | |
165 |
|
165 | |||
166 | Component.onCompleted: { |
|
166 | Component.onCompleted: { | |
167 | setAxisX(categoryAxis,myBarSeries) |
|
167 | createDefaultAxes(); | |
168 |
setAxisX(categoryAxis, |
|
168 | setAxisX(categoryAxis,myBarSeries) | |
169 |
|
|
169 | categoryAxis.min = "2007" | |
170 | setAxisX(categoryAxis,lineSeries3) |
|
170 | categoryAxis.max = "2014" | |
171 | setAxisX(categoryAxis,lineSeries4) |
|
|||
172 | setAxisX(categoryAxis,lineSeries5) |
|
|||
173 | setAxisY(yAxis,myBarSeries) |
|
|||
174 | setAxisY(yAxis,lineSeries1) |
|
|||
175 | setAxisY(yAxis,lineSeries2) |
|
|||
176 | setAxisY(yAxis,lineSeries3) |
|
|||
177 | setAxisY(yAxis,lineSeries4) |
|
|||
178 | setAxisY(yAxis,lineSeries5) |
|
|||
179 | categoryAxis.min = "2007" |
|
|||
180 | categoryAxis.max = "2014" |
|
|||
181 | } |
|
171 | } | |
182 | } |
|
172 | } | |
183 | } |
|
173 | } |
@@ -1,446 +1,474 | |||||
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 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "qabstractaxis_p.h" |
|
24 | #include "qabstractaxis_p.h" | |
25 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
27 | #include "chartanimator_p.h" |
|
27 | #include "chartanimator_p.h" | |
28 | #include "chartanimation_p.h" |
|
28 | #include "chartanimation_p.h" | |
29 | #include "qabstractseries_p.h" |
|
29 | #include "qabstractseries_p.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "chartaxis_p.h" |
|
31 | #include "chartaxis_p.h" | |
32 | //#include "chartaxisx_p.h" |
|
32 | //#include "chartaxisx_p.h" | |
33 | //#include "chartaxisy_p.h" |
|
33 | //#include "chartaxisy_p.h" | |
34 | #include "areachartitem_p.h" |
|
34 | #include "areachartitem_p.h" | |
35 | #include "chartbackground_p.h" |
|
35 | #include "chartbackground_p.h" | |
36 | #include "chartlayout_p.h" |
|
36 | #include "chartlayout_p.h" | |
37 | #include <QTimer> |
|
37 | #include <QTimer> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
41 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
42 | m_chart(chart), |
|
42 | m_chart(chart), | |
43 | m_animator(0), |
|
43 | m_animator(0), | |
44 | m_dataset(dataset), |
|
44 | m_dataset(dataset), | |
45 | m_chartTheme(0), |
|
45 | m_chartTheme(0), | |
46 | m_options(QChart::NoAnimation), |
|
46 | m_options(QChart::NoAnimation), | |
47 | m_state(ShowState), |
|
47 | m_state(ShowState), | |
48 | m_layout(new ChartLayout(this)), |
|
48 | m_layout(new ChartLayout(this)), | |
49 | m_backgroundItem(0), |
|
49 | m_backgroundItem(0), | |
50 | m_titleItem(0) |
|
50 | m_titleItem(0) | |
51 | { |
|
51 | { | |
52 |
|
52 | |||
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | ChartPresenter::~ChartPresenter() |
|
55 | ChartPresenter::~ChartPresenter() | |
56 | { |
|
56 | { | |
57 | delete m_chartTheme; |
|
57 | delete m_chartTheme; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void ChartPresenter::setGeometry(const QRectF& rect) |
|
60 | void ChartPresenter::setGeometry(const QRectF& rect) | |
61 | { |
|
61 | { | |
62 |
|
62 | |||
63 | Q_ASSERT(rect.isValid()); |
|
63 | Q_ASSERT(rect.isValid()); | |
64 |
|
64 | |||
65 | if(m_rect!=rect) { |
|
65 | if(m_rect!=rect) { | |
66 | m_rect=rect; |
|
66 | m_rect=rect; | |
67 | emit geometryChanged(m_rect); |
|
67 | emit geometryChanged(m_rect); | |
68 | } |
|
68 | } | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) |
|
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) | |
72 | { |
|
72 | { | |
73 | ChartAxis* item = axis->d_ptr->createGraphics(this); |
|
73 | ChartAxis* item = axis->d_ptr->createGraphics(this); | |
74 | item->setDomain(domain); |
|
74 | item->setDomain(domain); | |
75 |
|
75 | |||
76 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
76 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
77 | item->setAnimator(m_animator); |
|
77 | item->setAnimator(m_animator); | |
78 | item->setAnimation(new AxisAnimation(item)); |
|
78 | item->setAnimation(new AxisAnimation(item)); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | if(item->axisType()==ChartAxis::X_AXIS){ |
|
81 | if(item->axisType()==ChartAxis::X_AXIS){ | |
82 | m_chartTheme->decorate(axis,true); |
|
82 | m_chartTheme->decorate(axis,true); | |
83 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
83 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
84 | //initialize |
|
84 | //initialize | |
85 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
85 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 | else{ |
|
88 | else{ | |
89 | m_chartTheme->decorate(axis,false); |
|
89 | m_chartTheme->decorate(axis,false); | |
90 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
90 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
91 | //initialize |
|
91 | //initialize | |
92 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
92 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
95 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
96 | QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); |
|
96 | QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); | |
97 | //initialize |
|
97 | //initialize | |
98 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
98 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
99 | //reload visiblity |
|
99 | //reload visiblity | |
100 | m_axisItems.insert(axis, item); |
|
100 | m_axisItems.insert(axis, item); | |
101 | if(axis->isVisible()) axis->hide(); |
|
101 | selectVisibleAxis(); | |
102 | axis->show(); |
|
|||
103 |
|
102 | |||
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) |
|
105 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) | |
107 | { |
|
106 | { | |
108 | ChartAxis* item = m_axisItems.take(axis); |
|
107 | ChartAxis* item = m_axisItems.take(axis); | |
109 | Q_ASSERT(item); |
|
108 | Q_ASSERT(item); | |
|
109 | selectVisibleAxis(); | |||
110 | if(m_animator) m_animator->removeAnimation(item); |
|
110 | if(m_animator) m_animator->removeAnimation(item); | |
111 | item->deleteLater(); |
|
111 | item->deleteLater(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) |
|
115 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) | |
116 | { |
|
116 | { | |
117 | Chart *item = series->d_ptr->createGraphics(this); |
|
117 | Chart *item = series->d_ptr->createGraphics(this); | |
118 | Q_ASSERT(item); |
|
118 | Q_ASSERT(item); | |
119 | item->setDomain(domain); |
|
119 | item->setDomain(domain); | |
120 |
|
120 | |||
121 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
121 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
122 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
122 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
123 | //initialize |
|
123 | //initialize | |
124 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
124 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
125 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
125 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
126 | m_chartItems.insert(series,item); |
|
126 | m_chartItems.insert(series,item); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) |
|
129 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) | |
130 | { |
|
130 | { | |
131 | Chart* item = m_chartItems.take(series); |
|
131 | Chart* item = m_chartItems.take(series); | |
132 | Q_ASSERT(item); |
|
132 | Q_ASSERT(item); | |
133 | if(m_animator) { |
|
133 | if(m_animator) { | |
134 | //small hack to handle area animations |
|
134 | //small hack to handle area animations | |
135 | if(series->type() == QAbstractSeries::SeriesTypeArea){ |
|
135 | if(series->type() == QAbstractSeries::SeriesTypeArea){ | |
136 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
136 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
137 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
137 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
138 | m_animator->removeAnimation(area->upperLineItem()); |
|
138 | m_animator->removeAnimation(area->upperLineItem()); | |
139 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
139 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
140 | }else |
|
140 | }else | |
141 | m_animator->removeAnimation(item); |
|
141 | m_animator->removeAnimation(item); | |
142 | } |
|
142 | } | |
143 | item->deleteLater(); |
|
143 | item->deleteLater(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
|
146 | void ChartPresenter::selectVisibleAxis() | |||
|
147 | { | |||
|
148 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |||
|
149 | ||||
|
150 | while (i.hasNext()) { | |||
|
151 | i.next(); | |||
|
152 | i.key()->hide(); | |||
|
153 | } | |||
|
154 | ||||
|
155 | i.toFront(); | |||
|
156 | ||||
|
157 | bool axisX=false; | |||
|
158 | bool axisY=false; | |||
|
159 | ||||
|
160 | while (i.hasNext()) { | |||
|
161 | i.next(); | |||
|
162 | if(i.key()->d_ptr->m_orientation==Qt::Vertical && !axisY) { | |||
|
163 | axisY=true; | |||
|
164 | i.key()->show(); | |||
|
165 | } | |||
|
166 | if(i.key()->d_ptr->m_orientation==Qt::Horizontal && !axisX) { | |||
|
167 | axisX=true; | |||
|
168 | i.key()->show(); | |||
|
169 | } | |||
|
170 | ||||
|
171 | } | |||
|
172 | } | |||
|
173 | ||||
146 |
|
174 | |||
147 | void ChartPresenter::handleAxisVisibleChanged(bool visible) |
|
175 | void ChartPresenter::handleAxisVisibleChanged(bool visible) | |
148 | { |
|
176 | { | |
149 | QAbstractAxis* axis = static_cast<QAbstractAxis*> (sender()); |
|
177 | QAbstractAxis* axis = static_cast<QAbstractAxis*> (sender()); | |
150 | Q_ASSERT(axis); |
|
178 | Q_ASSERT(axis); | |
151 | if(visible){ |
|
179 | if(visible){ | |
152 |
|
180 | |||
153 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
181 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
154 |
|
182 | |||
155 | while (i.hasNext()) { |
|
183 | while (i.hasNext()) { | |
156 | i.next(); |
|
184 | i.next(); | |
157 | if(i.key()==axis) { |
|
185 | if(i.key()==axis) { | |
158 | continue; |
|
186 | continue; | |
159 | } |
|
187 | } | |
160 | if(i.key()->d_ptr->m_orientation==axis->d_ptr->m_orientation) { |
|
188 | if(i.key()->d_ptr->m_orientation==axis->d_ptr->m_orientation) { | |
161 | i.key()->setVisible(false); |
|
189 | i.key()->setVisible(false); | |
162 | } |
|
190 | } | |
163 | } |
|
191 | } | |
164 | } |
|
192 | } | |
165 | } |
|
193 | } | |
166 |
|
194 | |||
167 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
195 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
168 | { |
|
196 | { | |
169 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
197 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
170 | delete m_chartTheme; |
|
198 | delete m_chartTheme; | |
171 | m_chartTheme = ChartTheme::createTheme(theme); |
|
199 | m_chartTheme = ChartTheme::createTheme(theme); | |
172 | m_chartTheme->setForced(force); |
|
200 | m_chartTheme->setForced(force); | |
173 | m_chartTheme->decorate(m_chart); |
|
201 | m_chartTheme->decorate(m_chart); | |
174 | m_chartTheme->decorate(m_chart->legend()); |
|
202 | m_chartTheme->decorate(m_chart->legend()); | |
175 | resetAllElements(); |
|
203 | resetAllElements(); | |
176 |
|
204 | |||
177 | // We do not want "force" to stay on. |
|
205 | // We do not want "force" to stay on. | |
178 | // Bar/pie are calling decorate when adding/removing slices/bars which means |
|
206 | // Bar/pie are calling decorate when adding/removing slices/bars which means | |
179 | // that to preserve users colors "force" must not be on. |
|
207 | // that to preserve users colors "force" must not be on. | |
180 | m_chartTheme->setForced(false); |
|
208 | m_chartTheme->setForced(false); | |
181 | } |
|
209 | } | |
182 |
|
210 | |||
183 | QChart::ChartTheme ChartPresenter::theme() |
|
211 | QChart::ChartTheme ChartPresenter::theme() | |
184 | { |
|
212 | { | |
185 | return m_chartTheme->id(); |
|
213 | return m_chartTheme->id(); | |
186 | } |
|
214 | } | |
187 |
|
215 | |||
188 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
216 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
189 | { |
|
217 | { | |
190 | if(m_options!=options) { |
|
218 | if(m_options!=options) { | |
191 |
|
219 | |||
192 | m_options=options; |
|
220 | m_options=options; | |
193 |
|
221 | |||
194 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
222 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
195 | m_animator= new ChartAnimator(this); |
|
223 | m_animator= new ChartAnimator(this); | |
196 | } |
|
224 | } | |
197 | resetAllElements(); |
|
225 | resetAllElements(); | |
198 | } |
|
226 | } | |
199 |
|
227 | |||
200 | } |
|
228 | } | |
201 |
|
229 | |||
202 | void ChartPresenter::resetAllElements() |
|
230 | void ChartPresenter::resetAllElements() | |
203 | { |
|
231 | { | |
204 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
232 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
205 | while (i.hasNext()) { |
|
233 | while (i.hasNext()) { | |
206 | i.next(); |
|
234 | i.next(); | |
207 | Domain* domain = i.value()->domain(); |
|
235 | Domain* domain = i.value()->domain(); | |
208 | QAbstractAxis* axis = i.key(); |
|
236 | QAbstractAxis* axis = i.key(); | |
209 | handleAxisRemoved(axis); |
|
237 | handleAxisRemoved(axis); | |
210 | handleAxisAdded(axis,domain); |
|
238 | handleAxisAdded(axis,domain); | |
211 | } |
|
239 | } | |
212 |
|
240 | |||
213 | QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems); |
|
241 | QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems); | |
214 | while (j.hasNext()) { |
|
242 | while (j.hasNext()) { | |
215 | j.next(); |
|
243 | j.next(); | |
216 | Domain* domain = j.value()->domain(); |
|
244 | Domain* domain = j.value()->domain(); | |
217 | QAbstractSeries* series = j.key(); |
|
245 | QAbstractSeries* series = j.key(); | |
218 | handleSeriesRemoved(series); |
|
246 | handleSeriesRemoved(series); | |
219 | handleSeriesAdded(series,domain); |
|
247 | handleSeriesAdded(series,domain); | |
220 | } |
|
248 | } | |
221 | } |
|
249 | } | |
222 |
|
250 | |||
223 | void ChartPresenter::zoomIn(qreal factor) |
|
251 | void ChartPresenter::zoomIn(qreal factor) | |
224 | { |
|
252 | { | |
225 | QRectF rect = geometry(); |
|
253 | QRectF rect = geometry(); | |
226 | rect.setWidth(rect.width()/factor); |
|
254 | rect.setWidth(rect.width()/factor); | |
227 | rect.setHeight(rect.height()/factor); |
|
255 | rect.setHeight(rect.height()/factor); | |
228 | rect.moveCenter(geometry().center()); |
|
256 | rect.moveCenter(geometry().center()); | |
229 | zoomIn(rect); |
|
257 | zoomIn(rect); | |
230 | } |
|
258 | } | |
231 |
|
259 | |||
232 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
260 | void ChartPresenter::zoomIn(const QRectF& rect) | |
233 | { |
|
261 | { | |
234 | QRectF r = rect.normalized(); |
|
262 | QRectF r = rect.normalized(); | |
235 | r.translate(-geometry().topLeft()); |
|
263 | r.translate(-geometry().topLeft()); | |
236 | if (!r.isValid()) |
|
264 | if (!r.isValid()) | |
237 | return; |
|
265 | return; | |
238 |
|
266 | |||
239 | m_state = ZoomInState; |
|
267 | m_state = ZoomInState; | |
240 | m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
268 | m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height()); | |
241 | m_dataset->zoomInDomain(r,geometry().size()); |
|
269 | m_dataset->zoomInDomain(r,geometry().size()); | |
242 | m_state = ShowState; |
|
270 | m_state = ShowState; | |
243 | } |
|
271 | } | |
244 |
|
272 | |||
245 | void ChartPresenter::zoomOut(qreal factor) |
|
273 | void ChartPresenter::zoomOut(qreal factor) | |
246 | { |
|
274 | { | |
247 | m_state = ZoomOutState; |
|
275 | m_state = ZoomOutState; | |
248 |
|
276 | |||
249 | QRectF chartRect; |
|
277 | QRectF chartRect; | |
250 | chartRect.setSize(geometry().size()); |
|
278 | chartRect.setSize(geometry().size()); | |
251 |
|
279 | |||
252 | QRectF rect; |
|
280 | QRectF rect; | |
253 | rect.setSize(chartRect.size()/factor); |
|
281 | rect.setSize(chartRect.size()/factor); | |
254 | rect.moveCenter(chartRect.center()); |
|
282 | rect.moveCenter(chartRect.center()); | |
255 | if (!rect.isValid()) |
|
283 | if (!rect.isValid()) | |
256 | return; |
|
284 | return; | |
257 | m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height()); |
|
285 | m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height()); | |
258 | m_dataset->zoomOutDomain(rect, chartRect.size()); |
|
286 | m_dataset->zoomOutDomain(rect, chartRect.size()); | |
259 | m_state = ShowState; |
|
287 | m_state = ShowState; | |
260 | } |
|
288 | } | |
261 |
|
289 | |||
262 | void ChartPresenter::scroll(qreal dx,qreal dy) |
|
290 | void ChartPresenter::scroll(qreal dx,qreal dy) | |
263 | { |
|
291 | { | |
264 | if(dx<0) m_state=ScrollLeftState; |
|
292 | if(dx<0) m_state=ScrollLeftState; | |
265 | if(dx>0) m_state=ScrollRightState; |
|
293 | if(dx>0) m_state=ScrollRightState; | |
266 | if(dy<0) m_state=ScrollUpState; |
|
294 | if(dy<0) m_state=ScrollUpState; | |
267 | if(dy>0) m_state=ScrollDownState; |
|
295 | if(dy>0) m_state=ScrollDownState; | |
268 |
|
296 | |||
269 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
297 | m_dataset->scrollDomain(dx,dy,geometry().size()); | |
270 | m_state = ShowState; |
|
298 | m_state = ShowState; | |
271 | } |
|
299 | } | |
272 |
|
300 | |||
273 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
301 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
274 | { |
|
302 | { | |
275 | return m_options; |
|
303 | return m_options; | |
276 | } |
|
304 | } | |
277 |
|
305 | |||
278 | void ChartPresenter::createBackgroundItem() |
|
306 | void ChartPresenter::createBackgroundItem() | |
279 | { |
|
307 | { | |
280 | if (!m_backgroundItem) { |
|
308 | if (!m_backgroundItem) { | |
281 | m_backgroundItem = new ChartBackground(rootItem()); |
|
309 | m_backgroundItem = new ChartBackground(rootItem()); | |
282 | m_backgroundItem->setPen(Qt::NoPen); |
|
310 | m_backgroundItem->setPen(Qt::NoPen); | |
283 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
311 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
284 | } |
|
312 | } | |
285 | } |
|
313 | } | |
286 |
|
314 | |||
287 | void ChartPresenter::createTitleItem() |
|
315 | void ChartPresenter::createTitleItem() | |
288 | { |
|
316 | { | |
289 | if (!m_titleItem) { |
|
317 | if (!m_titleItem) { | |
290 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); |
|
318 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); | |
291 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
319 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
292 | } |
|
320 | } | |
293 | } |
|
321 | } | |
294 |
|
322 | |||
295 |
|
323 | |||
296 | void ChartPresenter::handleAnimationFinished() |
|
324 | void ChartPresenter::handleAnimationFinished() | |
297 | { |
|
325 | { | |
298 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); |
|
326 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); | |
299 | if(m_animations.empty()) emit animationsFinished(); |
|
327 | if(m_animations.empty()) emit animationsFinished(); | |
300 | } |
|
328 | } | |
301 |
|
329 | |||
302 | void ChartPresenter::startAnimation(ChartAnimation* animation) |
|
330 | void ChartPresenter::startAnimation(ChartAnimation* animation) | |
303 | { |
|
331 | { | |
304 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
332 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
305 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); |
|
333 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); | |
306 | if(!m_animations.isEmpty()){ |
|
334 | if(!m_animations.isEmpty()){ | |
307 | m_animations.append(animation); |
|
335 | m_animations.append(animation); | |
308 | } |
|
336 | } | |
309 | QTimer::singleShot(0, animation, SLOT(start())); |
|
337 | QTimer::singleShot(0, animation, SLOT(start())); | |
310 | } |
|
338 | } | |
311 |
|
339 | |||
312 | QGraphicsRectItem* ChartPresenter::backgroundItem() |
|
340 | QGraphicsRectItem* ChartPresenter::backgroundItem() | |
313 | { |
|
341 | { | |
314 | return m_backgroundItem; |
|
342 | return m_backgroundItem; | |
315 | } |
|
343 | } | |
316 |
|
344 | |||
317 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) |
|
345 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) | |
318 | { |
|
346 | { | |
319 | createBackgroundItem(); |
|
347 | createBackgroundItem(); | |
320 | m_backgroundItem->setBrush(brush); |
|
348 | m_backgroundItem->setBrush(brush); | |
321 | m_layout->invalidate(); |
|
349 | m_layout->invalidate(); | |
322 | } |
|
350 | } | |
323 |
|
351 | |||
324 | QBrush ChartPresenter::backgroundBrush() const |
|
352 | QBrush ChartPresenter::backgroundBrush() const | |
325 | { |
|
353 | { | |
326 | if (!m_backgroundItem) return QBrush(); |
|
354 | if (!m_backgroundItem) return QBrush(); | |
327 | return m_backgroundItem->brush(); |
|
355 | return m_backgroundItem->brush(); | |
328 | } |
|
356 | } | |
329 |
|
357 | |||
330 | void ChartPresenter::setBackgroundPen(const QPen& pen) |
|
358 | void ChartPresenter::setBackgroundPen(const QPen& pen) | |
331 | { |
|
359 | { | |
332 | createBackgroundItem(); |
|
360 | createBackgroundItem(); | |
333 | m_backgroundItem->setPen(pen); |
|
361 | m_backgroundItem->setPen(pen); | |
334 | m_layout->invalidate(); |
|
362 | m_layout->invalidate(); | |
335 | } |
|
363 | } | |
336 |
|
364 | |||
337 | QPen ChartPresenter::backgroundPen() const |
|
365 | QPen ChartPresenter::backgroundPen() const | |
338 | { |
|
366 | { | |
339 | if (!m_backgroundItem) return QPen(); |
|
367 | if (!m_backgroundItem) return QPen(); | |
340 | return m_backgroundItem->pen(); |
|
368 | return m_backgroundItem->pen(); | |
341 | } |
|
369 | } | |
342 |
|
370 | |||
343 | QGraphicsItem* ChartPresenter::titleItem() |
|
371 | QGraphicsItem* ChartPresenter::titleItem() | |
344 | { |
|
372 | { | |
345 | return m_titleItem; |
|
373 | return m_titleItem; | |
346 | } |
|
374 | } | |
347 |
|
375 | |||
348 | void ChartPresenter::setTitle(const QString& title) |
|
376 | void ChartPresenter::setTitle(const QString& title) | |
349 | { |
|
377 | { | |
350 | createTitleItem(); |
|
378 | createTitleItem(); | |
351 | m_titleItem->setText(title); |
|
379 | m_titleItem->setText(title); | |
352 | m_layout->invalidate(); |
|
380 | m_layout->invalidate(); | |
353 | } |
|
381 | } | |
354 |
|
382 | |||
355 | QString ChartPresenter::title() const |
|
383 | QString ChartPresenter::title() const | |
356 | { |
|
384 | { | |
357 | if (!m_titleItem) return QString(); |
|
385 | if (!m_titleItem) return QString(); | |
358 | return m_titleItem->text(); |
|
386 | return m_titleItem->text(); | |
359 | } |
|
387 | } | |
360 |
|
388 | |||
361 | void ChartPresenter::setTitleFont(const QFont& font) |
|
389 | void ChartPresenter::setTitleFont(const QFont& font) | |
362 | { |
|
390 | { | |
363 | createTitleItem(); |
|
391 | createTitleItem(); | |
364 | m_titleItem->setFont(font); |
|
392 | m_titleItem->setFont(font); | |
365 | m_layout->invalidate(); |
|
393 | m_layout->invalidate(); | |
366 | } |
|
394 | } | |
367 |
|
395 | |||
368 | QFont ChartPresenter::titleFont() const |
|
396 | QFont ChartPresenter::titleFont() const | |
369 | { |
|
397 | { | |
370 | if (!m_titleItem) return QFont(); |
|
398 | if (!m_titleItem) return QFont(); | |
371 | return m_titleItem->font(); |
|
399 | return m_titleItem->font(); | |
372 | } |
|
400 | } | |
373 |
|
401 | |||
374 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
402 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
375 | { |
|
403 | { | |
376 | createTitleItem(); |
|
404 | createTitleItem(); | |
377 | m_titleItem->setBrush(brush); |
|
405 | m_titleItem->setBrush(brush); | |
378 | m_layout->invalidate(); |
|
406 | m_layout->invalidate(); | |
379 | } |
|
407 | } | |
380 |
|
408 | |||
381 | QBrush ChartPresenter::titleBrush() const |
|
409 | QBrush ChartPresenter::titleBrush() const | |
382 | { |
|
410 | { | |
383 | if (!m_titleItem) return QBrush(); |
|
411 | if (!m_titleItem) return QBrush(); | |
384 | return m_titleItem->brush(); |
|
412 | return m_titleItem->brush(); | |
385 | } |
|
413 | } | |
386 |
|
414 | |||
387 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
415 | void ChartPresenter::setBackgroundVisible(bool visible) | |
388 | { |
|
416 | { | |
389 | createBackgroundItem(); |
|
417 | createBackgroundItem(); | |
390 | m_backgroundItem->setVisible(visible); |
|
418 | m_backgroundItem->setVisible(visible); | |
391 | } |
|
419 | } | |
392 |
|
420 | |||
393 |
|
421 | |||
394 | bool ChartPresenter::isBackgroundVisible() const |
|
422 | bool ChartPresenter::isBackgroundVisible() const | |
395 | { |
|
423 | { | |
396 | if (!m_backgroundItem) return false; |
|
424 | if (!m_backgroundItem) return false; | |
397 | return m_backgroundItem->isVisible(); |
|
425 | return m_backgroundItem->isVisible(); | |
398 | } |
|
426 | } | |
399 |
|
427 | |||
400 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
428 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
401 | { |
|
429 | { | |
402 | createBackgroundItem(); |
|
430 | createBackgroundItem(); | |
403 | m_backgroundItem->setDropShadowEnabled(enabled); |
|
431 | m_backgroundItem->setDropShadowEnabled(enabled); | |
404 | } |
|
432 | } | |
405 |
|
433 | |||
406 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
434 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
407 | { |
|
435 | { | |
408 | if (!m_backgroundItem) return false; |
|
436 | if (!m_backgroundItem) return false; | |
409 | return m_backgroundItem->isDropShadowEnabled(); |
|
437 | return m_backgroundItem->isDropShadowEnabled(); | |
410 | } |
|
438 | } | |
411 |
|
439 | |||
412 |
|
440 | |||
413 | QGraphicsLayout* ChartPresenter::layout() |
|
441 | QGraphicsLayout* ChartPresenter::layout() | |
414 | { |
|
442 | { | |
415 | return m_layout; |
|
443 | return m_layout; | |
416 | } |
|
444 | } | |
417 |
|
445 | |||
418 | void ChartPresenter::setMarginsMinimum(const QRectF& margins) |
|
446 | void ChartPresenter::setMarginsMinimum(const QRectF& margins) | |
419 | { |
|
447 | { | |
420 | Q_UNUSED(margins); |
|
448 | Q_UNUSED(margins); | |
421 | // m_layout->setMarginsMinimum(margins); |
|
449 | // m_layout->setMarginsMinimum(margins); | |
422 | } |
|
450 | } | |
423 |
|
451 | |||
424 | QRectF ChartPresenter::margins() const |
|
452 | QRectF ChartPresenter::margins() const | |
425 | { |
|
453 | { | |
426 | return QRectF();//m_layout->margins(); |
|
454 | return QRectF();//m_layout->margins(); | |
427 | } |
|
455 | } | |
428 |
|
456 | |||
429 | QLegend* ChartPresenter::legend() |
|
457 | QLegend* ChartPresenter::legend() | |
430 | { |
|
458 | { | |
431 | return m_chart->legend(); |
|
459 | return m_chart->legend(); | |
432 | } |
|
460 | } | |
433 |
|
461 | |||
434 | QList<ChartAxis*> ChartPresenter::axisItems() const |
|
462 | QList<ChartAxis*> ChartPresenter::axisItems() const | |
435 | { |
|
463 | { | |
436 | return m_axisItems.values(); |
|
464 | return m_axisItems.values(); | |
437 | } |
|
465 | } | |
438 |
|
466 | |||
439 | void ChartPresenter::setVisible(bool visible) |
|
467 | void ChartPresenter::setVisible(bool visible) | |
440 | { |
|
468 | { | |
441 | m_chart->setVisible(visible); |
|
469 | m_chart->setVisible(visible); | |
442 | } |
|
470 | } | |
443 |
|
471 | |||
444 | #include "moc_chartpresenter_p.cpp" |
|
472 | #include "moc_chartpresenter_p.cpp" | |
445 |
|
473 | |||
446 | QTCOMMERCIALCHART_END_NAMESPACE |
|
474 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,175 +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 Chart; |
|
39 | class Chart; | |
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 | SeriesZValue, |
|
58 | SeriesZValue, | |
59 | LineChartZValue = SeriesZValue, |
|
59 | LineChartZValue = SeriesZValue, | |
60 | BarSeriesZValue = SeriesZValue, |
|
60 | BarSeriesZValue = SeriesZValue, | |
61 | ScatterSeriesZValue = SeriesZValue, |
|
61 | ScatterSeriesZValue = SeriesZValue, | |
62 | PieSeriesZValue = SeriesZValue, |
|
62 | PieSeriesZValue = SeriesZValue, | |
63 | AxisZValue, |
|
63 | AxisZValue, | |
64 | LegendZValue |
|
64 | LegendZValue | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | enum State { |
|
67 | enum State { | |
68 | ShowState, |
|
68 | ShowState, | |
69 | ScrollUpState, |
|
69 | ScrollUpState, | |
70 | ScrollDownState, |
|
70 | ScrollDownState, | |
71 | ScrollLeftState, |
|
71 | ScrollLeftState, | |
72 | ScrollRightState, |
|
72 | ScrollRightState, | |
73 | ZoomInState, |
|
73 | ZoomInState, | |
74 | ZoomOutState |
|
74 | ZoomOutState | |
75 | }; |
|
75 | }; | |
76 |
|
76 | |||
77 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
77 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
78 | virtual ~ChartPresenter(); |
|
78 | virtual ~ChartPresenter(); | |
79 |
|
79 | |||
80 | ChartAnimator* animator() const { return m_animator; } |
|
80 | ChartAnimator* animator() const { return m_animator; } | |
81 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
81 | ChartTheme *chartTheme() const { return m_chartTheme; } | |
82 | ChartDataSet *dataSet() const { return m_dataset; } |
|
82 | ChartDataSet *dataSet() const { return m_dataset; } | |
83 | QGraphicsItem* rootItem() const { return m_chart; } |
|
83 | QGraphicsItem* rootItem() const { return m_chart; } | |
84 | QGraphicsRectItem* backgroundItem(); |
|
84 | QGraphicsRectItem* backgroundItem(); | |
85 | QGraphicsItem* titleItem(); |
|
85 | QGraphicsItem* titleItem(); | |
86 | QList<ChartAxis*> axisItems() const; |
|
86 | QList<ChartAxis*> axisItems() const; | |
87 |
|
87 | |||
88 | QLegend* legend(); |
|
88 | QLegend* legend(); | |
89 |
|
89 | |||
90 | void setBackgroundBrush(const QBrush& brush); |
|
90 | void setBackgroundBrush(const QBrush& brush); | |
91 | QBrush backgroundBrush() const; |
|
91 | QBrush backgroundBrush() const; | |
92 |
|
92 | |||
93 | void setBackgroundPen(const QPen& pen); |
|
93 | void setBackgroundPen(const QPen& pen); | |
94 | QPen backgroundPen() const; |
|
94 | QPen backgroundPen() const; | |
95 |
|
95 | |||
96 | void setTitle(const QString& title); |
|
96 | void setTitle(const QString& title); | |
97 | QString title() const; |
|
97 | QString title() const; | |
98 |
|
98 | |||
99 | void setTitleFont(const QFont& font); |
|
99 | void setTitleFont(const QFont& font); | |
100 | QFont titleFont() const; |
|
100 | QFont titleFont() const; | |
101 |
|
101 | |||
102 | void setTitleBrush(const QBrush &brush); |
|
102 | void setTitleBrush(const QBrush &brush); | |
103 | QBrush titleBrush() const; |
|
103 | QBrush titleBrush() const; | |
104 |
|
104 | |||
105 | void setBackgroundVisible(bool visible); |
|
105 | void setBackgroundVisible(bool visible); | |
106 | bool isBackgroundVisible() const; |
|
106 | bool isBackgroundVisible() const; | |
107 |
|
107 | |||
108 | void setBackgroundDropShadowEnabled(bool enabled); |
|
108 | void setBackgroundDropShadowEnabled(bool enabled); | |
109 | bool isBackgroundDropShadowEnabled() const; |
|
109 | bool isBackgroundDropShadowEnabled() const; | |
110 |
|
110 | |||
111 | void setVisible(bool visible); |
|
111 | void setVisible(bool visible); | |
112 |
|
112 | |||
113 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
113 | void setTheme(QChart::ChartTheme theme,bool force = true); | |
114 | QChart::ChartTheme theme(); |
|
114 | QChart::ChartTheme theme(); | |
115 |
|
115 | |||
116 | void setAnimationOptions(QChart::AnimationOptions options); |
|
116 | void setAnimationOptions(QChart::AnimationOptions options); | |
117 | QChart::AnimationOptions animationOptions() const; |
|
117 | QChart::AnimationOptions animationOptions() const; | |
118 |
|
118 | |||
119 | void zoomIn(qreal factor); |
|
119 | void zoomIn(qreal factor); | |
120 | void zoomIn(const QRectF& rect); |
|
120 | void zoomIn(const QRectF& rect); | |
121 | void zoomOut(qreal factor); |
|
121 | void zoomOut(qreal factor); | |
122 | void scroll(qreal dx,qreal dy); |
|
122 | void scroll(qreal dx,qreal dy); | |
123 |
|
123 | |||
124 | void setGeometry(const QRectF& rect); |
|
124 | void setGeometry(const QRectF& rect); | |
125 | QRectF geometry() { return m_rect; } |
|
125 | QRectF geometry() { return m_rect; } | |
126 |
|
126 | |||
127 | void startAnimation(ChartAnimation* animation); |
|
127 | void startAnimation(ChartAnimation* animation); | |
128 | State state() const { return m_state; } |
|
128 | State state() const { return m_state; } | |
129 | QPointF statePoint() const { return m_statePoint; } |
|
129 | QPointF statePoint() const { return m_statePoint; } | |
130 |
|
130 | |||
131 | void resetAllElements(); |
|
131 | void resetAllElements(); | |
132 |
|
132 | |||
133 | void setMarginsMinimum(const QRectF& margins); |
|
133 | void setMarginsMinimum(const QRectF& margins); | |
134 | QRectF margins() const; |
|
134 | QRectF margins() const; | |
135 | QGraphicsLayout* layout(); |
|
135 | QGraphicsLayout* layout(); | |
136 |
|
136 | |||
137 | private: |
|
137 | private: | |
138 | void createBackgroundItem(); |
|
138 | void createBackgroundItem(); | |
139 | void createTitleItem(); |
|
139 | void createTitleItem(); | |
|
140 | void selectVisibleAxis(); | |||
140 |
|
141 | |||
141 | public Q_SLOTS: |
|
142 | public Q_SLOTS: | |
142 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); |
|
143 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); | |
143 | void handleSeriesRemoved(QAbstractSeries* series); |
|
144 | void handleSeriesRemoved(QAbstractSeries* series); | |
144 | void handleAxisAdded(QAbstractAxis* axis,Domain* domain); |
|
145 | void handleAxisAdded(QAbstractAxis* axis,Domain* domain); | |
145 | void handleAxisRemoved(QAbstractAxis* axis); |
|
146 | void handleAxisRemoved(QAbstractAxis* axis); | |
146 | void handleAxisVisibleChanged(bool visible); |
|
147 | void handleAxisVisibleChanged(bool visible); | |
147 |
|
148 | |||
148 | private Q_SLOTS: |
|
149 | private Q_SLOTS: | |
149 | void handleAnimationFinished(); |
|
150 | void handleAnimationFinished(); | |
150 |
|
151 | |||
151 | Q_SIGNALS: |
|
152 | Q_SIGNALS: | |
152 | void geometryChanged(const QRectF& rect); |
|
153 | void geometryChanged(const QRectF& rect); | |
153 | void animationsFinished(); |
|
154 | void animationsFinished(); | |
154 | void marginsChanged(QRectF margins); |
|
155 | void marginsChanged(QRectF margins); | |
155 |
|
156 | |||
156 | private: |
|
157 | private: | |
157 | QChart* m_chart; |
|
158 | QChart* m_chart; | |
158 | ChartAnimator* m_animator; |
|
159 | ChartAnimator* m_animator; | |
159 | ChartDataSet* m_dataset; |
|
160 | ChartDataSet* m_dataset; | |
160 | ChartTheme *m_chartTheme; |
|
161 | ChartTheme *m_chartTheme; | |
161 | QMap<QAbstractSeries*, Chart*> m_chartItems; |
|
162 | QMap<QAbstractSeries*, Chart*> m_chartItems; | |
162 | QMap<QAbstractAxis*, ChartAxis*> m_axisItems; |
|
163 | QMap<QAbstractAxis*, ChartAxis*> m_axisItems; | |
163 | QRectF m_rect; |
|
164 | QRectF m_rect; | |
164 | QChart::AnimationOptions m_options; |
|
165 | QChart::AnimationOptions m_options; | |
165 | State m_state; |
|
166 | State m_state; | |
166 | QPointF m_statePoint; |
|
167 | QPointF m_statePoint; | |
167 | QList<ChartAnimation*> m_animations; |
|
168 | QList<ChartAnimation*> m_animations; | |
168 | ChartLayout* m_layout; |
|
169 | ChartLayout* m_layout; | |
169 | ChartBackground* m_backgroundItem; |
|
170 | ChartBackground* m_backgroundItem; | |
170 | QGraphicsSimpleTextItem* m_titleItem; |
|
171 | QGraphicsSimpleTextItem* m_titleItem; | |
171 | }; |
|
172 | }; | |
172 |
|
173 | |||
173 | QTCOMMERCIALCHART_END_NAMESPACE |
|
174 | QTCOMMERCIALCHART_END_NAMESPACE | |
174 |
|
175 | |||
175 | #endif /* CHARTPRESENTER_H_ */ |
|
176 | #endif /* CHARTPRESENTER_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now