##// END OF EJS Templates
block presenter code for now
Michal Klocek -
r135:b79456e09b8a
parent child
Show More
@@ -1,446 +1,446
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include "qscatterseries.h"
3 #include "qscatterseries.h"
4 #include "qscatterseries_p.h"
4 #include "qscatterseries_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include "qpieseries_p.h"
6 #include "qpieseries_p.h"
7 #include "qxychartseries.h"
7 #include "qxychartseries.h"
8 #include "qchartaxis.h"
8 #include "qchartaxis.h"
9 #include "barchartseries.h"
9 #include "barchartseries.h"
10 #include "bargroup.h"
10 #include "bargroup.h"
11 #include "stackedbarchartseries.h"
11 #include "stackedbarchartseries.h"
12 #include "stackedbargroup.h"
12 #include "stackedbargroup.h"
13 #include "percentbarchartseries.h"
13 #include "percentbarchartseries.h"
14 #include "percentbargroup.h"
14 #include "percentbargroup.h"
15 #include "charttheme_p.h"
15 #include "charttheme_p.h"
16 #include "chartitem_p.h"
16 #include "chartitem_p.h"
17
17
18 #include "xylinechartitem_p.h"
18 #include "xylinechartitem_p.h"
19 #include "plotdomain_p.h"
19 #include "plotdomain_p.h"
20 #include "axisitem_p.h"
20 #include "axisitem_p.h"
21 #include "chartpresenter_p.h"
21 #include "chartpresenter_p.h"
22 #include "chartdataset_p.h"
22 #include "chartdataset_p.h"
23 #include <QGraphicsScene>
23 #include <QGraphicsScene>
24 #include <QGraphicsSceneResizeEvent>
24 #include <QGraphicsSceneResizeEvent>
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
29 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
30 m_backgroundItem(0),
30 m_backgroundItem(0),
31 m_titleItem(0),
31 m_titleItem(0),
32 m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)),
32 m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)),
33 m_plotDataIndex(0),
33 m_plotDataIndex(0),
34 m_marginSize(0),
34 m_marginSize(0),
35 m_chartTheme(new ChartTheme(this)),
35 m_chartTheme(new ChartTheme(this)),
36 //m_engine(0),
36 m_dataset(0),
37 m_dataset(new ChartDataSet(this)),
37 //m_dataset(new ChartDataSet(this)),
38 //m_presenter(0)
38 m_presenter(0)
39 m_presenter(new ChartPresenter(this,m_dataset))
39 //m_presenter(new ChartPresenter(this,m_dataset))
40 {
40 {
41 // TODO: the default theme?
41 // TODO: the default theme?
42 setTheme(QChart::ChartThemeDefault);
42 setTheme(QChart::ChartThemeDefault);
43
43
44 PlotDomain domain;
44 PlotDomain domain;
45 m_plotDomainList << domain;
45 m_plotDomainList << domain;
46 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
46 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
47 m_chartItems << m_axisXItem;
47 m_chartItems << m_axisXItem;
48 m_chartItems << m_axisYItem.at(0);
48 m_chartItems << m_axisYItem.at(0);
49 }
49 }
50
50
51 QChart::~QChart(){}
51 QChart::~QChart(){}
52
52
53 void QChart::addSeries(QChartSeries* series)
53 void QChart::addSeries(QChartSeries* series)
54 {
54 {
55 if(m_dataset) {
55 if(m_dataset) {
56 m_dataset->addSeries(series);
56 m_dataset->addSeries(series);
57 return;
57 return;
58 }
58 }
59
59
60 Q_ASSERT(series);
60 Q_ASSERT(series);
61 Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid);
61 Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid);
62
62
63 // TODO: we should check the series not already added
63 // TODO: we should check the series not already added
64
64
65
65
66 m_chartSeries << series;
66 m_chartSeries << series;
67
67
68 m_plotDataIndex = 0 ;
68 m_plotDataIndex = 0 ;
69 m_plotDomainList.resize(1);
69 m_plotDomainList.resize(1);
70 PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
70 PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
71
71
72 switch(series->type())
72 switch(series->type())
73 {
73 {
74 case QChartSeries::SeriesTypeLine: {
74 case QChartSeries::SeriesTypeLine: {
75
75
76 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
76 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
77
77
78 for (int i = 0 ; i < xyseries->count() ; i++) {
78 for (int i = 0 ; i < xyseries->count() ; i++) {
79 qreal x = xyseries->x(i);
79 qreal x = xyseries->x(i);
80 qreal y = xyseries->y(i);
80 qreal y = xyseries->y(i);
81 domain.m_minX = qMin(domain.m_minX,x);
81 domain.m_minX = qMin(domain.m_minX,x);
82 domain.m_minY = qMin(domain.m_minY,y);
82 domain.m_minY = qMin(domain.m_minY,y);
83 domain.m_maxX = qMax(domain.m_maxX,x);
83 domain.m_maxX = qMax(domain.m_maxX,x);
84 domain.m_maxY = qMax(domain.m_maxY,y);
84 domain.m_maxY = qMax(domain.m_maxY,y);
85 }
85 }
86
86
87 //XYLineChartItem* item = new XYLineChartItem(xyseries,0,this);
87 //XYLineChartItem* item = new XYLineChartItem(xyseries,0,this);
88
88
89 //m_chartItems << item;
89 //m_chartItems << item;
90 // TODO:
90 // TODO:
91 //m_chartTheme->addObserver(xyseries);
91 //m_chartTheme->addObserver(xyseries);
92
92
93 break;
93 break;
94 }
94 }
95 case QChartSeries::SeriesTypeBar: {
95 case QChartSeries::SeriesTypeBar: {
96
96
97 qDebug() << "barSeries added";
97 qDebug() << "barSeries added";
98 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
98 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
99 BarGroup* barGroup = new BarGroup(*barSeries,this);
99 BarGroup* barGroup = new BarGroup(*barSeries,this);
100
100
101 // Add some fugly colors for 5 fist series...
101 // Add some fugly colors for 5 fist series...
102 barGroup->addColor(QColor(255,0,0,128));
102 barGroup->addColor(QColor(255,0,0,128));
103 barGroup->addColor(QColor(255,255,0,128));
103 barGroup->addColor(QColor(255,255,0,128));
104 barGroup->addColor(QColor(0,255,0,128));
104 barGroup->addColor(QColor(0,255,0,128));
105 barGroup->addColor(QColor(0,0,255,128));
105 barGroup->addColor(QColor(0,0,255,128));
106 barGroup->addColor(QColor(255,128,0,128));
106 barGroup->addColor(QColor(255,128,0,128));
107
107
108 m_chartItems << barGroup;
108 m_chartItems << barGroup;
109 childItems().append(barGroup);
109 childItems().append(barGroup);
110
110
111 qreal x = barSeries->countColumns();
111 qreal x = barSeries->countColumns();
112 qreal y = barSeries->max();
112 qreal y = barSeries->max();
113 domain.m_minX = qMin(domain.m_minX,x);
113 domain.m_minX = qMin(domain.m_minX,x);
114 domain.m_minY = qMin(domain.m_minY,y);
114 domain.m_minY = qMin(domain.m_minY,y);
115 domain.m_maxX = qMax(domain.m_maxX,x);
115 domain.m_maxX = qMax(domain.m_maxX,x);
116 domain.m_maxY = qMax(domain.m_maxY,y);
116 domain.m_maxY = qMax(domain.m_maxY,y);
117 m_axisXItem->setVisible(false);
117 m_axisXItem->setVisible(false);
118 break;
118 break;
119 }
119 }
120 case QChartSeries::SeriesTypeStackedBar: {
120 case QChartSeries::SeriesTypeStackedBar: {
121
121
122 qDebug() << "barSeries added";
122 qDebug() << "barSeries added";
123 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
123 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
124 StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this);
124 StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this);
125
125
126 // Add some fugly colors for 5 fist series...
126 // Add some fugly colors for 5 fist series...
127 stackedBarGroup->addColor(QColor(255,0,0,128));
127 stackedBarGroup->addColor(QColor(255,0,0,128));
128 stackedBarGroup->addColor(QColor(255,255,0,128));
128 stackedBarGroup->addColor(QColor(255,255,0,128));
129 stackedBarGroup->addColor(QColor(0,255,0,128));
129 stackedBarGroup->addColor(QColor(0,255,0,128));
130 stackedBarGroup->addColor(QColor(0,0,255,128));
130 stackedBarGroup->addColor(QColor(0,0,255,128));
131 stackedBarGroup->addColor(QColor(255,128,0,128));
131 stackedBarGroup->addColor(QColor(255,128,0,128));
132
132
133 m_chartItems << stackedBarGroup;
133 m_chartItems << stackedBarGroup;
134 childItems().append(stackedBarGroup);
134 childItems().append(stackedBarGroup);
135
135
136 qreal x = stackedBarSeries->countColumns();
136 qreal x = stackedBarSeries->countColumns();
137 qreal y = stackedBarSeries->maxColumnSum();
137 qreal y = stackedBarSeries->maxColumnSum();
138 domain.m_minX = qMin(domain.m_minX,x);
138 domain.m_minX = qMin(domain.m_minX,x);
139 domain.m_minY = qMin(domain.m_minY,y);
139 domain.m_minY = qMin(domain.m_minY,y);
140 domain.m_maxX = qMax(domain.m_maxX,x);
140 domain.m_maxX = qMax(domain.m_maxX,x);
141 domain.m_maxY = qMax(domain.m_maxY,y);
141 domain.m_maxY = qMax(domain.m_maxY,y);
142 m_axisXItem->setVisible(false);
142 m_axisXItem->setVisible(false);
143 break;
143 break;
144 }
144 }
145 case QChartSeries::SeriesTypePercentBar: {
145 case QChartSeries::SeriesTypePercentBar: {
146
146
147 qDebug() << "barSeries added";
147 qDebug() << "barSeries added";
148 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
148 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
149 PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this);
149 PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this);
150
150
151 // Add some fugly colors for 5 fist series...
151 // Add some fugly colors for 5 fist series...
152 percentBarGroup->addColor(QColor(255,0,0,128));
152 percentBarGroup->addColor(QColor(255,0,0,128));
153 percentBarGroup->addColor(QColor(255,255,0,128));
153 percentBarGroup->addColor(QColor(255,255,0,128));
154 percentBarGroup->addColor(QColor(0,255,0,128));
154 percentBarGroup->addColor(QColor(0,255,0,128));
155 percentBarGroup->addColor(QColor(0,0,255,128));
155 percentBarGroup->addColor(QColor(0,0,255,128));
156 percentBarGroup->addColor(QColor(255,128,0,128));
156 percentBarGroup->addColor(QColor(255,128,0,128));
157
157
158 m_chartItems << percentBarGroup;
158 m_chartItems << percentBarGroup;
159 childItems().append(percentBarGroup);
159 childItems().append(percentBarGroup);
160
160
161 qreal x = percentBarSeries->countColumns();
161 qreal x = percentBarSeries->countColumns();
162 domain.m_minX = qMin(domain.m_minX,x);
162 domain.m_minX = qMin(domain.m_minX,x);
163 domain.m_minY = 0;
163 domain.m_minY = 0;
164 domain.m_maxX = qMax(domain.m_maxX,x);
164 domain.m_maxX = qMax(domain.m_maxX,x);
165 domain.m_maxY = 100;
165 domain.m_maxY = 100;
166 m_axisXItem->setVisible(false);
166 m_axisXItem->setVisible(false);
167 break;
167 break;
168 }
168 }
169 case QChartSeries::SeriesTypeScatter: {
169 case QChartSeries::SeriesTypeScatter: {
170 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
170 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
171 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
171 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
172 scatterSeries->d->setParentItem(this);
172 scatterSeries->d->setParentItem(this);
173 scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
173 scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
174 m_chartItems << scatterSeries->d;
174 m_chartItems << scatterSeries->d;
175 m_chartTheme->addObserver(scatterSeries->d);
175 m_chartTheme->addObserver(scatterSeries->d);
176
176
177 foreach (qreal x, scatterSeries->d->m_x) {
177 foreach (qreal x, scatterSeries->d->m_x) {
178 domain.m_minX = qMin(domain.m_minX, x);
178 domain.m_minX = qMin(domain.m_minX, x);
179 domain.m_maxX = qMax(domain.m_maxX, x);
179 domain.m_maxX = qMax(domain.m_maxX, x);
180 }
180 }
181 foreach (qreal y, scatterSeries->d->m_y) {
181 foreach (qreal y, scatterSeries->d->m_y) {
182 domain.m_minY = qMin(domain.m_minY, y);
182 domain.m_minY = qMin(domain.m_minY, y);
183 domain.m_maxY = qMax(domain.m_maxY, y);
183 domain.m_maxY = qMax(domain.m_maxY, y);
184 }
184 }
185
185
186 break;
186 break;
187 }
187 }
188 case QChartSeries::SeriesTypePie: {
188 case QChartSeries::SeriesTypePie: {
189 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
189 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
190 pieSeries->d->setParentItem(this);
190 pieSeries->d->setParentItem(this);
191 m_chartItems << pieSeries->d;
191 m_chartItems << pieSeries->d;
192 pieSeries->d->m_chartTheme = m_chartTheme;
192 pieSeries->d->m_chartTheme = m_chartTheme;
193 m_chartTheme->addObserver(pieSeries->d);
193 m_chartTheme->addObserver(pieSeries->d);
194 break;
194 break;
195 }
195 }
196 default:
196 default:
197 break;
197 break;
198 }
198 }
199
199
200 // Update all the items to match the new visible area of the chart
200 // Update all the items to match the new visible area of the chart
201 foreach(ChartItem* i, m_chartItems)
201 foreach(ChartItem* i, m_chartItems)
202 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
202 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
203 }
203 }
204
204
205 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
205 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
206 {
206 {
207 // TODO: support also other types; not only scatter and pie
207 // TODO: support also other types; not only scatter and pie
208
208
209 QChartSeries *series(0);
209 QChartSeries *series(0);
210
210
211 switch (type) {
211 switch (type) {
212 case QChartSeries::SeriesTypeLine: {
212 case QChartSeries::SeriesTypeLine: {
213 series = QXYChartSeries::create();
213 series = QXYChartSeries::create();
214 break;
214 break;
215 }
215 }
216 case QChartSeries::SeriesTypeBar: {
216 case QChartSeries::SeriesTypeBar: {
217 series = new BarChartSeries(this);
217 series = new BarChartSeries(this);
218 break;
218 break;
219 }
219 }
220 case QChartSeries::SeriesTypeStackedBar: {
220 case QChartSeries::SeriesTypeStackedBar: {
221 series = new StackedBarChartSeries(this);
221 series = new StackedBarChartSeries(this);
222 break;
222 break;
223 }
223 }
224 case QChartSeries::SeriesTypePercentBar: {
224 case QChartSeries::SeriesTypePercentBar: {
225 series = new PercentBarChartSeries(this);
225 series = new PercentBarChartSeries(this);
226 break;
226 break;
227 }
227 }
228 case QChartSeries::SeriesTypeScatter: {
228 case QChartSeries::SeriesTypeScatter: {
229 series = new QScatterSeries(this);
229 series = new QScatterSeries(this);
230 break;
230 break;
231 }
231 }
232 case QChartSeries::SeriesTypePie: {
232 case QChartSeries::SeriesTypePie: {
233 series = new QPieSeries(this);
233 series = new QPieSeries(this);
234 break;
234 break;
235 }
235 }
236 default:
236 default:
237 Q_ASSERT(false);
237 Q_ASSERT(false);
238 break;
238 break;
239 }
239 }
240
240
241 addSeries(series);
241 addSeries(series);
242 return series;
242 return series;
243 }
243 }
244
244
245 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
245 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
246 {
246 {
247
247
248 if(!m_backgroundItem){
248 if(!m_backgroundItem){
249 m_backgroundItem = new QGraphicsRectItem(this);
249 m_backgroundItem = new QGraphicsRectItem(this);
250 m_backgroundItem->setZValue(-1);
250 m_backgroundItem->setZValue(-1);
251 }
251 }
252
252
253 m_bacgroundOrinetation = orientation;
253 m_bacgroundOrinetation = orientation;
254 m_backgroundGradient.setColorAt(0.0, startColor);
254 m_backgroundGradient.setColorAt(0.0, startColor);
255 m_backgroundGradient.setColorAt(1.0, endColor);
255 m_backgroundGradient.setColorAt(1.0, endColor);
256 m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
256 m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
257
257
258 if(orientation == VerticalGradientOrientation){
258 if(orientation == VerticalGradientOrientation){
259 m_backgroundGradient.setFinalStop(0,1);
259 m_backgroundGradient.setFinalStop(0,1);
260 }else{
260 }else{
261 m_backgroundGradient.setFinalStop(1,0);
261 m_backgroundGradient.setFinalStop(1,0);
262 }
262 }
263
263
264 m_backgroundItem->setBrush(m_backgroundGradient);
264 m_backgroundItem->setBrush(m_backgroundGradient);
265 m_backgroundItem->setPen(Qt::NoPen);
265 m_backgroundItem->setPen(Qt::NoPen);
266 m_backgroundItem->update();
266 m_backgroundItem->update();
267 }
267 }
268
268
269 void QChart::setChartBackgroundBrush(const QBrush& brush)
269 void QChart::setChartBackgroundBrush(const QBrush& brush)
270 {
270 {
271
271
272 if(!m_backgroundItem){
272 if(!m_backgroundItem){
273 m_backgroundItem = new QGraphicsRectItem(this);
273 m_backgroundItem = new QGraphicsRectItem(this);
274 m_backgroundItem->setZValue(-1);
274 m_backgroundItem->setZValue(-1);
275 }
275 }
276
276
277 m_backgroundItem->setBrush(brush);
277 m_backgroundItem->setBrush(brush);
278 m_backgroundItem->update();
278 m_backgroundItem->update();
279 }
279 }
280
280
281 void QChart::setChartBackgroundPen(const QPen& pen)
281 void QChart::setChartBackgroundPen(const QPen& pen)
282 {
282 {
283
283
284 if(!m_backgroundItem){
284 if(!m_backgroundItem){
285 m_backgroundItem = new QGraphicsRectItem(this);
285 m_backgroundItem = new QGraphicsRectItem(this);
286 m_backgroundItem->setZValue(-1);
286 m_backgroundItem->setZValue(-1);
287 }
287 }
288
288
289 m_backgroundItem->setPen(pen);
289 m_backgroundItem->setPen(pen);
290 m_backgroundItem->update();
290 m_backgroundItem->update();
291 }
291 }
292
292
293 void QChart::setTitle(const QString& title,const QFont& font)
293 void QChart::setTitle(const QString& title,const QFont& font)
294 {
294 {
295 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
295 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
296 m_titleItem->setPlainText(title);
296 m_titleItem->setPlainText(title);
297 m_titleItem->setFont(font);
297 m_titleItem->setFont(font);
298 }
298 }
299
299
300 int QChart::margin() const
300 int QChart::margin() const
301 {
301 {
302 return m_marginSize;
302 return m_marginSize;
303 }
303 }
304
304
305 void QChart::setMargin(int margin)
305 void QChart::setMargin(int margin)
306 {
306 {
307 m_marginSize = margin;
307 m_marginSize = margin;
308 }
308 }
309
309
310 void QChart::setTheme(QChart::ChartThemeId theme)
310 void QChart::setTheme(QChart::ChartThemeId theme)
311 {
311 {
312 m_chartTheme->setTheme(theme);
312 m_chartTheme->setTheme(theme);
313 setBackground(m_chartTheme->d->m_gradientStartColor,
313 setBackground(m_chartTheme->d->m_gradientStartColor,
314 m_chartTheme->d->m_gradientEndColor,
314 m_chartTheme->d->m_gradientEndColor,
315 m_bacgroundOrinetation);
315 m_bacgroundOrinetation);
316
316
317 // TODO: Move the controlling of the series presentations into private implementation of the
317 // TODO: Move the controlling of the series presentations into private implementation of the
318 // series instead of QChart controlling themes for each
318 // series instead of QChart controlling themes for each
319 // In other words, the following should be used when creating xy series:
319 // In other words, the following should be used when creating xy series:
320 // m_chartTheme->addObserver(xyseries)
320 // m_chartTheme->addObserver(xyseries)
321 foreach (QChartSeries *series, m_chartSeries) {
321 foreach (QChartSeries *series, m_chartSeries) {
322 if (series->type() == QChartSeries::SeriesTypeLine) {
322 if (series->type() == QChartSeries::SeriesTypeLine) {
323 QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series);
323 QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series);
324 SeriesTheme seriesTheme = m_chartTheme->themeForSeries();
324 SeriesTheme seriesTheme = m_chartTheme->themeForSeries();
325 xyseries->setPen(seriesTheme.linePen);
325 xyseries->setPen(seriesTheme.linePen);
326 }
326 }
327 }
327 }
328
328
329 update();
329 update();
330 }
330 }
331
331
332 QChart::ChartThemeId QChart::theme()
332 QChart::ChartThemeId QChart::theme()
333 {
333 {
334 return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme;
334 return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme;
335 }
335 }
336
336
337 void QChart::zoomInToRect(const QRectF& rectangle)
337 void QChart::zoomInToRect(const QRectF& rectangle)
338 {
338 {
339
339
340 if(!rectangle.isValid()) return;
340 if(!rectangle.isValid()) return;
341
341
342 qreal margin = this->margin();
342 qreal margin = this->margin();
343
343
344 QRectF rect = rectangle.normalized();
344 QRectF rect = rectangle.normalized();
345 rect.translate(-margin, -margin);
345 rect.translate(-margin, -margin);
346
346
347 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
347 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
348
348
349 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
349 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
350
350
351 m_plotDomainList.resize(m_plotDataIndex + 1);
351 m_plotDomainList.resize(m_plotDataIndex + 1);
352 m_plotDomainList<<domain;
352 m_plotDomainList<<domain;
353 m_plotDataIndex++;
353 m_plotDataIndex++;
354
354
355 foreach (ChartItem* item, m_chartItems)
355 foreach (ChartItem* item, m_chartItems)
356 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
356 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
357 update();
357 update();
358 }
358 }
359
359
360 void QChart::zoomIn()
360 void QChart::zoomIn()
361 {
361 {
362 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
362 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
363 m_plotDataIndex++;
363 m_plotDataIndex++;
364 foreach (ChartItem* item, m_chartItems)
364 foreach (ChartItem* item, m_chartItems)
365 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
365 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
366 update();
366 update();
367 } else {
367 } else {
368 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
368 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
369 rect.setWidth(rect.width()/2);
369 rect.setWidth(rect.width()/2);
370 rect.setHeight(rect.height()/2);
370 rect.setHeight(rect.height()/2);
371 rect.moveCenter(m_rect.center());
371 rect.moveCenter(m_rect.center());
372 zoomInToRect(rect);
372 zoomInToRect(rect);
373 }
373 }
374 }
374 }
375
375
376 void QChart::zoomOut()
376 void QChart::zoomOut()
377 {
377 {
378 if (m_plotDataIndex > 0) {
378 if (m_plotDataIndex > 0) {
379 m_plotDataIndex--;
379 m_plotDataIndex--;
380 foreach (ChartItem* item, m_chartItems)
380 foreach (ChartItem* item, m_chartItems)
381 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
381 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
382 update();
382 update();
383 }
383 }
384 }
384 }
385
385
386 void QChart::zoomReset()
386 void QChart::zoomReset()
387 {
387 {
388 if (m_plotDataIndex > 0) {
388 if (m_plotDataIndex > 0) {
389 m_plotDataIndex = 0;
389 m_plotDataIndex = 0;
390 foreach (ChartItem* item, m_chartItems)
390 foreach (ChartItem* item, m_chartItems)
391 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
391 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
392 update();
392 update();
393 }
393 }
394 }
394 }
395
395
396 void QChart::setAxisX(const QChartAxis& axis)
396 void QChart::setAxisX(const QChartAxis& axis)
397 {
397 {
398 setAxis(m_axisXItem,axis);
398 setAxis(m_axisXItem,axis);
399 }
399 }
400 void QChart::setAxisY(const QChartAxis& axis)
400 void QChart::setAxisY(const QChartAxis& axis)
401 {
401 {
402 setAxis(m_axisYItem.at(0),axis);
402 setAxis(m_axisYItem.at(0),axis);
403 }
403 }
404
404
405 void QChart::setAxisY(const QList<QChartAxis>& axis)
405 void QChart::setAxisY(const QList<QChartAxis>& axis)
406 {
406 {
407 //TODO not implemented
407 //TODO not implemented
408 }
408 }
409
409
410 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
410 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
411 {
411 {
412 item->setVisible(axis.isAxisVisible());
412 item->setVisible(axis.isAxisVisible());
413 }
413 }
414
414
415 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
415 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
416 {
416 {
417
417
418 m_rect = QRectF(QPoint(0,0),event->newSize());
418 m_rect = QRectF(QPoint(0,0),event->newSize());
419 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
419 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
420
420
421 // recalculate title position
421 // recalculate title position
422 if (m_titleItem) {
422 if (m_titleItem) {
423 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
423 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
424 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
424 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
425 }
425 }
426
426
427 //recalculate background gradient
427 //recalculate background gradient
428 if (m_backgroundItem) {
428 if (m_backgroundItem) {
429 m_backgroundItem->setRect(rect);
429 m_backgroundItem->setRect(rect);
430 }
430 }
431
431
432 // resize and reposition childs
432 // resize and reposition childs
433 foreach (ChartItem *item, m_chartItems) {
433 foreach (ChartItem *item, m_chartItems) {
434 item->setPos(rect.topLeft());
434 item->setPos(rect.topLeft());
435 item->setSize(rect.size());
435 item->setSize(rect.size());
436 }
436 }
437
437
438 QGraphicsWidget::resizeEvent(event);
438 QGraphicsWidget::resizeEvent(event);
439 update();
439 update();
440 }
440 }
441
441
442
442
443
443
444 #include "moc_qchart.cpp"
444 #include "moc_qchart.cpp"
445
445
446 QTCOMMERCIALCHART_END_NAMESPACE
446 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now