@@ -0,0 +1,43 | |||
|
1 | #ifndef QPIESLICE_P_H | |
|
2 | #define QPIESLICE_P_H | |
|
3 | ||
|
4 | #include <QObject> | |
|
5 | #include "qpieslice.h" | |
|
6 | #include "pieslicedata_p.h" | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | class QPieSlicePrivate : public QObject | |
|
11 | { | |
|
12 | Q_OBJECT | |
|
13 | ||
|
14 | public: | |
|
15 | QPieSlicePrivate(QPieSlice *parent); | |
|
16 | ~QPieSlicePrivate(); | |
|
17 | ||
|
18 | static QPieSlicePrivate* fromSlice(QPieSlice *slice); | |
|
19 | ||
|
20 | void setPen(const QPen &pen, bool themed); | |
|
21 | void setBrush(const QBrush &brush, bool themed); | |
|
22 | void setLabelPen(const QPen &pen, bool themed); | |
|
23 | void setLabelFont(const QFont &font, bool themed); | |
|
24 | ||
|
25 | void setPercentage(qreal percentage); | |
|
26 | void setStartAngle(qreal angle); | |
|
27 | void setAngleSpan(qreal span); | |
|
28 | ||
|
29 | private: | |
|
30 | PieSliceData m_data; | |
|
31 | ||
|
32 | private: | |
|
33 | friend class QPieSeriesPrivate; | |
|
34 | friend class ChartTheme; | |
|
35 | friend class PieChartItem; | |
|
36 | ||
|
37 | QPieSlice * const q_ptr; | |
|
38 | Q_DECLARE_PUBLIC(QPieSlice) | |
|
39 | }; | |
|
40 | ||
|
41 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
42 | ||
|
43 | #endif // QPIESLICE_P_H |
@@ -29,7 +29,7 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* dri | |||
|
29 | 29 | setValue(value); |
|
30 | 30 | updateLabel(); |
|
31 | 31 | setLabelFont(QFont("Arial", 8)); |
|
32 |
connect(this, SIGNAL( |
|
|
32 | connect(this, SIGNAL(percentageChanged()), this, SLOT(updateLabel())); | |
|
33 | 33 | connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); |
|
34 | 34 | } |
|
35 | 35 |
@@ -36,6 +36,7 | |||
|
36 | 36 | #include "qscatterseries.h" |
|
37 | 37 | #include "qpieseries.h" |
|
38 | 38 | #include "qpieslice.h" |
|
39 | #include "qpieslice_p.h" | |
|
39 | 40 | #include "qsplineseries.h" |
|
40 | 41 | |
|
41 | 42 | //items |
@@ -225,32 +226,19 void ChartTheme::decorate(QPieSeries *series, int index) | |||
|
225 | 226 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
226 | 227 | |
|
227 | 228 | QPieSlice *s = series->slices().at(i); |
|
228 |
PieSlice |
|
|
229 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
|
229 | 230 | |
|
230 |
if (data.m_slicePen.isThemed() || m_force) |
|
|
231 |
d |
|
|
232 | data.m_slicePen.setThemed(true); | |
|
233 | } | |
|
234 | ||
|
235 | if (data.m_sliceBrush.isThemed() || m_force) { | |
|
236 | data.m_sliceBrush = brushColor; | |
|
237 | data.m_sliceBrush.setThemed(true); | |
|
238 | } | |
|
231 | if (d->m_data.m_slicePen.isThemed() || m_force) | |
|
232 | d->setPen(penColor, true); | |
|
239 | 233 | |
|
240 |
if (data.m_ |
|
|
241 | data.m_labelPen = QPen(m_titleBrush.color()); | |
|
242 | data.m_labelPen.setThemed(true); | |
|
243 | } | |
|
234 | if (d->m_data.m_sliceBrush.isThemed() || m_force) | |
|
235 | d->setBrush(brushColor, true); | |
|
244 | 236 | |
|
245 |
if (data.m_label |
|
|
246 | data.m_labelFont = m_labelFont; | |
|
247 | data.m_labelFont.setThemed(true); | |
|
248 | } | |
|
237 | if (d->m_data.m_labelPen.isThemed() || m_force) | |
|
238 | d->setLabelPen(QPen(m_titleBrush.color()), true); | |
|
249 | 239 | |
|
250 | if (PieSliceData::fromSlice(s) != data) { | |
|
251 | PieSliceData::fromSlice(s) = data; | |
|
252 | emit PieSliceData::emitAppearanceChanged(s); | |
|
253 | } | |
|
240 | if (d->m_data.m_labelFont.isThemed() || m_force) | |
|
241 | d->setLabelFont(m_labelFont, true); | |
|
254 | 242 | } |
|
255 | 243 | } |
|
256 | 244 |
@@ -156,7 +156,7 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend | |||
|
156 | 156 | m_pieslice(pieslice) |
|
157 | 157 | { |
|
158 | 158 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
159 |
QObject::connect(pieslice, SIGNAL( |
|
|
159 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
|
160 | 160 | updated(); |
|
161 | 161 | } |
|
162 | 162 |
@@ -14,6 +14,7 PRIVATE_HEADERS += \ | |||
|
14 | 14 | $$PWD/pieslicedata_p.h \ |
|
15 | 15 | $$PWD/piechartitem_p.h \ |
|
16 | 16 | $$PWD/piesliceitem_p.h \ |
|
17 | $$PWD/qpieslice_p.h \ | |
|
17 | 18 | $$PWD/qpieseries_p.h \ |
|
18 | 19 | $$PWD/qpiemodelmapper_p.h |
|
19 | 20 | |
@@ -23,3 +24,4 PUBLIC_HEADERS += \ | |||
|
23 | 24 | $$PWD/qpiemodelmapper.h \ |
|
24 | 25 | $$PWD/qvpiemodelmapper.h \ |
|
25 | 26 | $$PWD/qhpiemodelmapper.h |
|
27 |
@@ -21,6 +21,7 | |||
|
21 | 21 | #include "piechartitem_p.h" |
|
22 | 22 | #include "piesliceitem_p.h" |
|
23 | 23 | #include "qpieslice.h" |
|
24 | #include "qpieslice_p.h" | |
|
24 | 25 | #include "qpieseries.h" |
|
25 | 26 | #include "qpieseries_p.h" |
|
26 | 27 | #include "chartpresenter_p.h" |
@@ -42,6 +43,7 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) | |||
|
42 | 43 | connect(series, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); |
|
43 | 44 | connect(series, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); |
|
44 | 45 | connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); |
|
46 | connect(QPieSeriesPrivate::fromSeries(series), SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); | |
|
45 | 47 | |
|
46 | 48 | // Note: the following does not affect as long as the item does not have anything to paint |
|
47 | 49 | setZValue(ChartPresenter::PieSeriesZValue); |
@@ -134,11 +136,18 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||
|
134 | 136 | PieSliceItem* sliceItem = new PieSliceItem(this); |
|
135 | 137 | m_sliceItems.insert(slice, sliceItem); |
|
136 | 138 | |
|
137 |
// |
|
|
138 | // to update the slice. | |
|
139 | connect(slice, SIGNAL(calculatedDataChanged()), this, SLOT(handleSliceChanged())); | |
|
139 | // Note: do need to connect to slice valueChanged() etc. | |
|
140 | // This is handled through calculatedDataChanged signal. | |
|
140 | 141 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); |
|
141 |
connect(slice, SIGNAL( |
|
|
142 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); | |
|
143 | connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); | |
|
144 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); | |
|
145 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); | |
|
146 | connect(slice, SIGNAL(labelPenChanged()), this, SLOT(handleSliceChanged())); | |
|
147 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); | |
|
148 | connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); | |
|
149 | connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); | |
|
150 | ||
|
142 | 151 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); |
|
143 | 152 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); |
|
144 | 153 | |
@@ -183,7 +192,7 void PieChartItem::handleSliceChanged() | |||
|
183 | 192 | |
|
184 | 193 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) |
|
185 | 194 | { |
|
186 |
PieSliceData &sliceData = PieSlice |
|
|
195 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; | |
|
187 | 196 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
188 | 197 | sliceData.m_radius = m_pieRadius; |
|
189 | 198 | return sliceData; |
@@ -104,24 +104,6 public: | |||
|
104 | 104 | return false; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | static void emitAppearanceChanged(QPieSlice *slice) | |
|
108 | { | |
|
109 | Q_ASSERT(slice); | |
|
110 | emit slice->appearanceChanged(); | |
|
111 | } | |
|
112 | ||
|
113 | static void emitCalculatedDataChanged(QPieSlice *slice) | |
|
114 | { | |
|
115 | Q_ASSERT(slice); | |
|
116 | emit slice->calculatedDataChanged(); | |
|
117 | } | |
|
118 | ||
|
119 | static PieSliceData &fromSlice(QPieSlice *slice) | |
|
120 | { | |
|
121 | Q_ASSERT(slice); | |
|
122 | return *slice->d; | |
|
123 | } | |
|
124 | ||
|
125 | 107 | qreal m_value; |
|
126 | 108 | |
|
127 | 109 | Themed<QPen> m_slicePen; |
@@ -143,7 +143,7 void PieSliceItem::updateGeometry() | |||
|
143 | 143 | QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) |
|
144 | 144 | { |
|
145 | 145 | if (slice->isExploded()) { |
|
146 |
qreal centerAngle = slice->startAngle() + ( |
|
|
146 | qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2); | |
|
147 | 147 | qreal len = radius * slice->explodeDistanceFactor(); |
|
148 | 148 | qreal dx = qSin(centerAngle*(PI/180)) * len; |
|
149 | 149 | qreal dy = -qCos(centerAngle*(PI/180)) * len; |
@@ -21,6 +21,7 | |||
|
21 | 21 | #include "qpieseries.h" |
|
22 | 22 | #include "qpieseries_p.h" |
|
23 | 23 | #include "qpieslice.h" |
|
24 | #include "qpieslice_p.h" | |
|
24 | 25 | #include "pieslicedata_p.h" |
|
25 | 26 | #include "chartdataset_p.h" |
|
26 | 27 | #include "charttheme_p.h" |
@@ -173,7 +174,7 bool QPieSeries::append(QList<QPieSlice*> slices) | |||
|
173 | 174 | d->updateDerivativeData(); |
|
174 | 175 | |
|
175 | 176 | foreach (QPieSlice* s, slices) { |
|
176 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceChanged())); | |
|
177 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
|
177 | 178 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
178 | 179 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
179 | 180 | } |
@@ -238,7 +239,7 bool QPieSeries::insert(int index, QPieSlice* slice) | |||
|
238 | 239 | |
|
239 | 240 | d->updateDerivativeData(); |
|
240 | 241 | |
|
241 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceChanged())); | |
|
242 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
|
242 | 243 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
243 | 244 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
244 | 245 | |
@@ -531,30 +532,23 void QPieSeriesPrivate::updateDerivativeData() | |||
|
531 | 532 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
532 | 533 | QVector<QPieSlice*> changed; |
|
533 | 534 | foreach (QPieSlice* s, m_slices) { |
|
534 | ||
|
535 | PieSliceData data = PieSliceData::fromSlice(s); | |
|
536 | data.m_percentage = s->value() / m_sum; | |
|
537 |
d |
|
|
538 | data.m_startAngle = sliceAngle; | |
|
539 | sliceAngle += data.m_angleSpan; | |
|
540 | ||
|
541 | if (PieSliceData::fromSlice(s) != data) { | |
|
542 | PieSliceData::fromSlice(s) = data; | |
|
543 | changed << s; | |
|
544 | } | |
|
535 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
|
536 | d->setPercentage(s->value() / m_sum); | |
|
537 | d->setStartAngle(sliceAngle); | |
|
538 | d->setAngleSpan(pieSpan * s->percentage()); | |
|
539 | sliceAngle += s->angleSpan(); | |
|
545 | 540 | } |
|
546 | 541 | |
|
547 | // emit signals | |
|
548 | foreach (QPieSlice* s, changed) | |
|
549 | PieSliceData::emitCalculatedDataChanged(s); | |
|
542 | ||
|
543 | emit calculatedDataChanged(); | |
|
550 | 544 | } |
|
551 | 545 | |
|
552 |
QPieSeriesPrivate* QPieSeriesPrivate:: |
|
|
546 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
|
553 | 547 | { |
|
554 |
return series |
|
|
548 | return series->d_func(); | |
|
555 | 549 | } |
|
556 | 550 | |
|
557 | void QPieSeriesPrivate::sliceChanged() | |
|
551 | void QPieSeriesPrivate::sliceValueChanged() | |
|
558 | 552 | { |
|
559 | 553 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
560 | 554 | updateDerivativeData(); |
@@ -41,14 +41,17 public: | |||
|
41 | 41 | |
|
42 | 42 | void updateDerivativeData(); |
|
43 | 43 | |
|
44 |
static QPieSeriesPrivate* |
|
|
44 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); | |
|
45 | ||
|
46 | signals: | |
|
47 | void calculatedDataChanged(); | |
|
45 | 48 | |
|
46 | 49 | public Q_SLOTS: |
|
47 | void sliceChanged(); | |
|
50 | void sliceValueChanged(); | |
|
48 | 51 | void sliceClicked(); |
|
49 | 52 | void sliceHovered(bool state); |
|
50 | 53 | |
|
51 | public: | |
|
54 | private: | |
|
52 | 55 | QList<QPieSlice*> m_slices; |
|
53 | 56 | qreal m_pieRelativeHorPos; |
|
54 | 57 | qreal m_pieRelativeVerPos; |
@@ -19,7 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpieslice.h" |
|
22 |
#include "pieslice |
|
|
22 | #include "qpieslice_p.h" | |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
@@ -59,7 +59,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
59 | 59 | */ |
|
60 | 60 | QPieSlice::QPieSlice(QObject *parent) |
|
61 | 61 | :QObject(parent), |
|
62 |
d(new PieSlice |
|
|
62 | d_ptr(new QPieSlicePrivate(this)) | |
|
63 | 63 | { |
|
64 | 64 | |
|
65 | 65 | } |
@@ -70,10 +70,10 QPieSlice::QPieSlice(QObject *parent) | |||
|
70 | 70 | */ |
|
71 | 71 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) |
|
72 | 72 | :QObject(parent), |
|
73 |
d(new PieSlice |
|
|
73 | d_ptr(new QPieSlicePrivate(this)) | |
|
74 | 74 | { |
|
75 | d->m_value = value; | |
|
76 | d->m_labelText = label; | |
|
75 | d_ptr->m_data.m_value = value; | |
|
76 | d_ptr->m_data.m_labelText = label; | |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | /*! |
@@ -82,7 +82,7 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) | |||
|
82 | 82 | */ |
|
83 | 83 | QPieSlice::~QPieSlice() |
|
84 | 84 | { |
|
85 | delete d; | |
|
85 | ||
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | /*! |
@@ -92,7 +92,7 QPieSlice::~QPieSlice() | |||
|
92 | 92 | */ |
|
93 | 93 | qreal QPieSlice::value() const |
|
94 | 94 | { |
|
95 | return d->m_value; | |
|
95 | return d_ptr->m_data.m_value; | |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | /*! |
@@ -101,7 +101,7 qreal QPieSlice::value() const | |||
|
101 | 101 | */ |
|
102 | 102 | QString QPieSlice::label() const |
|
103 | 103 | { |
|
104 | return d->m_labelText; | |
|
104 | return d_ptr->m_data.m_labelText; | |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | /*! |
@@ -110,7 +110,7 QString QPieSlice::label() const | |||
|
110 | 110 | */ |
|
111 | 111 | bool QPieSlice::isLabelVisible() const |
|
112 | 112 | { |
|
113 | return d->m_isLabelVisible; | |
|
113 | return d_ptr->m_data.m_isLabelVisible; | |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | /*! |
@@ -119,7 +119,7 bool QPieSlice::isLabelVisible() const | |||
|
119 | 119 | */ |
|
120 | 120 | bool QPieSlice::isExploded() const |
|
121 | 121 | { |
|
122 | return d->m_isExploded; | |
|
122 | return d_ptr->m_data.m_isExploded; | |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | /*! |
@@ -135,7 +135,7 bool QPieSlice::isExploded() const | |||
|
135 | 135 | */ |
|
136 | 136 | qreal QPieSlice::explodeDistanceFactor() const |
|
137 | 137 | { |
|
138 | return d->m_explodeDistanceFactor; | |
|
138 | return d_ptr->m_data.m_explodeDistanceFactor; | |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | /*! |
@@ -148,7 +148,7 qreal QPieSlice::explodeDistanceFactor() const | |||
|
148 | 148 | */ |
|
149 | 149 | qreal QPieSlice::percentage() const |
|
150 | 150 | { |
|
151 | return d->m_percentage; | |
|
151 | return d_ptr->m_data.m_percentage; | |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | /*! |
@@ -160,7 +160,7 qreal QPieSlice::percentage() const | |||
|
160 | 160 | */ |
|
161 | 161 | qreal QPieSlice::startAngle() const |
|
162 | 162 | { |
|
163 | return d->m_startAngle; | |
|
163 | return d_ptr->m_data.m_startAngle; | |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | /*! |
@@ -170,9 +170,9 qreal QPieSlice::startAngle() const | |||
|
170 | 170 | |
|
171 | 171 | Updated internally after the slice is added to the series. |
|
172 | 172 | */ |
|
173 |
qreal QPieSlice:: |
|
|
173 | qreal QPieSlice::angleSpan() const | |
|
174 | 174 | { |
|
175 |
return d->m_ |
|
|
175 | return d_ptr->m_data.m_angleSpan; | |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | /*! |
@@ -181,7 +181,7 qreal QPieSlice::endAngle() const | |||
|
181 | 181 | */ |
|
182 | 182 | QPen QPieSlice::pen() const |
|
183 | 183 | { |
|
184 | return d->m_slicePen; | |
|
184 | return d_ptr->m_data.m_slicePen; | |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | /*! |
@@ -190,7 +190,7 QPen QPieSlice::pen() const | |||
|
190 | 190 | */ |
|
191 | 191 | QBrush QPieSlice::brush() const |
|
192 | 192 | { |
|
193 | return d->m_sliceBrush; | |
|
193 | return d_ptr->m_data.m_sliceBrush; | |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | /*! |
@@ -199,7 +199,7 QBrush QPieSlice::brush() const | |||
|
199 | 199 | */ |
|
200 | 200 | QPen QPieSlice::labelPen() const |
|
201 | 201 | { |
|
202 | return d->m_labelPen; | |
|
202 | return d_ptr->m_data.m_labelPen; | |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | /*! |
@@ -208,7 +208,7 QPen QPieSlice::labelPen() const | |||
|
208 | 208 | */ |
|
209 | 209 | QFont QPieSlice::labelFont() const |
|
210 | 210 | { |
|
211 | return d->m_labelFont; | |
|
211 | return d_ptr->m_data.m_labelFont; | |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | /*! |
@@ -224,7 +224,7 QFont QPieSlice::labelFont() const | |||
|
224 | 224 | */ |
|
225 | 225 | qreal QPieSlice::labelArmLengthFactor() const |
|
226 | 226 | { |
|
227 | return d->m_labelArmLengthFactor; | |
|
227 | return d_ptr->m_data.m_labelArmLengthFactor; | |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
@@ -283,8 +283,8 qreal QPieSlice::labelArmLengthFactor() const | |||
|
283 | 283 | */ |
|
284 | 284 | void QPieSlice::setValue(qreal value) |
|
285 | 285 | { |
|
286 | if (!qFuzzyIsNull(d->m_value - value)) { | |
|
287 | d->m_value = value; | |
|
286 | if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) { | |
|
287 | d_ptr->m_data.m_value = value; | |
|
288 | 288 | emit valueChanged(); |
|
289 | 289 | } |
|
290 | 290 | } |
@@ -295,8 +295,8 void QPieSlice::setValue(qreal value) | |||
|
295 | 295 | */ |
|
296 | 296 | void QPieSlice::setLabel(QString label) |
|
297 | 297 | { |
|
298 | if (d->m_labelText != label) { | |
|
299 | d->m_labelText = label; | |
|
298 | if (d_ptr->m_data.m_labelText != label) { | |
|
299 | d_ptr->m_data.m_labelText = label; | |
|
300 | 300 | emit labelChanged(); |
|
301 | 301 | } |
|
302 | 302 | } |
@@ -307,9 +307,9 void QPieSlice::setLabel(QString label) | |||
|
307 | 307 | */ |
|
308 | 308 | void QPieSlice::setLabelVisible(bool visible) |
|
309 | 309 | { |
|
310 | if (d->m_isLabelVisible != visible) { | |
|
311 | d->m_isLabelVisible = visible; | |
|
312 |
emit |
|
|
310 | if (d_ptr->m_data.m_isLabelVisible != visible) { | |
|
311 | d_ptr->m_data.m_isLabelVisible = visible; | |
|
312 | emit labelVisibleChanged(); | |
|
313 | 313 | } |
|
314 | 314 | } |
|
315 | 315 | |
@@ -322,9 +322,9 void QPieSlice::setLabelVisible(bool visible) | |||
|
322 | 322 | */ |
|
323 | 323 | void QPieSlice::setExploded(bool exploded) |
|
324 | 324 | { |
|
325 | if (d->m_isExploded != exploded) { | |
|
326 | d->m_isExploded = exploded; | |
|
327 |
emit |
|
|
325 | if (d_ptr->m_data.m_isExploded != exploded) { | |
|
326 | d_ptr->m_data.m_isExploded = exploded; | |
|
327 | emit explodedChanged(); | |
|
328 | 328 | } |
|
329 | 329 | } |
|
330 | 330 | |
@@ -341,9 +341,9 void QPieSlice::setExploded(bool exploded) | |||
|
341 | 341 | */ |
|
342 | 342 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
343 | 343 | { |
|
344 | if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) { | |
|
345 | d->m_explodeDistanceFactor = factor; | |
|
346 |
emit |
|
|
344 | if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) { | |
|
345 | d_ptr->m_data.m_explodeDistanceFactor = factor; | |
|
346 | emit explodeDistanceFactorChanged(); | |
|
347 | 347 | } |
|
348 | 348 | } |
|
349 | 349 | |
@@ -356,11 +356,7 void QPieSlice::setExplodeDistanceFactor(qreal factor) | |||
|
356 | 356 | */ |
|
357 | 357 | void QPieSlice::setPen(const QPen &pen) |
|
358 | 358 | { |
|
359 | if (d->m_slicePen != pen) { | |
|
360 | d->m_slicePen = pen; | |
|
361 | d->m_slicePen.setThemed(false); | |
|
362 | emit appearanceChanged(); | |
|
363 | } | |
|
359 | d_ptr->setPen(pen, false); | |
|
364 | 360 | } |
|
365 | 361 | |
|
366 | 362 | /*! |
@@ -372,11 +368,7 void QPieSlice::setPen(const QPen &pen) | |||
|
372 | 368 | */ |
|
373 | 369 | void QPieSlice::setBrush(const QBrush &brush) |
|
374 | 370 | { |
|
375 | if (d->m_sliceBrush != brush) { | |
|
376 | d->m_sliceBrush = brush; | |
|
377 | d->m_sliceBrush.setThemed(false); | |
|
378 | emit appearanceChanged(); | |
|
379 | } | |
|
371 | d_ptr->setBrush(brush, false); | |
|
380 | 372 | } |
|
381 | 373 | |
|
382 | 374 | /*! |
@@ -388,11 +380,7 void QPieSlice::setBrush(const QBrush &brush) | |||
|
388 | 380 | */ |
|
389 | 381 | void QPieSlice::setLabelPen(const QPen &pen) |
|
390 | 382 | { |
|
391 | if (d->m_labelPen != pen) { | |
|
392 | d->m_labelPen = pen; | |
|
393 | d->m_labelPen.setThemed(false); | |
|
394 | emit appearanceChanged(); | |
|
395 | } | |
|
383 | d_ptr->setLabelPen(pen, false); | |
|
396 | 384 | } |
|
397 | 385 | |
|
398 | 386 | /*! |
@@ -404,11 +392,7 void QPieSlice::setLabelPen(const QPen &pen) | |||
|
404 | 392 | */ |
|
405 | 393 | void QPieSlice::setLabelFont(const QFont &font) |
|
406 | 394 | { |
|
407 | if (d->m_labelFont != font) { | |
|
408 | d->m_labelFont = font; | |
|
409 | d->m_labelFont.setThemed(false); | |
|
410 | emit appearanceChanged(); | |
|
411 | } | |
|
395 | d_ptr->setLabelFont(font, false); | |
|
412 | 396 | } |
|
413 | 397 | |
|
414 | 398 | /*! |
@@ -424,9 +408,86 void QPieSlice::setLabelFont(const QFont &font) | |||
|
424 | 408 | */ |
|
425 | 409 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
426 | 410 | { |
|
427 | if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) { | |
|
428 | d->m_labelArmLengthFactor = factor; | |
|
429 |
emit |
|
|
411 | if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) { | |
|
412 | d_ptr->m_data.m_labelArmLengthFactor = factor; | |
|
413 | emit labelArmLengthFactorChanged(); | |
|
414 | } | |
|
415 | } | |
|
416 | ||
|
417 | QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent) | |
|
418 | :QObject(parent), | |
|
419 | q_ptr(parent) | |
|
420 | { | |
|
421 | ||
|
422 | } | |
|
423 | ||
|
424 | QPieSlicePrivate::~QPieSlicePrivate() | |
|
425 | { | |
|
426 | ||
|
427 | } | |
|
428 | ||
|
429 | QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) | |
|
430 | { | |
|
431 | return slice->d_func(); | |
|
432 | } | |
|
433 | ||
|
434 | void QPieSlicePrivate::setPen(const QPen &pen, bool themed) | |
|
435 | { | |
|
436 | if (m_data.m_slicePen != pen) { | |
|
437 | m_data.m_slicePen = pen; | |
|
438 | m_data.m_slicePen.setThemed(themed); | |
|
439 | emit q_ptr->penChanged(); | |
|
440 | } | |
|
441 | } | |
|
442 | ||
|
443 | void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) | |
|
444 | { | |
|
445 | if (m_data.m_sliceBrush != brush) { | |
|
446 | m_data.m_sliceBrush = brush; | |
|
447 | m_data.m_sliceBrush.setThemed(themed); | |
|
448 | emit q_ptr->brushChanged(); | |
|
449 | } | |
|
450 | } | |
|
451 | ||
|
452 | void QPieSlicePrivate::setLabelPen(const QPen &pen, bool themed) | |
|
453 | { | |
|
454 | if (m_data.m_labelPen != pen) { | |
|
455 | m_data.m_labelPen = pen; | |
|
456 | m_data.m_labelPen.setThemed(themed); | |
|
457 | emit q_ptr->labelPenChanged(); | |
|
458 | } | |
|
459 | } | |
|
460 | ||
|
461 | void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed) | |
|
462 | { | |
|
463 | if (m_data.m_labelFont != font) { | |
|
464 | m_data.m_labelFont = font; | |
|
465 | m_data.m_labelFont.setThemed(themed); | |
|
466 | emit q_ptr->labelFontChanged(); | |
|
467 | } | |
|
468 | } | |
|
469 | ||
|
470 | void QPieSlicePrivate::setPercentage(qreal percentage) | |
|
471 | { | |
|
472 | if (!qFuzzyIsNull(m_data.m_percentage - percentage)) { | |
|
473 | m_data.m_percentage = percentage; | |
|
474 | emit q_ptr->percentageChanged(); | |
|
475 | } | |
|
476 | } | |
|
477 | ||
|
478 | void QPieSlicePrivate::setStartAngle(qreal angle) | |
|
479 | { | |
|
480 | if (!qFuzzyIsNull(m_data.m_startAngle - angle)) { | |
|
481 | m_data.m_startAngle = angle; | |
|
482 | emit q_ptr->startAngleChanged(); | |
|
483 | } | |
|
484 | } | |
|
485 | ||
|
486 | void QPieSlicePrivate::setAngleSpan(qreal span) | |
|
487 | { | |
|
488 | if (!qFuzzyIsNull(m_data.m_angleSpan - span)) { | |
|
489 | m_data.m_angleSpan = span; | |
|
490 | emit q_ptr->angleSpanChanged(); | |
|
430 | 491 | } |
|
431 | 492 | } |
|
432 | 493 | |
@@ -434,3 +495,4 QTCOMMERCIALCHART_END_NAMESPACE | |||
|
434 | 495 | |
|
435 | 496 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
436 | 497 | #include "moc_qpieslice.cpp" |
|
498 | #include "moc_qpieslice_p.cpp" |
@@ -28,20 +28,24 | |||
|
28 | 28 | #include <QFont> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 |
class PieSlice |
|
|
31 | class QPieSlicePrivate; | |
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
37 | 37 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) |
|
38 | Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible) | |
|
39 | Q_PROPERTY(bool exploded READ isExploded WRITE setExploded) | |
|
38 | Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged) | |
|
39 | Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged) | |
|
40 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) | |
|
41 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) | |
|
42 | Q_PROPERTY(QPen labelPen READ labelPen WRITE setLabelPen NOTIFY labelPenChanged) | |
|
43 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) | |
|
40 | 44 | Q_PROPERTY(qreal LabelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor) |
|
41 | 45 | Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor) |
|
42 |
Q_PROPERTY(qreal percentage READ percentage NOTIFY |
|
|
43 |
Q_PROPERTY(qreal startAngle READ startAngle NOTIFY |
|
|
44 |
Q_PROPERTY(qreal |
|
|
46 | Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged) | |
|
47 | Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged) | |
|
48 | Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged) | |
|
45 | 49 | |
|
46 | 50 | public: |
|
47 | 51 | explicit QPieSlice(QObject *parent = 0); |
@@ -54,45 +58,54 public: | |||
|
54 | 58 | void setValue(qreal value); |
|
55 | 59 | qreal value() const; |
|
56 | 60 | |
|
61 | void setLabelVisible(bool visible = true); | |
|
62 | bool isLabelVisible() const; | |
|
63 | ||
|
64 | void setExploded(bool exploded = true); | |
|
65 | bool isExploded() const; | |
|
66 | ||
|
57 | 67 | void setPen(const QPen &pen); |
|
58 | 68 | QPen pen() const; |
|
59 | 69 | |
|
60 | 70 | void setBrush(const QBrush &brush); |
|
61 | 71 | QBrush brush() const; |
|
62 | 72 | |
|
63 | void setLabelVisible(bool visible = true); | |
|
64 | bool isLabelVisible() const; | |
|
65 | ||
|
66 | void setLabelArmLengthFactor(qreal factor); | |
|
67 | qreal labelArmLengthFactor() const; | |
|
68 | ||
|
69 | 73 | void setLabelPen(const QPen &pen); |
|
70 | 74 | QPen labelPen() const; |
|
71 | 75 | |
|
72 | 76 | void setLabelFont(const QFont &font); |
|
73 | 77 | QFont labelFont() const; |
|
74 | 78 | |
|
75 | void setExploded(bool exploded = true); | |
|
76 | bool isExploded() const; | |
|
79 | void setLabelArmLengthFactor(qreal factor); | |
|
80 | qreal labelArmLengthFactor() const; | |
|
77 | 81 | |
|
78 | 82 | void setExplodeDistanceFactor(qreal factor); |
|
79 | 83 | qreal explodeDistanceFactor() const; |
|
80 | 84 | |
|
81 | 85 | qreal percentage() const; |
|
82 | 86 | qreal startAngle() const; |
|
83 |
qreal |
|
|
87 | qreal angleSpan() const; | |
|
84 | 88 | |
|
85 | 89 | Q_SIGNALS: |
|
86 | 90 | void labelChanged(); |
|
87 | 91 | void valueChanged(); |
|
88 |
void |
|
|
89 |
void |
|
|
92 | void labelVisibleChanged(); | |
|
93 | void explodedChanged(); | |
|
94 | void penChanged(); | |
|
95 | void brushChanged(); | |
|
96 | void labelPenChanged(); | |
|
97 | void labelFontChanged(); | |
|
98 | void labelArmLengthFactorChanged(); | |
|
99 | void explodeDistanceFactorChanged(); | |
|
100 | void percentageChanged(); | |
|
101 | void startAngleChanged(); | |
|
102 | void angleSpanChanged(); | |
|
90 | 103 | void clicked(); |
|
91 | 104 | void hovered(bool state); |
|
92 | 105 | |
|
93 | 106 | private: |
|
94 | friend class PieSliceData; | |
|
95 | PieSliceData * const d; | |
|
107 | QPieSlicePrivate * const d_ptr; | |
|
108 | Q_DECLARE_PRIVATE(QPieSlice) | |
|
96 | 109 | Q_DISABLE_COPY(QPieSlice) |
|
97 | 110 | }; |
|
98 | 111 |
@@ -260,14 +260,18 void tst_qpieseries::calculatedValues() | |||
|
260 | 260 | QPieSeries s; |
|
261 | 261 | |
|
262 | 262 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); |
|
263 |
QSignalSpy |
|
|
263 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); | |
|
264 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); | |
|
265 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); | |
|
264 | 266 | |
|
265 | 267 | // add a slice |
|
266 | 268 | s.append(slice1); |
|
267 | 269 | verifyCalculatedData(s, &ok); |
|
268 | 270 | if (!ok) |
|
269 | 271 | return; |
|
270 |
QCOMPARE( |
|
|
272 | QCOMPARE(percentageSpy.count(), 1); | |
|
273 | QCOMPARE(startAngleSpy.count(), 0); | |
|
274 | QCOMPARE(angleSpanSpy.count(), 1); | |
|
271 | 275 | |
|
272 | 276 | // add some more slices |
|
273 | 277 | QList<QPieSlice *> list; |
@@ -277,21 +281,27 void tst_qpieseries::calculatedValues() | |||
|
277 | 281 | verifyCalculatedData(s, &ok); |
|
278 | 282 | if (!ok) |
|
279 | 283 | return; |
|
280 |
QCOMPARE( |
|
|
284 | QCOMPARE(percentageSpy.count(), 2); | |
|
285 | QCOMPARE(startAngleSpy.count(), 0); | |
|
286 | QCOMPARE(angleSpanSpy.count(), 2); | |
|
281 | 287 | |
|
282 | 288 | // remove a slice |
|
283 | 289 | s.remove(list.first()); // remove slice 2 |
|
284 | 290 | verifyCalculatedData(s, &ok); |
|
285 | 291 | if (!ok) |
|
286 | 292 | return; |
|
287 |
QCOMPARE( |
|
|
293 | QCOMPARE(percentageSpy.count(), 3); | |
|
294 | QCOMPARE(startAngleSpy.count(), 0); | |
|
295 | QCOMPARE(angleSpanSpy.count(), 3); | |
|
288 | 296 | |
|
289 | 297 | // insert a slice |
|
290 | 298 | s.insert(0, new QPieSlice("Slice 4", 4)); |
|
291 | 299 | verifyCalculatedData(s, &ok); |
|
292 | 300 | if (!ok) |
|
293 | 301 | return; |
|
294 |
QCOMPARE( |
|
|
302 | QCOMPARE(percentageSpy.count(), 4); | |
|
303 | QCOMPARE(startAngleSpy.count(), 1); | |
|
304 | QCOMPARE(angleSpanSpy.count(), 4); | |
|
295 | 305 | |
|
296 | 306 | // modify pie angles |
|
297 | 307 | s.setPieStartAngle(-90); |
@@ -299,11 +309,16 void tst_qpieseries::calculatedValues() | |||
|
299 | 309 | verifyCalculatedData(s, &ok); |
|
300 | 310 | if (!ok) |
|
301 | 311 | return; |
|
302 |
QCOMPARE( |
|
|
312 | QCOMPARE(percentageSpy.count(), 4); | |
|
313 | QCOMPARE(startAngleSpy.count(), 3); | |
|
314 | QCOMPARE(angleSpanSpy.count(), 6); | |
|
303 | 315 | |
|
304 | 316 | // clear all |
|
305 | 317 | s.clear(); |
|
306 | 318 | verifyCalculatedData(s, &ok); |
|
319 | QCOMPARE(percentageSpy.count(), 4); | |
|
320 | QCOMPARE(startAngleSpy.count(), 3); | |
|
321 | QCOMPARE(angleSpanSpy.count(), 6); | |
|
307 | 322 | } |
|
308 | 323 | |
|
309 | 324 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) |
@@ -321,13 +336,13 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |||
|
321 | 336 | qreal ratio = slice->value() / sum; |
|
322 | 337 | qreal sliceSpan = pieAngleSpan * ratio; |
|
323 | 338 | QCOMPARE(slice->startAngle(), startAngle); |
|
324 |
QCOMPARE(slice-> |
|
|
339 | QCOMPARE(slice->angleSpan(), sliceSpan); | |
|
325 | 340 | QCOMPARE(slice->percentage(), ratio); |
|
326 | 341 | startAngle += sliceSpan; |
|
327 | 342 | } |
|
328 | 343 | |
|
329 | 344 | if (!series.isEmpty()) |
|
330 |
QCOMPARE(series.slices().last()-> |
|
|
345 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); | |
|
331 | 346 | |
|
332 | 347 | *ok = true; |
|
333 | 348 | } |
@@ -85,7 +85,7 void tst_qpieslice::construction() | |||
|
85 | 85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value |
|
86 | 86 | QCOMPARE(slice1.percentage(), 0.0); |
|
87 | 87 | QCOMPARE(slice1.startAngle(), 0.0); |
|
88 |
QCOMPARE(slice1. |
|
|
88 | QCOMPARE(slice1.angleSpan(), 0.0); | |
|
89 | 89 | |
|
90 | 90 | // value and label params |
|
91 | 91 | QPieSlice slice2("foobar", 1.0); |
@@ -101,7 +101,7 void tst_qpieslice::construction() | |||
|
101 | 101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value |
|
102 | 102 | QCOMPARE(slice2.percentage(), 0.0); |
|
103 | 103 | QCOMPARE(slice2.startAngle(), 0.0); |
|
104 |
QCOMPARE(slice2. |
|
|
104 | QCOMPARE(slice2.angleSpan(), 0.0); | |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void tst_qpieslice::changedSignals() |
@@ -110,8 +110,15 void tst_qpieslice::changedSignals() | |||
|
110 | 110 | |
|
111 | 111 | QSignalSpy valueSpy(&slice, SIGNAL(valueChanged())); |
|
112 | 112 | QSignalSpy labelSpy(&slice, SIGNAL(labelChanged())); |
|
113 |
QSignalSpy |
|
|
114 | // calculatedDataChanged signal is tested at tst_qpieseries::calculatedValues() | |
|
113 | QSignalSpy explodedSpy(&slice, SIGNAL(explodedChanged())); | |
|
114 | QSignalSpy penSpy(&slice, SIGNAL(penChanged())); | |
|
115 | QSignalSpy brushSpy(&slice, SIGNAL(brushChanged())); | |
|
116 | QSignalSpy labelPenSpy(&slice, SIGNAL(labelPenChanged())); | |
|
117 | QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged())); | |
|
118 | QSignalSpy labelArmLengthFactorSpy(&slice, SIGNAL(labelArmLengthFactorChanged())); | |
|
119 | QSignalSpy explodeDistanceFactorSpy(&slice, SIGNAL(explodeDistanceFactorChanged())); | |
|
120 | ||
|
121 | // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues() | |
|
115 | 122 | |
|
116 | 123 | // set everything twice to see we do not get unnecessary signals |
|
117 | 124 | slice.setValue(1); |
@@ -137,7 +144,13 void tst_qpieslice::changedSignals() | |||
|
137 | 144 | |
|
138 | 145 | TRY_COMPARE(valueSpy.count(), 1); |
|
139 | 146 | TRY_COMPARE(labelSpy.count(), 1); |
|
140 |
TRY_COMPARE( |
|
|
147 | TRY_COMPARE(explodedSpy.count(), 1); | |
|
148 | TRY_COMPARE(penSpy.count(), 1); | |
|
149 | TRY_COMPARE(brushSpy.count(), 1); | |
|
150 | TRY_COMPARE(labelPenSpy.count(), 1); | |
|
151 | TRY_COMPARE(labelFontSpy.count(), 1); | |
|
152 | TRY_COMPARE(labelArmLengthFactorSpy.count(), 1); | |
|
153 | TRY_COMPARE(explodeDistanceFactorSpy.count(), 1); | |
|
141 | 154 | } |
|
142 | 155 | |
|
143 | 156 | void tst_qpieslice::customize() |
General Comments 0
You need to be logged in to leave comments.
Login now