##// END OF EJS Templates
Release compilation fixes
Michal Klocek -
r689:15b9cd07deb2
parent child
Show More
@@ -1,121 +1,125
1 1 #include "areachartitem_p.h"
2 2 #include "qareaseries.h"
3 3 #include "qlineseries.h"
4 4 #include "chartpresenter_p.h"
5 5 #include <QPainter>
6 6 #include <QGraphicsSceneMouseEvent>
7 7
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 //TODO: optimize : remove points which are not visible
12 12
13 AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,ChartPresenter *presenter):Chart(presenter),QGraphicsItem(presenter->rootItem()),
13 AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,ChartPresenter *presenter):ChartItem(presenter),
14 14 m_series(areaSeries),
15 15 m_upper(0),
16 16 m_lower(0),
17 17 m_pointsVisible(false)
18 18 {
19 19 setZValue(ChartPresenter::LineChartZValue);
20 20 m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter);
21 21 if(m_series->lowerSeries()){
22 22 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
23 23 }
24 24
25 25 QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated()));
26 26 QObject::connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&)));
27 27
28 28 handleUpdated();
29 29 }
30 30
31 31 AreaChartItem::~AreaChartItem()
32 32 {
33 33 delete m_upper;
34 34 delete m_lower;
35 35 };
36 36
37 37 QRectF AreaChartItem::boundingRect() const
38 38 {
39 39 return m_rect;
40 40 }
41 41
42 42 QPainterPath AreaChartItem::shape() const
43 43 {
44 44 return m_path;
45 45 }
46 46
47 47 void AreaChartItem::updatePath()
48 48 {
49 49 QPainterPath path;
50 50
51 51 path.connectPath(m_upper->shape());
52 52 if(m_lower){
53 53 path.connectPath(m_lower->shape().toReversed());
54 54 }
55 55 else{
56 56 QPointF first = path.pointAtPercent(0);
57 57 QPointF last = path.pointAtPercent(1);
58 58 path.lineTo(last.x(),m_clipRect.bottom());
59 59 path.lineTo(first.x(),m_clipRect.bottom());
60 60 }
61 61 path.closeSubpath();
62 62 prepareGeometryChange();
63 63 m_path=path;
64 64 m_rect=path.boundingRect();
65 65 update();
66 66 }
67 67
68 68 void AreaChartItem::handleUpdated()
69 69 {
70 70 m_pointsVisible = m_series->pointsVisible();
71 71 m_linePen = m_series->pen();
72 72 m_brush = m_series->brush();
73 73 m_pointPen = m_series->pen();
74 74 m_pointPen.setWidthF(2*m_pointPen.width());
75 75
76 76 update();
77 77 }
78 78
79 79 void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
80 80 {
81 81 m_upper->handleDomainChanged(minX,maxX,minY,maxY);
82 82 if(m_lower)
83 83 m_lower->handleDomainChanged(minX,maxX,minY,maxY);
84 84 }
85 85
86 86 void AreaChartItem::handleGeometryChanged(const QRectF& rect)
87 87 {
88 88 m_clipRect=rect.translated(-rect.topLeft());
89 89 setPos(rect.topLeft());
90 90 m_upper->handleGeometryChanged(rect);
91 91 if(m_lower)
92 92 m_lower->handleGeometryChanged(rect);
93 93 }
94 94 //painter
95 95
96 96 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
97 97 {
98 98 Q_UNUSED(widget)
99 99 Q_UNUSED(option)
100 100
101 101 painter->save();
102 painter->setPen(m_linePen);
103 painter->setBrush(m_brush);
102 QPen pen;
103 pen.setCosmetic(false);
104 pen.setWidth(4);
105 pen.setColor(qRgb(200,0,250));
106 painter->setPen(pen);
107 //painter->setBrush(m_brush);
104 108 painter->setClipRect(m_clipRect);
105 109 painter->drawPath(m_path);
106 110 if(m_pointsVisible){
107 111 painter->setPen(m_pointPen);
108 112 painter->drawPoints(m_upper->points());
109 113 if(m_lower) painter->drawPoints(m_lower->points());
110 114 }
111 115 painter->restore();
112 116 }
113 117
114 118 void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
115 119 {
116 120 emit clicked(m_upper->calculateDomainPoint(event->pos()));
117 121 }
118 122
119 123 #include "moc_areachartitem_p.cpp"
120 124
121 125 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,75 +1,75
1 1 #ifndef AREACHARTITEM_H
2 2 #define AREACHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "linechartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QAreaSeries;
11 11 class AreaChartItem;
12 12
13 class AreaChartItem : public Chart, public QGraphicsItem
13 class AreaChartItem : public ChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 AreaChartItem(QAreaSeries* areaSeries, ChartPresenter *presenter);
18 18 ~ AreaChartItem();
19 19
20 20 //from QGraphicsItem
21 21 QRectF boundingRect() const;
22 22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 23 QPainterPath shape() const;
24 24
25 25 LineChartItem* upperLineItem() const { return m_upper ;}
26 26 LineChartItem* lowerLineItem() const { return m_lower ;}
27 27
28 28 void updatePath();
29 29
30 30 protected:
31 31 void mousePressEvent( QGraphicsSceneMouseEvent * event );
32 32
33 33 signals:
34 34 void clicked(const QPointF& point);
35 35
36 36 public slots:
37 37 void handleUpdated();
38 38 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
39 39 void handleGeometryChanged(const QRectF& size);
40 40
41 41 private:
42 42 QAreaSeries* m_series;
43 43 LineChartItem* m_upper;
44 44 LineChartItem* m_lower;
45 45 QPainterPath m_path;
46 46 QRectF m_rect;
47 47 QRectF m_clipRect;
48 48 QPen m_linePen;
49 49 QPen m_pointPen;
50 50 QBrush m_brush;
51 51 bool m_pointsVisible;
52 52
53 53 };
54 54
55 55 class AreaBoundItem : public LineChartItem
56 56 {
57 57 public:
58 58 AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries,ChartPresenter *presenter):LineChartItem(lineSeries,presenter),
59 59 m_item(item){};
60 60
61 61 ~AreaBoundItem(){};
62 62
63 63 void setLayout(QVector<QPointF>& points){
64 64 LineChartItem::setLayout(points);
65 65 m_item->updatePath();
66 66 }
67 67
68 68 private:
69 69 AreaChartItem* m_item;
70 70
71 71 };
72 72
73 73 QTCOMMERCIALCHART_END_NAMESPACE
74 74
75 75 #endif
@@ -1,641 +1,640
1 1 #include "qpieseries.h"
2 2 #include "qpiesliceprivate_p.h"
3 3 #include "qpieseriesprivate_p.h"
4 4 #include <QDebug>
5 5
6 6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7
8 8 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent)
9 9 :QObject(parent),
10 10 q_ptr(parent),
11 11 m_pieRelativeHorPos(0.5),
12 12 m_pieRelativeVerPos(0.5),
13 13 m_pieRelativeSize(0.7),
14 14 m_pieStartAngle(0),
15 15 m_pieEndAngle(360),
16 16 m_total(0)
17 17 {
18 18
19 19 }
20 20
21 21 QPieSeriesPrivate::~QPieSeriesPrivate()
22 22 {
23 23
24 24 }
25 25
26 26 void QPieSeriesPrivate::updateDerivativeData()
27 27 {
28 28 m_total = 0;
29 29
30 30 // nothing to do?
31 31 if (m_slices.count() == 0)
32 32 return;
33 33
34 34 // calculate total
35 35 foreach (QPieSlice* s, m_slices)
36 36 m_total += s->value();
37 37
38 38 // nothing to show..
39 39 if (m_total == 0)
40 40 return;
41 41
42 42 // update slice attributes
43 43 qreal sliceAngle = m_pieStartAngle;
44 44 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
45 45 QVector<QPieSlice*> changed;
46 46 foreach (QPieSlice* s, m_slices) {
47 47
48 48 bool isChanged = false;
49 49
50 50 qreal percentage = s->value() / m_total;
51 51 if (s->data_ptr()->m_data.m_percentage != percentage) {
52 52 s->data_ptr()->m_data.m_percentage = percentage;
53 53 isChanged = true;
54 54 }
55 55
56 56 qreal sliceSpan = pieSpan * percentage;
57 57 if (s->data_ptr()->m_data.m_angleSpan != sliceSpan) {
58 58 s->data_ptr()->m_data.m_angleSpan = sliceSpan;
59 59 isChanged = true;
60 60 }
61 61
62 62 if (s->data_ptr()->m_data.m_startAngle != sliceAngle) {
63 63 s->data_ptr()->m_data.m_startAngle = sliceAngle;
64 64 isChanged = true;
65 65 }
66 66 sliceAngle += sliceSpan;
67 67
68 68 if (isChanged)
69 69 changed << s;
70 70 }
71 71
72 72 // emit signals
73 73 foreach (QPieSlice* s, changed)
74 74 emit s->data_ptr()->changed();
75 75 }
76 76
77 77 void QPieSeriesPrivate::sliceChanged()
78 78 {
79 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
80 Q_ASSERT(m_slices.contains(slice));
79 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
81 80 updateDerivativeData();
82 81 }
83 82
84 83 void QPieSeriesPrivate::sliceClicked()
85 84 {
86 85 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
87 86 Q_ASSERT(m_slices.contains(slice));
88 87 Q_Q(QPieSeries);
89 88 emit q->clicked(slice);
90 89 }
91 90
92 91 void QPieSeriesPrivate::sliceHoverEnter()
93 92 {
94 93 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
95 94 Q_ASSERT(m_slices.contains(slice));
96 95 Q_Q(QPieSeries);
97 96 emit q->hoverEnter(slice);
98 97 }
99 98
100 99 void QPieSeriesPrivate::sliceHoverLeave()
101 100 {
102 101 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
103 102 Q_ASSERT(m_slices.contains(slice));
104 103 Q_Q(QPieSeries);
105 104 emit q->hoverLeave(slice);
106 105 }
107 106
108 107 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
109 108 {
110 109 Q_UNUSED(bottomRight)
111 110 Q_Q(QPieSeries);
112 111
113 112 if (m_mapOrientation == Qt::Vertical)
114 113 {
115 114 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
116 115 if (topLeft.column() == m_mapValues)
117 116 if (m_mapValues == m_mapLabels)
118 117 {
119 118 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
120 119 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
121 120 }
122 121 else
123 122 {
124 123 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
125 124 }
126 125 else if (topLeft.column() == m_mapLabels)
127 126 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
128 127 }
129 128 else
130 129 {
131 130 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
132 131 if (topLeft.row() == m_mapValues)
133 132 if (m_mapValues == m_mapLabels)
134 133 {
135 134 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
136 135 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
137 136 }
138 137 else
139 138 {
140 139 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
141 140 }
142 141 else if (topLeft.row() == m_mapLabels)
143 142 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
144 143 }
145 144 }
146 145
147 146 void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
148 147 {
149 148 Q_UNUSED(parent)
150 149 Q_UNUSED(end)
151 150 Q_Q(QPieSeries);
152 151
153 152 QPieSlice* newSlice = new QPieSlice;
154 153 newSlice->setLabelVisible(true);
155 154 if (m_mapOrientation == Qt::Vertical)
156 155 {
157 156 newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
158 157 newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
159 158 }
160 159 else
161 160 {
162 161 newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
163 162 newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
164 163 }
165 164
166 165 q->insert(start, newSlice);
167 166 }
168 167
169 168 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
170 169 {
171 170 Q_UNUSED(parent)
172 171 Q_UNUSED(end)
173 172 Q_Q(QPieSeries);
174 173 q->remove(m_slices.at(start));
175 174 }
176 175
177 176
178 177
179 178 /*!
180 179 \class QPieSeries
181 180 \brief Pie series API for QtCommercial Charts
182 181
183 182 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
184 183 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
185 184 The actual slice size is determined by that relative value.
186 185
187 186 By default the pie is defined as a full pie but it can be a partial pie.
188 187 This can be done by setting a starting angle and angle span to the series.
189 188 */
190 189
191 190 /*!
192 191 Constructs a series object which is a child of \a parent.
193 192 */
194 193 QPieSeries::QPieSeries(QObject *parent) :
195 194 QSeries(parent),
196 195 d_ptr(new QPieSeriesPrivate(this))
197 196 {
198 197
199 198 }
200 199
201 200 /*!
202 201 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
203 202 */
204 203 QPieSeries::~QPieSeries()
205 204 {
206 205 // NOTE: d_prt destroyed by QObject
207 206 }
208 207
209 208 /*!
210 209 Returns QChartSeries::SeriesTypePie.
211 210 */
212 211 QSeries::QSeriesType QPieSeries::type() const
213 212 {
214 213 return QSeries::SeriesTypePie;
215 214 }
216 215
217 216 /*!
218 217 Sets an array of \a slices to the series replacing the existing slices.
219 218 Slice ownership is passed to the series.
220 219 */
221 220 void QPieSeries::replace(QList<QPieSlice*> slices)
222 221 {
223 222 clear();
224 223 add(slices);
225 224 }
226 225
227 226 /*!
228 227 Adds an array of \a slices to the series.
229 228 Slice ownership is passed to the series.
230 229 */
231 230 void QPieSeries::add(QList<QPieSlice*> slices)
232 231 {
233 232 Q_D(QPieSeries);
234 233
235 234 foreach (QPieSlice* s, slices) {
236 235 s->setParent(this);
237 236 d->m_slices << s;
238 237 }
239 238
240 239 d->updateDerivativeData();
241 240
242 241 foreach (QPieSlice* s, slices) {
243 242 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
244 243 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
245 244 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
246 245 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
247 246 }
248 247
249 248 emit added(slices);
250 249 }
251 250
252 251 /*!
253 252 Adds a single \a slice to the series.
254 253 Slice ownership is passed to the series.
255 254 */
256 255 void QPieSeries::add(QPieSlice* slice)
257 256 {
258 257 add(QList<QPieSlice*>() << slice);
259 258 }
260 259
261 260 /*!
262 261 Adds a single \a slice to the series and returns a reference to the series.
263 262 Slice ownership is passed to the series.
264 263 */
265 264 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
266 265 {
267 266 add(slice);
268 267 return *this;
269 268 }
270 269
271 270
272 271 /*!
273 272 Adds a single slice to the series with give \a value and \a name.
274 273 Slice ownership is passed to the series.
275 274 */
276 275 QPieSlice* QPieSeries::add(qreal value, QString name)
277 276 {
278 277 QPieSlice* slice = new QPieSlice(value, name);
279 278 add(slice);
280 279 return slice;
281 280 }
282 281
283 282 void QPieSeries::insert(int i, QPieSlice* slice)
284 283 {
285 284 Q_D(QPieSeries);
286 285 Q_ASSERT(i <= d->m_slices.count());
287 286 slice->setParent(this);
288 287 d->m_slices.insert(i, slice);
289 288
290 289 d->updateDerivativeData();
291 290
292 291 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
293 292 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
294 293 connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
295 294 connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
296 295
297 296 emit added(QList<QPieSlice*>() << slice);
298 297 }
299 298
300 299 /*!
301 300 Removes a single \a slice from the series and deletes the slice.
302 301
303 302 Do not reference this pointer after this call.
304 303 */
305 304 void QPieSeries::remove(QPieSlice* slice)
306 305 {
307 306 Q_D(QPieSeries);
308 307 if (!d->m_slices.removeOne(slice)) {
309 308 Q_ASSERT(0); // TODO: how should this be reported?
310 309 return;
311 310 }
312 311
313 312 d->updateDerivativeData();
314 313
315 314 emit removed(QList<QPieSlice*>() << slice);
316 315
317 316 delete slice;
318 317 slice = NULL;
319 318 }
320 319
321 320 /*!
322 321 Clears all slices from the series.
323 322 */
324 323 void QPieSeries::clear()
325 324 {
326 325 Q_D(QPieSeries);
327 326 if (d->m_slices.count() == 0)
328 327 return;
329 328
330 329 QList<QPieSlice*> slices = d->m_slices;
331 330 foreach (QPieSlice* s, d->m_slices) {
332 331 d->m_slices.removeOne(s);
333 332 delete s;
334 333 }
335 334
336 335 d->updateDerivativeData();
337 336
338 337 emit removed(slices);
339 338 }
340 339
341 340 /*!
342 341 Counts the number of the slices in this series.
343 342 */
344 343 int QPieSeries::count() const
345 344 {
346 345 Q_D(const QPieSeries);
347 346 return d->m_slices.count();
348 347 }
349 348
350 349 /*!
351 350 Returns true is the series is empty.
352 351 */
353 352 bool QPieSeries::isEmpty() const
354 353 {
355 354 Q_D(const QPieSeries);
356 355 return d->m_slices.isEmpty();
357 356 }
358 357
359 358 /*!
360 359 Returns a list of slices that belong to this series.
361 360 */
362 361 QList<QPieSlice*> QPieSeries::slices() const
363 362 {
364 363 Q_D(const QPieSeries);
365 364 return d->m_slices;
366 365 }
367 366
368 367 /*!
369 368 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
370 369
371 370 The factors are relative to the chart rectangle where:
372 371
373 372 \a relativeHorizontalPosition 0.0 means the absolute left.
374 373 \a relativeHorizontalPosition 1.0 means the absolute right.
375 374 \a relativeVerticalPosition 0.0 means the absolute top.
376 375 \a relativeVerticalPosition 1.0 means the absolute bottom.
377 376
378 377 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
379 378
380 379 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
381 380 */
382 381 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
383 382 {
384 383 Q_D(QPieSeries);
385 384 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
386 385 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
387 386 return;
388 387
389 388 if (d->m_pieRelativeHorPos != relativeHorizontalPosition || d->m_pieRelativeVerPos != relativeVerticalPosition) {
390 389 d->m_pieRelativeHorPos = relativeHorizontalPosition;
391 390 d->m_pieRelativeVerPos = relativeVerticalPosition;
392 391 emit piePositionChanged();
393 392 }
394 393 }
395 394
396 395 /*!
397 396 Gets the horizontal position of the pie.
398 397
399 398 The returned value is relative to the chart rectangle where:
400 399
401 400 0.0 means the absolute left.
402 401 1.0 means the absolute right.
403 402
404 403 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
405 404
406 405 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
407 406 */
408 407 qreal QPieSeries::pieHorizontalPosition() const
409 408 {
410 409 Q_D(const QPieSeries);
411 410 return d->m_pieRelativeHorPos;
412 411 }
413 412
414 413 /*!
415 414 Gets the vertical position position of the pie.
416 415
417 416 The returned value is relative to the chart rectangle where:
418 417
419 418 0.0 means the absolute top.
420 419 1.0 means the absolute bottom.
421 420
422 421 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
423 422
424 423 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
425 424 */
426 425 qreal QPieSeries::pieVerticalPosition() const
427 426 {
428 427 Q_D(const QPieSeries);
429 428 return d->m_pieRelativeVerPos;
430 429 }
431 430
432 431 /*!
433 432 Sets the relative size of the pie.
434 433
435 434 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
436 435
437 436 Default value is 0.7.
438 437
439 438 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
440 439 */
441 440 void QPieSeries::setPieSize(qreal relativeSize)
442 441 {
443 442 Q_D(QPieSeries);
444 443 if (relativeSize < 0.0 || relativeSize > 1.0)
445 444 return;
446 445
447 446 if (d->m_pieRelativeSize != relativeSize) {
448 447 d->m_pieRelativeSize = relativeSize;
449 448 emit pieSizeChanged();
450 449 }
451 450 }
452 451
453 452 /*!
454 453 Gets the relative size of the pie.
455 454
456 455 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
457 456
458 457 Default value is 0.7.
459 458
460 459 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
461 460 */
462 461 qreal QPieSeries::pieSize() const
463 462 {
464 463 Q_D(const QPieSeries);
465 464 return d->m_pieRelativeSize;
466 465 }
467 466
468 467
469 468 /*!
470 469 Sets the end angle of the pie.
471 470
472 471 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
473 472
474 473 \a angle must be less than pie end angle. Default value is 0.
475 474
476 475 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
477 476 */
478 477 void QPieSeries::setPieStartAngle(qreal angle)
479 478 {
480 479 Q_D(QPieSeries);
481 480 if (angle >= 0 && angle <= 360 && angle != d->m_pieStartAngle && angle <= d->m_pieEndAngle) {
482 481 d->m_pieStartAngle = angle;
483 482 d->updateDerivativeData();
484 483 }
485 484 }
486 485
487 486 /*!
488 487 Gets the start angle of the pie.
489 488
490 489 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
491 490
492 491 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
493 492 */
494 493 qreal QPieSeries::pieStartAngle() const
495 494 {
496 495 Q_D(const QPieSeries);
497 496 return d->m_pieStartAngle;
498 497 }
499 498
500 499 /*!
501 500 Sets the end angle of the pie.
502 501
503 502 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
504 503
505 504 \a angle must be greater than start angle.
506 505
507 506 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
508 507 */
509 508 void QPieSeries::setPieEndAngle(qreal angle)
510 509 {
511 510 Q_D(QPieSeries);
512 511 if (angle >= 0 && angle <= 360 && angle != d->m_pieEndAngle && angle >= d->m_pieStartAngle) {
513 512 d->m_pieEndAngle = angle;
514 513 d->updateDerivativeData();
515 514 }
516 515 }
517 516
518 517 /*!
519 518 Returns the end angle of the pie.
520 519
521 520 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
522 521
523 522 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
524 523 */
525 524 qreal QPieSeries::pieEndAngle() const
526 525 {
527 526 Q_D(const QPieSeries);
528 527 return d->m_pieEndAngle;
529 528 }
530 529
531 530 /*!
532 531 Sets the all the slice labels \a visible or invisible.
533 532
534 533 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
535 534 */
536 535 void QPieSeries::setLabelsVisible(bool visible)
537 536 {
538 537 Q_D(QPieSeries);
539 538 foreach (QPieSlice* s, d->m_slices)
540 539 s->setLabelVisible(visible);
541 540 }
542 541
543 542 /*!
544 543 Returns the sum of all slice values in this series.
545 544
546 545 \sa QPieSlice::value(), QPieSlice::setValue()
547 546 */
548 547 qreal QPieSeries::total() const
549 548 {
550 549 Q_D(const QPieSeries);
551 550 return d->m_total;
552 551 }
553 552
554 553 /*!
555 554 \fn void QPieSeries::clicked(QPieSlice* slice)
556 555
557 556 This signal is emitted when a \a slice has been clicked.
558 557
559 558 \sa QPieSlice::clicked()
560 559 */
561 560
562 561 /*!
563 562 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
564 563
565 564 This signal is emitted when user has hovered over a \a slice.
566 565
567 566 \sa QPieSlice::hoverEnter()
568 567 */
569 568
570 569 /*!
571 570 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
572 571
573 572 This signal is emitted when user has hovered away from a \a slice.
574 573
575 574 \sa QPieSlice::hoverLeave()
576 575 */
577 576
578 577
579 578
580 579
581 580 bool QPieSeries::setModel(QAbstractItemModel* model)
582 581 {
583 582 Q_D(QPieSeries);
584 583 // disconnect signals from old model
585 584 if(m_model)
586 585 {
587 586 disconnect(m_model, 0, this, 0);
588 587 d->m_mapValues = -1;
589 588 d->m_mapLabels = -1;
590 589 d->m_mapOrientation = Qt::Vertical;
591 590 }
592 591
593 592 // set new model
594 593 if(model)
595 594 {
596 595 m_model = model;
597 596 return true;
598 597 }
599 598 else
600 599 {
601 600 m_model = NULL;
602 601 return false;
603 602 }
604 603 }
605 604
606 605 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
607 606 {
608 607 Q_D(QPieSeries);
609 608
610 609 if (m_model == NULL)
611 610 return;
612 611
613 612 d->m_mapValues = modelValuesLine;
614 613 d->m_mapLabels = modelLabelsLine;
615 614 d->m_mapOrientation = orientation;
616 615
617 616 // connect the signals
618 617 if (d->m_mapOrientation == Qt::Vertical) {
619 618 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
620 619 connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
621 620 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
622 621 } else {
623 622 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
624 623 connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
625 624 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
626 625 }
627 626
628 627 // create the initial slices set
629 628 if (d->m_mapOrientation == Qt::Vertical) {
630 629 for (int i = 0; i < m_model->rowCount(); i++)
631 630 add(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString());
632 631 } else {
633 632 for (int i = 0; i < m_model->columnCount(); i++)
634 633 add(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString());
635 634 }
636 635 }
637 636
638 637 #include "moc_qpieseries.cpp"
639 638 #include "moc_qpieseriesprivate_p.cpp"
640 639
641 640 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,170 +1,170
1 1 #include "scatterchartitem_p.h"
2 2 #include "qscatterseries.h"
3 3 #include "chartpresenter_p.h"
4 4 #include <QPainter>
5 5 #include <QGraphicsScene>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
10 10 XYChartItem(series,presenter),
11 11 m_series(series),
12 12 m_items(this),
13 13 m_shape(QScatterSeries::MarkerShapeRectangle),
14 14 m_size(15)
15 15
16 16 {
17 17 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
18 18
19 19 setZValue(ChartPresenter::ScatterSeriesZValue);
20 20 setFlags(QGraphicsItem::ItemHasNoContents);
21 21 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
22 22
23 23 handleUpdated();
24 24
25 25 m_items.setHandlesChildEvents(false);
26 26
27 27 // TODO: how to draw a drop shadow?
28 28 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
29 29 // dropShadow->setOffset(2.0);
30 30 // dropShadow->setBlurRadius(2.0);
31 31 // setGraphicsEffect(dropShadow);
32 32 }
33 33
34 34
35 35 QRectF ScatterChartItem::boundingRect() const
36 36 {
37 37 return m_rect;
38 38 }
39 39
40 40 void ScatterChartItem::createPoints(int count)
41 41 {
42 42 for (int i = 0; i < count; ++i) {
43 43
44 QGraphicsItem *item;
44 QGraphicsItem *item = 0;
45 45
46 46 switch (m_shape) {
47 47 case QScatterSeries::MarkerShapeCircle:{
48 48 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
49 49 const QRectF& rect = i->boundingRect();
50 50 i->setPos(-rect.width()/2,-rect.height()/2);
51 51 item = new Marker(i,this);
52 52 break;
53 53 }
54 54 case QScatterSeries::MarkerShapeRectangle:{
55 55 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
56 56 i->setPos(-m_size/2,-m_size/2);
57 57 item = new Marker(i,this);
58 58 break;
59 59 }
60 60 default:
61 61 qWarning()<<"Unsupported marker type";
62 62 break;
63 63
64 64 }
65 65 m_items.addToGroup(item);
66 66 }
67 67 }
68 68
69 69 void ScatterChartItem::deletePoints(int count)
70 70 {
71 71 QList<QGraphicsItem *> items = m_items.childItems();
72 72
73 73 for (int i = 0; i < count; ++i) {
74 74 delete(items.takeLast());
75 75 }
76 76 }
77 77
78 78 void ScatterChartItem::markerSelected(Marker* marker)
79 79 {
80 80 emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index())));
81 81 }
82 82
83 83 void ScatterChartItem::setLayout(QVector<QPointF>& points)
84 84 {
85 85 if(points.size()==0)
86 86 {
87 87 XYChartItem::setLayout(points);
88 88 return;
89 89 }
90 90
91 91 int diff = XYChartItem::points().size() - points.size();
92 92
93 93 if(diff>0) {
94 94 deletePoints(diff);
95 95 }
96 96 else if(diff<0) {
97 97 createPoints(-diff);
98 98 }
99 99
100 100 if(diff!=0) handleUpdated();
101 101
102 102 QList<QGraphicsItem*> items = m_items.childItems();
103 103
104 104 for(int i=0; i< points.size();i++) {
105 105 Marker* item = static_cast<Marker*>(items.at(i));
106 106 const QPointF& point = points.at(i);
107 107 const QRectF& rect = item->boundingRect();
108 108 item->setIndex(i);
109 109 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
110 110 if(!clipRect().contains(point)) {
111 111 item->setVisible(false);
112 112 }
113 113 else {
114 114 item->setVisible(true);
115 115 }
116 116 }
117 117
118 118 prepareGeometryChange();
119 119 m_rect = clipRect();
120 120 XYChartItem::setLayout(points);
121 121 }
122 122
123 123
124 124 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
125 125 {
126 126 Q_UNUSED(painter)
127 127 Q_UNUSED(option)
128 128 Q_UNUSED(widget)
129 129 }
130 130
131 131 void ScatterChartItem::setPen(const QPen& pen)
132 132 {
133 133 foreach(QGraphicsItem* item , m_items.childItems()) {
134 134 static_cast<Marker*>(item)->setPen(pen);
135 135 }
136 136 }
137 137
138 138 void ScatterChartItem::setBrush(const QBrush& brush)
139 139 {
140 140 foreach(QGraphicsItem* item , m_items.childItems()) {
141 141 static_cast<Marker*>(item)->setBrush(brush);
142 142 }
143 143 }
144 144
145 145 void ScatterChartItem::handleUpdated()
146 146 {
147 147
148 148 int count = m_items.childItems().count();
149 149
150 150 if(count==0) return;
151 151
152 152 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
153 153
154 154 //TODO: only rewrite on size change
155 155
156 156 m_size = m_series->size();
157 157 m_shape = m_series->shape();
158 158
159 159 if(recreate){
160 160 deletePoints(count);
161 161 createPoints(count);
162 162 }
163 163
164 164 setPen(m_series->pen());
165 165 setBrush(m_series->brush());
166 166 }
167 167
168 168 #include "moc_scatterchartitem_p.cpp"
169 169
170 170 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now