@@ -206,20 +206,30 void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |||
|
206 | 206 | |
|
207 | 207 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
208 | 208 | { |
|
209 | QPen pen; | |
|
210 | QBrush brush; | |
|
211 | ||
|
212 | 209 | for (int i(0); i < series->slices().count(); i++) { |
|
213 | if (pen == series->slices().at(i)->slicePen() || force) { | |
|
214 |
|
|
|
215 | series->slices().at(i)->setSlicePen(penColor); | |
|
216 | } | |
|
210 | ||
|
211 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
|
217 | 212 | |
|
218 | 213 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
219 | 214 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
220 | if (brush == series->slices().at(i)->sliceBrush() || force) { | |
|
221 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
222 |
|
|
|
215 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
216 | ||
|
217 | QPieSlice::DataPtr s = series->slices().at(i)->data_ptr(); | |
|
218 | PieSliceData data = s->m_data; | |
|
219 | ||
|
220 | if (data.m_slicePen.isThemed() || force) { | |
|
221 | data.m_slicePen = penColor; | |
|
222 | data.m_slicePen.setThemed(true); | |
|
223 | } | |
|
224 | ||
|
225 | if (data.m_sliceBrush.isThemed() || force) { | |
|
226 | data.m_sliceBrush = brushColor; | |
|
227 | data.m_sliceBrush.setThemed(true); | |
|
228 | } | |
|
229 | ||
|
230 | if (s->m_data != data) { | |
|
231 | s->m_data = data; | |
|
232 | emit s->changed(); | |
|
223 | 233 | } |
|
224 | 234 | } |
|
225 | 235 | } |
@@ -51,7 +51,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||
|
51 | 51 | { |
|
52 | 52 | bool isEmpty = m_slices.isEmpty(); |
|
53 | 53 | |
|
54 | presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
|
54 | presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false); | |
|
55 | 55 | |
|
56 | 56 | foreach (QPieSlice *s, slices) { |
|
57 | 57 | PieSliceItem* item = new PieSliceItem(this); |
@@ -72,7 +72,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||
|
72 | 72 | |
|
73 | 73 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) |
|
74 | 74 | { |
|
75 | presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
|
75 | presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false); | |
|
76 | 76 | |
|
77 | 77 | foreach (QPieSlice *s, slices) { |
|
78 | 78 | if (animator()) |
@@ -130,7 +130,6 PieSliceData PieChartItem::sliceData(QPieSlice *slice) | |||
|
130 | 130 | PieSliceData sliceData = slice->data_ptr()->m_data; |
|
131 | 131 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
132 | 132 | sliceData.m_radius = m_pieRadius; |
|
133 | sliceData.m_angleSpan = slice->endAngle() - slice->startAngle(); | |
|
134 | 133 | return sliceData; |
|
135 | 134 | } |
|
136 | 135 |
@@ -4,37 +4,99 | |||
|
4 | 4 | #include <qchartglobal.h> |
|
5 | 5 | #include <QPen> |
|
6 | 6 | #include <QBrush> |
|
7 | #include <QDebug> | |
|
7 | 8 | |
|
8 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 10 | |
|
11 | template <class T> | |
|
12 | class Themed : public T | |
|
13 | { | |
|
14 | public: | |
|
15 | Themed():m_isThemed(true) {} | |
|
16 | ||
|
17 | inline T &operator=(const T &other) { return T::operator =(other); } | |
|
18 | ||
|
19 | inline bool operator!=(const T &other) { return T::operator !=(other); } | |
|
20 | inline bool operator!=(const Themed &other) | |
|
21 | { | |
|
22 | if (T::operator !=(other)) | |
|
23 | return true; | |
|
24 | ||
|
25 | if (m_isThemed != other.m_isThemed) | |
|
26 | return true; | |
|
27 | ||
|
28 | return false; | |
|
29 | } | |
|
30 | ||
|
31 | inline void setThemed(bool state) { m_isThemed = state; } | |
|
32 | inline bool isThemed() const { return m_isThemed; } | |
|
33 | ||
|
34 | private: | |
|
35 | bool m_isThemed; | |
|
36 | }; | |
|
37 | ||
|
10 | 38 | class PieSliceData |
|
11 | 39 | { |
|
12 | 40 | public: |
|
13 | 41 | PieSliceData() |
|
14 | 42 | { |
|
15 | 43 | m_value = 0; |
|
16 | m_percentage = 0; | |
|
17 | m_startAngle = 0; | |
|
18 | m_angleSpan = 0; | |
|
44 | ||
|
19 | 45 | m_isExploded = false; |
|
20 | 46 | m_explodeDistanceFactor = 0.15; |
|
21 | m_labelVisible = false; | |
|
47 | ||
|
48 | m_isLabelVisible = false; | |
|
22 | 49 | m_labelArmLengthFactor = 0.15; |
|
50 | ||
|
51 | m_percentage = 0; | |
|
52 | m_radius = 0; | |
|
53 | m_startAngle = 0; | |
|
54 | m_angleSpan = 0; | |
|
55 | } | |
|
56 | ||
|
57 | bool operator!=(const PieSliceData &other) | |
|
58 | { | |
|
59 | if (m_value != other.m_value) | |
|
60 | return true; | |
|
61 | ||
|
62 | if (m_slicePen != other.m_slicePen || | |
|
63 | m_sliceBrush != other.m_sliceBrush) | |
|
64 | return true; | |
|
65 | ||
|
66 | if (m_isExploded != other.m_isExploded || | |
|
67 | m_explodeDistanceFactor != other.m_explodeDistanceFactor) | |
|
68 | return true; | |
|
69 | ||
|
70 | if (m_isLabelVisible != other.m_isLabelVisible || | |
|
71 | m_labelText != other.m_labelText || | |
|
72 | m_labelFont != other.m_labelFont || | |
|
73 | m_labelArmLengthFactor != other.m_labelArmLengthFactor || | |
|
74 | m_labelArmPen != other.m_labelArmPen) | |
|
75 | return true; | |
|
76 | ||
|
77 | if (m_percentage != other.m_percentage || | |
|
78 | m_center != other.m_center || | |
|
79 | m_radius != other.m_radius || | |
|
80 | m_startAngle != other.m_startAngle || | |
|
81 | m_angleSpan != other.m_angleSpan) | |
|
82 | return true; | |
|
83 | ||
|
84 | return false; | |
|
23 | 85 | } |
|
24 | 86 | |
|
25 | 87 | qreal m_value; |
|
26 | 88 | |
|
27 | QPen m_slicePen; | |
|
28 | QBrush m_sliceBrush; | |
|
89 | Themed<QPen> m_slicePen; | |
|
90 | Themed<QBrush> m_sliceBrush; | |
|
29 | 91 | |
|
30 | 92 | bool m_isExploded; |
|
31 | 93 | qreal m_explodeDistanceFactor; |
|
32 | 94 | |
|
33 |
bool m_ |
|
|
95 | bool m_isLabelVisible; | |
|
34 | 96 | QString m_labelText; |
|
35 | QFont m_labelFont; | |
|
97 | Themed<QFont> m_labelFont; | |
|
36 | 98 | qreal m_labelArmLengthFactor; |
|
37 | QPen m_labelArmPen; | |
|
99 | Themed<QPen> m_labelArmPen; | |
|
38 | 100 | |
|
39 | 101 | qreal m_percentage; |
|
40 | 102 | QPointF m_center; |
@@ -55,7 +55,7 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op | |||
|
55 | 55 | painter->drawPath(m_slicePath); |
|
56 | 56 | painter->restore(); |
|
57 | 57 | |
|
58 |
if (m_data.m_ |
|
|
58 | if (m_data.m_isLabelVisible) { | |
|
59 | 59 | painter->save(); |
|
60 | 60 | painter->setPen(m_data.m_labelArmPen); |
|
61 | 61 | painter->drawPath(m_labelArmPath); |
@@ -93,7 +93,7 QString QPieSlice::label() const | |||
|
93 | 93 | bool QPieSlice::isLabelVisible() const |
|
94 | 94 | { |
|
95 | 95 | Q_D(const QPieSlice); |
|
96 |
return d->m_data.m_ |
|
|
96 | return d->m_data.m_isLabelVisible; | |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | /*! |
@@ -202,7 +202,7 QFont QPieSlice::labelFont() const | |||
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 |
Gets the label arm leng |
|
|
205 | Gets the label arm length factor. | |
|
206 | 206 | |
|
207 | 207 | The factor is relative to pie radius. For example: |
|
208 | 208 | 1.0 means the length is the same as the radius. |
@@ -288,8 +288,8 void QPieSlice::setLabel(QString label) | |||
|
288 | 288 | void QPieSlice::setLabelVisible(bool visible) |
|
289 | 289 | { |
|
290 | 290 | Q_D(QPieSlice); |
|
291 |
if (d->m_data.m_ |
|
|
292 |
d->m_data.m_ |
|
|
291 | if (d->m_data.m_isLabelVisible != visible) { | |
|
292 | d->m_data.m_isLabelVisible = visible; | |
|
293 | 293 | emit changed(); |
|
294 | 294 | } |
|
295 | 295 | } |
@@ -337,6 +337,7 void QPieSlice::setSlicePen(const QPen &pen) | |||
|
337 | 337 | Q_D(QPieSlice); |
|
338 | 338 | if (d->m_data.m_slicePen != pen) { |
|
339 | 339 | d->m_data.m_slicePen = pen; |
|
340 | d->m_data.m_slicePen.setThemed(false); | |
|
340 | 341 | emit changed(); |
|
341 | 342 | } |
|
342 | 343 | } |
@@ -351,6 +352,7 void QPieSlice::setSliceBrush(const QBrush &brush) | |||
|
351 | 352 | Q_D(QPieSlice); |
|
352 | 353 | if (d->m_data.m_sliceBrush != brush) { |
|
353 | 354 | d->m_data.m_sliceBrush = brush; |
|
355 | d->m_data.m_sliceBrush.setThemed(false); | |
|
354 | 356 | emit changed(); |
|
355 | 357 | } |
|
356 | 358 | } |
@@ -365,6 +367,7 void QPieSlice::setLabelArmPen(const QPen &pen) | |||
|
365 | 367 | Q_D(QPieSlice); |
|
366 | 368 | if (d->m_data.m_labelArmPen != pen) { |
|
367 | 369 | d->m_data.m_labelArmPen = pen; |
|
370 | d->m_data.m_labelArmPen.setThemed(false); | |
|
368 | 371 | emit changed(); |
|
369 | 372 | } |
|
370 | 373 | } |
@@ -379,12 +382,13 void QPieSlice::setLabelFont(const QFont &font) | |||
|
379 | 382 | Q_D(QPieSlice); |
|
380 | 383 | if (d->m_data.m_labelFont != font) { |
|
381 | 384 | d->m_data.m_labelFont = font; |
|
385 | d->m_data.m_labelFont.setThemed(false); | |
|
382 | 386 | emit changed(); |
|
383 | 387 | } |
|
384 | 388 | } |
|
385 | 389 | |
|
386 | 390 | /*! |
|
387 |
Sets the label arm leng |
|
|
391 | Sets the label arm length \a factor. | |
|
388 | 392 | |
|
389 | 393 | The factor is relative to pie radius. For example: |
|
390 | 394 | 1.0 means the length is the same as the radius. |
General Comments 0
You need to be logged in to leave comments.
Login now