##// END OF EJS Templates
Changes background item...
Michal Klocek -
r639:4f21953d9289
parent child
Show More
@@ -1,401 +1,390
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 #include "chartanimator_p.h"
6 #include "chartanimator_p.h"
7 //series
7 //series
8 #include "qbarseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlineseries.h"
11 #include "qlineseries.h"
12 #include "qareaseries.h"
12 #include "qareaseries.h"
13 #include "qpieseries.h"
13 #include "qpieseries.h"
14 #include "qscatterseries.h"
14 #include "qscatterseries.h"
15 #include "qsplineseries.h"
15 #include "qsplineseries.h"
16 //items
16 //items
17 #include "axisitem_p.h"
17 #include "axisitem_p.h"
18 #include "areachartitem_p.h"
18 #include "areachartitem_p.h"
19 #include "barpresenter_p.h"
19 #include "barpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
22 #include "linechartitem_p.h"
22 #include "linechartitem_p.h"
23 #include "piechartitem_p.h"
23 #include "piechartitem_p.h"
24 #include "scatterchartitem_p.h"
24 #include "scatterchartitem_p.h"
25 #include "splinechartitem_p.h"
25 #include "splinechartitem_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
30 m_chart(chart),
30 m_chart(chart),
31 m_animator(0),
31 m_animator(0),
32 m_dataset(dataset),
32 m_dataset(dataset),
33 m_chartTheme(0),
33 m_chartTheme(0),
34 m_zoomIndex(0),
34 m_zoomIndex(0),
35 m_marginSize(0),
36 m_rect(QRectF(QPoint(0,0),m_chart->size())),
35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
37 m_options(QChart::NoAnimation)
36 m_options(QChart::NoAnimation)
38 {
37 {
39 createConnections();
38 createConnections();
40 setChartTheme(QChart::ChartThemeDefault);
39 setChartTheme(QChart::ChartThemeDefault);
41 }
40 }
42
41
43 ChartPresenter::~ChartPresenter()
42 ChartPresenter::~ChartPresenter()
44 {
43 {
45 delete m_chartTheme;
44 delete m_chartTheme;
46 }
45 }
47
46
48 void ChartPresenter::createConnections()
47 void ChartPresenter::createConnections()
49 {
48 {
50 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
49 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
51 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
50 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
52 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
51 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
53 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
52 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
54 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
53 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
55 }
54 }
56
55
57
56
58 QRectF ChartPresenter::geometry() const
57 QRectF ChartPresenter::geometry() const
59 {
58 {
60 return m_rect;
59 return m_rect;
61 }
60 }
62
61
63 void ChartPresenter::handleGeometryChanged()
62 void ChartPresenter::handleGeometryChanged()
64 {
63 {
65 QRectF rect(QPoint(0,0),m_chart->size());
64 QRectF rect(QPoint(0,0),m_chart->size());
66 rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
65 rect.adjust(m_chart->padding(),m_chart->padding(), -m_chart->padding(), -m_chart->padding());
67
66
68 //rewrite zoom stack
67 //rewrite zoom stack
69 for(int i=0;i<m_zoomStack.count();i++){
68 for(int i=0;i<m_zoomStack.count();i++){
70 QRectF r = m_zoomStack[i];
69 QRectF r = m_zoomStack[i];
71 qreal w = rect.width()/m_rect.width();
70 qreal w = rect.width()/m_rect.width();
72 qreal h = rect.height()/m_rect.height();
71 qreal h = rect.height()/m_rect.height();
73 QPointF tl = r.topLeft();
72 QPointF tl = r.topLeft();
74 tl.setX(tl.x()*w);
73 tl.setX(tl.x()*w);
75 tl.setY(tl.y()*h);
74 tl.setY(tl.y()*h);
76 QPointF br = r.bottomRight();
75 QPointF br = r.bottomRight();
77 br.setX(br.x()*w);
76 br.setX(br.x()*w);
78 br.setY(br.y()*h);
77 br.setY(br.y()*h);
79 r.setTopLeft(tl);
78 r.setTopLeft(tl);
80 r.setBottomRight(br);
79 r.setBottomRight(br);
81 m_zoomStack[i]=r;
80 m_zoomStack[i]=r;
82 }
81 }
83
82
84 m_rect = rect;
83 m_rect = rect;
85 Q_ASSERT(m_rect.isValid());
84 Q_ASSERT(m_rect.isValid());
86 emit geometryChanged(m_rect);
85 emit geometryChanged(m_rect);
87 }
86 }
88
87
89 int ChartPresenter::margin() const
90 {
91 return m_marginSize;
92 }
93
94 void ChartPresenter::setMargin(int margin)
95 {
96 m_marginSize = margin;
97 }
98
99 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
88 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
100 {
89 {
101 AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
90 AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
102
91
103 if(m_options.testFlag(QChart::GridAxisAnimations)){
92 if(m_options.testFlag(QChart::GridAxisAnimations)){
104 m_animator->addAnimation(item);
93 m_animator->addAnimation(item);
105 }
94 }
106
95
107 if(axis==m_dataset->axisX()){
96 if(axis==m_dataset->axisX()){
108 m_chartTheme->decorate(axis,true);
97 m_chartTheme->decorate(axis,true);
109 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
98 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
110 //initialize
99 //initialize
111 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
100 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
112
101
113 }
102 }
114 else{
103 else{
115 m_chartTheme->decorate(axis,false);
104 m_chartTheme->decorate(axis,false);
116 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
105 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
117 //initialize
106 //initialize
118 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
107 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
119 }
108 }
120
109
121 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
110 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
122 //initialize
111 //initialize
123 item->handleGeometryChanged(m_rect);
112 item->handleGeometryChanged(m_rect);
124 m_axisItems.insert(axis, item);
113 m_axisItems.insert(axis, item);
125 }
114 }
126
115
127 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
116 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
128 {
117 {
129 AxisItem* item = m_axisItems.take(axis);
118 AxisItem* item = m_axisItems.take(axis);
130 Q_ASSERT(item);
119 Q_ASSERT(item);
131 if(m_animator) m_animator->removeAnimation(item);
120 if(m_animator) m_animator->removeAnimation(item);
132 delete item;
121 delete item;
133 }
122 }
134
123
135
124
136 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
125 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
137 {
126 {
138 ChartItem *item = 0 ;
127 ChartItem *item = 0 ;
139
128
140 switch(series->type())
129 switch(series->type())
141 {
130 {
142 case QSeries::SeriesTypeLine: {
131 case QSeries::SeriesTypeLine: {
143
132
144 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
133 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
145 LineChartItem* line = new LineChartItem(lineSeries,m_chart);
134 LineChartItem* line = new LineChartItem(lineSeries,m_chart);
146 if(m_options.testFlag(QChart::SeriesAnimations)) {
135 if(m_options.testFlag(QChart::SeriesAnimations)) {
147 m_animator->addAnimation(line);
136 m_animator->addAnimation(line);
148 }
137 }
149 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series));
138 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series));
150 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
139 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
151 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
140 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
152 item = line;
141 item = line;
153 break;
142 break;
154 }
143 }
155
144
156 case QSeries::SeriesTypeArea: {
145 case QSeries::SeriesTypeArea: {
157
146
158 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
147 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
159 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
148 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
160 if(m_options.testFlag(QChart::SeriesAnimations)) {
149 if(m_options.testFlag(QChart::SeriesAnimations)) {
161 m_animator->addAnimation(area->upperLineItem());
150 m_animator->addAnimation(area->upperLineItem());
162 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
151 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
163 }
152 }
164 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series));
153 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series));
165 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
154 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
166 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
155 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
167 item=area;
156 item=area;
168 break;
157 break;
169 }
158 }
170
159
171 case QSeries::SeriesTypeBar: {
160 case QSeries::SeriesTypeBar: {
172 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
161 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
173 BarPresenter* bar = new BarPresenter(barSeries,m_chart);
162 BarPresenter* bar = new BarPresenter(barSeries,m_chart);
174 if(m_options.testFlag(QChart::SeriesAnimations)) {
163 if(m_options.testFlag(QChart::SeriesAnimations)) {
175 // m_animator->addAnimation(bar);
164 // m_animator->addAnimation(bar);
176 }
165 }
177 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries));
166 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries));
178 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
167 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
179 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
168 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
180 item=bar;
169 item=bar;
181 break;
170 break;
182 }
171 }
183
172
184 case QSeries::SeriesTypeStackedBar: {
173 case QSeries::SeriesTypeStackedBar: {
185 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
174 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
186 StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart);
175 StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart);
187 if(m_options.testFlag(QChart::SeriesAnimations)) {
176 if(m_options.testFlag(QChart::SeriesAnimations)) {
188 // m_animator->addAnimation(bar);
177 // m_animator->addAnimation(bar);
189 }
178 }
190 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries));
179 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries));
191 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
180 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
192 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
181 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
193 item=bar;
182 item=bar;
194 break;
183 break;
195 }
184 }
196
185
197 case QSeries::SeriesTypePercentBar: {
186 case QSeries::SeriesTypePercentBar: {
198 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
187 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
199 PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart);
188 PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart);
200 if(m_options.testFlag(QChart::SeriesAnimations)) {
189 if(m_options.testFlag(QChart::SeriesAnimations)) {
201 // m_animator->addAnimation(bar);
190 // m_animator->addAnimation(bar);
202 }
191 }
203 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries));
192 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries));
204 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
193 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
205 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
194 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
206 item=bar;
195 item=bar;
207 break;
196 break;
208 }
197 }
209
198
210 case QSeries::SeriesTypeScatter: {
199 case QSeries::SeriesTypeScatter: {
211 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
200 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
212 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart);
201 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart);
213 if(m_options.testFlag(QChart::SeriesAnimations)) {
202 if(m_options.testFlag(QChart::SeriesAnimations)) {
214 m_animator->addAnimation(scatter);
203 m_animator->addAnimation(scatter);
215 }
204 }
216 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series));
205 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series));
217 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
206 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
218 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
207 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
219 item = scatter;
208 item = scatter;
220 break;
209 break;
221 }
210 }
222
211
223 case QSeries::SeriesTypePie: {
212 case QSeries::SeriesTypePie: {
224 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
213 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
225 PieChartItem* pie = new PieChartItem(m_chart, pieSeries);
214 PieChartItem* pie = new PieChartItem(m_chart, pieSeries);
226 if(m_options.testFlag(QChart::SeriesAnimations)) {
215 if(m_options.testFlag(QChart::SeriesAnimations)) {
227 m_animator->addAnimation(pie);
216 m_animator->addAnimation(pie);
228 }
217 }
229 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series));
218 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series));
230 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
219 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
231 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
220 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
232 // Hide all from background when there is only piechart
221 // Hide all from background when there is only piechart
233 // TODO: refactor this ugly code... should be one setting for this
222 // TODO: refactor this ugly code... should be one setting for this
234 if (m_chartItems.count() == 0) {
223 if (m_chartItems.count() == 0) {
235 m_chart->axisX()->hide();
224 m_chart->axisX()->hide();
236 m_chart->axisY()->hide();
225 m_chart->axisY()->hide();
237 m_chart->setChartBackgroundBrush(Qt::transparent);
226 m_chart->setChartBackgroundBrush(Qt::transparent);
238 }
227 }
239 item=pie;
228 item=pie;
240 break;
229 break;
241 }
230 }
242
231
243 case QSeries::SeriesTypeSpline: {
232 case QSeries::SeriesTypeSpline: {
244 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
233 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
245 SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart);
234 SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart);
246 if(m_options.testFlag(QChart::SeriesAnimations)) {
235 if(m_options.testFlag(QChart::SeriesAnimations)) {
247 m_animator->addAnimation(spline);
236 m_animator->addAnimation(spline);
248 }
237 }
249 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series));
238 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series));
250 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
239 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
251 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
240 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
252 item=spline;
241 item=spline;
253 break;
242 break;
254 }
243 }
255 default: {
244 default: {
256 qDebug()<< "Series type" << series->type() << "not implemented.";
245 qDebug()<< "Series type" << series->type() << "not implemented.";
257 break;
246 break;
258 }
247 }
259 }
248 }
260
249
261 //initialize
250 //initialize
262 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
251 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
263 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
252 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
264 m_chartItems.insert(series,item);
253 m_chartItems.insert(series,item);
265 zoomReset();
254 zoomReset();
266 }
255 }
267
256
268 void ChartPresenter::handleSeriesRemoved(QSeries* series)
257 void ChartPresenter::handleSeriesRemoved(QSeries* series)
269 {
258 {
270 ChartItem* item = m_chartItems.take(series);
259 ChartItem* item = m_chartItems.take(series);
271 Q_ASSERT(item);
260 Q_ASSERT(item);
272 if(m_animator) {
261 if(m_animator) {
273 //small hack to handle area animations
262 //small hack to handle area animations
274 if(series->type()==QSeries::SeriesTypeArea){
263 if(series->type()==QSeries::SeriesTypeArea){
275 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
264 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
276 AreaChartItem* area = static_cast<AreaChartItem*>(item);
265 AreaChartItem* area = static_cast<AreaChartItem*>(item);
277 m_animator->removeAnimation(area->upperLineItem());
266 m_animator->removeAnimation(area->upperLineItem());
278 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
267 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
279 }else
268 }else
280 m_animator->removeAnimation(item);
269 m_animator->removeAnimation(item);
281 }
270 }
282 delete item;
271 delete item;
283 }
272 }
284
273
285 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
274 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
286 {
275 {
287 if(m_chartTheme && m_chartTheme->id() == theme) return;
276 if(m_chartTheme && m_chartTheme->id() == theme) return;
288 delete m_chartTheme;
277 delete m_chartTheme;
289 m_chartTheme = ChartTheme::createTheme(theme);
278 m_chartTheme = ChartTheme::createTheme(theme);
290 m_chartTheme->decorate(m_chart);
279 m_chartTheme->decorate(m_chart);
291 m_chartTheme->decorate(m_chart->legend());
280 m_chartTheme->decorate(m_chart->legend());
292 resetAllElements();
281 resetAllElements();
293 }
282 }
294
283
295 QChart::ChartTheme ChartPresenter::chartTheme()
284 QChart::ChartTheme ChartPresenter::chartTheme()
296 {
285 {
297 return m_chartTheme->id();
286 return m_chartTheme->id();
298 }
287 }
299
288
300 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
289 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
301 {
290 {
302 if(m_options!=options) {
291 if(m_options!=options) {
303
292
304 m_options=options;
293 m_options=options;
305
294
306 if(m_options!=QChart::NoAnimation && !m_animator) {
295 if(m_options!=QChart::NoAnimation && !m_animator) {
307 m_animator= new ChartAnimator(this);
296 m_animator= new ChartAnimator(this);
308
297
309 }
298 }
310 resetAllElements();
299 resetAllElements();
311 }
300 }
312
301
313 }
302 }
314
303
315 void ChartPresenter::resetAllElements()
304 void ChartPresenter::resetAllElements()
316 {
305 {
317 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
306 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
318 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
307 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
319
308
320 foreach(QChartAxis* axis, axisList) {
309 foreach(QChartAxis* axis, axisList) {
321 handleAxisRemoved(axis);
310 handleAxisRemoved(axis);
322 handleAxisAdded(axis,m_dataset->domain(axis));
311 handleAxisAdded(axis,m_dataset->domain(axis));
323 }
312 }
324 foreach(QSeries* series, seriesList) {
313 foreach(QSeries* series, seriesList) {
325 handleSeriesRemoved(series);
314 handleSeriesRemoved(series);
326 handleSeriesAdded(series,m_dataset->domain(series));
315 handleSeriesAdded(series,m_dataset->domain(series));
327 }
316 }
328 }
317 }
329
318
330 void ChartPresenter::zoomIn()
319 void ChartPresenter::zoomIn()
331 {
320 {
332 QRectF rect = geometry();
321 QRectF rect = geometry();
333 rect.setWidth(rect.width()/2);
322 rect.setWidth(rect.width()/2);
334 rect.setHeight(rect.height()/2);
323 rect.setHeight(rect.height()/2);
335 rect.moveCenter(geometry().center());
324 rect.moveCenter(geometry().center());
336 zoomIn(rect);
325 zoomIn(rect);
337 }
326 }
338
327
339 void ChartPresenter::zoomIn(const QRectF& rect)
328 void ChartPresenter::zoomIn(const QRectF& rect)
340 {
329 {
341 QRectF r = rect.normalized();
330 QRectF r = rect.normalized();
342 r.translate(-m_marginSize, -m_marginSize);
331 r.translate(-m_chart->padding(), -m_chart->padding());
343 if(m_animator) {
332 if(m_animator) {
344
333
345 QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height());
334 QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height());
346 m_animator->setState(ChartAnimator::ZoomInState,point);
335 m_animator->setState(ChartAnimator::ZoomInState,point);
347 }
336 }
348 m_dataset->zoomInDomain(r,geometry().size());
337 m_dataset->zoomInDomain(r,geometry().size());
349 m_zoomStack<<r;
338 m_zoomStack<<r;
350 m_zoomIndex++;
339 m_zoomIndex++;
351 if(m_animator) {
340 if(m_animator) {
352 m_animator->setState(ChartAnimator::ShowState);
341 m_animator->setState(ChartAnimator::ShowState);
353 }
342 }
354 }
343 }
355
344
356 void ChartPresenter::zoomOut()
345 void ChartPresenter::zoomOut()
357 {
346 {
358 if(m_zoomIndex==0) return;
347 if(m_zoomIndex==0) return;
359 if(m_animator)
348 if(m_animator)
360 {
349 {
361 m_animator->setState(ChartAnimator::ZoomOutState);
350 m_animator->setState(ChartAnimator::ZoomOutState);
362 }
351 }
363 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
352 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
364 m_zoomIndex--;
353 m_zoomIndex--;
365 m_zoomStack.resize(m_zoomIndex);
354 m_zoomStack.resize(m_zoomIndex);
366 if(m_animator){
355 if(m_animator){
367 m_animator->setState(ChartAnimator::ShowState);
356 m_animator->setState(ChartAnimator::ShowState);
368 }
357 }
369 }
358 }
370
359
371 void ChartPresenter::zoomReset()
360 void ChartPresenter::zoomReset()
372 {
361 {
373 m_zoomIndex=0;
362 m_zoomIndex=0;
374 m_zoomStack.resize(m_zoomIndex);
363 m_zoomStack.resize(m_zoomIndex);
375 }
364 }
376
365
377 void ChartPresenter::scroll(int dx,int dy)
366 void ChartPresenter::scroll(int dx,int dy)
378 {
367 {
379 if(m_animator){
368 if(m_animator){
380 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
369 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
381 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
370 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
382 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
371 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
383 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
372 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
384 }
373 }
385
374
386 m_dataset->scrollDomain(dx,dy,geometry().size());
375 m_dataset->scrollDomain(dx,dy,geometry().size());
387
376
388 if(m_animator){
377 if(m_animator){
389 m_animator->setState(ChartAnimator::ShowState);
378 m_animator->setState(ChartAnimator::ShowState);
390 }
379 }
391 }
380 }
392
381
393 QChart::AnimationOptions ChartPresenter::animationOptions() const
382 QChart::AnimationOptions ChartPresenter::animationOptions() const
394 {
383 {
395 return m_options;
384 return m_options;
396 }
385 }
397
386
398
387
399 #include "moc_chartpresenter_p.cpp"
388 #include "moc_chartpresenter_p.cpp"
400
389
401 QTCOMMERCIALCHART_END_NAMESPACE
390 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,86 +1,85
1 #ifndef CHARTPRESENTER_H_
1 #ifndef CHARTPRESENTER_H_
2 #define CHARTPRESENTER_H_
2 #define CHARTPRESENTER_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
5 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
6 #include "qchartaxis.h"
6 #include "qchartaxis.h"
7 #include <QRectF>
7 #include <QRectF>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class ChartItem;
11 class ChartItem;
12 class QSeries;
12 class QSeries;
13 class ChartDataSet;
13 class ChartDataSet;
14 class Domain;
14 class Domain;
15 class AxisItem;
15 class AxisItem;
16 class ChartTheme;
16 class ChartTheme;
17 class ChartAnimator;
17 class ChartAnimator;
18
18
19 class ChartPresenter: public QObject
19 class ChartPresenter: public QObject
20 {
20 {
21 Q_OBJECT
21 Q_OBJECT
22 public:
22 public:
23 enum ZValues {
23 enum ZValues {
24 BackgroundZValue = -1,
24 BackgroundZValue = -1,
25 ShadesZValue,
25 ShadesZValue,
26 GridZValue,
26 GridZValue,
27 AxisZValue,
27 AxisZValue,
28 LineChartZValue,
28 LineChartZValue,
29 BarSeriesZValue,
29 BarSeriesZValue,
30 ScatterSeriesZValue,
30 ScatterSeriesZValue,
31 PieSeriesZValue,
31 PieSeriesZValue,
32 LegendZValue
32 LegendZValue
33 };
33 };
34
34
35 ChartPresenter(QChart* chart,ChartDataSet *dataset);
35 ChartPresenter(QChart* chart,ChartDataSet *dataset);
36 virtual ~ChartPresenter();
36 virtual ~ChartPresenter();
37
37
38 void setMargin(int margin);
38 void setMargin(int margin);
39 int margin() const;
39 int margin() const;
40
40
41 QRectF geometry() const;
41 QRectF geometry() const;
42 ChartAnimator* animator() const {return m_animator;};
42 ChartAnimator* animator() const {return m_animator;};
43
43
44 void setChartTheme(QChart::ChartTheme theme);
44 void setChartTheme(QChart::ChartTheme theme);
45 QChart::ChartTheme chartTheme();
45 QChart::ChartTheme chartTheme();
46
46
47 void setAnimationOptions(QChart::AnimationOptions options);
47 void setAnimationOptions(QChart::AnimationOptions options);
48 QChart::AnimationOptions animationOptions() const;
48 QChart::AnimationOptions animationOptions() const;
49
49
50 void zoomIn();
50 void zoomIn();
51 void zoomIn(const QRectF& rect);
51 void zoomIn(const QRectF& rect);
52 void zoomOut();
52 void zoomOut();
53 void zoomReset();
53 void zoomReset();
54 void scroll(int dx,int dy);
54 void scroll(int dx,int dy);
55 private:
55 private:
56 void createConnections();
56 void createConnections();
57 void resetAllElements();
57 void resetAllElements();
58
58
59 public slots:
59 public slots:
60 void handleSeriesAdded(QSeries* series,Domain* domain);
60 void handleSeriesAdded(QSeries* series,Domain* domain);
61 void handleSeriesRemoved(QSeries* series);
61 void handleSeriesRemoved(QSeries* series);
62 void handleAxisAdded(QChartAxis* axis,Domain* domain);
62 void handleAxisAdded(QChartAxis* axis,Domain* domain);
63 void handleAxisRemoved(QChartAxis* axis);
63 void handleAxisRemoved(QChartAxis* axis);
64 void handleGeometryChanged();
64 void handleGeometryChanged();
65
65
66 signals:
66 signals:
67 void geometryChanged(const QRectF& rect);
67 void geometryChanged(const QRectF& rect);
68
68
69 private:
69 private:
70 QChart* m_chart;
70 QChart* m_chart;
71 ChartAnimator* m_animator;
71 ChartAnimator* m_animator;
72 ChartDataSet* m_dataset;
72 ChartDataSet* m_dataset;
73 ChartTheme *m_chartTheme;
73 ChartTheme *m_chartTheme;
74 int m_zoomIndex;
74 int m_zoomIndex;
75 int m_marginSize;
76 QMap<QSeries*,ChartItem*> m_chartItems;
75 QMap<QSeries*,ChartItem*> m_chartItems;
77 QMap<QChartAxis*,AxisItem*> m_axisItems;
76 QMap<QChartAxis*,AxisItem*> m_axisItems;
78 QVector<QRectF> m_zoomStack;
77 QVector<QRectF> m_zoomStack;
79 QRectF m_rect;
78 QRectF m_rect;
80 QChart::AnimationOptions m_options;
79 QChart::AnimationOptions m_options;
81
80
82 };
81 };
83
82
84 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
85
84
86 #endif /* CHARTPRESENTER_H_ */
85 #endif /* CHARTPRESENTER_H_ */
@@ -1,357 +1,372
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "qlegend.h"
3 #include "qlegend.h"
4 #include "chartpresenter_p.h"
4 #include "chartpresenter_p.h"
5 #include "chartdataset_p.h"
5 #include "chartdataset_p.h"
6 #include "chartbackground_p.h"
6 #include <QGraphicsScene>
7 #include <QGraphicsScene>
7 #include <QGraphicsSceneResizeEvent>
8 #include <QGraphicsSceneResizeEvent>
8 #include <QDebug>
9 #include <QDebug>
9
10
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
12
12 /*!
13 /*!
13 \enum QChart::ChartTheme
14 \enum QChart::ChartTheme
14
15
15 This enum describes the theme used by the chart.
16 This enum describes the theme used by the chart.
16
17
17 \value ChartThemeDefault Follows the GUI style of the Operating System
18 \value ChartThemeDefault Follows the GUI style of the Operating System
18 \value ChartThemeVanilla
19 \value ChartThemeVanilla
19 \value ChartThemeIcy
20 \value ChartThemeIcy
20 \value ChartThemeGrayscale
21 \value ChartThemeGrayscale
21 \value ChartThemeScientific
22 \value ChartThemeScientific
22 \value ChartThemeBlueCerulean
23 \value ChartThemeBlueCerulean
23 \value ChartThemeLight
24 \value ChartThemeLight
24 \value ChartThemeCount Not really a theme; the total count of themes.
25 \value ChartThemeCount Not really a theme; the total count of themes.
25 */
26 */
26
27
27 /*!
28 /*!
28 \enum QChart::AnimationOption
29 \enum QChart::AnimationOption
29
30
30 For enabling/disabling animations. Defaults to NoAnimation.
31 For enabling/disabling animations. Defaults to NoAnimation.
31
32
32 \value NoAnimation
33 \value NoAnimation
33 \value GridAxisAnimations
34 \value GridAxisAnimations
34 \value SeriesAnimations
35 \value SeriesAnimations
35 \value AllAnimations
36 \value AllAnimations
36 */
37 */
37
38
38 /*!
39 /*!
39 \class QChart
40 \class QChart
40 \brief QtCommercial chart API.
41 \brief QtCommercial chart API.
41
42
42 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
43 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
43 representation of different types of QChartSeries and other chart related objects like
44 representation of different types of QChartSeries and other chart related objects like
44 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
45 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
45 convenience class QChartView instead of QChart.
46 convenience class QChartView instead of QChart.
46 \sa QChartView
47 \sa QChartView
47 */
48 */
48
49
49 /*!
50 /*!
50 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
51 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
51 */
52 */
52 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
53 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
53 m_backgroundItem(0),
54 m_backgroundItem(0),
54 m_titleItem(0),
55 m_titleItem(0),
55 m_legend(new QLegend(this)),
56 m_legend(new QLegend(this)),
56 m_dataset(new ChartDataSet(this)),
57 m_dataset(new ChartDataSet(this)),
57 m_presenter(new ChartPresenter(this,m_dataset))
58 m_presenter(new ChartPresenter(this,m_dataset)),
59 m_padding(50),
60 m_backgroundPadding(10)
58 {
61 {
59 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
62 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
60 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
63 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
61 }
64 }
62
65
63 /*!
66 /*!
64 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
67 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
65 */
68 */
66 QChart::~QChart()
69 QChart::~QChart()
67 {
70 {
68 disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
71 disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
69 disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
72 disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
70 }
73 }
71
74
72 /*!
75 /*!
73 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
76 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
74 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
77 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
75 the y axis).
78 the y axis).
76 */
79 */
77 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
80 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
78 {
81 {
79 m_dataset->addSeries(series, axisY);
82 m_dataset->addSeries(series, axisY);
80 }
83 }
81
84
82 /*!
85 /*!
83 Removes the \a series specified in a perameter from the QChartView.
86 Removes the \a series specified in a perameter from the QChartView.
84 It releses its ownership of the specified QChartSeries object.
87 It releses its ownership of the specified QChartSeries object.
85 It does not delete the pointed QChartSeries data object
88 It does not delete the pointed QChartSeries data object
86 \sa addSeries(), removeAllSeries()
89 \sa addSeries(), removeAllSeries()
87 */
90 */
88 void QChart::removeSeries(QSeries* series)
91 void QChart::removeSeries(QSeries* series)
89 {
92 {
90 m_dataset->removeSeries(series);
93 m_dataset->removeSeries(series);
91 }
94 }
92
95
93 /*!
96 /*!
94 Removes all the QChartSeries that have been added to the QChartView
97 Removes all the QChartSeries that have been added to the QChartView
95 It also deletes the pointed QChartSeries data objects
98 It also deletes the pointed QChartSeries data objects
96 \sa addSeries(), removeSeries()
99 \sa addSeries(), removeSeries()
97 */
100 */
98 void QChart::removeAllSeries()
101 void QChart::removeAllSeries()
99 {
102 {
100 m_dataset->removeAllSeries();
103 m_dataset->removeAllSeries();
101 }
104 }
102
105
103 /*!
106 /*!
104 Sets the \a brush that is used for painting the background of the chart area.
107 Sets the \a brush that is used for painting the background of the chart area.
105 */
108 */
106 void QChart::setChartBackgroundBrush(const QBrush& brush)
109 void QChart::setChartBackgroundBrush(const QBrush& brush)
107 {
110 {
108 createChartBackgroundItem();
111 createChartBackgroundItem();
109 m_backgroundItem->setBrush(brush);
112 m_backgroundItem->setBrush(brush);
110 m_backgroundItem->update();
113 m_backgroundItem->update();
111 }
114 }
112
115
113 /*!
116 /*!
114 Sets the \a pen that is used for painting the background of the chart area.
117 Sets the \a pen that is used for painting the background of the chart area.
115 */
118 */
116 void QChart::setChartBackgroundPen(const QPen& pen)
119 void QChart::setChartBackgroundPen(const QPen& pen)
117 {
120 {
118 createChartBackgroundItem();
121 createChartBackgroundItem();
119 m_backgroundItem->setPen(pen);
122 m_backgroundItem->setPen(pen);
120 m_backgroundItem->update();
123 m_backgroundItem->update();
121 }
124 }
122
125
123 /*!
126 /*!
124 Sets the chart \a title. The description text that is drawn above the chart.
127 Sets the chart \a title. The description text that is drawn above the chart.
125 */
128 */
126 void QChart::setChartTitle(const QString& title)
129 void QChart::setChartTitle(const QString& title)
127 {
130 {
128 createChartTitleItem();
131 createChartTitleItem();
129 m_titleItem->setText(title);
132 m_titleItem->setText(title);
130 updateLayout();
133 updateLayout();
131 }
134 }
132
135
133 /*!
136 /*!
134 Returns the chart title. The description text that is drawn above the chart.
137 Returns the chart title. The description text that is drawn above the chart.
135 */
138 */
136 QString QChart::chartTitle() const
139 QString QChart::chartTitle() const
137 {
140 {
138 if(m_titleItem)
141 if(m_titleItem)
139 return m_titleItem->text();
142 return m_titleItem->text();
140 else
143 else
141 return QString();
144 return QString();
142 }
145 }
143
146
144 /*!
147 /*!
145 Sets the \a font that is used for rendering the description text that is rendered above the chart.
148 Sets the \a font that is used for rendering the description text that is rendered above the chart.
146 */
149 */
147 void QChart::setChartTitleFont(const QFont& font)
150 void QChart::setChartTitleFont(const QFont& font)
148 {
151 {
149 createChartTitleItem();
152 createChartTitleItem();
150 m_titleItem->setFont(font);
153 m_titleItem->setFont(font);
151 updateLayout();
154 updateLayout();
152 }
155 }
153
156
154 /*!
157 /*!
155 Sets the \a brush used for rendering the title text.
158 Sets the \a brush used for rendering the title text.
156 */
159 */
157 void QChart::setChartTitleBrush(const QBrush &brush)
160 void QChart::setChartTitleBrush(const QBrush &brush)
158 {
161 {
159 createChartTitleItem();
162 createChartTitleItem();
160 m_titleItem->setBrush(brush);
163 m_titleItem->setBrush(brush);
161 updateLayout();
164 updateLayout();
162 }
165 }
163
166
164 /*!
167 /*!
165 Returns the brush used for rendering the title text.
168 Returns the brush used for rendering the title text.
166 */
169 */
167 QBrush QChart::chartTitleBrush()
170 QBrush QChart::chartTitleBrush()
168 {
171 {
169 createChartTitleItem();
172 createChartTitleItem();
170 return m_titleItem->brush();
173 return m_titleItem->brush();
171 }
174 }
172
175
173 void QChart::createChartBackgroundItem()
176 void QChart::createChartBackgroundItem()
174 {
177 {
175 if(!m_backgroundItem) {
178 if(!m_backgroundItem) {
176 m_backgroundItem = new QGraphicsRectItem(this);
179 m_backgroundItem = new ChartBackground(this);
177 m_backgroundItem->setPen(Qt::NoPen);
180 m_backgroundItem->setPen(Qt::NoPen);
178 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
181 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
179 }
182 }
180 }
183 }
181
184
182 void QChart::createChartTitleItem()
185 void QChart::createChartTitleItem()
183 {
186 {
184 if(!m_titleItem) {
187 if(!m_titleItem) {
185 m_titleItem = new QGraphicsSimpleTextItem(this);
188 m_titleItem = new QGraphicsSimpleTextItem(this);
186 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
189 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
187 }
190 }
188 }
191 }
189
192
190 /*!
193 /*!
191 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
192 \sa setMargin()
193 */
194 int QChart::margin() const
195 {
196 return m_presenter->margin();
197 }
198
199 /*!
200 Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
201 \sa margin()
202 */
203 void QChart::setMargin(int margin)
204 {
205 m_presenter->setMargin(margin);
206 updateLayout();
207 }
208
209 /*!
210 Sets the \a theme used by the chart for rendering the graphical representation of the data
194 Sets the \a theme used by the chart for rendering the graphical representation of the data
211 \sa ChartTheme, chartTheme()
195 \sa ChartTheme, chartTheme()
212 */
196 */
213 void QChart::setChartTheme(QChart::ChartTheme theme)
197 void QChart::setChartTheme(QChart::ChartTheme theme)
214 {
198 {
215 m_presenter->setChartTheme(theme);
199 m_presenter->setChartTheme(theme);
216 }
200 }
217
201
218 /*!
202 /*!
219 Returns the theme enum used by the chart.
203 Returns the theme enum used by the chart.
220 \sa ChartTheme, setChartTheme()
204 \sa ChartTheme, setChartTheme()
221 */
205 */
222 QChart::ChartTheme QChart::chartTheme() const
206 QChart::ChartTheme QChart::chartTheme() const
223 {
207 {
224 return m_presenter->chartTheme();
208 return m_presenter->chartTheme();
225 }
209 }
226
210
227 /*!
211 /*!
228 Zooms in the view by a factor of 2
212 Zooms in the view by a factor of 2
229 */
213 */
230 void QChart::zoomIn()
214 void QChart::zoomIn()
231 {
215 {
232 m_presenter->zoomIn();
216 m_presenter->zoomIn();
233 }
217 }
234
218
235 /*!
219 /*!
236 Zooms in the view to a maximum level at which \a rect is still fully visible.
220 Zooms in the view to a maximum level at which \a rect is still fully visible.
237 */
221 */
238 void QChart::zoomIn(const QRectF& rect)
222 void QChart::zoomIn(const QRectF& rect)
239 {
223 {
240
224
241 if(!rect.isValid()) return;
225 if(!rect.isValid()) return;
242 m_presenter->zoomIn(rect);
226 m_presenter->zoomIn(rect);
243 }
227 }
244
228
245 /*!
229 /*!
246 Restores the view zoom level to the previous one.
230 Restores the view zoom level to the previous one.
247 */
231 */
248 void QChart::zoomOut()
232 void QChart::zoomOut()
249 {
233 {
250 m_presenter->zoomOut();
234 m_presenter->zoomOut();
251 }
235 }
252
236
253 /*!
237 /*!
254 Resets to the default view.
238 Resets to the default view.
255 */
239 */
256 void QChart::zoomReset()
240 void QChart::zoomReset()
257 {
241 {
258 m_presenter->zoomReset();
242 m_presenter->zoomReset();
259 }
243 }
260
244
261 /*!
245 /*!
262 Returns the pointer to the x axis object of the chart
246 Returns the pointer to the x axis object of the chart
263 */
247 */
264 QChartAxis* QChart::axisX() const
248 QChartAxis* QChart::axisX() const
265 {
249 {
266 return m_dataset->axisX();
250 return m_dataset->axisX();
267 }
251 }
268
252
269 /*!
253 /*!
270 Returns the pointer to the y axis object of the chart
254 Returns the pointer to the y axis object of the chart
271 */
255 */
272 QChartAxis* QChart::axisY() const
256 QChartAxis* QChart::axisY() const
273 {
257 {
274 return m_dataset->axisY();
258 return m_dataset->axisY();
275 }
259 }
276
260
277 /*!
261 /*!
278 Returns the legend object of the chart
262 Returns the legend object of the chart
279 */
263 */
280 QLegend* QChart::legend()
264 QLegend* QChart::legend()
281 {
265 {
282 return m_legend;
266 return m_legend;
283 }
267 }
284
268
285 /*!
269 /*!
286 Resizes and updates the chart area using the \a event data
270 Resizes and updates the chart area using the \a event data
287 */
271 */
288 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
272 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
289 {
273 {
290
274
291 m_rect = QRectF(QPoint(0,0),event->newSize());
275 m_rect = QRectF(QPoint(0,0),event->newSize());
292 updateLayout();
276 updateLayout();
293 QGraphicsWidget::resizeEvent(event);
277 QGraphicsWidget::resizeEvent(event);
294 update();
278 update();
295 }
279 }
296
280
297 /*!
281 /*!
298 Sets animation \a options for the chart
282 Sets animation \a options for the chart
299 */
283 */
300 void QChart::setAnimationOptions(AnimationOptions options)
284 void QChart::setAnimationOptions(AnimationOptions options)
301 {
285 {
302 m_presenter->setAnimationOptions(options);
286 m_presenter->setAnimationOptions(options);
303 }
287 }
304
288
305 /*!
289 /*!
306 Returns animation options for the chart
290 Returns animation options for the chart
307 */
291 */
308 QChart::AnimationOptions QChart::animationOptions() const
292 QChart::AnimationOptions QChart::animationOptions() const
309 {
293 {
310 return m_presenter->animationOptions();
294 return m_presenter->animationOptions();
311 }
295 }
312
296
313 void QChart::scrollLeft()
297 void QChart::scrollLeft()
314 {
298 {
315 m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
299 m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
316 }
300 }
317
301
318 void QChart::scrollRight()
302 void QChart::scrollRight()
319 {
303 {
320 m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
304 m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
321 }
305 }
322 void QChart::scrollUp()
306 void QChart::scrollUp()
323 {
307 {
324 m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1));
308 m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1));
325 }
309 }
326 void QChart::scrollDown()
310 void QChart::scrollDown()
327 {
311 {
328 m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1));
312 m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1));
329 }
313 }
330
314
331 void QChart::updateLayout()
315 void QChart::updateLayout()
332 {
316 {
333 if(!m_rect.isValid()) return;
317 if(!m_rect.isValid()) return;
334
318
335 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
319 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
336
320
337 // recalculate title position
321 // recalculate title position
338 if (m_titleItem) {
322 if (m_titleItem) {
339 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
323 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
340 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
324 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
341 }
325 }
342
326
343 //recalculate background gradient
327 //recalculate background gradient
344 if (m_backgroundItem) {
328 if (m_backgroundItem) {
345 m_backgroundItem->setRect(rect);
329 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
346 }
330 }
347
331
348 // recalculate legend position
332 // recalculate legend position
349 if (m_legend) {
333 if (m_legend) {
350 m_legend->setMaximumSize(rect.size());
334 m_legend->setMaximumSize(rect.size());
351 m_legend->setPos(rect.topLeft());
335 m_legend->setPos(rect.topLeft());
352 m_legend->setPreferredLayout(QLegend::PreferredLayoutHorizontal);
336 m_legend->setPreferredLayout(QLegend::PreferredLayoutHorizontal);
353 }
337 }
354 }
338 }
339
340
341 int QChart::padding() const
342 {
343 return m_padding;
344 }
345
346 void QChart::setPadding(int padding)
347 {
348 if(m_padding==padding){
349 m_padding = padding;
350 m_presenter->handleGeometryChanged();
351 updateLayout();
352 }
353 }
354
355 void QChart::setBackgroundPadding(int padding)
356 {
357 if(m_backgroundPadding!=padding){
358 m_backgroundPadding = padding;
359 updateLayout();
360 }
361 }
362
363 void QChart::setBackgroundDiameter(int diameter)
364 {
365 createChartBackgroundItem();
366 m_backgroundItem->setDimeter(diameter);
367 m_backgroundItem->update();
368 }
369
355 #include "moc_qchart.cpp"
370 #include "moc_qchart.cpp"
356
371
357 QTCOMMERCIALCHART_END_NAMESPACE
372 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,109 +1,117
1 #ifndef QCHART_H
1 #ifndef QCHART_H
2 #define QCHART_H
2 #define QCHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qseries.h>
5 #include <qseries.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 QSeries;
15 class QSeries;
16 class PlotDomain;
16 class PlotDomain;
17 class BarPresenter;
17 class BarPresenter;
18 class QChartAxis;
18 class QChartAxis;
19 class ChartTheme;
19 class ChartTheme;
20 class ChartItem;
20 class ChartItem;
21 class ChartDataSet;
21 class ChartDataSet;
22 class ChartPresenter;
22 class ChartPresenter;
23 class QLegend;
23 class QLegend;
24 class ChartBackground;
25
24
26
25 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
27 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
26 {
28 {
27 Q_OBJECT
29 Q_OBJECT
28 public:
30 public:
29 enum ChartTheme {
31 enum ChartTheme {
30 ChartThemeDefault,
32 ChartThemeDefault,
31 ChartThemeVanilla,
33 ChartThemeVanilla,
32 ChartThemeIcy,
34 ChartThemeIcy,
33 ChartThemeGrayscale,
35 ChartThemeGrayscale,
34 ChartThemeScientific,
36 ChartThemeScientific,
35 ChartThemeBlueCerulean,
37 ChartThemeBlueCerulean,
36 ChartThemeLight,
38 ChartThemeLight,
37 ChartThemeCount
39 ChartThemeCount
38 };
40 };
39
41
40 enum AnimationOption {
42 enum AnimationOption {
41 NoAnimation = 0x0,
43 NoAnimation = 0x0,
42 GridAxisAnimations = 0x1,
44 GridAxisAnimations = 0x1,
43 SeriesAnimations =0x2,
45 SeriesAnimations =0x2,
44 AllAnimations = 0x3
46 AllAnimations = 0x3
45 };
47 };
46 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
48 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
47
49
48 public:
50 public:
49 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
51 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
50 ~QChart();
52 ~QChart();
51
53
52 void addSeries(QSeries* series, QChartAxis* axisY = 0);
54 void addSeries(QSeries* series, QChartAxis* axisY = 0);
53 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
55 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
54 void removeAllSeries(); // deletes series and axis
56 void removeAllSeries(); // deletes series and axis
55
57
56 void setMargin(int margin);
57 int margin() const;
58 void setChartTheme(QChart::ChartTheme theme);
58 void setChartTheme(QChart::ChartTheme theme);
59 QChart::ChartTheme chartTheme() const;
59 QChart::ChartTheme chartTheme() const;
60
60
61 void setChartTitle(const QString& title);
61 void setChartTitle(const QString& title);
62 QString chartTitle() const;
62 QString chartTitle() const;
63 void setChartTitleFont(const QFont& font);
63 void setChartTitleFont(const QFont& font);
64 void setChartTitleBrush(const QBrush &brush);
64 void setChartTitleBrush(const QBrush &brush);
65 QBrush chartTitleBrush();
65 QBrush chartTitleBrush();
66 void setChartBackgroundBrush(const QBrush& brush);
66 void setChartBackgroundBrush(const QBrush& brush);
67 void setChartBackgroundPen(const QPen& pen);
67 void setChartBackgroundPen(const QPen& pen);
68
68
69 void setAnimationOptions(AnimationOptions options);
69 void setAnimationOptions(AnimationOptions options);
70 AnimationOptions animationOptions() const;
70 AnimationOptions animationOptions() const;
71
71
72 void zoomIn();
72 void zoomIn();
73 void zoomIn(const QRectF& rect);
73 void zoomIn(const QRectF& rect);
74 void zoomOut();
74 void zoomOut();
75 void zoomReset();
75 void zoomReset();
76 void scrollLeft();
76 void scrollLeft();
77 void scrollRight();
77 void scrollRight();
78 void scrollUp();
78 void scrollUp();
79 void scrollDown();
79 void scrollDown();
80
80
81 QChartAxis* axisX() const;
81 QChartAxis* axisX() const;
82 QChartAxis* axisY() const;
82 QChartAxis* axisY() const;
83
83
84 // TODO: take (and give) legend instead of this.
84 // TODO: take (and give) legend instead of this.
85 QLegend* legend();
85 QLegend* legend();
86
86
87
88 int padding() const;
89
87 protected:
90 protected:
88 void resizeEvent(QGraphicsSceneResizeEvent *event);
91 void resizeEvent(QGraphicsSceneResizeEvent *event);
89
92
90 private:
93 private:
91 inline void createChartBackgroundItem();
94 inline void createChartBackgroundItem();
92 inline void createChartTitleItem();
95 inline void createChartTitleItem();
96 void setPadding(int padding);
97 void setBackgroundPadding(int padding);
98 void setBackgroundDiameter(int diameter);
93 void updateLayout();
99 void updateLayout();
94
100
95 private:
101 private:
96 Q_DISABLE_COPY(QChart)
102 Q_DISABLE_COPY(QChart)
97 QGraphicsRectItem* m_backgroundItem;
103 ChartBackground* m_backgroundItem;
98 QGraphicsSimpleTextItem* m_titleItem;
104 QGraphicsSimpleTextItem* m_titleItem;
99 QRectF m_rect;
105 QRectF m_rect;
100 QLegend* m_legend;
106 QLegend* m_legend;
101 ChartDataSet *m_dataset;
107 ChartDataSet *m_dataset;
102 ChartPresenter *m_presenter;
108 ChartPresenter *m_presenter;
109 int m_padding;
110 int m_backgroundPadding;
103 };
111 };
104
112
105 QTCOMMERCIALCHART_END_NAMESPACE
113 QTCOMMERCIALCHART_END_NAMESPACE
106
114
107 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
115 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
108
116
109 #endif
117 #endif
@@ -1,406 +1,397
1 #include "qchartview.h"
1 #include "qchartview.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QGraphicsView>
4 #include <QGraphicsView>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QRubberBand>
6 #include <QRubberBand>
7 #include <QResizeEvent>
7 #include <QResizeEvent>
8 #include <QDebug>
8 #include <QDebug>
9
9
10 /*!
10 /*!
11 \enum QChartView::RubberBandPolicy
11 \enum QChartView::RubberBandPolicy
12
12
13 This enum describes the different types of rubber bands that can be used for zoom rect selection
13 This enum describes the different types of rubber bands that can be used for zoom rect selection
14
14
15 \value NoRubberBand
15 \value NoRubberBand
16 \value VerticalRubberBand
16 \value VerticalRubberBand
17 \value HorizonalRubberBand
17 \value HorizonalRubberBand
18 \value RectangleRubberBand
18 \value RectangleRubberBand
19 */
19 */
20
20
21 /*!
21 /*!
22 \class QChartView
22 \class QChartView
23 \brief Standalone charting widget.
23 \brief Standalone charting widget.
24
24
25 QChartView is a standalone widget that can display charts. It does not require separate
25 QChartView is a standalone widget that can display charts. It does not require separate
26 QGraphicsScene to work. It manages the graphical representation of different types of
26 QGraphicsScene to work. It manages the graphical representation of different types of
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
29
29
30 \sa QChart
30 \sa QChart
31 */
31 */
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 Constructs a chartView object which is a child of a\a parent.
36 Constructs a chartView object which is a child of a\a parent.
37 */
37 */
38 QChartView::QChartView(QWidget *parent) :
38 QChartView::QChartView(QWidget *parent) :
39 QGraphicsView(parent),
39 QGraphicsView(parent),
40 m_scene(new QGraphicsScene(this)),
40 m_scene(new QGraphicsScene(this)),
41 m_chart(new QChart()),
41 m_chart(new QChart()),
42 m_rubberBand(0),
42 m_rubberBand(0),
43 m_verticalRubberBand(false),
43 m_verticalRubberBand(false),
44 m_horizonalRubberBand(false)
44 m_horizonalRubberBand(false)
45 {
45 {
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
48 setScene(m_scene);
48 setScene(m_scene);
49 m_chart->setMargin(50);
50 m_scene->addItem(m_chart);
49 m_scene->addItem(m_chart);
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
50 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
52 }
51 }
53
52
54
53
55 /*!
54 /*!
56 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
55 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
57 */
56 */
58 QChartView::~QChartView()
57 QChartView::~QChartView()
59 {
58 {
60 }
59 }
61
60
62 /*!
61 /*!
63 Resizes and updates the chart area using the \a event data
62 Resizes and updates the chart area using the \a event data
64 */
63 */
65 void QChartView::resizeEvent(QResizeEvent *event)
64 void QChartView::resizeEvent(QResizeEvent *event)
66 {
65 {
67 m_scene->setSceneRect(0,0,size().width(),size().height());
66 m_scene->setSceneRect(0,0,size().width(),size().height());
68 m_chart->resize(size());
67 m_chart->resize(size());
69 QWidget::resizeEvent(event);
68 QWidget::resizeEvent(event);
70 }
69 }
71
70
72 /*!
71 /*!
73 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
72 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
74 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
73 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
75 the y axis).
74 the y axis).
76 \sa removeSeries(), removeAllSeries()
75 \sa removeSeries(), removeAllSeries()
77 */
76 */
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
77 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
79 {
78 {
80 m_chart->addSeries(series,axisY);
79 m_chart->addSeries(series,axisY);
81 }
80 }
82
81
83 /*!
82 /*!
84 Removes the \a series specified in a perameter from the QChartView.
83 Removes the \a series specified in a perameter from the QChartView.
85 It releses its ownership of the specified QChartSeries object.
84 It releses its ownership of the specified QChartSeries object.
86 It does not delete the pointed QChartSeries data object
85 It does not delete the pointed QChartSeries data object
87 \sa addSeries(), removeAllSeries()
86 \sa addSeries(), removeAllSeries()
88 */
87 */
89 void QChartView::removeSeries(QSeries* series)
88 void QChartView::removeSeries(QSeries* series)
90 {
89 {
91 m_chart->removeSeries(series);
90 m_chart->removeSeries(series);
92 }
91 }
93
92
94 /*!
93 /*!
95 Removes all the QChartSeries that have been added to the QChartView
94 Removes all the QChartSeries that have been added to the QChartView
96 It also deletes the pointed QChartSeries data objects
95 It also deletes the pointed QChartSeries data objects
97 \sa addSeries(), removeSeries()
96 \sa addSeries(), removeSeries()
98 */
97 */
99 void QChartView::removeAllSeries()
98 void QChartView::removeAllSeries()
100 {
99 {
101 m_chart->removeAllSeries();
100 m_chart->removeAllSeries();
102 }
101 }
103
102
104 /*!
103 /*!
105 Zooms in the view by a factor of 2
104 Zooms in the view by a factor of 2
106 */
105 */
107 void QChartView::zoomIn()
106 void QChartView::zoomIn()
108 {
107 {
109 m_chart->zoomIn();
108 m_chart->zoomIn();
110 }
109 }
111
110
112 /*!
111 /*!
113 Zooms in the view to a maximum level at which \a rect is still fully visible.
112 Zooms in the view to a maximum level at which \a rect is still fully visible.
114 */
113 */
115 void QChartView::zoomIn(const QRect& rect)
114 void QChartView::zoomIn(const QRect& rect)
116 {
115 {
117 m_chart->zoomIn(rect);
116 m_chart->zoomIn(rect);
118 }
117 }
119
118
120 /*!
119 /*!
121 Restores the view zoom level to the previous one.
120 Restores the view zoom level to the previous one.
122 */
121 */
123 void QChartView::zoomOut()
122 void QChartView::zoomOut()
124 {
123 {
125 m_chart->zoomOut();
124 m_chart->zoomOut();
126 }
125 }
127
126
128 /*!
127 /*!
129 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
130 */
131 int QChartView::margin() const
132 {
133 return m_chart->margin();
134 }
135
136 /*!
137 Sets the chart \a title. A description text that is drawn above the chart.
128 Sets the chart \a title. A description text that is drawn above the chart.
138 */
129 */
139 void QChartView::setChartTitle(const QString& title)
130 void QChartView::setChartTitle(const QString& title)
140 {
131 {
141 m_chart->setChartTitle(title);
132 m_chart->setChartTitle(title);
142 }
133 }
143
134
144 /*!
135 /*!
145 Returns the chart's title. A description text that is drawn above the chart.
136 Returns the chart's title. A description text that is drawn above the chart.
146 */
137 */
147 QString QChartView::chartTitle() const
138 QString QChartView::chartTitle() const
148 {
139 {
149 return m_chart->chartTitle();
140 return m_chart->chartTitle();
150 }
141 }
151
142
152 /*!
143 /*!
153 Sets the \a font that is used for rendering the description text that is rendered above the chart.
144 Sets the \a font that is used for rendering the description text that is rendered above the chart.
154 */
145 */
155 void QChartView::setChartTitleFont(const QFont& font)
146 void QChartView::setChartTitleFont(const QFont& font)
156 {
147 {
157 m_chart->setChartTitleFont(font);
148 m_chart->setChartTitleFont(font);
158 }
149 }
159
150
160 /*!
151 /*!
161 Sets the \a brush used for rendering the title text.
152 Sets the \a brush used for rendering the title text.
162 */
153 */
163 void QChartView::setChartTitleBrush(const QBrush &brush)
154 void QChartView::setChartTitleBrush(const QBrush &brush)
164 {
155 {
165 m_chart->setChartTitleBrush(brush);
156 m_chart->setChartTitleBrush(brush);
166 }
157 }
167
158
168 /*!
159 /*!
169 Returns the brush used for rendering the title text.
160 Returns the brush used for rendering the title text.
170 */
161 */
171 QBrush QChartView::chartTitleBrush()
162 QBrush QChartView::chartTitleBrush()
172 {
163 {
173 return m_chart->chartTitleBrush();
164 return m_chart->chartTitleBrush();
174 }
165 }
175
166
176 /*!
167 /*!
177 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
168 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
178 */
169 */
179 void QChartView::setChartBackgroundBrush(const QBrush& brush)
170 void QChartView::setChartBackgroundBrush(const QBrush& brush)
180 {
171 {
181 m_chart->setChartBackgroundBrush(brush);
172 m_chart->setChartBackgroundBrush(brush);
182 }
173 }
183
174
184 /*!
175 /*!
185 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
176 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
186 */
177 */
187 void QChartView::setChartBackgroundPen(const QPen& pen)
178 void QChartView::setChartBackgroundPen(const QPen& pen)
188 {
179 {
189 m_chart->setChartBackgroundPen(pen);
180 m_chart->setChartBackgroundPen(pen);
190 }
181 }
191
182
192 /*!
183 /*!
193 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
184 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
194 */
185 */
195 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
186 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
196 {
187 {
197 switch(policy) {
188 switch(policy) {
198 case VerticalRubberBand:
189 case VerticalRubberBand:
199 m_verticalRubberBand = true;
190 m_verticalRubberBand = true;
200 m_horizonalRubberBand = false;
191 m_horizonalRubberBand = false;
201 break;
192 break;
202 case HorizonalRubberBand:
193 case HorizonalRubberBand:
203 m_verticalRubberBand = false;
194 m_verticalRubberBand = false;
204 m_horizonalRubberBand = true;
195 m_horizonalRubberBand = true;
205 break;
196 break;
206 case RectangleRubberBand:
197 case RectangleRubberBand:
207 m_verticalRubberBand = true;
198 m_verticalRubberBand = true;
208 m_horizonalRubberBand = true;
199 m_horizonalRubberBand = true;
209 break;
200 break;
210 case NoRubberBand:
201 case NoRubberBand:
211 default:
202 default:
212 delete m_rubberBand;
203 delete m_rubberBand;
213 m_rubberBand=0;
204 m_rubberBand=0;
214 m_horizonalRubberBand = false;
205 m_horizonalRubberBand = false;
215 m_verticalRubberBand = false;
206 m_verticalRubberBand = false;
216 return;
207 return;
217 }
208 }
218 if(!m_rubberBand) {
209 if(!m_rubberBand) {
219 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
210 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
220 m_rubberBand->setEnabled(true);
211 m_rubberBand->setEnabled(true);
221 }
212 }
222 }
213 }
223
214
224 /*!
215 /*!
225 Returns the RubberBandPolicy that is currently being used by the widget.
216 Returns the RubberBandPolicy that is currently being used by the widget.
226 */
217 */
227 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
218 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
228 {
219 {
229 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
220 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
230 if(m_horizonalRubberBand) return HorizonalRubberBand;
221 if(m_horizonalRubberBand) return HorizonalRubberBand;
231 if(m_verticalRubberBand) return VerticalRubberBand;
222 if(m_verticalRubberBand) return VerticalRubberBand;
232 return NoRubberBand;
223 return NoRubberBand;
233 }
224 }
234
225
235 /*!
226 /*!
236 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
227 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
237 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
228 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
238 */
229 */
239 void QChartView::mousePressEvent(QMouseEvent *event)
230 void QChartView::mousePressEvent(QMouseEvent *event)
240 {
231 {
241 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
232 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
242
233
243 int margin = m_chart->margin();
234 int padding = m_chart->padding();
244 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
235 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
245
236
246 if (rect.contains(event->pos())) {
237 if (rect.contains(event->pos())) {
247 m_rubberBandOrigin = event->pos();
238 m_rubberBandOrigin = event->pos();
248 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
239 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
249 m_rubberBand->show();
240 m_rubberBand->show();
250 event->accept();
241 event->accept();
251 }
242 }
252 }
243 }
253 else {
244 else {
254 QGraphicsView::mousePressEvent(event);
245 QGraphicsView::mousePressEvent(event);
255 }
246 }
256 }
247 }
257
248
258 /*!
249 /*!
259 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
250 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
260 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
251 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
261 */
252 */
262 void QChartView::mouseMoveEvent(QMouseEvent *event)
253 void QChartView::mouseMoveEvent(QMouseEvent *event)
263 {
254 {
264 if(m_rubberBand && m_rubberBand->isVisible()) {
255 if(m_rubberBand && m_rubberBand->isVisible()) {
265 int margin = m_chart->margin();
256 int padding = m_chart->padding();
266 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
257 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
267 int width = event->pos().x() - m_rubberBandOrigin.x();
258 int width = event->pos().x() - m_rubberBandOrigin.x();
268 int height = event->pos().y() - m_rubberBandOrigin.y();
259 int height = event->pos().y() - m_rubberBandOrigin.y();
269 if(!m_verticalRubberBand) {
260 if(!m_verticalRubberBand) {
270 m_rubberBandOrigin.setY(rect.top());
261 m_rubberBandOrigin.setY(rect.top());
271 height = rect.height();
262 height = rect.height();
272 }
263 }
273 if(!m_horizonalRubberBand) {
264 if(!m_horizonalRubberBand) {
274 m_rubberBandOrigin.setX(rect.left());
265 m_rubberBandOrigin.setX(rect.left());
275 width= rect.width();
266 width= rect.width();
276 }
267 }
277 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
268 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
278 }
269 }
279 else {
270 else {
280 QGraphicsView::mouseMoveEvent(event);
271 QGraphicsView::mouseMoveEvent(event);
281 }
272 }
282 }
273 }
283
274
284 /*!
275 /*!
285 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
276 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
286 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
277 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
287 */
278 */
288 void QChartView::mouseReleaseEvent(QMouseEvent *event)
279 void QChartView::mouseReleaseEvent(QMouseEvent *event)
289 {
280 {
290 if(m_rubberBand) {
281 if(m_rubberBand) {
291 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
282 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
292 m_rubberBand->hide();
283 m_rubberBand->hide();
293 QRect rect = m_rubberBand->geometry();
284 QRect rect = m_rubberBand->geometry();
294 m_chart->zoomIn(rect);
285 m_chart->zoomIn(rect);
295 event->accept();
286 event->accept();
296 }
287 }
297
288
298 if(event->button()==Qt::RightButton)
289 if(event->button()==Qt::RightButton)
299 m_chart->zoomReset();
290 m_chart->zoomReset();
300 }
291 }
301 else {
292 else {
302 QGraphicsView::mouseReleaseEvent(event);
293 QGraphicsView::mouseReleaseEvent(event);
303 }
294 }
304 }
295 }
305
296
306 /*!
297 /*!
307 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
298 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
308 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
299 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
309 */
300 */
310 void QChartView::keyPressEvent(QKeyEvent *event)
301 void QChartView::keyPressEvent(QKeyEvent *event)
311 {
302 {
312 switch (event->key()) {
303 switch (event->key()) {
313 case Qt::Key_Plus:
304 case Qt::Key_Plus:
314 zoomIn();
305 zoomIn();
315 break;
306 break;
316 case Qt::Key_Minus:
307 case Qt::Key_Minus:
317 zoomOut();
308 zoomOut();
318 break;
309 break;
319 default:
310 default:
320 QGraphicsView::keyPressEvent(event);
311 QGraphicsView::keyPressEvent(event);
321 break;
312 break;
322 }
313 }
323 }
314 }
324
315
325 /*!
316 /*!
326 Sets the \a theme used by the chart for rendering the graphical representation of the data
317 Sets the \a theme used by the chart for rendering the graphical representation of the data
327 \sa QChart::ChartTheme, chartTheme()
318 \sa QChart::ChartTheme, chartTheme()
328 */
319 */
329 void QChartView::setChartTheme(QChart::ChartTheme theme)
320 void QChartView::setChartTheme(QChart::ChartTheme theme)
330 {
321 {
331 m_chart->setChartTheme(theme);
322 m_chart->setChartTheme(theme);
332 }
323 }
333
324
334 /*!
325 /*!
335 Returns the theme enum used by the chart.
326 Returns the theme enum used by the chart.
336 \sa setChartTheme()
327 \sa setChartTheme()
337 */
328 */
338 QChart::ChartTheme QChartView::chartTheme() const
329 QChart::ChartTheme QChartView::chartTheme() const
339 {
330 {
340 return m_chart->chartTheme();
331 return m_chart->chartTheme();
341 }
332 }
342
333
343 /*!
334 /*!
344 Returns the pointer to the x axis object of the chart
335 Returns the pointer to the x axis object of the chart
345 */
336 */
346 QChartAxis* QChartView::axisX() const
337 QChartAxis* QChartView::axisX() const
347 {
338 {
348 return m_chart->axisX();
339 return m_chart->axisX();
349 }
340 }
350
341
351 /*!
342 /*!
352 Returns the pointer to the y axis object of the chart
343 Returns the pointer to the y axis object of the chart
353 */
344 */
354 QChartAxis* QChartView::axisY() const
345 QChartAxis* QChartView::axisY() const
355 {
346 {
356 return m_chart->axisY();
347 return m_chart->axisY();
357 }
348 }
358
349
359 /*!
350 /*!
360 Returns the pointer to legend object of the chart
351 Returns the pointer to legend object of the chart
361 */
352 */
362 QLegend* QChartView::legend() const
353 QLegend* QChartView::legend() const
363 {
354 {
364 return m_chart->legend();
355 return m_chart->legend();
365 }
356 }
366
357
367 /*!
358 /*!
368 Sets animation \a options for the chart
359 Sets animation \a options for the chart
369 */
360 */
370 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
361 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
371 {
362 {
372 m_chart->setAnimationOptions(options);
363 m_chart->setAnimationOptions(options);
373 }
364 }
374
365
375 /*!
366 /*!
376 Returns animation options for the chart
367 Returns animation options for the chart
377 */
368 */
378 QChart::AnimationOptions QChartView::animationOptions() const
369 QChart::AnimationOptions QChartView::animationOptions() const
379 {
370 {
380 return m_chart->animationOptions();
371 return m_chart->animationOptions();
381 }
372 }
382
373
383 void QChartView::scrollLeft()
374 void QChartView::scrollLeft()
384 {
375 {
385 m_chart->scrollLeft();
376 m_chart->scrollLeft();
386 }
377 }
387
378
388 void QChartView::scrollRight()
379 void QChartView::scrollRight()
389 {
380 {
390 m_chart->scrollRight();
381 m_chart->scrollRight();
391 }
382 }
392
383
393 void QChartView::scrollUp()
384 void QChartView::scrollUp()
394 {
385 {
395 m_chart->scrollUp();
386 m_chart->scrollUp();
396 }
387 }
397
388
398 void QChartView::scrollDown()
389 void QChartView::scrollDown()
399 {
390 {
400 m_chart->scrollDown();
391 m_chart->scrollDown();
401 }
392 }
402
393
403
394
404 #include "moc_qchartview.cpp"
395 #include "moc_qchartview.cpp"
405
396
406 QTCOMMERCIALCHART_END_NAMESPACE
397 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,83 +1,82
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartaxis.h"
5 #include "qchartaxis.h"
6 #include "qseries.h"
6 #include "qseries.h"
7 #include "qchart.h"
7 #include "qchart.h"
8 #include <QGraphicsView>
8 #include <QGraphicsView>
9
9
10 class QGraphicsScene;
10 class QGraphicsScene;
11 class QRubberBand;
11 class QRubberBand;
12
12
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
14
15 class QChart;
15 class QChart;
16
16
17 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
17 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
18 {
18 {
19 Q_OBJECT
19 Q_OBJECT
20
20
21 public:
21 public:
22 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
22 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
23
23
24 explicit QChartView(QWidget *parent = 0);
24 explicit QChartView(QWidget *parent = 0);
25 ~QChartView();
25 ~QChartView();
26
26
27 //implement from QWidget
27 //implement from QWidget
28 void resizeEvent(QResizeEvent *event);
28 void resizeEvent(QResizeEvent *event);
29
29
30 void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
30 void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
31 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
31 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
32 void removeAllSeries(); // deletes series and axis
32 void removeAllSeries(); // deletes series and axis
33 int margin() const;
34
33
35 void setChartTitle(const QString& title);
34 void setChartTitle(const QString& title);
36 QString chartTitle() const;
35 QString chartTitle() const;
37 void setChartTitleFont(const QFont& font);
36 void setChartTitleFont(const QFont& font);
38 void setChartTitleBrush(const QBrush &brush);
37 void setChartTitleBrush(const QBrush &brush);
39 QBrush chartTitleBrush();
38 QBrush chartTitleBrush();
40 void setChartBackgroundBrush(const QBrush& brush);
39 void setChartBackgroundBrush(const QBrush& brush);
41 void setChartBackgroundPen(const QPen& pen);
40 void setChartBackgroundPen(const QPen& pen);
42
41
43 void zoomIn();
42 void zoomIn();
44 void zoomIn(const QRect& rect);
43 void zoomIn(const QRect& rect);
45 void zoomOut();
44 void zoomOut();
46 void scrollLeft();
45 void scrollLeft();
47 void scrollRight();
46 void scrollRight();
48 void scrollUp();
47 void scrollUp();
49 void scrollDown();
48 void scrollDown();
50
49
51 void setRubberBandPolicy(const RubberBandPolicy );
50 void setRubberBandPolicy(const RubberBandPolicy );
52 RubberBandPolicy rubberBandPolicy() const;
51 RubberBandPolicy rubberBandPolicy() const;
53
52
54 void setChartTheme(QChart::ChartTheme theme);
53 void setChartTheme(QChart::ChartTheme theme);
55 QChart::ChartTheme chartTheme() const;
54 QChart::ChartTheme chartTheme() const;
56
55
57 void setAnimationOptions(QChart::AnimationOptions options);
56 void setAnimationOptions(QChart::AnimationOptions options);
58 QChart::AnimationOptions animationOptions() const;
57 QChart::AnimationOptions animationOptions() const;
59
58
60 QChartAxis* axisX() const;
59 QChartAxis* axisX() const;
61 QChartAxis* axisY() const;
60 QChartAxis* axisY() const;
62
61
63 QLegend* legend() const;
62 QLegend* legend() const;
64
63
65 protected:
64 protected:
66 void mousePressEvent(QMouseEvent *event);
65 void mousePressEvent(QMouseEvent *event);
67 void mouseMoveEvent(QMouseEvent *event);
66 void mouseMoveEvent(QMouseEvent *event);
68 void mouseReleaseEvent(QMouseEvent *event);
67 void mouseReleaseEvent(QMouseEvent *event);
69 void keyPressEvent(QKeyEvent *event);
68 void keyPressEvent(QKeyEvent *event);
70
69
71 private:
70 private:
72 QGraphicsScene *m_scene;
71 QGraphicsScene *m_scene;
73 QChart* m_chart;
72 QChart* m_chart;
74 QPoint m_rubberBandOrigin;
73 QPoint m_rubberBandOrigin;
75 QRubberBand* m_rubberBand;
74 QRubberBand* m_rubberBand;
76 bool m_verticalRubberBand;
75 bool m_verticalRubberBand;
77 bool m_horizonalRubberBand;
76 bool m_horizonalRubberBand;
78 Q_DISABLE_COPY(QChartView)
77 Q_DISABLE_COPY(QChartView)
79 };
78 };
80
79
81 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
82
81
83 #endif // QCHARTWIDGET_H
82 #endif // QCHARTWIDGET_H
@@ -1,142 +1,144
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 TARGET = QtCommercialChart
2 TARGET = QtCommercialChart
3 DESTDIR = $$CHART_BUILD_LIB_DIR
3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 TEMPLATE = lib
4 TEMPLATE = lib
5 QT += core \
5 QT += core \
6 gui
6 gui
7 win32-msvc*: LIBS += User32.lib
7 win32-msvc*: LIBS += User32.lib
8 CONFIG += debug_and_release
8 CONFIG += debug_and_release
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
10 SOURCES += \
10 SOURCES += \
11 chartdataset.cpp \
11 chartdataset.cpp \
12 chartpresenter.cpp \
12 chartpresenter.cpp \
13 charttheme.cpp \
13 charttheme.cpp \
14 domain.cpp \
14 domain.cpp \
15 qchart.cpp \
15 qchart.cpp \
16 qchartview.cpp \
16 qchartview.cpp \
17 qseries.cpp \
17 qseries.cpp \
18 qlegend.cpp \
18 qlegend.cpp \
19 legendmarker.cpp
19 legendmarker.cpp \
20 chartbackground.cpp
20 PRIVATE_HEADERS += \
21 PRIVATE_HEADERS += \
21 chartdataset_p.h \
22 chartdataset_p.h \
22 chartitem_p.h \
23 chartitem_p.h \
23 chartpresenter_p.h \
24 chartpresenter_p.h \
24 charttheme_p.h \
25 charttheme_p.h \
25 domain_p.h \
26 domain_p.h \
26 legendmarker_p.h
27 legendmarker_p.h \
28 chartbackground_p.h
27 PUBLIC_HEADERS += \
29 PUBLIC_HEADERS += \
28 qchart.h \
30 qchart.h \
29 qchartglobal.h \
31 qchartglobal.h \
30 qseries.h \
32 qseries.h \
31 qchartview.h \
33 qchartview.h \
32 qlegend.h
34 qlegend.h
33
35
34 include(animations/animations.pri)
36 include(animations/animations.pri)
35 include(axis/axis.pri)
37 include(axis/axis.pri)
36 include(xychart/xychart.pri)
38 include(xychart/xychart.pri)
37 include(linechart/linechart.pri)
39 include(linechart/linechart.pri)
38 include(areachart/areachart.pri)
40 include(areachart/areachart.pri)
39 include(barchart/barchart.pri)
41 include(barchart/barchart.pri)
40 include(piechart/piechart.pri)
42 include(piechart/piechart.pri)
41 include(scatterseries/scatter.pri)
43 include(scatterseries/scatter.pri)
42 include(splinechart/splinechart.pri)
44 include(splinechart/splinechart.pri)
43
45
44 THEMES += themes/chartthemedefault_p.h \
46 THEMES += themes/chartthemedefault_p.h \
45 themes/chartthemeicy_p.h \
47 themes/chartthemeicy_p.h \
46 themes/chartthemegrayscale_p.h \
48 themes/chartthemegrayscale_p.h \
47 themes/chartthemescientific_p.h \
49 themes/chartthemescientific_p.h \
48 themes/chartthemevanilla_p.h \
50 themes/chartthemevanilla_p.h \
49 themes/chartthemebluecerulean_p.h \
51 themes/chartthemebluecerulean_p.h \
50 themes/chartthemelight_p.h
52 themes/chartthemelight_p.h
51
53
52 HEADERS += $$PUBLIC_HEADERS
54 HEADERS += $$PUBLIC_HEADERS
53 HEADERS += $$PRIVATE_HEADERS
55 HEADERS += $$PRIVATE_HEADERS
54 HEADERS += $$THEMES
56 HEADERS += $$THEMES
55 INCLUDEPATH += linechart \
57 INCLUDEPATH += linechart \
56 barchart \
58 barchart \
57 themes \
59 themes \
58 .
60 .
59 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
61 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
60 MOC_DIR = $$CHART_BUILD_DIR/lib
62 MOC_DIR = $$CHART_BUILD_DIR/lib
61 UI_DIR = $$CHART_BUILD_DIR/lib
63 UI_DIR = $$CHART_BUILD_DIR/lib
62 RCC_DIR = $$CHART_BUILD_DIR/lib
64 RCC_DIR = $$CHART_BUILD_DIR/lib
63 DEFINES += QTCOMMERCIALCHART_LIBRARY
65 DEFINES += QTCOMMERCIALCHART_LIBRARY
64
66
65 #qt public headers
67 #qt public headers
66 #this is very primitive and lame parser , TODO: make perl script insted
68 #this is very primitive and lame parser , TODO: make perl script insted
67 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR)
69 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR)
68 {
70 {
69 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
71 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
70 }
72 }
71
73
72 for(file, PUBLIC_HEADERS) {
74 for(file, PUBLIC_HEADERS) {
73 name = $$split(file,'/')
75 name = $$split(file,'/')
74 name = $$last(name)
76 name = $$last(name)
75 class = "$$cat($$file)"
77 class = "$$cat($$file)"
76 class = $$find(class,class)
78 class = $$find(class,class)
77 !isEmpty(class){
79 !isEmpty(class){
78 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
80 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
79 class = $$member(class,1)
81 class = $$member(class,1)
80 class = $$split(class,' ')
82 class = $$split(class,' ')
81 class = $$replace(class,' ','')
83 class = $$replace(class,' ','')
82 class = $$member(class,0)
84 class = $$member(class,0)
83 win32:{
85 win32:{
84 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
86 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
85 }else{
87 }else{
86 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
88 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
87 }
89 }
88 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
90 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
89 system($$command)
91 system($$command)
90 }
92 }
91 }
93 }
92
94
93 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
95 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
94 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
96 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
95
97
96 target.path = $$[QT_INSTALL_LIBS]
98 target.path = $$[QT_INSTALL_LIBS]
97 INSTALLS += target public_headers
99 INSTALLS += target public_headers
98
100
99 install_build_public_headers.name = build_public_headers
101 install_build_public_headers.name = build_public_headers
100 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
102 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
101 install_build_public_headers.input = PUBLIC_HEADERS
103 install_build_public_headers.input = PUBLIC_HEADERS
102 install_build_public_headers.commands = $$QMAKE_COPY \
104 install_build_public_headers.commands = $$QMAKE_COPY \
103 ${QMAKE_FILE_NAME} \
105 ${QMAKE_FILE_NAME} \
104 $$CHART_BUILD_PUBLIC_HEADER_DIR
106 $$CHART_BUILD_PUBLIC_HEADER_DIR
105 install_build_public_headers.CONFIG += target_predeps \
107 install_build_public_headers.CONFIG += target_predeps \
106 no_link
108 no_link
107
109
108 install_build_private_headers.name = buld_private_headers
110 install_build_private_headers.name = buld_private_headers
109 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
111 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
110 install_build_private_headers.input = PRIVATE_HEADERS
112 install_build_private_headers.input = PRIVATE_HEADERS
111 install_build_private_headers.commands = $$QMAKE_COPY \
113 install_build_private_headers.commands = $$QMAKE_COPY \
112 ${QMAKE_FILE_NAME} \
114 ${QMAKE_FILE_NAME} \
113 $$CHART_BUILD_PRIVATE_HEADER_DIR
115 $$CHART_BUILD_PRIVATE_HEADER_DIR
114 install_build_private_headers.CONFIG += target_predeps \
116 install_build_private_headers.CONFIG += target_predeps \
115 no_link
117 no_link
116
118
117 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
119 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
118 install_build_private_headers \
120 install_build_private_headers \
119
121
120 chartversion.target = qchartversion_p.h
122 chartversion.target = qchartversion_p.h
121 chartversion.commands = @echo \
123 chartversion.commands = @echo \
122 "build_time" \
124 "build_time" \
123 > \
125 > \
124 $$chartversion.target;
126 $$chartversion.target;
125 chartversion.depends = $$HEADERS \
127 chartversion.depends = $$HEADERS \
126 $$SOURCES
128 $$SOURCES
127 PRE_TARGETDEPS += qchartversion_p.h
129 PRE_TARGETDEPS += qchartversion_p.h
128 QMAKE_CLEAN += qchartversion_p.h
130 QMAKE_CLEAN += qchartversion_p.h
129 QMAKE_EXTRA_TARGETS += chartversion
131 QMAKE_EXTRA_TARGETS += chartversion
130 unix:QMAKE_DISTCLEAN += -r \
132 unix:QMAKE_DISTCLEAN += -r \
131 $$CHART_BUILD_HEADER_DIR \
133 $$CHART_BUILD_HEADER_DIR \
132 $$CHART_BUILD_LIB_DIR
134 $$CHART_BUILD_LIB_DIR
133 win32:QMAKE_DISTCLEAN += /Q \
135 win32:QMAKE_DISTCLEAN += /Q \
134 $$CHART_BUILD_HEADER_DIR \
136 $$CHART_BUILD_HEADER_DIR \
135 $$CHART_BUILD_LIB_DIR
137 $$CHART_BUILD_LIB_DIR
136
138
137 # treat warnings as errors
139 # treat warnings as errors
138 win32-msvc*: {
140 win32-msvc*: {
139 QMAKE_CXXFLAGS += /WX
141 QMAKE_CXXFLAGS += /WX
140 } else {
142 } else {
141 QMAKE_CXXFLAGS += -Werror
143 QMAKE_CXXFLAGS += -Werror
142 }
144 }
General Comments 0
You need to be logged in to leave comments. Login now