@@ -1,65 +1,70 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chart.h" |
|
22 | 22 | #include <QAbstractAxis> |
|
23 | 23 | #include <QSplineSeries> |
|
24 | #include <QValuesAxis> | |
|
24 | 25 | #include <QTime> |
|
26 | #include <QDebug> | |
|
25 | 27 | |
|
26 | 28 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
27 | 29 | :QChart(parent, wFlags), |
|
28 |
m_step( |
|
|
29 | m_x(0), | |
|
30 | m_step(0), | |
|
31 | m_axis(new QValuesAxis), | |
|
32 | m_x(5), | |
|
30 | 33 | m_y(1) |
|
31 | 34 | { |
|
32 | 35 | qsrand((uint) QTime::currentTime().msec()); |
|
33 | 36 | |
|
34 | 37 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); |
|
35 | 38 | m_timer.setInterval(1000); |
|
36 | 39 | |
|
37 | 40 | m_series = new QSplineSeries(this); |
|
38 | 41 | QPen green(Qt::red); |
|
39 | 42 | green.setWidth(3); |
|
40 | 43 | m_series->setPen(green); |
|
41 | 44 | m_series->append(m_x, m_y); |
|
42 | 45 | |
|
43 | 46 | addSeries(m_series); |
|
44 | 47 | createDefaultAxes(); |
|
45 | ||
|
46 |
axis |
|
|
47 |
axisX()->setRange( |
|
|
48 | //TODO:axisX()->setTicksCount(11); | |
|
48 | setAxisX(m_axis,m_series); | |
|
49 | m_axis->setTicksCount(5); | |
|
50 | axisX()->setRange(0, 10); | |
|
51 | axisY()->setRange(-5, 10); | |
|
49 | 52 | |
|
50 | 53 | m_timer.start(); |
|
51 | 54 | } |
|
52 | 55 | |
|
53 | 56 | Chart::~Chart() |
|
54 | 57 | { |
|
55 | 58 | |
|
56 | 59 | } |
|
57 | 60 | |
|
58 | 61 | void Chart::handleTimeout() |
|
59 | 62 | { |
|
60 | m_x += m_step; | |
|
63 | qreal x = plotArea().width()/m_axis->ticksCount(); | |
|
64 | qreal y =(m_axis->max() - m_axis->min())/m_axis->ticksCount(); | |
|
65 | m_x += y; | |
|
61 | 66 | m_y = qrand() % 5 - 2.5; |
|
62 | 67 | m_series->append(m_x, m_y); |
|
63 |
scroll( |
|
|
68 | scroll(x,0); | |
|
64 | 69 | if(m_x==100) m_timer.stop(); |
|
65 | 70 | } |
@@ -1,54 +1,56 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef CHART_H_ |
|
22 | 22 | #define CHART_H_ |
|
23 | 23 | |
|
24 | 24 | #include <QChart> |
|
25 | 25 | #include <QTimer> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | class QSplineSeries; |
|
29 | class QValuesAxis; | |
|
29 | 30 | QTCOMMERCIALCHART_END_NAMESPACE |
|
30 | 31 | |
|
31 | 32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | 33 | |
|
33 | 34 | //![1] |
|
34 | 35 | class Chart: public QChart |
|
35 | 36 | { |
|
36 | 37 | Q_OBJECT |
|
37 | 38 | public: |
|
38 | 39 | Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
39 | 40 | virtual ~Chart(); |
|
40 | 41 | |
|
41 | 42 | public slots: |
|
42 | 43 | void handleTimeout(); |
|
43 | 44 | |
|
44 | 45 | private: |
|
45 | 46 | QTimer m_timer; |
|
46 | 47 | QSplineSeries* m_series; |
|
47 | 48 | QStringList m_titles; |
|
49 | QValuesAxis* m_axis; | |
|
48 | 50 | qreal m_step; |
|
49 | 51 | qreal m_x; |
|
50 | 52 | qreal m_y; |
|
51 | 53 | }; |
|
52 | 54 | //![1] |
|
53 | 55 | |
|
54 | 56 | #endif /* CHART_H_ */ |
@@ -1,474 +1,474 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | #include "chartpresenter_p.h" |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "qabstractaxis.h" |
|
24 | 24 | #include "qabstractaxis_p.h" |
|
25 | 25 | #include "chartdataset_p.h" |
|
26 | 26 | #include "charttheme_p.h" |
|
27 | 27 | #include "chartanimator_p.h" |
|
28 | 28 | #include "chartanimation_p.h" |
|
29 | 29 | #include "qabstractseries_p.h" |
|
30 | 30 | #include "qareaseries.h" |
|
31 | 31 | #include "chartaxis_p.h" |
|
32 | 32 | //#include "chartaxisx_p.h" |
|
33 | 33 | //#include "chartaxisy_p.h" |
|
34 | 34 | #include "areachartitem_p.h" |
|
35 | 35 | #include "chartbackground_p.h" |
|
36 | 36 | #include "chartlayout_p.h" |
|
37 | 37 | #include <QTimer> |
|
38 | 38 | |
|
39 | 39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
42 | 42 | m_chart(chart), |
|
43 | 43 | m_animator(0), |
|
44 | 44 | m_dataset(dataset), |
|
45 | 45 | m_chartTheme(0), |
|
46 | 46 | m_options(QChart::NoAnimation), |
|
47 | 47 | m_state(ShowState), |
|
48 | 48 | m_layout(new ChartLayout(this)), |
|
49 | 49 | m_backgroundItem(0), |
|
50 | 50 | m_titleItem(0) |
|
51 | 51 | { |
|
52 | 52 | |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | ChartPresenter::~ChartPresenter() |
|
56 | 56 | { |
|
57 | 57 | delete m_chartTheme; |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void ChartPresenter::setGeometry(const QRectF& rect) |
|
61 | 61 | { |
|
62 | 62 | |
|
63 | 63 | Q_ASSERT(rect.isValid()); |
|
64 | 64 | |
|
65 | 65 | if(m_rect!=rect) { |
|
66 | 66 | m_rect=rect; |
|
67 | 67 | emit geometryChanged(m_rect); |
|
68 | 68 | } |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) |
|
72 | 72 | { |
|
73 | 73 | ChartAxis* item = axis->d_ptr->createGraphics(this); |
|
74 | 74 | item->setDomain(domain); |
|
75 | 75 | |
|
76 | 76 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
77 | 77 | item->setAnimator(m_animator); |
|
78 | 78 | item->setAnimation(new AxisAnimation(item)); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | if(item->axisType()==ChartAxis::X_AXIS){ |
|
82 | 82 | m_chartTheme->decorate(axis,true); |
|
83 | 83 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
84 | 84 | //initialize |
|
85 | 85 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
86 | 86 | |
|
87 | 87 | } |
|
88 | 88 | else{ |
|
89 | 89 | m_chartTheme->decorate(axis,false); |
|
90 | 90 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
91 | 91 | //initialize |
|
92 | 92 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
96 | 96 | QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); |
|
97 | 97 | //initialize |
|
98 | 98 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
99 | 99 | //reload visiblity |
|
100 | 100 | m_axisItems.insert(axis, item); |
|
101 | 101 | selectVisibleAxis(); |
|
102 | 102 | |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) |
|
106 | 106 | { |
|
107 | 107 | ChartAxis* item = m_axisItems.take(axis); |
|
108 | 108 | Q_ASSERT(item); |
|
109 | 109 | selectVisibleAxis(); |
|
110 | 110 | if(m_animator) m_animator->removeAnimation(item); |
|
111 | 111 | item->deleteLater(); |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) |
|
116 | 116 | { |
|
117 | 117 | Chart *item = series->d_ptr->createGraphics(this); |
|
118 | 118 | Q_ASSERT(item); |
|
119 | 119 | item->setDomain(domain); |
|
120 | 120 | |
|
121 | 121 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
122 | 122 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
123 | 123 | //initialize |
|
124 | 124 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
125 | 125 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
126 | 126 | m_chartItems.insert(series,item); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) |
|
130 | 130 | { |
|
131 | 131 | Chart* item = m_chartItems.take(series); |
|
132 | 132 | Q_ASSERT(item); |
|
133 | 133 | if(m_animator) { |
|
134 | 134 | //small hack to handle area animations |
|
135 | 135 | if(series->type() == QAbstractSeries::SeriesTypeArea){ |
|
136 | 136 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
137 | 137 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
138 | 138 | m_animator->removeAnimation(area->upperLineItem()); |
|
139 | 139 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
140 | 140 | }else |
|
141 | 141 | m_animator->removeAnimation(item); |
|
142 | 142 | } |
|
143 | 143 | item->deleteLater(); |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | void ChartPresenter::selectVisibleAxis() |
|
147 | 147 | { |
|
148 | 148 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
149 | 149 | |
|
150 | 150 | while (i.hasNext()) { |
|
151 | 151 | i.next(); |
|
152 | 152 | i.key()->hide(); |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | i.toFront(); |
|
156 | 156 | |
|
157 | 157 | bool axisX=false; |
|
158 | 158 | bool axisY=false; |
|
159 | 159 | |
|
160 | 160 | while (i.hasNext()) { |
|
161 | 161 | i.next(); |
|
162 | 162 | if(i.key()->d_ptr->m_orientation==Qt::Vertical && !axisY) { |
|
163 | 163 | axisY=true; |
|
164 | 164 | i.key()->show(); |
|
165 | 165 | } |
|
166 | 166 | if(i.key()->d_ptr->m_orientation==Qt::Horizontal && !axisX) { |
|
167 | 167 | axisX=true; |
|
168 | 168 | i.key()->show(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | } |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | |
|
175 | 175 | void ChartPresenter::handleAxisVisibleChanged(bool visible) |
|
176 | 176 | { |
|
177 | 177 | QAbstractAxis* axis = static_cast<QAbstractAxis*> (sender()); |
|
178 | 178 | Q_ASSERT(axis); |
|
179 | 179 | if(visible){ |
|
180 | 180 | |
|
181 | 181 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
182 | 182 | |
|
183 | 183 | while (i.hasNext()) { |
|
184 | 184 | i.next(); |
|
185 | 185 | if(i.key()==axis) { |
|
186 | 186 | continue; |
|
187 | 187 | } |
|
188 | 188 | if(i.key()->d_ptr->m_orientation==axis->d_ptr->m_orientation) { |
|
189 | 189 | i.key()->setVisible(false); |
|
190 | 190 | } |
|
191 | 191 | } |
|
192 | 192 | } |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
196 | 196 | { |
|
197 | 197 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
198 | 198 | delete m_chartTheme; |
|
199 | 199 | m_chartTheme = ChartTheme::createTheme(theme); |
|
200 | 200 | m_chartTheme->setForced(force); |
|
201 | 201 | m_chartTheme->decorate(m_chart); |
|
202 | 202 | m_chartTheme->decorate(m_chart->legend()); |
|
203 | 203 | resetAllElements(); |
|
204 | 204 | |
|
205 | 205 | // We do not want "force" to stay on. |
|
206 | 206 | // Bar/pie are calling decorate when adding/removing slices/bars which means |
|
207 | 207 | // that to preserve users colors "force" must not be on. |
|
208 | 208 | m_chartTheme->setForced(false); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | QChart::ChartTheme ChartPresenter::theme() |
|
212 | 212 | { |
|
213 | 213 | return m_chartTheme->id(); |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
217 | 217 | { |
|
218 | 218 | if(m_options!=options) { |
|
219 | 219 | |
|
220 | 220 | m_options=options; |
|
221 | 221 | |
|
222 | 222 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
223 | 223 | m_animator= new ChartAnimator(this); |
|
224 | 224 | } |
|
225 | 225 | resetAllElements(); |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | void ChartPresenter::resetAllElements() |
|
231 | 231 | { |
|
232 | 232 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
233 | 233 | while (i.hasNext()) { |
|
234 | 234 | i.next(); |
|
235 | 235 | Domain* domain = i.value()->domain(); |
|
236 | 236 | QAbstractAxis* axis = i.key(); |
|
237 | 237 | handleAxisRemoved(axis); |
|
238 | 238 | handleAxisAdded(axis,domain); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems); |
|
242 | 242 | while (j.hasNext()) { |
|
243 | 243 | j.next(); |
|
244 | 244 | Domain* domain = j.value()->domain(); |
|
245 | 245 | QAbstractSeries* series = j.key(); |
|
246 | 246 | handleSeriesRemoved(series); |
|
247 | 247 | handleSeriesAdded(series,domain); |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void ChartPresenter::zoomIn(qreal factor) |
|
252 | 252 | { |
|
253 | 253 | QRectF rect = geometry(); |
|
254 | 254 | rect.setWidth(rect.width()/factor); |
|
255 | 255 | rect.setHeight(rect.height()/factor); |
|
256 | 256 | rect.moveCenter(geometry().center()); |
|
257 | 257 | zoomIn(rect); |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
261 | 261 | { |
|
262 | 262 | QRectF r = rect.normalized(); |
|
263 | 263 | r.translate(-geometry().topLeft()); |
|
264 | 264 | if (!r.isValid()) |
|
265 | 265 | return; |
|
266 | 266 | |
|
267 | 267 | m_state = ZoomInState; |
|
268 | 268 | m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
269 | 269 | m_dataset->zoomInDomain(r,geometry().size()); |
|
270 | 270 | m_state = ShowState; |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void ChartPresenter::zoomOut(qreal factor) |
|
274 | 274 | { |
|
275 | 275 | m_state = ZoomOutState; |
|
276 | 276 | |
|
277 | 277 | QRectF chartRect; |
|
278 | 278 | chartRect.setSize(geometry().size()); |
|
279 | 279 | |
|
280 | 280 | QRectF rect; |
|
281 | 281 | rect.setSize(chartRect.size()/factor); |
|
282 | 282 | rect.moveCenter(chartRect.center()); |
|
283 | 283 | if (!rect.isValid()) |
|
284 | 284 | return; |
|
285 | 285 | m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height()); |
|
286 | 286 | m_dataset->zoomOutDomain(rect, chartRect.size()); |
|
287 | 287 | m_state = ShowState; |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | void ChartPresenter::scroll(qreal dx,qreal dy) |
|
291 | 291 | { |
|
292 | 292 | if(dx<0) m_state=ScrollLeftState; |
|
293 | 293 | if(dx>0) m_state=ScrollRightState; |
|
294 | 294 | if(dy<0) m_state=ScrollUpState; |
|
295 | 295 | if(dy>0) m_state=ScrollDownState; |
|
296 | 296 | |
|
297 | 297 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
298 | 298 | m_state = ShowState; |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
302 | 302 | { |
|
303 | 303 | return m_options; |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | void ChartPresenter::createBackgroundItem() |
|
307 | 307 | { |
|
308 | 308 | if (!m_backgroundItem) { |
|
309 | 309 | m_backgroundItem = new ChartBackground(rootItem()); |
|
310 | 310 | m_backgroundItem->setPen(Qt::NoPen); |
|
311 | 311 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
312 | 312 | } |
|
313 | 313 | } |
|
314 | 314 | |
|
315 | 315 | void ChartPresenter::createTitleItem() |
|
316 | 316 | { |
|
317 | 317 | if (!m_titleItem) { |
|
318 | 318 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); |
|
319 | 319 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
320 | 320 | } |
|
321 | 321 | } |
|
322 | 322 | |
|
323 | 323 | |
|
324 | 324 | void ChartPresenter::handleAnimationFinished() |
|
325 | 325 | { |
|
326 | 326 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); |
|
327 | 327 | if(m_animations.empty()) emit animationsFinished(); |
|
328 | 328 | } |
|
329 | 329 | |
|
330 | 330 | void ChartPresenter::startAnimation(ChartAnimation* animation) |
|
331 | 331 | { |
|
332 | 332 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
333 | 333 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); |
|
334 | 334 | if(!m_animations.isEmpty()){ |
|
335 | 335 | m_animations.append(animation); |
|
336 | 336 | } |
|
337 | 337 | QTimer::singleShot(0, animation, SLOT(start())); |
|
338 | 338 | } |
|
339 | 339 | |
|
340 | 340 | QGraphicsRectItem* ChartPresenter::backgroundItem() |
|
341 | 341 | { |
|
342 | 342 | return m_backgroundItem; |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) |
|
346 | 346 | { |
|
347 | 347 | createBackgroundItem(); |
|
348 | 348 | m_backgroundItem->setBrush(brush); |
|
349 | 349 | m_layout->invalidate(); |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | QBrush ChartPresenter::backgroundBrush() const |
|
353 | 353 | { |
|
354 | 354 | if (!m_backgroundItem) return QBrush(); |
|
355 | 355 | return m_backgroundItem->brush(); |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | void ChartPresenter::setBackgroundPen(const QPen& pen) |
|
359 | 359 | { |
|
360 | 360 | createBackgroundItem(); |
|
361 | 361 | m_backgroundItem->setPen(pen); |
|
362 | 362 | m_layout->invalidate(); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | QPen ChartPresenter::backgroundPen() const |
|
366 | 366 | { |
|
367 | 367 | if (!m_backgroundItem) return QPen(); |
|
368 | 368 | return m_backgroundItem->pen(); |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | QGraphicsItem* ChartPresenter::titleItem() |
|
372 | 372 | { |
|
373 | 373 | return m_titleItem; |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | void ChartPresenter::setTitle(const QString& title) |
|
377 | 377 | { |
|
378 | 378 | createTitleItem(); |
|
379 | 379 | m_titleItem->setText(title); |
|
380 | 380 | m_layout->invalidate(); |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | QString ChartPresenter::title() const |
|
384 | 384 | { |
|
385 | 385 | if (!m_titleItem) return QString(); |
|
386 | 386 | return m_titleItem->text(); |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | void ChartPresenter::setTitleFont(const QFont& font) |
|
390 | 390 | { |
|
391 | 391 | createTitleItem(); |
|
392 | 392 | m_titleItem->setFont(font); |
|
393 | 393 | m_layout->invalidate(); |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | QFont ChartPresenter::titleFont() const |
|
397 | 397 | { |
|
398 | 398 | if (!m_titleItem) return QFont(); |
|
399 | 399 | return m_titleItem->font(); |
|
400 | 400 | } |
|
401 | 401 | |
|
402 | 402 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
403 | 403 | { |
|
404 | 404 | createTitleItem(); |
|
405 | 405 | m_titleItem->setBrush(brush); |
|
406 | 406 | m_layout->invalidate(); |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | QBrush ChartPresenter::titleBrush() const |
|
410 | 410 | { |
|
411 | 411 | if (!m_titleItem) return QBrush(); |
|
412 | 412 | return m_titleItem->brush(); |
|
413 | 413 | } |
|
414 | 414 | |
|
415 | 415 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
416 | 416 | { |
|
417 | 417 | createBackgroundItem(); |
|
418 | 418 | m_backgroundItem->setVisible(visible); |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | |
|
422 | 422 | bool ChartPresenter::isBackgroundVisible() const |
|
423 | 423 | { |
|
424 | 424 | if (!m_backgroundItem) return false; |
|
425 | 425 | return m_backgroundItem->isVisible(); |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
429 | 429 | { |
|
430 | 430 | createBackgroundItem(); |
|
431 | 431 | m_backgroundItem->setDropShadowEnabled(enabled); |
|
432 | 432 | } |
|
433 | 433 | |
|
434 | 434 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
435 | 435 | { |
|
436 | 436 | if (!m_backgroundItem) return false; |
|
437 | 437 | return m_backgroundItem->isDropShadowEnabled(); |
|
438 | 438 | } |
|
439 | 439 | |
|
440 | 440 | |
|
441 | 441 | QGraphicsLayout* ChartPresenter::layout() |
|
442 | 442 | { |
|
443 | 443 | return m_layout; |
|
444 | 444 | } |
|
445 | 445 | |
|
446 | 446 | void ChartPresenter::setMarginsMinimum(const QRectF& margins) |
|
447 | 447 | { |
|
448 | 448 | Q_UNUSED(margins); |
|
449 | 449 | // m_layout->setMarginsMinimum(margins); |
|
450 | 450 | } |
|
451 | 451 | |
|
452 | 452 | QRectF ChartPresenter::margins() const |
|
453 | 453 | { |
|
454 |
return |
|
|
454 | return m_layout->margins(); | |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | 457 | QLegend* ChartPresenter::legend() |
|
458 | 458 | { |
|
459 | 459 | return m_chart->legend(); |
|
460 | 460 | } |
|
461 | 461 | |
|
462 | 462 | QList<ChartAxis*> ChartPresenter::axisItems() const |
|
463 | 463 | { |
|
464 | 464 | return m_axisItems.values(); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | void ChartPresenter::setVisible(bool visible) |
|
468 | 468 | { |
|
469 | 469 | m_chart->setVisible(visible); |
|
470 | 470 | } |
|
471 | 471 | |
|
472 | 472 | #include "moc_chartpresenter_p.cpp" |
|
473 | 473 | |
|
474 | 474 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,485 +1,490 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "legendscroller_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | 25 | #include "chartbackground_p.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include <QGraphicsScene> |
|
28 | 28 | #include <QGraphicsSceneResizeEvent> |
|
29 | 29 | #include <QGraphicsLayout> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \enum QChart::ChartTheme |
|
35 | 35 | |
|
36 | 36 | This enum describes the theme used by the chart. |
|
37 | 37 | |
|
38 | 38 | \value ChartThemeLight The default theme |
|
39 | 39 | \value ChartThemeBlueCerulean |
|
40 | 40 | \value ChartThemeDark |
|
41 | 41 | \value ChartThemeBrownSand |
|
42 | 42 | \value ChartThemeBlueNcs |
|
43 | 43 | \value ChartThemeHighContrast |
|
44 | 44 | \value ChartThemeBlueIcy |
|
45 | 45 | */ |
|
46 | 46 | |
|
47 | 47 | /*! |
|
48 | 48 | \enum QChart::AnimationOption |
|
49 | 49 | |
|
50 | 50 | For enabling/disabling animations. Defaults to NoAnimation. |
|
51 | 51 | |
|
52 | 52 | \value NoAnimation |
|
53 | 53 | \value GridAxisAnimations |
|
54 | 54 | \value SeriesAnimations |
|
55 | 55 | \value AllAnimations |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \class QChart |
|
60 | 60 | \brief QtCommercial chart API. |
|
61 | 61 | |
|
62 | 62 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
63 | 63 | representation of different types of series and other chart related objects like |
|
64 | 64 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
65 | 65 | convenience class QChartView instead of QChart. |
|
66 | 66 | \sa QChartView |
|
67 | 67 | */ |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | \property QChart::animationOptions |
|
71 | 71 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \property QChart::backgroundVisible |
|
76 | 76 | Whether the chart background is visible or not. |
|
77 | 77 | \sa setBackgroundBrush(), setBackgroundPen() |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \property QChart::dropShadowEnabled |
|
82 | 82 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
83 | 83 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \property QChart::margins |
|
88 | 88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \property QChart::theme |
|
93 | 93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
94 | 94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
95 | 95 | different themes. |
|
96 | 96 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::title |
|
101 | 101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \fn void QChart::marginsChanged(QRectF newMargins) |
|
106 | 106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, |
|
107 | 107 | modify axes or hide/show legend. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
112 | 112 | */ |
|
113 | 113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
114 | 114 | d_ptr(new QChartPrivate()) |
|
115 | 115 | { |
|
116 | 116 | d_ptr->m_dataset = new ChartDataSet(this); |
|
117 | 117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
118 | 118 | d_ptr->createConnections(); |
|
119 | 119 | d_ptr->m_legend = new LegendScroller(this); |
|
120 | 120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
121 | 121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
122 | 122 | setLayout(d_ptr->m_presenter->layout()); |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | Destroys the object and it's children, like series and axis objects added to it. |
|
127 | 127 | */ |
|
128 | 128 | QChart::~QChart() |
|
129 | 129 | { |
|
130 | 130 | //delete first presenter , since this is a root of all the graphical items |
|
131 | 131 | setLayout(0); |
|
132 | 132 | delete d_ptr->m_presenter; |
|
133 | 133 | d_ptr->m_presenter=0; |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | Adds the \a series onto the chart and takes the ownership of the object. |
|
138 | 138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
139 | 139 | the y axis). |
|
140 | 140 | |
|
141 | 141 | \sa removeSeries(), removeAllSeries() |
|
142 | 142 | */ |
|
143 | 143 | void QChart::addSeries(QAbstractSeries *series) |
|
144 | 144 | { |
|
145 | 145 | Q_ASSERT(series); |
|
146 | 146 | d_ptr->m_dataset->addSeries(series); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | Removes the \a series specified in a perameter from the QChartView. |
|
151 | 151 | It releses its ownership of the specified QChartSeries object. |
|
152 | 152 | It does not delete the pointed QChartSeries data object |
|
153 | 153 | \sa addSeries(), removeAllSeries() |
|
154 | 154 | */ |
|
155 | 155 | void QChart::removeSeries(QAbstractSeries *series) |
|
156 | 156 | { |
|
157 | 157 | Q_ASSERT(series); |
|
158 | 158 | d_ptr->m_dataset->removeSeries(series); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | Removes all the QChartSeries that have been added to the QChartView |
|
163 | 163 | It also deletes the pointed QChartSeries data objects |
|
164 | 164 | \sa addSeries(), removeSeries() |
|
165 | 165 | */ |
|
166 | 166 | void QChart::removeAllSeries() |
|
167 | 167 | { |
|
168 | 168 | d_ptr->m_dataset->removeAllSeries(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | Sets the \a brush that is used for painting the background of the chart area. |
|
173 | 173 | */ |
|
174 | 174 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
175 | 175 | { |
|
176 | 176 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | Gets the brush that is used for painting the background of the chart area. |
|
181 | 181 | */ |
|
182 | 182 | QBrush QChart::backgroundBrush() const |
|
183 | 183 | { |
|
184 | 184 | return d_ptr->m_presenter->backgroundBrush(); |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | Sets the \a pen that is used for painting the background of the chart area. |
|
189 | 189 | */ |
|
190 | 190 | void QChart::setBackgroundPen(const QPen& pen) |
|
191 | 191 | { |
|
192 | 192 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | Gets the pen that is used for painting the background of the chart area. |
|
197 | 197 | */ |
|
198 | 198 | QPen QChart::backgroundPen() const |
|
199 | 199 | { |
|
200 | 200 | return d_ptr->m_presenter->backgroundPen(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Sets the chart \a title. The description text that is drawn above the chart. |
|
205 | 205 | */ |
|
206 | 206 | void QChart::setTitle(const QString& title) |
|
207 | 207 | { |
|
208 | 208 | d_ptr->m_presenter->setTitle(title); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | Returns the chart title. The description text that is drawn above the chart. |
|
213 | 213 | */ |
|
214 | 214 | QString QChart::title() const |
|
215 | 215 | { |
|
216 | 216 | return d_ptr->m_presenter->title(); |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
221 | 221 | */ |
|
222 | 222 | void QChart::setTitleFont(const QFont& font) |
|
223 | 223 | { |
|
224 | 224 | d_ptr->m_presenter->setTitleFont(font); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | /*! |
|
228 | 228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
229 | 229 | */ |
|
230 | 230 | QFont QChart::titleFont() const |
|
231 | 231 | { |
|
232 | 232 | return d_ptr->m_presenter->titleFont(); |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | Sets the \a brush used for rendering the title text. |
|
237 | 237 | */ |
|
238 | 238 | void QChart::setTitleBrush(const QBrush &brush) |
|
239 | 239 | { |
|
240 | 240 | d_ptr->m_presenter->setTitleBrush(brush); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | Returns the brush used for rendering the title text. |
|
245 | 245 | */ |
|
246 | 246 | QBrush QChart::titleBrush() const |
|
247 | 247 | { |
|
248 | 248 | return d_ptr->m_presenter->titleBrush(); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void QChart::setTheme(QChart::ChartTheme theme) |
|
252 | 252 | { |
|
253 | 253 | d_ptr->m_presenter->setTheme(theme); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | QChart::ChartTheme QChart::theme() const |
|
257 | 257 | { |
|
258 | 258 | return d_ptr->m_presenter->theme(); |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Zooms in the view by a factor of 2 |
|
263 | 263 | */ |
|
264 | 264 | void QChart::zoomIn() |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_presenter->zoomIn(2.0); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | /*! |
|
270 | 270 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
271 | 271 | */ |
|
272 | 272 | void QChart::zoomIn(const QRectF& rect) |
|
273 | 273 | { |
|
274 | 274 | if (!rect.isValid()) return; |
|
275 | 275 | d_ptr->m_presenter->zoomIn(rect); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Restores the view zoom level to the previous one. |
|
280 | 280 | */ |
|
281 | 281 | void QChart::zoomOut() |
|
282 | 282 | { |
|
283 | 283 | d_ptr->m_presenter->zoomOut(2.0); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | Zooms in the view by a \a factor. |
|
288 | 288 | |
|
289 | 289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
290 | 290 | */ |
|
291 | 291 | void QChart::zoom(qreal factor) |
|
292 | 292 | { |
|
293 | 293 | if (qFuzzyIsNull(factor)) |
|
294 | 294 | return; |
|
295 | 295 | |
|
296 | 296 | if (qFuzzyCompare(factor, 1.0)) |
|
297 | 297 | return; |
|
298 | 298 | |
|
299 | 299 | if (factor < 0) |
|
300 | 300 | return; |
|
301 | 301 | |
|
302 | 302 | if (factor > 1.0) |
|
303 | 303 | d_ptr->m_presenter->zoomIn(factor); |
|
304 | 304 | else |
|
305 | 305 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | /*! |
|
309 | 309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
310 | 310 | If no series is provided then pointer to currently visible axis is provided |
|
311 | 311 | */ |
|
312 | 312 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const |
|
313 | 313 | { |
|
314 | 314 | return d_ptr->m_dataset->axisX(series); |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
319 | 319 | If no series is provided then pointer to currently visible axis is provided |
|
320 | 320 | */ |
|
321 | 321 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const |
|
322 | 322 | { |
|
323 | 323 | return d_ptr->m_dataset->axisY(series); |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | /*! |
|
327 | 327 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
328 | 328 | |
|
329 | 329 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
330 | 330 | |
|
331 | 331 | \table |
|
332 | 332 | \header |
|
333 | 333 | \o Series type |
|
334 | 334 | \o X-axis |
|
335 | 335 | \o Y-axis |
|
336 | 336 | \row |
|
337 | 337 | \o QXYSeries |
|
338 | 338 | \o QValuesAxis |
|
339 | 339 | \o QValuesAxis |
|
340 | 340 | \row |
|
341 | 341 | \o QBarSeries |
|
342 | 342 | \o QBarCategoriesAxis |
|
343 | 343 | \o QValuesAxis |
|
344 | 344 | \row |
|
345 | 345 | \o QPieSeries |
|
346 | 346 | \o None |
|
347 | 347 | \o None |
|
348 | 348 | \endtable |
|
349 | 349 | |
|
350 | 350 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
351 | 351 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
352 | 352 | |
|
353 | 353 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
354 | 354 | |
|
355 | 355 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
356 | 356 | QPieSeries does not create any axes. |
|
357 | 357 | |
|
358 | 358 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
359 | 359 | */ |
|
360 | 360 | void QChart::createDefaultAxes() |
|
361 | 361 | { |
|
362 | 362 | d_ptr->m_dataset->createDefaultAxes(); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | /*! |
|
366 | 366 | Returns the legend object of the chart. Ownership stays in chart. |
|
367 | 367 | */ |
|
368 | 368 | QLegend* QChart::legend() const |
|
369 | 369 | { |
|
370 | 370 | return d_ptr->m_legend; |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | /*! |
|
374 | 374 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
375 | 375 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
376 | 376 | */ |
|
377 | 377 | QRectF QChart::margins() const |
|
378 | 378 | { |
|
379 | 379 | return d_ptr->m_presenter->margins(); |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | QRectF QChart::plotArea() const | |
|
383 | { | |
|
384 | return d_ptr->m_presenter->geometry(); | |
|
385 | } | |
|
386 | ||
|
382 | 387 | /*! |
|
383 | 388 | Sets animation \a options for the chart |
|
384 | 389 | */ |
|
385 | 390 | |
|
386 | 391 | void QChart::setAnimationOptions(AnimationOptions options) |
|
387 | 392 | { |
|
388 | 393 | d_ptr->m_presenter->setAnimationOptions(options); |
|
389 | 394 | } |
|
390 | 395 | |
|
391 | 396 | QChart::AnimationOptions QChart::animationOptions() const |
|
392 | 397 | { |
|
393 | 398 | return d_ptr->m_presenter->animationOptions(); |
|
394 | 399 | } |
|
395 | 400 | |
|
396 | 401 | /*! |
|
397 | 402 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
398 | 403 | */ |
|
399 | 404 | void QChart::scroll(qreal dx, qreal dy) |
|
400 | 405 | { |
|
401 | 406 | d_ptr->m_presenter->scroll(dx, dy); |
|
402 | 407 | } |
|
403 | 408 | |
|
404 | 409 | void QChart::setBackgroundVisible(bool visible) |
|
405 | 410 | { |
|
406 | 411 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
407 | 412 | } |
|
408 | 413 | |
|
409 | 414 | bool QChart::isBackgroundVisible() const |
|
410 | 415 | { |
|
411 | 416 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
412 | 417 | } |
|
413 | 418 | |
|
414 | 419 | void QChart::setDropShadowEnabled(bool enabled) |
|
415 | 420 | { |
|
416 | 421 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
417 | 422 | } |
|
418 | 423 | |
|
419 | 424 | bool QChart::isDropShadowEnabled() const |
|
420 | 425 | { |
|
421 | 426 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
422 | 427 | } |
|
423 | 428 | |
|
424 | 429 | /*! |
|
425 | 430 | Returns all the series that are added to the chart. |
|
426 | 431 | |
|
427 | 432 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
428 | 433 | */ |
|
429 | 434 | QList<QAbstractSeries*> QChart::series() const |
|
430 | 435 | { |
|
431 | 436 | return d_ptr->m_dataset->series(); |
|
432 | 437 | } |
|
433 | 438 | |
|
434 | 439 | void QChart::setMarginsMinimum(const QRectF& margins) |
|
435 | 440 | { |
|
436 | 441 | d_ptr->m_presenter->setMarginsMinimum(margins); |
|
437 | 442 | } |
|
438 | 443 | |
|
439 | 444 | /*! |
|
440 | 445 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
441 | 446 | |
|
442 | 447 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
443 | 448 | */ |
|
444 | 449 | void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) |
|
445 | 450 | { |
|
446 | 451 | d_ptr->m_dataset->setAxisX(series,axis); |
|
447 | 452 | } |
|
448 | 453 | |
|
449 | 454 | /*! |
|
450 | 455 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
451 | 456 | |
|
452 | 457 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
453 | 458 | */ |
|
454 | 459 | void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series) |
|
455 | 460 | { |
|
456 | 461 | d_ptr->m_dataset->setAxisY(series,axis); |
|
457 | 462 | } |
|
458 | 463 | |
|
459 | 464 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
460 | 465 | |
|
461 | 466 | QChartPrivate::QChartPrivate(): |
|
462 | 467 | m_legend(0), |
|
463 | 468 | m_dataset(0), |
|
464 | 469 | m_presenter(0) |
|
465 | 470 | { |
|
466 | 471 | |
|
467 | 472 | } |
|
468 | 473 | |
|
469 | 474 | QChartPrivate::~QChartPrivate() |
|
470 | 475 | { |
|
471 | 476 | |
|
472 | 477 | } |
|
473 | 478 | |
|
474 | 479 | void QChartPrivate::createConnections() |
|
475 | 480 | { |
|
476 | 481 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
477 | 482 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
478 | 483 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
479 | 484 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
480 | 485 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
481 | 486 | } |
|
482 | 487 | |
|
483 | 488 | #include "moc_qchart.cpp" |
|
484 | 489 | |
|
485 | 490 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,135 +1,136 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QCHART_H |
|
22 | 22 | #define QCHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QAbstractSeries> |
|
25 | 25 | #include <QLegend> |
|
26 | 26 | #include <QGraphicsWidget> |
|
27 | 27 | |
|
28 | 28 | class QGraphicsSceneResizeEvent; |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | class QAbstractSeries; |
|
33 | 33 | class QAbstractAxis; |
|
34 | 34 | class QLegend; |
|
35 | 35 | struct QChartPrivate; |
|
36 | 36 | |
|
37 | 37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
41 | 41 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
42 | 42 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
43 | 43 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
44 | 44 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
45 | 45 | Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged) |
|
46 | 46 | Q_ENUMS(ChartTheme) |
|
47 | 47 | Q_ENUMS(AnimationOption) |
|
48 | 48 | |
|
49 | 49 | public: |
|
50 | 50 | enum ChartTheme { |
|
51 | 51 | ChartThemeLight = 0, |
|
52 | 52 | ChartThemeBlueCerulean, |
|
53 | 53 | ChartThemeDark, |
|
54 | 54 | ChartThemeBrownSand, |
|
55 | 55 | ChartThemeBlueNcs, |
|
56 | 56 | ChartThemeHighContrast, |
|
57 | 57 | ChartThemeBlueIcy |
|
58 | 58 | }; |
|
59 | 59 | |
|
60 | 60 | enum AnimationOption { |
|
61 | 61 | NoAnimation = 0x0, |
|
62 | 62 | GridAxisAnimations = 0x1, |
|
63 | 63 | SeriesAnimations =0x2, |
|
64 | 64 | AllAnimations = 0x3 |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | 67 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
68 | 68 | |
|
69 | 69 | public: |
|
70 | 70 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
71 | 71 | ~QChart(); |
|
72 | 72 | |
|
73 | 73 | void addSeries(QAbstractSeries *series); |
|
74 | 74 | void removeSeries(QAbstractSeries *series); |
|
75 | 75 | void removeAllSeries(); |
|
76 | 76 | QList<QAbstractSeries*> series() const; |
|
77 | 77 | |
|
78 | 78 | void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
79 | 79 | void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
80 | 80 | |
|
81 | 81 | QAbstractAxis* axisX(QAbstractSeries* series = 0) const; |
|
82 | 82 | QAbstractAxis* axisY(QAbstractSeries* series = 0) const; |
|
83 | 83 | |
|
84 | 84 | void createDefaultAxes(); |
|
85 | 85 | |
|
86 | 86 | void setTheme(QChart::ChartTheme theme); |
|
87 | 87 | QChart::ChartTheme theme() const; |
|
88 | 88 | |
|
89 | 89 | void setTitle(const QString& title); |
|
90 | 90 | QString title() const; |
|
91 | 91 | void setTitleFont(const QFont& font); |
|
92 | 92 | QFont titleFont() const; |
|
93 | 93 | void setTitleBrush(const QBrush &brush); |
|
94 | 94 | QBrush titleBrush() const; |
|
95 | 95 | |
|
96 | 96 | void setBackgroundBrush(const QBrush &brush); |
|
97 | 97 | QBrush backgroundBrush() const; |
|
98 | 98 | void setBackgroundPen(const QPen &pen); |
|
99 | 99 | QPen backgroundPen() const; |
|
100 | 100 | void setBackgroundVisible(bool visible = true); |
|
101 | 101 | bool isBackgroundVisible() const; |
|
102 | 102 | |
|
103 | 103 | void setDropShadowEnabled(bool enabled = true); |
|
104 | 104 | bool isDropShadowEnabled() const; |
|
105 | 105 | void setAnimationOptions(AnimationOptions options); |
|
106 | 106 | AnimationOptions animationOptions() const; |
|
107 | 107 | |
|
108 | 108 | void zoomIn(); |
|
109 | 109 | void zoomIn(const QRectF &rect); |
|
110 | 110 | void zoomOut(); |
|
111 | 111 | void zoom(qreal factor); |
|
112 | 112 | void scroll(qreal dx, qreal dy); |
|
113 | 113 | |
|
114 | 114 | void adjustViewToSeries(QAbstractSeries* series = 0); |
|
115 | 115 | |
|
116 | 116 | QLegend* legend() const; |
|
117 | 117 | |
|
118 | 118 | void setMarginsMinimum(const QRectF& margins); |
|
119 | 119 | QRectF margins() const; |
|
120 | QRectF plotArea() const; | |
|
120 | 121 | |
|
121 | 122 | Q_SIGNALS: |
|
122 | 123 | void marginsChanged(QRectF newMargins); |
|
123 | 124 | |
|
124 | 125 | protected: |
|
125 | 126 | QScopedPointer<QChartPrivate> d_ptr; |
|
126 | 127 | friend class QLegend; |
|
127 | 128 | friend class ChartPresenter; |
|
128 | 129 | Q_DISABLE_COPY(QChart) |
|
129 | 130 | }; |
|
130 | 131 | |
|
131 | 132 | QTCOMMERCIALCHART_END_NAMESPACE |
|
132 | 133 | |
|
133 | 134 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
134 | 135 | |
|
135 | 136 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now