@@ -206,20 +206,30 void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |||||
206 |
|
206 | |||
207 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
207 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
208 | { |
|
208 | { | |
209 | QPen pen; |
|
|||
210 | QBrush brush; |
|
|||
211 |
|
||||
212 | for (int i(0); i < series->slices().count(); i++) { |
|
209 | for (int i(0); i < series->slices().count(); i++) { | |
213 | if (pen == series->slices().at(i)->slicePen() || force) { |
|
210 | ||
214 |
|
|
211 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
215 | series->slices().at(i)->setSlicePen(penColor); |
|
|||
216 | } |
|
|||
217 |
|
212 | |||
218 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
213 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
219 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
214 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
220 | if (brush == series->slices().at(i)->sliceBrush() || force) { |
|
215 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
221 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
216 | ||
222 |
|
|
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 | bool isEmpty = m_slices.isEmpty(); |
|
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 | foreach (QPieSlice *s, slices) { |
|
56 | foreach (QPieSlice *s, slices) { | |
57 | PieSliceItem* item = new PieSliceItem(this); |
|
57 | PieSliceItem* item = new PieSliceItem(this); | |
@@ -72,7 +72,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||||
72 |
|
72 | |||
73 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) |
|
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 | foreach (QPieSlice *s, slices) { |
|
77 | foreach (QPieSlice *s, slices) { | |
78 | if (animator()) |
|
78 | if (animator()) | |
@@ -130,7 +130,6 PieSliceData PieChartItem::sliceData(QPieSlice *slice) | |||||
130 | PieSliceData sliceData = slice->data_ptr()->m_data; |
|
130 | PieSliceData sliceData = slice->data_ptr()->m_data; | |
131 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
131 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
132 | sliceData.m_radius = m_pieRadius; |
|
132 | sliceData.m_radius = m_pieRadius; | |
133 | sliceData.m_angleSpan = slice->endAngle() - slice->startAngle(); |
|
|||
134 | return sliceData; |
|
133 | return sliceData; | |
135 | } |
|
134 | } | |
136 |
|
135 |
@@ -4,37 +4,99 | |||||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 | #include <QBrush> |
|
6 | #include <QBrush> | |
|
7 | #include <QDebug> | |||
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
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 | class PieSliceData |
|
38 | class PieSliceData | |
11 | { |
|
39 | { | |
12 | public: |
|
40 | public: | |
13 | PieSliceData() |
|
41 | PieSliceData() | |
14 | { |
|
42 | { | |
15 | m_value = 0; |
|
43 | m_value = 0; | |
16 | m_percentage = 0; |
|
44 | ||
17 | m_startAngle = 0; |
|
|||
18 | m_angleSpan = 0; |
|
|||
19 | m_isExploded = false; |
|
45 | m_isExploded = false; | |
20 | m_explodeDistanceFactor = 0.15; |
|
46 | m_explodeDistanceFactor = 0.15; | |
21 | m_labelVisible = false; |
|
47 | ||
|
48 | m_isLabelVisible = false; | |||
22 | m_labelArmLengthFactor = 0.15; |
|
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 | qreal m_value; |
|
87 | qreal m_value; | |
26 |
|
88 | |||
27 | QPen m_slicePen; |
|
89 | Themed<QPen> m_slicePen; | |
28 | QBrush m_sliceBrush; |
|
90 | Themed<QBrush> m_sliceBrush; | |
29 |
|
91 | |||
30 | bool m_isExploded; |
|
92 | bool m_isExploded; | |
31 | qreal m_explodeDistanceFactor; |
|
93 | qreal m_explodeDistanceFactor; | |
32 |
|
94 | |||
33 |
bool m_ |
|
95 | bool m_isLabelVisible; | |
34 | QString m_labelText; |
|
96 | QString m_labelText; | |
35 | QFont m_labelFont; |
|
97 | Themed<QFont> m_labelFont; | |
36 | qreal m_labelArmLengthFactor; |
|
98 | qreal m_labelArmLengthFactor; | |
37 | QPen m_labelArmPen; |
|
99 | Themed<QPen> m_labelArmPen; | |
38 |
|
100 | |||
39 | qreal m_percentage; |
|
101 | qreal m_percentage; | |
40 | QPointF m_center; |
|
102 | QPointF m_center; |
@@ -55,7 +55,7 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op | |||||
55 | painter->drawPath(m_slicePath); |
|
55 | painter->drawPath(m_slicePath); | |
56 | painter->restore(); |
|
56 | painter->restore(); | |
57 |
|
57 | |||
58 |
if (m_data.m_ |
|
58 | if (m_data.m_isLabelVisible) { | |
59 | painter->save(); |
|
59 | painter->save(); | |
60 | painter->setPen(m_data.m_labelArmPen); |
|
60 | painter->setPen(m_data.m_labelArmPen); | |
61 | painter->drawPath(m_labelArmPath); |
|
61 | painter->drawPath(m_labelArmPath); |
@@ -93,7 +93,7 QString QPieSlice::label() const | |||||
93 | bool QPieSlice::isLabelVisible() const |
|
93 | bool QPieSlice::isLabelVisible() const | |
94 | { |
|
94 | { | |
95 | Q_D(const QPieSlice); |
|
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 | The factor is relative to pie radius. For example: |
|
207 | The factor is relative to pie radius. For example: | |
208 | 1.0 means the length is the same as the radius. |
|
208 | 1.0 means the length is the same as the radius. | |
@@ -288,8 +288,8 void QPieSlice::setLabel(QString label) | |||||
288 | void QPieSlice::setLabelVisible(bool visible) |
|
288 | void QPieSlice::setLabelVisible(bool visible) | |
289 | { |
|
289 | { | |
290 | Q_D(QPieSlice); |
|
290 | Q_D(QPieSlice); | |
291 |
if (d->m_data.m_ |
|
291 | if (d->m_data.m_isLabelVisible != visible) { | |
292 |
d->m_data.m_ |
|
292 | d->m_data.m_isLabelVisible = visible; | |
293 | emit changed(); |
|
293 | emit changed(); | |
294 | } |
|
294 | } | |
295 | } |
|
295 | } | |
@@ -337,6 +337,7 void QPieSlice::setSlicePen(const QPen &pen) | |||||
337 | Q_D(QPieSlice); |
|
337 | Q_D(QPieSlice); | |
338 | if (d->m_data.m_slicePen != pen) { |
|
338 | if (d->m_data.m_slicePen != pen) { | |
339 | d->m_data.m_slicePen = pen; |
|
339 | d->m_data.m_slicePen = pen; | |
|
340 | d->m_data.m_slicePen.setThemed(false); | |||
340 | emit changed(); |
|
341 | emit changed(); | |
341 | } |
|
342 | } | |
342 | } |
|
343 | } | |
@@ -351,6 +352,7 void QPieSlice::setSliceBrush(const QBrush &brush) | |||||
351 | Q_D(QPieSlice); |
|
352 | Q_D(QPieSlice); | |
352 | if (d->m_data.m_sliceBrush != brush) { |
|
353 | if (d->m_data.m_sliceBrush != brush) { | |
353 | d->m_data.m_sliceBrush = brush; |
|
354 | d->m_data.m_sliceBrush = brush; | |
|
355 | d->m_data.m_sliceBrush.setThemed(false); | |||
354 | emit changed(); |
|
356 | emit changed(); | |
355 | } |
|
357 | } | |
356 | } |
|
358 | } | |
@@ -365,6 +367,7 void QPieSlice::setLabelArmPen(const QPen &pen) | |||||
365 | Q_D(QPieSlice); |
|
367 | Q_D(QPieSlice); | |
366 | if (d->m_data.m_labelArmPen != pen) { |
|
368 | if (d->m_data.m_labelArmPen != pen) { | |
367 | d->m_data.m_labelArmPen = pen; |
|
369 | d->m_data.m_labelArmPen = pen; | |
|
370 | d->m_data.m_labelArmPen.setThemed(false); | |||
368 | emit changed(); |
|
371 | emit changed(); | |
369 | } |
|
372 | } | |
370 | } |
|
373 | } | |
@@ -379,12 +382,13 void QPieSlice::setLabelFont(const QFont &font) | |||||
379 | Q_D(QPieSlice); |
|
382 | Q_D(QPieSlice); | |
380 | if (d->m_data.m_labelFont != font) { |
|
383 | if (d->m_data.m_labelFont != font) { | |
381 | d->m_data.m_labelFont = font; |
|
384 | d->m_data.m_labelFont = font; | |
|
385 | d->m_data.m_labelFont.setThemed(false); | |||
382 | emit changed(); |
|
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 | The factor is relative to pie radius. For example: |
|
393 | The factor is relative to pie radius. For example: | |
390 | 1.0 means the length is the same as the radius. |
|
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