##// END OF EJS Templates
minor . Compilation fixes due to rebase
Michal Klocek -
r858:18a50cb1eb30
parent child
Show More
@@ -1,533 +1,532
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qchartaxis.h"
23 #include "qchartaxis.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_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 //series
28 //series
29 #include "qbarseries.h"
29 #include "qbarseries.h"
30 #include "qstackedbarseries.h"
30 #include "qstackedbarseries.h"
31 #include "qpercentbarseries.h"
31 #include "qpercentbarseries.h"
32 #include "qlineseries.h"
32 #include "qlineseries.h"
33 #include "qareaseries.h"
33 #include "qareaseries.h"
34 #include "qpieseries.h"
34 #include "qpieseries.h"
35 #include "qscatterseries.h"
35 #include "qscatterseries.h"
36 #include "qsplineseries.h"
36 #include "qsplineseries.h"
37 //items
37 //items
38 #include "axisitem_p.h"
38 #include "axisitem_p.h"
39 #include "areachartitem_p.h"
39 #include "areachartitem_p.h"
40 #include "barchartitem_p.h"
40 #include "barchartitem_p.h"
41 #include "stackedbarchartitem_p.h"
41 #include "stackedbarchartitem_p.h"
42 #include "percentbarchartitem_p.h"
42 #include "percentbarchartitem_p.h"
43 #include "linechartitem_p.h"
43 #include "linechartitem_p.h"
44 #include "piechartitem_p.h"
44 #include "piechartitem_p.h"
45 #include "scatterchartitem_p.h"
45 #include "scatterchartitem_p.h"
46 #include "splinechartitem_p.h"
46 #include "splinechartitem_p.h"
47
47
48 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48 QTCOMMERCIALCHART_BEGIN_NAMESPACE
49
49
50 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
50 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
51 m_chart(chart),
51 m_chart(chart),
52 m_animator(0),
52 m_animator(0),
53 m_dataset(dataset),
53 m_dataset(dataset),
54 m_chartTheme(0),
54 m_chartTheme(0),
55 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
55 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
56 m_options(QChart::NoAnimation),
56 m_options(QChart::NoAnimation),
57 m_themeForce(false),
57 m_themeForce(false),
58 m_minLeftMargin(0),
58 m_minLeftMargin(0),
59 m_minBottomMargin(0),
59 m_minBottomMargin(0),
60 m_backgroundItem(0),
60 m_backgroundItem(0),
61 m_titleItem(0),
61 m_titleItem(0),
62 m_marginBig(60),
62 m_marginBig(60),
63 m_marginSmall(20),
63 m_marginSmall(20),
64 m_marginTiny(10),
64 m_marginTiny(10),
65 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
65 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
66 {
66 {
67 createConnections();
67 createConnections();
68 setTheme(QChart::ChartThemeLight, false);
69 }
68 }
70
69
71 ChartPresenter::~ChartPresenter()
70 ChartPresenter::~ChartPresenter()
72 {
71 {
73 delete m_chartTheme;
72 delete m_chartTheme;
74 }
73 }
75
74
76 void ChartPresenter::createConnections()
75 void ChartPresenter::createConnections()
77 {
76 {
78 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
77 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
79 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
78 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
80 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
79 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
81 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
80 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
82 }
81 }
83
82
84 void ChartPresenter::setGeometry(const QRectF& rect)
83 void ChartPresenter::setGeometry(const QRectF& rect)
85 {
84 {
86 m_rect = rect;
85 m_rect = rect;
87 Q_ASSERT(m_rect.isValid());
86 Q_ASSERT(m_rect.isValid());
88 updateLayout();
87 updateLayout();
89 }
88 }
90
89
91 void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width)
90 void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width)
92 {
91 {
93 switch(axis->axisType()){
92 switch(axis->axisType()){
94 case Axis::X_AXIS:
93 case Axis::X_AXIS:
95 {
94 {
96 if(width>m_chartRect.width()+ m_chartMargins.left()) {
95 if(width>m_chartRect.width()+ m_chartMargins.left()) {
97 m_minLeftMargin= width - m_chartRect.width();
96 m_minLeftMargin= width - m_chartRect.width();
98 updateLayout();
97 updateLayout();
99 }
98 }
100 break;
99 break;
101 }
100 }
102 case Axis::Y_AXIS:
101 case Axis::Y_AXIS:
103 {
102 {
104
103
105 if(m_minLeftMargin!=width){
104 if(m_minLeftMargin!=width){
106 m_minLeftMargin= width;
105 m_minLeftMargin= width;
107 updateLayout();
106 updateLayout();
108 }
107 }
109 break;
108 break;
110 }
109 }
111
110
112 }
111 }
113 }
112 }
114
113
115 void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height)
114 void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height)
116 {
115 {
117 switch(axis->axisType()){
116 switch(axis->axisType()){
118 case Axis::X_AXIS:
117 case Axis::X_AXIS:
119 {
118 {
120 if(m_minBottomMargin!=height) {
119 if(m_minBottomMargin!=height) {
121 m_minBottomMargin= height;
120 m_minBottomMargin= height;
122 updateLayout();
121 updateLayout();
123 }
122 }
124 break;
123 break;
125 }
124 }
126 case Axis::Y_AXIS:
125 case Axis::Y_AXIS:
127 {
126 {
128
127
129 if(height>m_chartMargins.bottom()+m_chartRect.height()){
128 if(height>m_chartMargins.bottom()+m_chartRect.height()){
130 m_minBottomMargin= height - m_chartRect.height();
129 m_minBottomMargin= height - m_chartRect.height();
131 updateLayout();
130 updateLayout();
132 }
131 }
133 break;
132 break;
134 }
133 }
135
134
136 }
135 }
137 }
136 }
138
137
139 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
138 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
140 {
139 {
141 Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS);
140 Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS);
142
141
143 if(m_options.testFlag(QChart::GridAxisAnimations)){
142 if(m_options.testFlag(QChart::GridAxisAnimations)){
144 m_animator->addAnimation(item);
143 m_animator->addAnimation(item);
145 }
144 }
146
145
147 if(axis==m_dataset->axisX()){
146 if(axis==m_dataset->axisX()){
148 m_chartTheme->decorate(axis,true,m_themeForce);
147 m_chartTheme->decorate(axis,true,m_themeForce);
149 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
148 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
150 //initialize
149 //initialize
151 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
150 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
152
151
153 }
152 }
154 else{
153 else{
155 m_chartTheme->decorate(axis,false,m_themeForce);
154 m_chartTheme->decorate(axis,false,m_themeForce);
156 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
155 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
157 //initialize
156 //initialize
158 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
157 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
159 }
158 }
160
159
161 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
160 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
162 //initialize
161 //initialize
163 item->handleGeometryChanged(m_chartRect);
162 item->handleGeometryChanged(m_chartRect);
164 m_axisItems.insert(axis, item);
163 m_axisItems.insert(axis, item);
165 }
164 }
166
165
167 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
166 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
168 {
167 {
169 Axis* item = m_axisItems.take(axis);
168 Axis* item = m_axisItems.take(axis);
170 Q_ASSERT(item);
169 Q_ASSERT(item);
171 if(m_animator) m_animator->removeAnimation(item);
170 if(m_animator) m_animator->removeAnimation(item);
172 delete item;
171 delete item;
173 }
172 }
174
173
175
174
176 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
175 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
177 {
176 {
178 Chart *item = 0 ;
177 Chart *item = 0 ;
179
178
180 switch(series->type())
179 switch(series->type())
181 {
180 {
182 case QSeries::SeriesTypeLine: {
181 case QSeries::SeriesTypeLine: {
183
182
184 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
183 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
185 LineChartItem* line = new LineChartItem(lineSeries,this);
184 LineChartItem* line = new LineChartItem(lineSeries,this);
186 if(m_options.testFlag(QChart::SeriesAnimations)) {
185 if(m_options.testFlag(QChart::SeriesAnimations)) {
187 m_animator->addAnimation(line);
186 m_animator->addAnimation(line);
188 }
187 }
189 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
188 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
190 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
189 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
191 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
190 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
192 item = line;
191 item = line;
193 break;
192 break;
194 }
193 }
195
194
196 case QSeries::SeriesTypeArea: {
195 case QSeries::SeriesTypeArea: {
197
196
198 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
197 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
199 AreaChartItem* area = new AreaChartItem(areaSeries,this);
198 AreaChartItem* area = new AreaChartItem(areaSeries,this);
200 if(m_options.testFlag(QChart::SeriesAnimations)) {
199 if(m_options.testFlag(QChart::SeriesAnimations)) {
201 m_animator->addAnimation(area->upperLineItem());
200 m_animator->addAnimation(area->upperLineItem());
202 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
201 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
203 }
202 }
204 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
203 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
205 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
204 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
206 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
205 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
207 item=area;
206 item=area;
208 break;
207 break;
209 }
208 }
210
209
211 case QSeries::SeriesTypeBar: {
210 case QSeries::SeriesTypeBar: {
212 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
211 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
213 BarChartItem* bar = new BarChartItem(barSeries,this);
212 BarChartItem* bar = new BarChartItem(barSeries,this);
214 if(m_options.testFlag(QChart::SeriesAnimations)) {
213 if(m_options.testFlag(QChart::SeriesAnimations)) {
215 m_animator->addAnimation(bar);
214 m_animator->addAnimation(bar);
216 }
215 }
217 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
216 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
218 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
217 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
219 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
218 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
220 item=bar;
219 item=bar;
221 break;
220 break;
222 }
221 }
223
222
224 case QSeries::SeriesTypeStackedBar: {
223 case QSeries::SeriesTypeStackedBar: {
225 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
224 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
226 StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this);
225 StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this);
227 if(m_options.testFlag(QChart::SeriesAnimations)) {
226 if(m_options.testFlag(QChart::SeriesAnimations)) {
228 m_animator->addAnimation(bar);
227 m_animator->addAnimation(bar);
229 }
228 }
230 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
229 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
231 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
230 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
232 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
231 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
233 item=bar;
232 item=bar;
234 break;
233 break;
235 }
234 }
236
235
237 case QSeries::SeriesTypePercentBar: {
236 case QSeries::SeriesTypePercentBar: {
238 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
237 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
239 PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this);
238 PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this);
240 if(m_options.testFlag(QChart::SeriesAnimations)) {
239 if(m_options.testFlag(QChart::SeriesAnimations)) {
241 m_animator->addAnimation(bar);
240 m_animator->addAnimation(bar);
242 }
241 }
243 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
242 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
244 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
243 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
245 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
244 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
246 item=bar;
245 item=bar;
247 break;
246 break;
248 }
247 }
249
248
250 case QSeries::SeriesTypeScatter: {
249 case QSeries::SeriesTypeScatter: {
251 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
250 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
252 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this);
251 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this);
253 if(m_options.testFlag(QChart::SeriesAnimations)) {
252 if(m_options.testFlag(QChart::SeriesAnimations)) {
254 m_animator->addAnimation(scatter);
253 m_animator->addAnimation(scatter);
255 }
254 }
256 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
255 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
257 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
256 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
258 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
257 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
259 item = scatter;
258 item = scatter;
260 break;
259 break;
261 }
260 }
262
261
263 case QSeries::SeriesTypePie: {
262 case QSeries::SeriesTypePie: {
264 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
263 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
265 PieChartItem* pie = new PieChartItem(pieSeries, this);
264 PieChartItem* pie = new PieChartItem(pieSeries, this);
266 if(m_options.testFlag(QChart::SeriesAnimations)) {
265 if(m_options.testFlag(QChart::SeriesAnimations)) {
267 m_animator->addAnimation(pie);
266 m_animator->addAnimation(pie);
268 }
267 }
269 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
268 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
270 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
269 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
271 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
270 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
272 // Hide all from background when there is only piechart
271 // Hide all from background when there is only piechart
273 // TODO: refactor this ugly code... should be one setting for this
272 // TODO: refactor this ugly code... should be one setting for this
274 if (m_chartItems.count() == 0) {
273 if (m_chartItems.count() == 0) {
275 m_chart->axisX()->hide();
274 m_chart->axisX()->hide();
276 m_chart->axisY()->hide();
275 m_chart->axisY()->hide();
277 }
276 }
278 item=pie;
277 item=pie;
279 break;
278 break;
280 }
279 }
281
280
282 case QSeries::SeriesTypeSpline: {
281 case QSeries::SeriesTypeSpline: {
283 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
282 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
284 SplineChartItem* spline = new SplineChartItem(splineSeries, this);
283 SplineChartItem* spline = new SplineChartItem(splineSeries, this);
285 if(m_options.testFlag(QChart::SeriesAnimations)) {
284 if(m_options.testFlag(QChart::SeriesAnimations)) {
286 m_animator->addAnimation(spline);
285 m_animator->addAnimation(spline);
287 }
286 }
288 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
287 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
289 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
288 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
290 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
289 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
291 item=spline;
290 item=spline;
292 break;
291 break;
293 }
292 }
294 default: {
293 default: {
295 qDebug()<< "Series type" << series->type() << "not implemented.";
294 qDebug()<< "Series type" << series->type() << "not implemented.";
296 break;
295 break;
297 }
296 }
298 }
297 }
299
298
300 //initialize
299 //initialize
301 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
300 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
302 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
301 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
303 m_chartItems.insert(series,item);
302 m_chartItems.insert(series,item);
304 }
303 }
305
304
306 void ChartPresenter::handleSeriesRemoved(QSeries* series)
305 void ChartPresenter::handleSeriesRemoved(QSeries* series)
307 {
306 {
308 Chart* item = m_chartItems.take(series);
307 Chart* item = m_chartItems.take(series);
309 Q_ASSERT(item);
308 Q_ASSERT(item);
310 if(m_animator) {
309 if(m_animator) {
311 //small hack to handle area animations
310 //small hack to handle area animations
312 if(series->type()==QSeries::SeriesTypeArea){
311 if(series->type()==QSeries::SeriesTypeArea){
313 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
312 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
314 AreaChartItem* area = static_cast<AreaChartItem*>(item);
313 AreaChartItem* area = static_cast<AreaChartItem*>(item);
315 m_animator->removeAnimation(area->upperLineItem());
314 m_animator->removeAnimation(area->upperLineItem());
316 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
315 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
317 }else
316 }else
318 m_animator->removeAnimation(item);
317 m_animator->removeAnimation(item);
319 }
318 }
320 delete item;
319 delete item;
321 }
320 }
322
321
323 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
322 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
324 {
323 {
325 if(m_chartTheme && m_chartTheme->id() == theme) return;
324 if(m_chartTheme && m_chartTheme->id() == theme) return;
326 delete m_chartTheme;
325 delete m_chartTheme;
327 m_themeForce = force;
326 m_themeForce = force;
328 m_chartTheme = ChartTheme::createTheme(theme);
327 m_chartTheme = ChartTheme::createTheme(theme);
329 m_chartTheme->decorate(m_chart,m_themeForce);
328 m_chartTheme->decorate(m_chart,m_themeForce);
330 m_chartTheme->decorate(m_chart->legend(),m_themeForce);
329 m_chartTheme->decorate(m_chart->legend(),m_themeForce);
331 resetAllElements();
330 resetAllElements();
332 }
331 }
333
332
334 QChart::ChartTheme ChartPresenter::theme()
333 QChart::ChartTheme ChartPresenter::theme()
335 {
334 {
336 return m_chartTheme->id();
335 return m_chartTheme->id();
337 }
336 }
338
337
339 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
338 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
340 {
339 {
341 if(m_options!=options) {
340 if(m_options!=options) {
342
341
343 m_options=options;
342 m_options=options;
344
343
345 if(m_options!=QChart::NoAnimation && !m_animator) {
344 if(m_options!=QChart::NoAnimation && !m_animator) {
346 m_animator= new ChartAnimator(this);
345 m_animator= new ChartAnimator(this);
347
346
348 }
347 }
349 resetAllElements();
348 resetAllElements();
350 }
349 }
351
350
352 }
351 }
353
352
354 void ChartPresenter::resetAllElements()
353 void ChartPresenter::resetAllElements()
355 {
354 {
356 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
355 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
357 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
356 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
358
357
359 foreach(QChartAxis* axis, axisList) {
358 foreach(QChartAxis* axis, axisList) {
360 handleAxisRemoved(axis);
359 handleAxisRemoved(axis);
361 handleAxisAdded(axis,m_dataset->domain(axis));
360 handleAxisAdded(axis,m_dataset->domain(axis));
362 }
361 }
363 foreach(QSeries* series, seriesList) {
362 foreach(QSeries* series, seriesList) {
364 handleSeriesRemoved(series);
363 handleSeriesRemoved(series);
365 handleSeriesAdded(series,m_dataset->domain(series));
364 handleSeriesAdded(series,m_dataset->domain(series));
366 }
365 }
367 }
366 }
368
367
369 void ChartPresenter::zoomIn()
368 void ChartPresenter::zoomIn()
370 {
369 {
371 QRectF rect = chartGeometry();
370 QRectF rect = chartGeometry();
372 rect.setWidth(rect.width()/2);
371 rect.setWidth(rect.width()/2);
373 rect.setHeight(rect.height()/2);
372 rect.setHeight(rect.height()/2);
374 rect.moveCenter(chartGeometry().center());
373 rect.moveCenter(chartGeometry().center());
375 zoomIn(rect);
374 zoomIn(rect);
376 }
375 }
377
376
378 void ChartPresenter::zoomIn(const QRectF& rect)
377 void ChartPresenter::zoomIn(const QRectF& rect)
379 {
378 {
380 QRectF r = rect.normalized();
379 QRectF r = rect.normalized();
381 r.translate(-m_chartMargins.topLeft());
380 r.translate(-m_chartMargins.topLeft());
382 if(m_animator) {
381 if(m_animator) {
383
382
384 QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
383 QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
385 m_animator->setState(ChartAnimator::ZoomInState,point);
384 m_animator->setState(ChartAnimator::ZoomInState,point);
386 }
385 }
387 m_dataset->zoomInDomain(r,chartGeometry().size());
386 m_dataset->zoomInDomain(r,chartGeometry().size());
388 if(m_animator) {
387 if(m_animator) {
389 m_animator->setState(ChartAnimator::ShowState);
388 m_animator->setState(ChartAnimator::ShowState);
390 }
389 }
391 }
390 }
392
391
393 void ChartPresenter::zoomOut()
392 void ChartPresenter::zoomOut()
394 {
393 {
395 if(m_animator)
394 if(m_animator)
396 {
395 {
397 m_animator->setState(ChartAnimator::ZoomOutState);
396 m_animator->setState(ChartAnimator::ZoomOutState);
398 }
397 }
399
398
400 QSizeF size = chartGeometry().size();
399 QSizeF size = chartGeometry().size();
401 QRectF rect = chartGeometry();
400 QRectF rect = chartGeometry();
402 rect.translate(-m_chartMargins.topLeft());
401 rect.translate(-m_chartMargins.topLeft());
403 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
402 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
404 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
403 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
405
404
406 if(m_animator){
405 if(m_animator){
407 m_animator->setState(ChartAnimator::ShowState);
406 m_animator->setState(ChartAnimator::ShowState);
408 }
407 }
409 }
408 }
410
409
411 void ChartPresenter::scroll(int dx,int dy)
410 void ChartPresenter::scroll(int dx,int dy)
412 {
411 {
413 if(m_animator){
412 if(m_animator){
414 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
413 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
415 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
414 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
416 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
415 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
417 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
416 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
418 }
417 }
419
418
420 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
419 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
421
420
422 if(m_animator){
421 if(m_animator){
423 m_animator->setState(ChartAnimator::ShowState);
422 m_animator->setState(ChartAnimator::ShowState);
424 }
423 }
425 }
424 }
426
425
427 QChart::AnimationOptions ChartPresenter::animationOptions() const
426 QChart::AnimationOptions ChartPresenter::animationOptions() const
428 {
427 {
429 return m_options;
428 return m_options;
430 }
429 }
431
430
432 void ChartPresenter::updateLayout()
431 void ChartPresenter::updateLayout()
433 {
432 {
434 if (!m_rect.isValid()) return;
433 if (!m_rect.isValid()) return;
435
434
436 // recalculate title size
435 // recalculate title size
437
436
438 QSize titleSize;
437 QSize titleSize;
439 int titlePadding=0;
438 int titlePadding=0;
440
439
441 if (m_titleItem) {
440 if (m_titleItem) {
442 titleSize= m_titleItem->boundingRect().size().toSize();
441 titleSize= m_titleItem->boundingRect().size().toSize();
443 }
442 }
444
443
445 //defaults
444 //defaults
446 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
445 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
447 titlePadding = m_chartMargins.top()/2;
446 titlePadding = m_chartMargins.top()/2;
448
447
449 QLegend* legend = m_chart->d_ptr->m_legend;
448 QLegend* legend = m_chart->d_ptr->m_legend;
450
449
451 // recalculate legend position
450 // recalculate legend position
452 if (legend->isAttachedToChart() && legend->isEnabled()) {
451 if (legend->isAttachedToChart() && legend->isEnabled()) {
453
452
454 QRect legendRect;
453 QRect legendRect;
455
454
456 // Reserve some space for legend
455 // Reserve some space for legend
457 switch (legend->alignment()) {
456 switch (legend->alignment()) {
458
457
459 case QLegend::AlignmentTop: {
458 case QLegend::AlignmentTop: {
460 int ledgendSize = legend->minHeight();
459 int ledgendSize = legend->minHeight();
461 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
460 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
462 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
461 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
463 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
462 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
464 titlePadding = m_marginTiny + m_marginTiny;
463 titlePadding = m_marginTiny + m_marginTiny;
465 break;
464 break;
466 }
465 }
467 case QLegend::AlignmentBottom: {
466 case QLegend::AlignmentBottom: {
468 int ledgendSize = legend->minHeight();
467 int ledgendSize = legend->minHeight();
469 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
468 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
470 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
469 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
471 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
470 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
472 titlePadding = m_chartMargins.top()/2;
471 titlePadding = m_chartMargins.top()/2;
473 break;
472 break;
474 }
473 }
475 case QLegend::AlignmentLeft: {
474 case QLegend::AlignmentLeft: {
476 int ledgendSize = legend->minWidht();
475 int ledgendSize = legend->minWidht();
477 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
476 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
478 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
477 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
479 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
478 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
480 titlePadding = m_chartMargins.top()/2;
479 titlePadding = m_chartMargins.top()/2;
481 break;
480 break;
482 }
481 }
483 case QLegend::AlignmentRight: {
482 case QLegend::AlignmentRight: {
484 int ledgendSize = legend->minWidht();
483 int ledgendSize = legend->minWidht();
485 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
484 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
486 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
485 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
487 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
486 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
488 titlePadding = m_chartMargins.top()/2;
487 titlePadding = m_chartMargins.top()/2;
489 break;
488 break;
490 }
489 }
491 default: {
490 default: {
492 break;
491 break;
493 }
492 }
494 }
493 }
495 }
494 }
496
495
497 // recalculate title position
496 // recalculate title position
498 if (m_titleItem) {
497 if (m_titleItem) {
499 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
498 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
500 m_titleItem->setPos(center.x(),titlePadding);
499 m_titleItem->setPos(center.x(),titlePadding);
501 }
500 }
502
501
503 //recalculate background gradient
502 //recalculate background gradient
504 if (m_backgroundItem) {
503 if (m_backgroundItem) {
505 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
504 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
506 }
505 }
507
506
508 m_chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
507 m_chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
509
508
510 emit geometryChanged(m_chartRect);
509 emit geometryChanged(m_chartRect);
511 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
510 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
512 }
511 }
513
512
514 void ChartPresenter::createChartBackgroundItem()
513 void ChartPresenter::createChartBackgroundItem()
515 {
514 {
516 if (!m_backgroundItem) {
515 if (!m_backgroundItem) {
517 m_backgroundItem = new ChartBackground(rootItem());
516 m_backgroundItem = new ChartBackground(rootItem());
518 m_backgroundItem->setPen(Qt::NoPen);
517 m_backgroundItem->setPen(Qt::NoPen);
519 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
518 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
520 }
519 }
521 }
520 }
522
521
523 void ChartPresenter::createChartTitleItem()
522 void ChartPresenter::createChartTitleItem()
524 {
523 {
525 if (!m_titleItem) {
524 if (!m_titleItem) {
526 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
525 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
527 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
526 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
528 }
527 }
529 }
528 }
530
529
531 #include "moc_chartpresenter_p.cpp"
530 #include "moc_chartpresenter_p.cpp"
532
531
533 QTCOMMERCIALCHART_END_NAMESPACE
532 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,351 +1,351
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include <QGraphicsScene>
23 #include <QGraphicsScene>
24 #include <QGraphicsSceneResizeEvent>
24 #include <QGraphicsSceneResizeEvent>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \enum QChart::ChartTheme
29 \enum QChart::ChartTheme
30
30
31 This enum describes the theme used by the chart.
31 This enum describes the theme used by the chart.
32
32
33 \value ChartThemeLight The default theme
33 \value ChartThemeLight The default theme
34 \value ChartThemeBlueCerulean
34 \value ChartThemeBlueCerulean
35 \value ChartThemeDark
35 \value ChartThemeDark
36 \value ChartThemeBrownSand
36 \value ChartThemeBrownSand
37 \value ChartThemeBlueNcs
37 \value ChartThemeBlueNcs
38 \value ChartThemeHighContrast
38 \value ChartThemeHighContrast
39 \value ChartThemeBlueIcy
39 \value ChartThemeBlueIcy
40 \value ChartThemeCount Not really a theme; the total count of themes.
40 \value ChartThemeCount Not really a theme; the total count of themes.
41 */
41 */
42
42
43 /*!
43 /*!
44 \enum QChart::AnimationOption
44 \enum QChart::AnimationOption
45
45
46 For enabling/disabling animations. Defaults to NoAnimation.
46 For enabling/disabling animations. Defaults to NoAnimation.
47
47
48 \value NoAnimation
48 \value NoAnimation
49 \value GridAxisAnimations
49 \value GridAxisAnimations
50 \value SeriesAnimations
50 \value SeriesAnimations
51 \value AllAnimations
51 \value AllAnimations
52 */
52 */
53
53
54 /*!
54 /*!
55 \class QChart
55 \class QChart
56 \brief QtCommercial chart API.
56 \brief QtCommercial chart API.
57
57
58 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
58 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
59 representation of different types of QChartSeries and other chart related objects like
59 representation of different types of QChartSeries and other chart related objects like
60 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
60 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
61 convenience class QChartView instead of QChart.
61 convenience class QChartView instead of QChart.
62 \sa QChartView
62 \sa QChartView
63 */
63 */
64
64
65 /*!
65 /*!
66 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
66 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
67 */
67 */
68 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
68 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
69 d_ptr(new QChartPrivate())
69 d_ptr(new QChartPrivate())
70 {
70 {
71 d_ptr->m_legend = new QLegend(this);
71 d_ptr->m_legend = new QLegend(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeDefault,false);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
75 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
75 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
76 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
76 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
77 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
77 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
78 }
78 }
79
79
80 /*!
80 /*!
81 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
81 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
82 */
82 */
83 QChart::~QChart()
83 QChart::~QChart()
84 {
84 {
85 //delete first presenter , since this is a root of all the graphical items
85 //delete first presenter , since this is a root of all the graphical items
86 delete d_ptr->m_presenter;
86 delete d_ptr->m_presenter;
87 d_ptr->m_presenter=0;
87 d_ptr->m_presenter=0;
88 }
88 }
89
89
90 /*!
90 /*!
91 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
91 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
92 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
92 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
93 the y axis).
93 the y axis).
94 */
94 */
95 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
95 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
96 {
96 {
97 d_ptr->m_dataset->addSeries(series, axisY);
97 d_ptr->m_dataset->addSeries(series, axisY);
98 }
98 }
99
99
100 /*!
100 /*!
101 Removes the \a series specified in a perameter from the QChartView.
101 Removes the \a series specified in a perameter from the QChartView.
102 It releses its ownership of the specified QChartSeries object.
102 It releses its ownership of the specified QChartSeries object.
103 It does not delete the pointed QChartSeries data object
103 It does not delete the pointed QChartSeries data object
104 \sa addSeries(), removeAllSeries()
104 \sa addSeries(), removeAllSeries()
105 */
105 */
106 void QChart::removeSeries(QSeries* series)
106 void QChart::removeSeries(QSeries* series)
107 {
107 {
108 d_ptr->m_dataset->removeSeries(series);
108 d_ptr->m_dataset->removeSeries(series);
109 }
109 }
110
110
111 /*!
111 /*!
112 Removes all the QChartSeries that have been added to the QChartView
112 Removes all the QChartSeries that have been added to the QChartView
113 It also deletes the pointed QChartSeries data objects
113 It also deletes the pointed QChartSeries data objects
114 \sa addSeries(), removeSeries()
114 \sa addSeries(), removeSeries()
115 */
115 */
116 void QChart::removeAllSeries()
116 void QChart::removeAllSeries()
117 {
117 {
118 d_ptr->m_dataset->removeAllSeries();
118 d_ptr->m_dataset->removeAllSeries();
119 }
119 }
120
120
121 /*!
121 /*!
122 Sets the \a brush that is used for painting the background of the chart area.
122 Sets the \a brush that is used for painting the background of the chart area.
123 */
123 */
124 void QChart::setBackgroundBrush(const QBrush& brush)
124 void QChart::setBackgroundBrush(const QBrush& brush)
125 {
125 {
126 d_ptr->m_presenter->createChartBackgroundItem();
126 d_ptr->m_presenter->createChartBackgroundItem();
127 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
127 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
128 d_ptr->m_presenter->m_backgroundItem->update();
128 d_ptr->m_presenter->m_backgroundItem->update();
129 }
129 }
130
130
131 QBrush QChart::backgroundBrush() const
131 QBrush QChart::backgroundBrush() const
132 {
132 {
133 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
133 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
134 return (d_ptr->m_presenter->m_backgroundItem)->brush();
134 return (d_ptr->m_presenter->m_backgroundItem)->brush();
135 }
135 }
136
136
137 /*!
137 /*!
138 Sets the \a pen that is used for painting the background of the chart area.
138 Sets the \a pen that is used for painting the background of the chart area.
139 */
139 */
140 void QChart::setBackgroundPen(const QPen& pen)
140 void QChart::setBackgroundPen(const QPen& pen)
141 {
141 {
142 d_ptr->m_presenter->createChartBackgroundItem();
142 d_ptr->m_presenter->createChartBackgroundItem();
143 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
143 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
144 d_ptr->m_presenter->m_backgroundItem->update();
144 d_ptr->m_presenter->m_backgroundItem->update();
145 }
145 }
146
146
147 QPen QChart::backgroundPen() const
147 QPen QChart::backgroundPen() const
148 {
148 {
149 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
149 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
150 return d_ptr->m_presenter->m_backgroundItem->pen();
150 return d_ptr->m_presenter->m_backgroundItem->pen();
151 }
151 }
152
152
153 /*!
153 /*!
154 Sets the chart \a title. The description text that is drawn above the chart.
154 Sets the chart \a title. The description text that is drawn above the chart.
155 */
155 */
156 void QChart::setTitle(const QString& title)
156 void QChart::setTitle(const QString& title)
157 {
157 {
158 d_ptr->m_presenter->createChartTitleItem();
158 d_ptr->m_presenter->createChartTitleItem();
159 d_ptr->m_presenter->m_titleItem->setText(title);
159 d_ptr->m_presenter->m_titleItem->setText(title);
160 d_ptr->m_presenter->updateLayout();
160 d_ptr->m_presenter->updateLayout();
161 }
161 }
162
162
163 /*!
163 /*!
164 Returns the chart title. The description text that is drawn above the chart.
164 Returns the chart title. The description text that is drawn above the chart.
165 */
165 */
166 QString QChart::title() const
166 QString QChart::title() const
167 {
167 {
168 if (d_ptr->m_presenter->m_titleItem)
168 if (d_ptr->m_presenter->m_titleItem)
169 return d_ptr->m_presenter->m_titleItem->text();
169 return d_ptr->m_presenter->m_titleItem->text();
170 else
170 else
171 return QString();
171 return QString();
172 }
172 }
173
173
174 /*!
174 /*!
175 Sets the \a font that is used for rendering the description text that is rendered above the chart.
175 Sets the \a font that is used for rendering the description text that is rendered above the chart.
176 */
176 */
177 void QChart::setTitleFont(const QFont& font)
177 void QChart::setTitleFont(const QFont& font)
178 {
178 {
179 d_ptr->m_presenter->createChartTitleItem();
179 d_ptr->m_presenter->createChartTitleItem();
180 d_ptr->m_presenter->m_titleItem->setFont(font);
180 d_ptr->m_presenter->m_titleItem->setFont(font);
181 d_ptr->m_presenter->updateLayout();
181 d_ptr->m_presenter->updateLayout();
182 }
182 }
183
183
184 /*!
184 /*!
185 Sets the \a brush used for rendering the title text.
185 Sets the \a brush used for rendering the title text.
186 */
186 */
187 void QChart::setTitleBrush(const QBrush &brush)
187 void QChart::setTitleBrush(const QBrush &brush)
188 {
188 {
189 d_ptr->m_presenter->createChartTitleItem();
189 d_ptr->m_presenter->createChartTitleItem();
190 d_ptr->m_presenter->m_titleItem->setBrush(brush);
190 d_ptr->m_presenter->m_titleItem->setBrush(brush);
191 d_ptr->m_presenter->updateLayout();
191 d_ptr->m_presenter->updateLayout();
192 }
192 }
193
193
194 /*!
194 /*!
195 Returns the brush used for rendering the title text.
195 Returns the brush used for rendering the title text.
196 */
196 */
197 QBrush QChart::titleBrush() const
197 QBrush QChart::titleBrush() const
198 {
198 {
199 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
199 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
200 return d_ptr->m_presenter->m_titleItem->brush();
200 return d_ptr->m_presenter->m_titleItem->brush();
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets the \a theme used by the chart for rendering the graphical representation of the data
204 Sets the \a theme used by the chart for rendering the graphical representation of the data
205 \sa ChartTheme, chartTheme()
205 \sa ChartTheme, chartTheme()
206 */
206 */
207 void QChart::setTheme(QChart::ChartTheme theme)
207 void QChart::setTheme(QChart::ChartTheme theme)
208 {
208 {
209 d_ptr->m_presenter->setTheme(theme);
209 d_ptr->m_presenter->setTheme(theme);
210 }
210 }
211
211
212 /*!
212 /*!
213 Returns the theme enum used by the chart.
213 Returns the theme enum used by the chart.
214 \sa ChartTheme, setChartTheme()
214 \sa ChartTheme, setChartTheme()
215 */
215 */
216 QChart::ChartTheme QChart::theme() const
216 QChart::ChartTheme QChart::theme() const
217 {
217 {
218 return d_ptr->m_presenter->theme();
218 return d_ptr->m_presenter->theme();
219 }
219 }
220
220
221 /*!
221 /*!
222 Zooms in the view by a factor of 2
222 Zooms in the view by a factor of 2
223 */
223 */
224 void QChart::zoomIn()
224 void QChart::zoomIn()
225 {
225 {
226 d_ptr->m_presenter->zoomIn();
226 d_ptr->m_presenter->zoomIn();
227 }
227 }
228
228
229 /*!
229 /*!
230 Zooms in the view to a maximum level at which \a rect is still fully visible.
230 Zooms in the view to a maximum level at which \a rect is still fully visible.
231 */
231 */
232 void QChart::zoomIn(const QRectF& rect)
232 void QChart::zoomIn(const QRectF& rect)
233 {
233 {
234 if (!rect.isValid()) return;
234 if (!rect.isValid()) return;
235 d_ptr->m_presenter->zoomIn(rect);
235 d_ptr->m_presenter->zoomIn(rect);
236 }
236 }
237
237
238 /*!
238 /*!
239 Restores the view zoom level to the previous one.
239 Restores the view zoom level to the previous one.
240 */
240 */
241 void QChart::zoomOut()
241 void QChart::zoomOut()
242 {
242 {
243 d_ptr->m_presenter->zoomOut();
243 d_ptr->m_presenter->zoomOut();
244 }
244 }
245
245
246 /*!
246 /*!
247 Returns the pointer to the x axis object of the chart
247 Returns the pointer to the x axis object of the chart
248 */
248 */
249 QChartAxis* QChart::axisX() const
249 QChartAxis* QChart::axisX() const
250 {
250 {
251 return d_ptr->m_dataset->axisX();
251 return d_ptr->m_dataset->axisX();
252 }
252 }
253
253
254 /*!
254 /*!
255 Returns the pointer to the y axis object of the chart
255 Returns the pointer to the y axis object of the chart
256 */
256 */
257 QChartAxis* QChart::axisY() const
257 QChartAxis* QChart::axisY() const
258 {
258 {
259 return d_ptr->m_dataset->axisY();
259 return d_ptr->m_dataset->axisY();
260 }
260 }
261
261
262 /*!
262 /*!
263 Returns the legend object of the chart. Ownership stays in chart.
263 Returns the legend object of the chart. Ownership stays in chart.
264 */
264 */
265 QLegend* QChart::legend() const
265 QLegend* QChart::legend() const
266 {
266 {
267 return d_ptr->m_legend;
267 return d_ptr->m_legend;
268 }
268 }
269
269
270 QRect QChart::margins() const
270 QRect QChart::margins() const
271 {
271 {
272 return d_ptr->m_presenter->margins();
272 return d_ptr->m_presenter->margins();
273 }
273 }
274
274
275
275
276 /*!
276 /*!
277 Resizes and updates the chart area using the \a event data
277 Resizes and updates the chart area using the \a event data
278 */
278 */
279 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
279 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
280 {
280 {
281 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
281 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
282 QGraphicsWidget::resizeEvent(event);
282 QGraphicsWidget::resizeEvent(event);
283 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
283 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
284 }
284 }
285
285
286 /*!
286 /*!
287 Sets animation \a options for the chart
287 Sets animation \a options for the chart
288 */
288 */
289 void QChart::setAnimationOptions(AnimationOptions options)
289 void QChart::setAnimationOptions(AnimationOptions options)
290 {
290 {
291 d_ptr->m_presenter->setAnimationOptions(options);
291 d_ptr->m_presenter->setAnimationOptions(options);
292 }
292 }
293
293
294 /*!
294 /*!
295 Returns animation options for the chart
295 Returns animation options for the chart
296 */
296 */
297 QChart::AnimationOptions QChart::animationOptions() const
297 QChart::AnimationOptions QChart::animationOptions() const
298 {
298 {
299 return d_ptr->m_presenter->animationOptions();
299 return d_ptr->m_presenter->animationOptions();
300 }
300 }
301
301
302 void QChart::scrollLeft()
302 void QChart::scrollLeft()
303 {
303 {
304 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
304 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
305 }
305 }
306
306
307 void QChart::scrollRight()
307 void QChart::scrollRight()
308 {
308 {
309 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
309 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
310 }
310 }
311
311
312 void QChart::scrollUp()
312 void QChart::scrollUp()
313 {
313 {
314 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
314 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
315 }
315 }
316
316
317 void QChart::scrollDown()
317 void QChart::scrollDown()
318 {
318 {
319 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
319 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
320 }
320 }
321
321
322 void QChart::setBackgroundVisible(bool visible)
322 void QChart::setBackgroundVisible(bool visible)
323 {
323 {
324 d_ptr->m_presenter->createChartBackgroundItem();
324 d_ptr->m_presenter->createChartBackgroundItem();
325 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
325 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
326 }
326 }
327
327
328 bool QChart::isBackgroundVisible() const
328 bool QChart::isBackgroundVisible() const
329 {
329 {
330 if (!d_ptr->m_presenter->m_backgroundItem) return false;
330 if (!d_ptr->m_presenter->m_backgroundItem) return false;
331 return d_ptr->m_presenter->m_backgroundItem->isVisible();
331 return d_ptr->m_presenter->m_backgroundItem->isVisible();
332 }
332 }
333
333
334 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
334 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
335
335
336 QChartPrivate::QChartPrivate():
336 QChartPrivate::QChartPrivate():
337 m_legend(0),
337 m_legend(0),
338 m_dataset(0),
338 m_dataset(0),
339 m_presenter(0)
339 m_presenter(0)
340 {
340 {
341
341
342 }
342 }
343
343
344 QChartPrivate::~QChartPrivate()
344 QChartPrivate::~QChartPrivate()
345 {
345 {
346
346
347 }
347 }
348
348
349 #include "moc_qchart.cpp"
349 #include "moc_qchart.cpp"
350
350
351 QTCOMMERCIALCHART_END_NAMESPACE
351 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,153 +1,152
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 QLEGEND_H
21 #ifndef QLEGEND_H
22 #define QLEGEND_H
22 #define QLEGEND_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QGraphicsWidget>
25 #include <QGraphicsWidget>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class Domain;
31 class Domain;
32 class LegendMarker;
32 class LegendMarker;
33 class QPieSlice;
33 class QPieSlice;
34 class QXYSeries;
34 class QXYSeries;
35 class QBarSet;
35 class QBarSet;
36 class QBarSeries;
36 class QBarSeries;
37 class QPieSeries;
37 class QPieSeries;
38 class QAreaSeries;
38 class QAreaSeries;
39 class LegendScrollButton;
39 class LegendScrollButton;
40 class QSeries;
40 class QSeries;
41 class QChart;
41 class QChart;
42 class Scroller;
42 class Scroller;
43
43
44 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
44 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48
48
49 // We only support these alignments (for now)
49 // We only support these alignments (for now)
50 enum Alignment {
50 enum Alignment {
51 AlignmentTop = Qt::AlignTop,
51 AlignmentTop = Qt::AlignTop,
52 AlignmentBottom = Qt::AlignBottom,
52 AlignmentBottom = Qt::AlignBottom,
53 AlignmentLeft = Qt::AlignLeft,
53 AlignmentLeft = Qt::AlignLeft,
54 AlignmentRight = Qt::AlignRight
54 AlignmentRight = Qt::AlignRight
55 };
55 };
56
56
57 Q_DECLARE_FLAGS(Alignments, Alignment)
57 Q_DECLARE_FLAGS(Alignments, Alignment)
58
58
59 private:
59 private:
60 explicit QLegend(QChart *chart);
60 explicit QLegend(QChart *chart);
61
61
62 public:
62 public:
63 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
63 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
64 QRectF boundingRect() const;
64 QRectF boundingRect() const;
65
65
66 void setBrush(const QBrush &brush);
66 void setBrush(const QBrush &brush);
67 QBrush brush() const;
67 QBrush brush() const;
68
68
69 void setPen(const QPen &pen);
69 void setPen(const QPen &pen);
70 QPen pen() const;
70 QPen pen() const;
71
71
72 void setAlignmnent(QLegend::Alignments alignment);
72 void setAlignmnent(QLegend::Alignments alignment);
73 QLegend::Alignments alignment() const;
73 QLegend::Alignments alignment() const;
74
74
75
75
76 void detachFromChart();
76 void detachFromChart();
77 void attachToChart();
77 void attachToChart();
78 bool isAttachedToChart();
78 bool isAttachedToChart();
79
79
80 qreal minWidht() const { return m_minWidth;}
80 qreal minWidht() const { return m_minWidth;}
81 qreal minHeight() const { return m_minHeight;}
81 qreal minHeight() const { return m_minHeight;}
82
82
83 void setBackgroundVisible(bool visible);
83 void setBackgroundVisible(bool visible);
84 bool isBackgroundVisible() const;
84 bool isBackgroundVisible() const;
85
85
86 void setOffset(const QPointF& point);
86 void setOffset(const QPointF& point);
87 QPointF offset() const;
87 QPointF offset() const;
88
88
89 protected:
89 protected:
90 void resizeEvent(QGraphicsSceneResizeEvent *event);
90 void resizeEvent(QGraphicsSceneResizeEvent *event);
91 void hideEvent(QHideEvent *event);
91 void hideEvent(QHideEvent *event);
92 void showEvent(QShowEvent *event);
92 void showEvent(QShowEvent *event);
93 void mousePressEvent(QGraphicsSceneMouseEvent* event);
93 void mousePressEvent(QGraphicsSceneMouseEvent* event);
94 void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
94 void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
95 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
95 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
96
96
97 public Q_SLOTS:
97 public Q_SLOTS:
98 // PIMPL --->
98 // PIMPL --->
99 void handleSeriesAdded(QSeries *series, Domain *domain);
99 void handleSeriesAdded(QSeries *series, Domain *domain);
100 void handleSeriesRemoved(QSeries *series);
100 void handleSeriesRemoved(QSeries *series);
101 void handleAdded(QList<QPieSlice *> slices);
101 void handleAdded(QList<QPieSlice *> slices);
102 void handleRemoved(QList<QPieSlice *> slices);
102 void handleRemoved(QList<QPieSlice *> slices);
103 void handleMarkerDestroyed();
103 void handleMarkerDestroyed();
104
104
105 // PIMPL <---
105 // PIMPL <---
106
106
107 private:
107 private:
108 // PIMPL --->
108 // PIMPL --->
109 void appendMarkers(QAreaSeries *series);
109 void appendMarkers(QAreaSeries *series);
110 void appendMarkers(QXYSeries *series);
110 void appendMarkers(QXYSeries *series);
111 void appendMarkers(QBarSeries *series);
111 void appendMarkers(QBarSeries *series);
112 void appendMarkers(QPieSeries *series);
112 void appendMarkers(QPieSeries *series);
113 void deleteMarkers(QSeries *series);
113 void deleteMarkers(QSeries *series);
114
114
115
115
116
116
117
117
118 private Q_SLOTS:
118 private Q_SLOTS:
119 void updateLayout();
119 void updateLayout();
120 void scroll();
121
120
122 private:
121 private:
123 qreal m_margin;
122 qreal m_margin;
124
123
125 QRectF m_rect;
124 QRectF m_rect;
126 qreal m_offsetX;
125 qreal m_offsetX;
127 qreal m_offsetY;
126 qreal m_offsetY;
128
127
129 //QList<LegendMarker *> m_markers;
128 //QList<LegendMarker *> m_markers;
130
129
131 QBrush m_brush;
130 QBrush m_brush;
132 QPen m_pen;
131 QPen m_pen;
133 QLegend::Alignments m_alignment;
132 QLegend::Alignments m_alignment;
134 QGraphicsItemGroup* m_markers;
133 QGraphicsItemGroup* m_markers;
135
134
136
135
137 bool m_attachedToChart;
136 bool m_attachedToChart;
138
137
139 QChart *m_chart;
138 QChart *m_chart;
140 qreal m_minWidth;
139 qreal m_minWidth;
141 qreal m_minHeight;
140 qreal m_minHeight;
142 qreal m_width;
141 qreal m_width;
143 qreal m_height;
142 qreal m_height;
144 bool m_visible;
143 bool m_visible;
145 bool m_dirty;
144 bool m_dirty;
146 Scroller* m_scroller;
145 Scroller* m_scroller;
147 friend class QChart;
146 friend class QChart;
148 // <--- PIMPL
147 // <--- PIMPL
149 };
148 };
150
149
151 QTCOMMERCIALCHART_END_NAMESPACE
150 QTCOMMERCIALCHART_END_NAMESPACE
152
151
153 #endif // QLEGEND_H
152 #endif // QLEGEND_H
General Comments 0
You need to be logged in to leave comments. Login now