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