@@ -1,210 +1,210 | |||||
1 |
|
1 | |||
2 | #include "piepresenter_p.h" |
|
2 | #include "piepresenter_p.h" | |
3 | #include "pieslice_p.h" |
|
3 | #include "pieslice_p.h" | |
4 | #include "qpieslice.h" |
|
4 | #include "qpieslice.h" | |
5 | #include "pieslicelabel_p.h" |
|
5 | #include "pieslicelabel_p.h" | |
6 | #include "qpieseries.h" |
|
6 | #include "qpieseries.h" | |
7 | #include <qmath.h> |
|
7 | #include <qmath.h> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 | #include <QFontMetrics> |
|
9 | #include <QFontMetrics> | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) |
|
14 | PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) | |
15 | :ChartItem(parent), |
|
15 | :ChartItem(parent), | |
16 | m_series(series) |
|
16 | m_series(series) | |
17 | { |
|
17 | { | |
18 | Q_ASSERT(series); |
|
18 | Q_ASSERT(series); | |
19 | connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&))); |
|
19 | connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&))); | |
20 | connect(series, SIGNAL(sizeFactorChanged()), this, SLOT(updateGeometry())); |
|
20 | connect(series, SIGNAL(sizeFactorChanged()), this, SLOT(updateGeometry())); | |
21 | connect(series, SIGNAL(positionChanged()), this, SLOT(updateGeometry())); |
|
21 | connect(series, SIGNAL(positionChanged()), this, SLOT(updateGeometry())); | |
22 |
|
22 | |||
23 | if (m_series->count()) { |
|
23 | if (m_series->count()) { | |
24 | QPieSeries::ChangeSet changeSet; |
|
24 | QPieSeries::ChangeSet changeSet; | |
25 | changeSet.appendAdded(m_series->m_slices); |
|
25 | changeSet.appendAdded(m_series->m_slices); | |
26 | handleSeriesChanged(changeSet); |
|
26 | handleSeriesChanged(changeSet); | |
27 | } |
|
27 | } | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | PiePresenter::~PiePresenter() |
|
30 | PiePresenter::~PiePresenter() | |
31 | { |
|
31 | { | |
32 | // slices deleted automatically through QGraphicsItem |
|
32 | // slices deleted automatically through QGraphicsItem | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void PiePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
35 | void PiePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) | |
36 | { |
|
36 | { | |
37 | // TODO: paint shadows for all components |
|
37 | // TODO: paint shadows for all components | |
38 | // - get paths from items & merge & offset and draw with shadow color? |
|
38 | // - get paths from items & merge & offset and draw with shadow color? | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | void PiePresenter::handleSeriesChanged(const QPieSeries::ChangeSet& changeSet) |
|
41 | void PiePresenter::handleSeriesChanged(const QPieSeries::ChangeSet& changeSet) | |
42 | { |
|
42 | { | |
43 | //qDebug() << "PiePresenter::handleSeriesChanged()"; |
|
43 | //qDebug() << "PiePresenter::handleSeriesChanged()"; | |
44 | //qDebug() << " added : " << changeSet.added(); |
|
44 | //qDebug() << " added : " << changeSet.added(); | |
45 | //qDebug() << " changed: " << changeSet.changed(); |
|
45 | //qDebug() << " changed: " << changeSet.changed(); | |
46 | //qDebug() << " removed: " << changeSet.removed(); |
|
46 | //qDebug() << " removed: " << changeSet.removed(); | |
47 |
|
47 | |||
48 | foreach (QPieSlice* s, changeSet.added()) |
|
48 | foreach (QPieSlice* s, changeSet.added()) | |
49 | addSlice(s); |
|
49 | addSlice(s); | |
50 |
|
50 | |||
51 | foreach (QPieSlice* s, changeSet.changed()) |
|
51 | foreach (QPieSlice* s, changeSet.changed()) | |
52 | updateSlice(s); |
|
52 | updateSlice(s); | |
53 |
|
53 | |||
54 | foreach (QPieSlice* s, changeSet.removed()) |
|
54 | foreach (QPieSlice* s, changeSet.removed()) | |
55 | deleteSlice(s); |
|
55 | deleteSlice(s); | |
56 |
|
56 | |||
57 | // every change possibly changes the actual pie size |
|
57 | // every change possibly changes the actual pie size | |
58 | updateGeometry(); |
|
58 | updateGeometry(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void PiePresenter::handleDomainChanged(const Domain& domain) |
|
61 | void PiePresenter::handleDomainChanged(const Domain& domain) | |
62 | { |
|
62 | { | |
63 | // TODO |
|
63 | // TODO | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void PiePresenter::handleGeometryChanged(const QRectF& rect) |
|
66 | void PiePresenter::handleGeometryChanged(const QRectF& rect) | |
67 | { |
|
67 | { | |
68 | m_rect = rect; |
|
68 | m_rect = rect; | |
69 | prepareGeometryChange(); |
|
69 | prepareGeometryChange(); | |
70 | updateGeometry(); |
|
70 | updateGeometry(); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void PiePresenter::updateGeometry() |
|
73 | void PiePresenter::updateGeometry() | |
74 | { |
|
74 | { | |
75 | if (!m_rect.isValid() || m_rect.isEmpty()) |
|
75 | if (!m_rect.isValid() || m_rect.isEmpty()) | |
76 | return; |
|
76 | return; | |
77 |
|
77 | |||
78 | // calculate maximum rectangle for pie |
|
78 | // calculate maximum rectangle for pie | |
79 | QRectF pieRect = m_rect; |
|
79 | QRectF pieRect = m_rect; | |
80 | if (pieRect.width() < pieRect.height()) { |
|
80 | if (pieRect.width() < pieRect.height()) { | |
81 | pieRect.setWidth(pieRect.width() * m_series->sizeFactor()); |
|
81 | pieRect.setWidth(pieRect.width() * m_series->sizeFactor()); | |
82 | pieRect.setHeight(pieRect.width()); |
|
82 | pieRect.setHeight(pieRect.width()); | |
83 | pieRect.moveCenter(m_rect.center()); |
|
83 | pieRect.moveCenter(m_rect.center()); | |
84 | } else { |
|
84 | } else { | |
85 | pieRect.setHeight(pieRect.height() * m_series->sizeFactor()); |
|
85 | pieRect.setHeight(pieRect.height() * m_series->sizeFactor()); | |
86 | pieRect.setWidth(pieRect.height()); |
|
86 | pieRect.setWidth(pieRect.height()); | |
87 | pieRect.moveCenter(m_rect.center()); |
|
87 | pieRect.moveCenter(m_rect.center()); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | // position the pie rectangle |
|
90 | // position the pie rectangle | |
91 | switch (m_series->position()) { |
|
91 | switch (m_series->position()) { | |
92 | case QPieSeries::PiePositionTopLeft: { |
|
92 | case QPieSeries::PiePositionTopLeft: { | |
93 | pieRect.setHeight(pieRect.height() / 2); |
|
93 | pieRect.setHeight(pieRect.height() / 2); | |
94 | pieRect.setWidth(pieRect.height()); |
|
94 | pieRect.setWidth(pieRect.height()); | |
95 | pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2)); |
|
95 | pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2)); | |
96 | break; |
|
96 | break; | |
97 | } |
|
97 | } | |
98 | case QPieSeries::PiePositionTopRight: { |
|
98 | case QPieSeries::PiePositionTopRight: { | |
99 | pieRect.setHeight(pieRect.height() / 2); |
|
99 | pieRect.setHeight(pieRect.height() / 2); | |
100 | pieRect.setWidth(pieRect.height()); |
|
100 | pieRect.setWidth(pieRect.height()); | |
101 | pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2)); |
|
101 | pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2)); | |
102 | break; |
|
102 | break; | |
103 | } |
|
103 | } | |
104 | case QPieSeries::PiePositionBottomLeft: { |
|
104 | case QPieSeries::PiePositionBottomLeft: { | |
105 | pieRect.setHeight(pieRect.height() / 2); |
|
105 | pieRect.setHeight(pieRect.height() / 2); | |
106 | pieRect.setWidth(pieRect.height()); |
|
106 | pieRect.setWidth(pieRect.height()); | |
107 | pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3)); |
|
107 | pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3)); | |
108 | break; |
|
108 | break; | |
109 | } |
|
109 | } | |
110 | case QPieSeries::PiePositionBottomRight: { |
|
110 | case QPieSeries::PiePositionBottomRight: { | |
111 | pieRect.setHeight(pieRect.height() / 2); |
|
111 | pieRect.setHeight(pieRect.height() / 2); | |
112 | pieRect.setWidth(pieRect.height()); |
|
112 | pieRect.setWidth(pieRect.height()); | |
113 | pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3)); |
|
113 | pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3)); | |
114 | break; |
|
114 | break; | |
115 | } |
|
115 | } | |
116 | default: |
|
116 | default: | |
117 | break; |
|
117 | break; | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | // calculate how much space we need around the pie rectangle (labels & exploding) |
|
120 | // calculate how much space we need around the pie rectangle (labels & exploding) | |
121 | qreal delta = 0; |
|
121 | qreal delta = 0; | |
122 | qreal pieRadius = pieRect.height() / 2; |
|
122 | qreal pieRadius = pieRect.height() / 2; | |
123 | foreach (QPieSlice* s, m_series->m_slices) { |
|
123 | foreach (QPieSlice* s, m_series->m_slices) { | |
124 |
|
124 | |||
125 | // calculate the farthest point in the slice from the pie center |
|
125 | // calculate the farthest point in the slice from the pie center | |
126 |
qreal centerAngle = s->angle |
|
126 | qreal centerAngle = s->m_startAngle + (s->m_angleSpan / 2); | |
127 | qreal len = pieRadius + s->labelArmLength() + s->explodeDistance(); |
|
127 | qreal len = pieRadius + s->labelArmLength() + s->explodeDistance(); | |
128 | QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len); |
|
128 | QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len); | |
129 | QPointF p = pieRect.center() + dp; |
|
129 | QPointF p = pieRect.center() + dp; | |
130 |
|
130 | |||
131 | // TODO: consider the label text |
|
131 | // TODO: consider the label text | |
132 |
|
132 | |||
133 | // calculate how much the radius must get smaller to fit that point in the base rectangle |
|
133 | // calculate how much the radius must get smaller to fit that point in the base rectangle | |
134 | qreal dt = m_rect.top() - p.y(); |
|
134 | qreal dt = m_rect.top() - p.y(); | |
135 | if (dt > delta) delta = dt; |
|
135 | if (dt > delta) delta = dt; | |
136 | qreal dl = m_rect.left() - p.x(); |
|
136 | qreal dl = m_rect.left() - p.x(); | |
137 | if (dl > delta) delta = dl; |
|
137 | if (dl > delta) delta = dl; | |
138 | qreal dr = p.x() - m_rect.right(); |
|
138 | qreal dr = p.x() - m_rect.right(); | |
139 | if (dr > delta) delta = dr; |
|
139 | if (dr > delta) delta = dr; | |
140 | qreal db = p.y() - m_rect.bottom(); |
|
140 | qreal db = p.y() - m_rect.bottom(); | |
141 | if (db > delta) delta = db; |
|
141 | if (db > delta) delta = db; | |
142 |
|
142 | |||
143 | //if (!m_rect.contains(p)) qDebug() << s->label() << dt << dl << dr << db << "delta" << delta; |
|
143 | //if (!m_rect.contains(p)) qDebug() << s->label() << dt << dl << dr << db << "delta" << delta; | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | // shrink the pie rectangle so that everything outside it fits the base rectangle |
|
146 | // shrink the pie rectangle so that everything outside it fits the base rectangle | |
147 | pieRect.adjust(delta, delta, -delta, -delta); |
|
147 | pieRect.adjust(delta, delta, -delta, -delta); | |
148 |
|
148 | |||
149 | // update slices |
|
149 | // update slices | |
150 | if (m_pieRect != pieRect) { |
|
150 | if (m_pieRect != pieRect) { | |
151 | m_pieRect = pieRect; |
|
151 | m_pieRect = pieRect; | |
152 | //qDebug() << "PiePresenter::updateGeometry()" << m_rect << m_pieRect; |
|
152 | //qDebug() << "PiePresenter::updateGeometry()" << m_rect << m_pieRect; | |
153 | foreach (PieSlice* s, m_slices.values()) { |
|
153 | foreach (PieSlice* s, m_slices.values()) { | |
154 | s->setPieRect(m_pieRect); |
|
154 | s->setPieRect(m_pieRect); | |
155 | s->updateGeometry(); |
|
155 | s->updateGeometry(); | |
156 | s->update(); |
|
156 | s->update(); | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void PiePresenter::addSlice(QPieSlice* sliceData) |
|
161 | void PiePresenter::addSlice(QPieSlice* sliceData) | |
162 | { |
|
162 | { | |
163 | //qDebug() << "PiePresenter::addSlice()" << sliceData; |
|
163 | //qDebug() << "PiePresenter::addSlice()" << sliceData; | |
164 |
|
164 | |||
165 | if (m_slices.keys().contains(sliceData)) { |
|
165 | if (m_slices.keys().contains(sliceData)) { | |
166 | Q_ASSERT(0); // TODO: how to handle this nicely? |
|
166 | Q_ASSERT(0); // TODO: how to handle this nicely? | |
167 | return; |
|
167 | return; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | // create slice |
|
170 | // create slice | |
171 | PieSlice *slice = new PieSlice(this); |
|
171 | PieSlice *slice = new PieSlice(this); | |
172 | slice->setPieRect(m_pieRect); |
|
172 | slice->setPieRect(m_pieRect); | |
173 | slice->updateData(sliceData); |
|
173 | slice->updateData(sliceData); | |
174 | slice->updateGeometry(); |
|
174 | slice->updateGeometry(); | |
175 | slice->update(); |
|
175 | slice->update(); | |
176 | m_slices.insert(sliceData, slice); |
|
176 | m_slices.insert(sliceData, slice); | |
177 |
|
177 | |||
178 | // connect signals |
|
178 | // connect signals | |
179 | connect(slice, SIGNAL(clicked()), sliceData, SIGNAL(clicked())); |
|
179 | connect(slice, SIGNAL(clicked()), sliceData, SIGNAL(clicked())); | |
180 | connect(slice, SIGNAL(hoverEnter()), sliceData, SIGNAL(hoverEnter())); |
|
180 | connect(slice, SIGNAL(hoverEnter()), sliceData, SIGNAL(hoverEnter())); | |
181 | connect(slice, SIGNAL(hoverLeave()), sliceData, SIGNAL(hoverLeave())); |
|
181 | connect(slice, SIGNAL(hoverLeave()), sliceData, SIGNAL(hoverLeave())); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void PiePresenter::updateSlice(QPieSlice* sliceData) |
|
184 | void PiePresenter::updateSlice(QPieSlice* sliceData) | |
185 | { |
|
185 | { | |
186 | //qDebug() << "PiePresenter::updateSlice()" << sliceData; |
|
186 | //qDebug() << "PiePresenter::updateSlice()" << sliceData; | |
187 |
|
187 | |||
188 | if (!m_slices.contains(sliceData)) { |
|
188 | if (!m_slices.contains(sliceData)) { | |
189 | Q_ASSERT(0); // TODO: how to handle this nicely? |
|
189 | Q_ASSERT(0); // TODO: how to handle this nicely? | |
190 | return; |
|
190 | return; | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | m_slices[sliceData]->updateData(sliceData); |
|
193 | m_slices[sliceData]->updateData(sliceData); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void PiePresenter::deleteSlice(QPieSlice* sliceData) |
|
196 | void PiePresenter::deleteSlice(QPieSlice* sliceData) | |
197 | { |
|
197 | { | |
198 | //qDebug() << "PiePresenter::deleteSlice()" << sliceData; |
|
198 | //qDebug() << "PiePresenter::deleteSlice()" << sliceData; | |
199 |
|
199 | |||
200 | if (!m_slices.contains(sliceData)) { |
|
200 | if (!m_slices.contains(sliceData)) { | |
201 | Q_ASSERT(0); // TODO: how to handle this nicely? |
|
201 | Q_ASSERT(0); // TODO: how to handle this nicely? | |
202 | return; |
|
202 | return; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | delete m_slices.take(sliceData); |
|
205 | delete m_slices.take(sliceData); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | #include "moc_piepresenter_p.cpp" |
|
208 | #include "moc_piepresenter_p.cpp" | |
209 |
|
209 | |||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
210 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,135 +1,135 | |||||
1 | #include "pieslice_p.h" |
|
1 | #include "pieslice_p.h" | |
2 | #include "pieslicelabel_p.h" |
|
2 | #include "pieslicelabel_p.h" | |
3 | #include "piepresenter_p.h" |
|
3 | #include "piepresenter_p.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include "qpieslice.h" |
|
5 | #include "qpieslice.h" | |
6 | #include <QPainter> |
|
6 | #include <QPainter> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 | #include <qmath.h> |
|
8 | #include <qmath.h> | |
9 | #include <QGraphicsSceneEvent> |
|
9 | #include <QGraphicsSceneEvent> | |
10 | #include <QTime> |
|
10 | #include <QTime> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | QPointF offset(qreal angle, qreal length) |
|
14 | QPointF offset(qreal angle, qreal length) | |
15 | { |
|
15 | { | |
16 | qreal dx = qSin(angle*(PI/180)) * length; |
|
16 | qreal dx = qSin(angle*(PI/180)) * length; | |
17 | qreal dy = qCos(angle*(PI/180)) * length; |
|
17 | qreal dy = qCos(angle*(PI/180)) * length; | |
18 | return QPointF(dx, -dy); |
|
18 | return QPointF(dx, -dy); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | PieSlice::PieSlice(QGraphicsItem* parent) |
|
21 | PieSlice::PieSlice(QGraphicsItem* parent) | |
22 | :QGraphicsObject(parent), |
|
22 | :QGraphicsObject(parent), | |
23 | m_slicelabel(new PieSliceLabel(this)), |
|
23 | m_slicelabel(new PieSliceLabel(this)), | |
24 | m_angle(0), |
|
24 | m_startAngle(0), | |
25 | m_angleSpan(0), |
|
25 | m_angleSpan(0), | |
26 | m_isExploded(false), |
|
26 | m_isExploded(false), | |
27 | m_explodeDistance(0) |
|
27 | m_explodeDistance(0) | |
28 | { |
|
28 | { | |
29 | setAcceptHoverEvents(true); |
|
29 | setAcceptHoverEvents(true); | |
30 | setAcceptedMouseButtons(Qt::LeftButton); |
|
30 | setAcceptedMouseButtons(Qt::LeftButton); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | PieSlice::~PieSlice() |
|
33 | PieSlice::~PieSlice() | |
34 | { |
|
34 | { | |
35 |
|
35 | |||
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QRectF PieSlice::boundingRect() const |
|
38 | QRectF PieSlice::boundingRect() const | |
39 | { |
|
39 | { | |
40 | return m_path.boundingRect(); |
|
40 | return m_path.boundingRect(); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QPainterPath PieSlice::shape() const |
|
43 | QPainterPath PieSlice::shape() const | |
44 | { |
|
44 | { | |
45 | return m_path; |
|
45 | return m_path; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) |
|
48 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
49 | { |
|
49 | { | |
50 | painter->setPen(m_pen); |
|
50 | painter->setPen(m_pen); | |
51 | painter->setBrush(m_brush); |
|
51 | painter->setBrush(m_brush); | |
52 | painter->drawPath(m_path); |
|
52 | painter->drawPath(m_path); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
55 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) | |
56 | { |
|
56 | { | |
57 | emit hoverEnter(); |
|
57 | emit hoverEnter(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
60 | void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | |
61 | { |
|
61 | { | |
62 | emit hoverLeave(); |
|
62 | emit hoverLeave(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) |
|
65 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) | |
66 | { |
|
66 | { | |
67 | emit clicked(); |
|
67 | emit clicked(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void PieSlice::setPieRect(QRectF rect) |
|
70 | void PieSlice::setPieRect(QRectF rect) | |
71 | { |
|
71 | { | |
72 | m_pieRect = rect; |
|
72 | m_pieRect = rect; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void PieSlice::updateGeometry() |
|
75 | void PieSlice::updateGeometry() | |
76 | { |
|
76 | { | |
77 | if (!m_pieRect.isValid() || m_pieRect.isEmpty()) |
|
77 | if (!m_pieRect.isValid() || m_pieRect.isEmpty()) | |
78 | return; |
|
78 | return; | |
79 |
|
79 | |||
80 | prepareGeometryChange(); |
|
80 | prepareGeometryChange(); | |
81 |
|
81 | |||
82 | // calculate center angle |
|
82 | // calculate center angle | |
83 | qreal centerAngle = m_angle + (m_angleSpan/2); |
|
83 | qreal centerAngle = m_startAngle + (m_angleSpan/2); | |
84 |
|
84 | |||
85 | // adjust rect for exploding |
|
85 | // adjust rect for exploding | |
86 | QRectF rect = m_pieRect; |
|
86 | QRectF rect = m_pieRect; | |
87 | if (m_isExploded) { |
|
87 | if (m_isExploded) { | |
88 | qreal dx = qSin(centerAngle*(PI/180)) * m_explodeDistance; |
|
88 | qreal dx = qSin(centerAngle*(PI/180)) * m_explodeDistance; | |
89 | qreal dy = -qCos(centerAngle*(PI/180)) * m_explodeDistance; |
|
89 | qreal dy = -qCos(centerAngle*(PI/180)) * m_explodeDistance; | |
90 | rect.translate(dx, dy); |
|
90 | rect.translate(dx, dy); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | // update slice path |
|
93 | // update slice path | |
94 | // TODO: draw the shape so that it might have a hole in the center |
|
94 | // TODO: draw the shape so that it might have a hole in the center | |
95 | QPainterPath path; |
|
95 | QPainterPath path; | |
96 | path.moveTo(rect.center()); |
|
96 | path.moveTo(rect.center()); | |
97 | path.arcTo(rect, -m_angle + 90, -m_angleSpan); |
|
97 | path.arcTo(rect, -m_startAngle + 90, -m_angleSpan); | |
98 | path.closeSubpath(); |
|
98 | path.closeSubpath(); | |
99 | m_path = path; |
|
99 | m_path = path; | |
100 |
|
100 | |||
101 | // update label position |
|
101 | // update label position | |
102 | qreal radius = rect.height() / 2; |
|
102 | qreal radius = rect.height() / 2; | |
103 | QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5); |
|
103 | QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5); | |
104 | m_slicelabel->setArmStartPoint(edgeCenter); |
|
104 | m_slicelabel->setArmStartPoint(edgeCenter); | |
105 | m_slicelabel->setArmAngle(centerAngle); |
|
105 | m_slicelabel->setArmAngle(centerAngle); | |
106 | m_slicelabel->updateGeometry(); |
|
106 | m_slicelabel->updateGeometry(); | |
107 | m_slicelabel->update(); |
|
107 | m_slicelabel->update(); | |
108 |
|
108 | |||
109 | //qDebug() << "PieSlice::updateGeometry" << m_slicelabel->text() << boundingRect() << m_angle << m_span; |
|
109 | //qDebug() << "PieSlice::updateGeometry" << m_slicelabel->text() << boundingRect() << m_angle << m_span; | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void PieSlice::updateData(const QPieSlice* sliceData) |
|
112 | void PieSlice::updateData(const QPieSlice* sliceData) | |
113 | { |
|
113 | { | |
114 | // TODO: compare what has changes to avoid unneccesary geometry updates |
|
114 | // TODO: compare what has changes to avoid unneccesary geometry updates | |
115 |
|
115 | |||
116 | m_angle = sliceData->angle(); |
|
116 | m_startAngle = sliceData->startAngle(); | |
117 |
m_angleSpan = sliceData->angleSpan |
|
117 | m_angleSpan = sliceData->m_angleSpan; | |
118 | m_isExploded = sliceData->isExploded(); |
|
118 | m_isExploded = sliceData->isExploded(); | |
119 | m_explodeDistance = sliceData->explodeDistance(); // TODO: expose to public API |
|
119 | m_explodeDistance = sliceData->explodeDistance(); // TODO: expose to public API | |
120 | m_pen = sliceData->pen(); |
|
120 | m_pen = sliceData->pen(); | |
121 | m_brush = sliceData->brush(); |
|
121 | m_brush = sliceData->brush(); | |
122 |
|
122 | |||
123 | m_slicelabel->setVisible(sliceData->isLabelVisible()); |
|
123 | m_slicelabel->setVisible(sliceData->isLabelVisible()); | |
124 | m_slicelabel->setText(sliceData->label()); |
|
124 | m_slicelabel->setText(sliceData->label()); | |
125 | m_slicelabel->setPen(sliceData->labelPen()); |
|
125 | m_slicelabel->setPen(sliceData->labelPen()); | |
126 | m_slicelabel->setFont(sliceData->labelFont()); |
|
126 | m_slicelabel->setFont(sliceData->labelFont()); | |
127 | m_slicelabel->setArmLength(sliceData->labelArmLength()); |
|
127 | m_slicelabel->setArmLength(sliceData->labelArmLength()); | |
128 |
|
128 | |||
129 | updateGeometry(); |
|
129 | updateGeometry(); | |
130 | update(); |
|
130 | update(); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | #include "moc_pieslice_p.cpp" |
|
133 | #include "moc_pieslice_p.cpp" | |
134 |
|
134 | |||
135 | QTCOMMERCIALCHART_END_NAMESPACE |
|
135 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,64 +1,64 | |||||
1 | #ifndef PIESLICE_H |
|
1 | #ifndef PIESLICE_H | |
2 | #define PIESLICE_H |
|
2 | #define PIESLICE_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include "qpieseries.h" |
|
6 | #include "qpieseries.h" | |
7 | #include <QGraphicsItem> |
|
7 | #include <QGraphicsItem> | |
8 | #include <QRectF> |
|
8 | #include <QRectF> | |
9 | #include <QColor> |
|
9 | #include <QColor> | |
10 | #include <QPen> |
|
10 | #include <QPen> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 | class PiePresenter; |
|
13 | class PiePresenter; | |
14 | class PieSliceLabel; |
|
14 | class PieSliceLabel; | |
15 | class QPieSlice; |
|
15 | class QPieSlice; | |
16 |
|
16 | |||
17 | class PieSlice : public QGraphicsObject |
|
17 | class PieSlice : public QGraphicsObject | |
18 | { |
|
18 | { | |
19 | Q_OBJECT |
|
19 | Q_OBJECT | |
20 |
|
20 | |||
21 | public: |
|
21 | public: | |
22 | PieSlice(QGraphicsItem* parent = 0); |
|
22 | PieSlice(QGraphicsItem* parent = 0); | |
23 | ~PieSlice(); |
|
23 | ~PieSlice(); | |
24 |
|
24 | |||
25 | public: // from QGraphicsItem |
|
25 | public: // from QGraphicsItem | |
26 | QRectF boundingRect() const; |
|
26 | QRectF boundingRect() const; | |
27 | QPainterPath shape() const; |
|
27 | QPainterPath shape() const; | |
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
29 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
29 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
30 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
30 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
31 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
31 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
32 |
|
32 | |||
33 | Q_SIGNALS: |
|
33 | Q_SIGNALS: | |
34 | void clicked(); |
|
34 | void clicked(); | |
35 | void hoverEnter(); |
|
35 | void hoverEnter(); | |
36 | void hoverLeave(); |
|
36 | void hoverLeave(); | |
37 |
|
37 | |||
38 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
39 | void setPieRect(QRectF rect); |
|
39 | void setPieRect(QRectF rect); | |
40 | void updateGeometry(); |
|
40 | void updateGeometry(); | |
41 | void updateData(const QPieSlice *sliceData); |
|
41 | void updateData(const QPieSlice *sliceData); | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | PieSliceLabel* label() { return m_slicelabel; } |
|
44 | PieSliceLabel* label() { return m_slicelabel; } | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | PieSliceLabel* m_slicelabel; |
|
47 | PieSliceLabel* m_slicelabel; | |
48 |
|
48 | |||
49 | QRectF m_pieRect; |
|
49 | QRectF m_pieRect; | |
50 | QPainterPath m_path; |
|
50 | QPainterPath m_path; | |
51 |
|
51 | |||
52 | qreal m_angle; |
|
52 | qreal m_startAngle; | |
53 | qreal m_angleSpan; |
|
53 | qreal m_angleSpan; | |
54 |
|
54 | |||
55 | bool m_isExploded; |
|
55 | bool m_isExploded; | |
56 | qreal m_explodeDistance; |
|
56 | qreal m_explodeDistance; | |
57 |
|
57 | |||
58 | QPen m_pen; |
|
58 | QPen m_pen; | |
59 | QBrush m_brush; |
|
59 | QBrush m_brush; | |
60 | }; |
|
60 | }; | |
61 |
|
61 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
62 | QTCOMMERCIALCHART_END_NAMESPACE | |
63 |
|
63 | |||
64 | #endif // PIESLICE_H |
|
64 | #endif // PIESLICE_H |
@@ -1,534 +1,534 | |||||
1 | #include "qpieseries.h" |
|
1 | #include "qpieseries.h" | |
2 | #include "qpieslice.h" |
|
2 | #include "qpieslice.h" | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QPieSeries::ChangeSet |
|
9 | \class QPieSeries::ChangeSet | |
10 | \brief Defines the changes in the series. |
|
10 | \brief Defines the changes in the series. | |
11 |
|
11 | |||
12 | Contains the changes that have occurred in the series. Lists of added, changed and removed slices. |
|
12 | Contains the changes that have occurred in the series. Lists of added, changed and removed slices. | |
13 |
|
13 | |||
14 | \sa QPieSeries::changed() |
|
14 | \sa QPieSeries::changed() | |
15 | */ |
|
15 | */ | |
16 |
|
16 | |||
17 | /*! |
|
17 | /*! | |
18 | \internal |
|
18 | \internal | |
19 | */ |
|
19 | */ | |
20 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) |
|
20 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) | |
21 | { |
|
21 | { | |
22 | if (!m_added.contains(slice)) |
|
22 | if (!m_added.contains(slice)) | |
23 | m_added << slice; |
|
23 | m_added << slice; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \internal |
|
27 | \internal | |
28 | */ |
|
28 | */ | |
29 | void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices) |
|
29 | void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices) | |
30 | { |
|
30 | { | |
31 | foreach (QPieSlice* s, slices) |
|
31 | foreach (QPieSlice* s, slices) | |
32 | appendAdded(s); |
|
32 | appendAdded(s); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \internal |
|
36 | \internal | |
37 | */ |
|
37 | */ | |
38 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) |
|
38 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) | |
39 | { |
|
39 | { | |
40 | if (!m_changed.contains(slice)) |
|
40 | if (!m_changed.contains(slice)) | |
41 | m_changed << slice; |
|
41 | m_changed << slice; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 | \internal |
|
45 | \internal | |
46 | */ |
|
46 | */ | |
47 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) |
|
47 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) | |
48 | { |
|
48 | { | |
49 | if (!m_removed.contains(slice)) |
|
49 | if (!m_removed.contains(slice)) | |
50 | m_removed << slice; |
|
50 | m_removed << slice; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | Returns a list of slices that have been added to the series. |
|
54 | Returns a list of slices that have been added to the series. | |
55 | \sa QPieSeries::changed() |
|
55 | \sa QPieSeries::changed() | |
56 | */ |
|
56 | */ | |
57 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const |
|
57 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const | |
58 | { |
|
58 | { | |
59 | return m_added; |
|
59 | return m_added; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | Returns a list of slices that have been changed in the series. |
|
63 | Returns a list of slices that have been changed in the series. | |
64 | \sa QPieSeries::changed() |
|
64 | \sa QPieSeries::changed() | |
65 | */ |
|
65 | */ | |
66 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const |
|
66 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const | |
67 | { |
|
67 | { | |
68 | return m_changed; |
|
68 | return m_changed; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Returns a list of slices that have been removed from the series. |
|
72 | Returns a list of slices that have been removed from the series. | |
73 | \sa QPieSeries::changed() |
|
73 | \sa QPieSeries::changed() | |
74 | */ |
|
74 | */ | |
75 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const |
|
75 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const | |
76 | { |
|
76 | { | |
77 | return m_removed; |
|
77 | return m_removed; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Returns true if there are no added/changed or removed slices in the change set. |
|
82 | Returns true if there are no added/changed or removed slices in the change set. | |
83 | */ |
|
83 | */ | |
84 | bool QPieSeries::ChangeSet::isEmpty() const |
|
84 | bool QPieSeries::ChangeSet::isEmpty() const | |
85 | { |
|
85 | { | |
86 | if (m_added.count() || m_changed.count() || m_removed.count()) |
|
86 | if (m_added.count() || m_changed.count() || m_removed.count()) | |
87 | return false; |
|
87 | return false; | |
88 | return true; |
|
88 | return true; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \enum QPieSeries::PiePosition |
|
92 | \enum QPieSeries::PiePosition | |
93 |
|
93 | |||
94 | This enum describes pie position within its bounding rectangle |
|
94 | This enum describes pie position within its bounding rectangle | |
95 |
|
95 | |||
96 | \value PiePositionMaximized |
|
96 | \value PiePositionMaximized | |
97 | \value PiePositionTopLeft |
|
97 | \value PiePositionTopLeft | |
98 | \value PiePositionTopRight |
|
98 | \value PiePositionTopRight | |
99 | \value PiePositionBottomLeft |
|
99 | \value PiePositionBottomLeft | |
100 | \value PiePositionBottomRight |
|
100 | \value PiePositionBottomRight | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \class QPieSeries |
|
104 | \class QPieSeries | |
105 | \brief Pie series API for QtCommercial Charts |
|
105 | \brief Pie series API for QtCommercial Charts | |
106 |
|
106 | |||
107 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
107 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
108 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
108 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
109 | The actual slice size (span) is determined by that relative value. |
|
109 | The actual slice size (span) is determined by that relative value. | |
110 |
|
110 | |||
111 | By default the pie is defined as full but it can be a partial pie. |
|
111 | By default the pie is defined as full but it can be a partial pie. | |
112 | This can be done by setting a starting angle and angle span to the series. |
|
112 | This can be done by setting a starting angle and angle span to the series. | |
113 |
|
113 | |||
114 | Example on how to create a chart with pie series: |
|
114 | Example on how to create a chart with pie series: | |
115 | \snippet ../example/piechart/main.cpp 1 |
|
115 | \snippet ../example/piechart/main.cpp 1 | |
116 |
|
116 | |||
117 | To help with the most common user intercation scenarions there some convenience functions. Specifically |
|
117 | To help with the most common user intercation scenarions there some convenience functions. Specifically | |
118 | exploding and higlighting: |
|
118 | exploding and higlighting: | |
119 | \snippet ../example/piechart/main.cpp 2 |
|
119 | \snippet ../example/piechart/main.cpp 2 | |
120 |
|
120 | |||
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Constructs a series object which is a child of \a parent. |
|
124 | Constructs a series object which is a child of \a parent. | |
125 | */ |
|
125 | */ | |
126 | QPieSeries::QPieSeries(QObject *parent) : |
|
126 | QPieSeries::QPieSeries(QObject *parent) : | |
127 | QChartSeries(parent), |
|
127 | QChartSeries(parent), | |
128 | m_sizeFactor(1.0), |
|
128 | m_sizeFactor(1.0), | |
129 | m_position(PiePositionMaximized), |
|
129 | m_position(PiePositionMaximized), | |
130 | m_pieStartAngle(0), |
|
130 | m_pieStartAngle(0), | |
131 | m_pieAngleSpan(360) |
|
131 | m_pieAngleSpan(360) | |
132 | { |
|
132 | { | |
133 |
|
133 | |||
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
137 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
138 | */ |
|
138 | */ | |
139 | QPieSeries::~QPieSeries() |
|
139 | QPieSeries::~QPieSeries() | |
140 | { |
|
140 | { | |
141 |
|
141 | |||
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | Returns QChartSeries::SeriesTypePie. |
|
145 | Returns QChartSeries::SeriesTypePie. | |
146 | */ |
|
146 | */ | |
147 | QChartSeries::QChartSeriesType QPieSeries::type() const |
|
147 | QChartSeries::QChartSeriesType QPieSeries::type() const | |
148 | { |
|
148 | { | |
149 | return QChartSeries::SeriesTypePie; |
|
149 | return QChartSeries::SeriesTypePie; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \internal \a data |
|
153 | \internal \a data | |
154 | */ |
|
154 | */ | |
155 | bool QPieSeries::setData(QList<qreal> data) |
|
155 | bool QPieSeries::setData(QList<qreal> data) | |
156 | { |
|
156 | { | |
157 | // TODO: remove this function |
|
157 | // TODO: remove this function | |
158 | QList<QPieSlice*> slices; |
|
158 | QList<QPieSlice*> slices; | |
159 | foreach (qreal value, data) |
|
159 | foreach (qreal value, data) | |
160 | slices << new QPieSlice(value, QString::number(value)); |
|
160 | slices << new QPieSlice(value, QString::number(value)); | |
161 | replace(slices); |
|
161 | replace(slices); | |
162 | return true; |
|
162 | return true; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | Sets an array of \a slices to the series replacing the existing slices. |
|
166 | Sets an array of \a slices to the series replacing the existing slices. | |
167 | Slice ownership is passed to the series. |
|
167 | Slice ownership is passed to the series. | |
168 | */ |
|
168 | */ | |
169 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
169 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
170 | { |
|
170 | { | |
171 | clear(); |
|
171 | clear(); | |
172 | add(slices); |
|
172 | add(slices); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | Adds an array of \a slices to the series. |
|
176 | Adds an array of \a slices to the series. | |
177 | Slice ownership is passed to the series. |
|
177 | Slice ownership is passed to the series. | |
178 | */ |
|
178 | */ | |
179 | void QPieSeries::add(QList<QPieSlice*> slices) |
|
179 | void QPieSeries::add(QList<QPieSlice*> slices) | |
180 | { |
|
180 | { | |
181 | ChangeSet changeSet; |
|
181 | ChangeSet changeSet; | |
182 | foreach (QPieSlice* s, slices) { |
|
182 | foreach (QPieSlice* s, slices) { | |
183 | s->setParent(this); |
|
183 | s->setParent(this); | |
184 | m_slices << s; |
|
184 | m_slices << s; | |
185 | changeSet.appendAdded(s); |
|
185 | changeSet.appendAdded(s); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | updateDerivativeData(); |
|
188 | updateDerivativeData(); | |
189 |
|
189 | |||
190 | foreach (QPieSlice* s, slices) { |
|
190 | foreach (QPieSlice* s, slices) { | |
191 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); |
|
191 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); | |
192 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); |
|
192 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); | |
193 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); |
|
193 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); | |
194 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); |
|
194 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | emit changed(changeSet); |
|
197 | emit changed(changeSet); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Adds a single \a slice to the series. |
|
201 | Adds a single \a slice to the series. | |
202 | Slice ownership is passed to the series. |
|
202 | Slice ownership is passed to the series. | |
203 | */ |
|
203 | */ | |
204 | void QPieSeries::add(QPieSlice* slice) |
|
204 | void QPieSeries::add(QPieSlice* slice) | |
205 | { |
|
205 | { | |
206 | add(QList<QPieSlice*>() << slice); |
|
206 | add(QList<QPieSlice*>() << slice); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Adds a single slice to the series with give \a value and \a name. |
|
211 | Adds a single slice to the series with give \a value and \a name. | |
212 | Slice ownership is passed to the series. |
|
212 | Slice ownership is passed to the series. | |
213 | */ |
|
213 | */ | |
214 | QPieSlice* QPieSeries::add(qreal value, QString name) |
|
214 | QPieSlice* QPieSeries::add(qreal value, QString name) | |
215 | { |
|
215 | { | |
216 | QPieSlice* slice = new QPieSlice(value, name); |
|
216 | QPieSlice* slice = new QPieSlice(value, name); | |
217 | add(slice); |
|
217 | add(slice); | |
218 | return slice; |
|
218 | return slice; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Removes a single \a slice from the series and deletes the slice. |
|
222 | Removes a single \a slice from the series and deletes the slice. | |
223 |
|
223 | |||
224 | Do not reference this pointer after this call. |
|
224 | Do not reference this pointer after this call. | |
225 | */ |
|
225 | */ | |
226 | void QPieSeries::remove(QPieSlice* slice) |
|
226 | void QPieSeries::remove(QPieSlice* slice) | |
227 | { |
|
227 | { | |
228 | if (!m_slices.removeOne(slice)) { |
|
228 | if (!m_slices.removeOne(slice)) { | |
229 | Q_ASSERT(0); // TODO: how should this be reported? |
|
229 | Q_ASSERT(0); // TODO: how should this be reported? | |
230 | return; |
|
230 | return; | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | ChangeSet changeSet; |
|
233 | ChangeSet changeSet; | |
234 | changeSet.appendRemoved(slice); |
|
234 | changeSet.appendRemoved(slice); | |
235 | emit changed(changeSet); |
|
235 | emit changed(changeSet); | |
236 |
|
236 | |||
237 | delete slice; |
|
237 | delete slice; | |
238 | slice = NULL; |
|
238 | slice = NULL; | |
239 |
|
239 | |||
240 | updateDerivativeData(); |
|
240 | updateDerivativeData(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Clears all slices from the series. |
|
244 | Clears all slices from the series. | |
245 | */ |
|
245 | */ | |
246 | void QPieSeries::clear() |
|
246 | void QPieSeries::clear() | |
247 | { |
|
247 | { | |
248 | if (m_slices.count() == 0) |
|
248 | if (m_slices.count() == 0) | |
249 | return; |
|
249 | return; | |
250 |
|
250 | |||
251 | ChangeSet changeSet; |
|
251 | ChangeSet changeSet; | |
252 | foreach (QPieSlice* s, m_slices) { |
|
252 | foreach (QPieSlice* s, m_slices) { | |
253 | changeSet.appendRemoved(s); |
|
253 | changeSet.appendRemoved(s); | |
254 | m_slices.removeOne(s); |
|
254 | m_slices.removeOne(s); | |
255 | delete s; |
|
255 | delete s; | |
256 | } |
|
256 | } | |
257 | emit changed(changeSet); |
|
257 | emit changed(changeSet); | |
258 | updateDerivativeData(); |
|
258 | updateDerivativeData(); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Counts the number of the slices in this series. |
|
262 | Counts the number of the slices in this series. | |
263 | */ |
|
263 | */ | |
264 | int QPieSeries::count() const |
|
264 | int QPieSeries::count() const | |
265 | { |
|
265 | { | |
266 | return m_slices.count(); |
|
266 | return m_slices.count(); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Returns a list of slices that belong to this series. |
|
270 | Returns a list of slices that belong to this series. | |
271 | */ |
|
271 | */ | |
272 | QList<QPieSlice*> QPieSeries::slices() const |
|
272 | QList<QPieSlice*> QPieSeries::slices() const | |
273 | { |
|
273 | { | |
274 | return m_slices; |
|
274 | return m_slices; | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | /*! |
|
277 | /*! | |
278 | Sets the size \a factor of the pie. 1.0 is the default value. |
|
278 | Sets the size \a factor of the pie. 1.0 is the default value. | |
279 | Note that the pie will not grow beyond its absolute maximum size. |
|
279 | Note that the pie will not grow beyond its absolute maximum size. | |
280 | In practice its use is to make the pie appear smaller. |
|
280 | In practice its use is to make the pie appear smaller. | |
281 | \sa sizeFactor() |
|
281 | \sa sizeFactor() | |
282 | */ |
|
282 | */ | |
283 | void QPieSeries::setSizeFactor(qreal factor) |
|
283 | void QPieSeries::setSizeFactor(qreal factor) | |
284 | { |
|
284 | { | |
285 | if (factor < 0.0) |
|
285 | if (factor < 0.0) | |
286 | return; |
|
286 | return; | |
287 |
|
287 | |||
288 | if (m_sizeFactor != factor) { |
|
288 | if (m_sizeFactor != factor) { | |
289 | m_sizeFactor = factor; |
|
289 | m_sizeFactor = factor; | |
290 | emit sizeFactorChanged(); |
|
290 | emit sizeFactorChanged(); | |
291 | } |
|
291 | } | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Gets the size factor of the pie. |
|
295 | Gets the size factor of the pie. | |
296 | \sa setSizeFactor() |
|
296 | \sa setSizeFactor() | |
297 | */ |
|
297 | */ | |
298 | qreal QPieSeries::sizeFactor() const |
|
298 | qreal QPieSeries::sizeFactor() const | |
299 | { |
|
299 | { | |
300 | return m_sizeFactor; |
|
300 | return m_sizeFactor; | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | /*! |
|
303 | /*! | |
304 | Sets the \a position of the pie within its bounding rectangle. |
|
304 | Sets the \a position of the pie within its bounding rectangle. | |
305 | \sa PiePosition, position() |
|
305 | \sa PiePosition, position() | |
306 | */ |
|
306 | */ | |
307 | void QPieSeries::setPosition(PiePosition position) |
|
307 | void QPieSeries::setPosition(PiePosition position) | |
308 | { |
|
308 | { | |
309 | if (m_position != position) { |
|
309 | if (m_position != position) { | |
310 | m_position = position; |
|
310 | m_position = position; | |
311 | emit positionChanged(); |
|
311 | emit positionChanged(); | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | /*! |
|
315 | /*! | |
316 | Gets the position of the pie within its bounding rectangle. |
|
316 | Gets the position of the pie within its bounding rectangle. | |
317 | \sa PiePosition, setPosition() |
|
317 | \sa PiePosition, setPosition() | |
318 | */ |
|
318 | */ | |
319 | QPieSeries::PiePosition QPieSeries::position() const |
|
319 | QPieSeries::PiePosition QPieSeries::position() const | |
320 | { |
|
320 | { | |
321 | return m_position; |
|
321 | return m_position; | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 |
|
324 | |||
325 | /*! |
|
325 | /*! | |
326 | Sets the \a startAngle and \a angleSpan of this series. |
|
326 | Sets the \a startAngle and \a angleSpan of this series. | |
327 |
|
327 | |||
328 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
328 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
329 | */ |
|
329 | */ | |
330 | void QPieSeries::setSpan(qreal startAngle, qreal angleSpan) |
|
330 | void QPieSeries::setSpan(qreal startAngle, qreal angleSpan) | |
331 | { |
|
331 | { | |
332 | if (startAngle >= 0 && startAngle < 360 && |
|
332 | if (startAngle >= 0 && startAngle < 360 && | |
333 | angleSpan > 0 && angleSpan <= 360) { |
|
333 | angleSpan > 0 && angleSpan <= 360) { | |
334 | m_pieStartAngle = startAngle; |
|
334 | m_pieStartAngle = startAngle; | |
335 | m_pieAngleSpan = angleSpan; |
|
335 | m_pieAngleSpan = angleSpan; | |
336 | updateDerivativeData(); |
|
336 | updateDerivativeData(); | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Sets the all the slice labels \a visible or invisible. |
|
341 | Sets the all the slice labels \a visible or invisible. | |
342 |
|
342 | |||
343 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
343 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
344 | */ |
|
344 | */ | |
345 | void QPieSeries::setLabelsVisible(bool visible) |
|
345 | void QPieSeries::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | foreach (QPieSlice* s, m_slices) |
|
347 | foreach (QPieSlice* s, m_slices) | |
348 | s->setLabelVisible(visible); |
|
348 | s->setLabelVisible(visible); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | /*! |
|
351 | /*! | |
352 | Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to |
|
352 | Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to | |
353 | explode slices by clicking. |
|
353 | explode slices by clicking. | |
354 |
|
354 | |||
355 | \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance() |
|
355 | \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance() | |
356 | */ |
|
356 | */ | |
357 | void QPieSeries::enableClickExplodes(bool enable) |
|
357 | void QPieSeries::enableClickExplodes(bool enable) | |
358 | { |
|
358 | { | |
359 | if (enable) |
|
359 | if (enable) | |
360 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); |
|
360 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); | |
361 | else |
|
361 | else | |
362 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); |
|
362 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | Convenience method for highlighting a slice when user hovers over the slice. |
|
366 | Convenience method for highlighting a slice when user hovers over the slice. | |
367 | It changes the slice color to be lighter and shows the label of the slice. |
|
367 | It changes the slice color to be lighter and shows the label of the slice. | |
368 | Set \a enable to true to highlight a slice when user hovers on top of it. |
|
368 | Set \a enable to true to highlight a slice when user hovers on top of it. | |
369 |
|
369 | |||
370 | \sa QPieSlice::isExploded(), QPieSlice::setExploded() |
|
370 | \sa QPieSlice::isExploded(), QPieSlice::setExploded() | |
371 | */ |
|
371 | */ | |
372 |
|
372 | |||
373 | void QPieSeries::enableHoverHighlight(bool enable) |
|
373 | void QPieSeries::enableHoverHighlight(bool enable) | |
374 | { |
|
374 | { | |
375 | if (enable) { |
|
375 | if (enable) { | |
376 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); |
|
376 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); | |
377 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); |
|
377 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); | |
378 | } else { |
|
378 | } else { | |
379 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); |
|
379 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); | |
380 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); |
|
380 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); | |
381 | } |
|
381 | } | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | /*! |
|
384 | /*! | |
385 | \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet) |
|
385 | \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet) | |
386 |
|
386 | |||
387 | This signal emitted when something has changed in the series. |
|
387 | This signal emitted when something has changed in the series. | |
388 | The \a changeSet contains the details of which slices have been added, changed or removed. |
|
388 | The \a changeSet contains the details of which slices have been added, changed or removed. | |
389 |
|
389 | |||
390 | \sa QPieSeries::ChangeSet, QPieSlice::changed() |
|
390 | \sa QPieSeries::ChangeSet, QPieSlice::changed() | |
391 | */ |
|
391 | */ | |
392 |
|
392 | |||
393 | /*! |
|
393 | /*! | |
394 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
394 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
395 |
|
395 | |||
396 | This signal is emitted when a \a slice has been clicked. |
|
396 | This signal is emitted when a \a slice has been clicked. | |
397 |
|
397 | |||
398 | \sa QPieSlice::clicked() |
|
398 | \sa QPieSlice::clicked() | |
399 | */ |
|
399 | */ | |
400 |
|
400 | |||
401 | /*! |
|
401 | /*! | |
402 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
402 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
403 |
|
403 | |||
404 | This signal is emitted when user has hovered over a \a slice. |
|
404 | This signal is emitted when user has hovered over a \a slice. | |
405 |
|
405 | |||
406 | \sa QPieSlice::hoverEnter() |
|
406 | \sa QPieSlice::hoverEnter() | |
407 | */ |
|
407 | */ | |
408 |
|
408 | |||
409 | /*! |
|
409 | /*! | |
410 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
410 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
411 |
|
411 | |||
412 | This signal is emitted when user has hovered away from a \a slice. |
|
412 | This signal is emitted when user has hovered away from a \a slice. | |
413 |
|
413 | |||
414 | \sa QPieSlice::hoverLeave() |
|
414 | \sa QPieSlice::hoverLeave() | |
415 | */ |
|
415 | */ | |
416 |
|
416 | |||
417 | /*! |
|
417 | /*! | |
418 | \fn void QPieSeries::sizeFactorChanged() |
|
418 | \fn void QPieSeries::sizeFactorChanged() | |
419 |
|
419 | |||
420 | This signal is emitted when size factor has been changed. |
|
420 | This signal is emitted when size factor has been changed. | |
421 |
|
421 | |||
422 | \sa sizeFactor(), setSizeFactor() |
|
422 | \sa sizeFactor(), setSizeFactor() | |
423 | */ |
|
423 | */ | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | \fn void QPieSeries::positionChanged() |
|
426 | \fn void QPieSeries::positionChanged() | |
427 |
|
427 | |||
428 | This signal is emitted when position of the pie has been changed. |
|
428 | This signal is emitted when position of the pie has been changed. | |
429 |
|
429 | |||
430 | \sa position(), setPosition() |
|
430 | \sa position(), setPosition() | |
431 | */ |
|
431 | */ | |
432 |
|
432 | |||
433 | void QPieSeries::sliceChanged() |
|
433 | void QPieSeries::sliceChanged() | |
434 | { |
|
434 | { | |
435 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
435 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
436 | Q_ASSERT(m_slices.contains(slice)); |
|
436 | Q_ASSERT(m_slices.contains(slice)); | |
437 |
|
437 | |||
438 | ChangeSet changeSet; |
|
438 | ChangeSet changeSet; | |
439 | changeSet.appendChanged(slice); |
|
439 | changeSet.appendChanged(slice); | |
440 | emit changed(changeSet); |
|
440 | emit changed(changeSet); | |
441 |
|
441 | |||
442 | updateDerivativeData(); |
|
442 | updateDerivativeData(); | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | void QPieSeries::sliceClicked() |
|
445 | void QPieSeries::sliceClicked() | |
446 | { |
|
446 | { | |
447 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
447 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
448 | Q_ASSERT(m_slices.contains(slice)); |
|
448 | Q_ASSERT(m_slices.contains(slice)); | |
449 | emit clicked(slice); |
|
449 | emit clicked(slice); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | void QPieSeries::sliceHoverEnter() |
|
452 | void QPieSeries::sliceHoverEnter() | |
453 | { |
|
453 | { | |
454 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
454 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
455 | Q_ASSERT(m_slices.contains(slice)); |
|
455 | Q_ASSERT(m_slices.contains(slice)); | |
456 | emit hoverEnter(slice); |
|
456 | emit hoverEnter(slice); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | void QPieSeries::sliceHoverLeave() |
|
459 | void QPieSeries::sliceHoverLeave() | |
460 | { |
|
460 | { | |
461 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
461 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
462 | Q_ASSERT(m_slices.contains(slice)); |
|
462 | Q_ASSERT(m_slices.contains(slice)); | |
463 | emit hoverLeave(slice); |
|
463 | emit hoverLeave(slice); | |
464 | } |
|
464 | } | |
465 |
|
465 | |||
466 | void QPieSeries::toggleExploded(QPieSlice* slice) |
|
466 | void QPieSeries::toggleExploded(QPieSlice* slice) | |
467 | { |
|
467 | { | |
468 | Q_ASSERT(slice); |
|
468 | Q_ASSERT(slice); | |
469 | slice->setExploded(!slice->isExploded()); |
|
469 | slice->setExploded(!slice->isExploded()); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | void QPieSeries::highlightOn(QPieSlice* slice) |
|
472 | void QPieSeries::highlightOn(QPieSlice* slice) | |
473 | { |
|
473 | { | |
474 | Q_ASSERT(slice); |
|
474 | Q_ASSERT(slice); | |
475 | QColor c = slice->brush().color().lighter(); |
|
475 | QColor c = slice->brush().color().lighter(); | |
476 | slice->setBrush(c); |
|
476 | slice->setBrush(c); | |
477 | slice->setLabelVisible(true); |
|
477 | slice->setLabelVisible(true); | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | void QPieSeries::highlightOff(QPieSlice* slice) |
|
480 | void QPieSeries::highlightOff(QPieSlice* slice) | |
481 | { |
|
481 | { | |
482 | Q_ASSERT(slice); |
|
482 | Q_ASSERT(slice); | |
483 | QColor c = slice->brush().color().darker(150); |
|
483 | QColor c = slice->brush().color().darker(150); | |
484 | slice->setBrush(c); |
|
484 | slice->setBrush(c); | |
485 | slice->setLabelVisible(false); |
|
485 | slice->setLabelVisible(false); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | void QPieSeries::updateDerivativeData() |
|
488 | void QPieSeries::updateDerivativeData() | |
489 | { |
|
489 | { | |
490 | m_total = 0; |
|
490 | m_total = 0; | |
491 |
|
491 | |||
492 | // nothing to do? |
|
492 | // nothing to do? | |
493 | if (m_slices.count() == 0) |
|
493 | if (m_slices.count() == 0) | |
494 | return; |
|
494 | return; | |
495 |
|
495 | |||
496 | // calculate total |
|
496 | // calculate total | |
497 | foreach (QPieSlice* s, m_slices) |
|
497 | foreach (QPieSlice* s, m_slices) | |
498 | m_total += s->value(); |
|
498 | m_total += s->value(); | |
499 |
|
499 | |||
500 | // we must have some values |
|
500 | // we must have some values | |
501 | Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this? |
|
501 | Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this? | |
502 |
|
502 | |||
503 | // update slice attributes |
|
503 | // update slice attributes | |
504 | qreal sliceAngle = m_pieStartAngle; |
|
504 | qreal sliceAngle = m_pieStartAngle; | |
505 | foreach (QPieSlice* s, m_slices) { |
|
505 | foreach (QPieSlice* s, m_slices) { | |
506 |
|
506 | |||
507 | bool changed = false; |
|
507 | bool changed = false; | |
508 |
|
508 | |||
509 | qreal percentage = s->value() / m_total; |
|
509 | qreal percentage = s->value() / m_total; | |
510 | if (s->m_percentage != percentage) { |
|
510 | if (s->m_percentage != percentage) { | |
511 | s->m_percentage = percentage; |
|
511 | s->m_percentage = percentage; | |
512 | changed = true; |
|
512 | changed = true; | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | qreal sliceSpan = m_pieAngleSpan * percentage; |
|
515 | qreal sliceSpan = m_pieAngleSpan * percentage; | |
516 | if (s->m_angleSpan != sliceSpan) { |
|
516 | if (s->m_angleSpan != sliceSpan) { | |
517 | s->m_angleSpan = sliceSpan; |
|
517 | s->m_angleSpan = sliceSpan; | |
518 | changed = true; |
|
518 | changed = true; | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | if (s->m_angle != sliceAngle) { |
|
521 | if (s->m_startAngle != sliceAngle) { | |
522 | s->m_angle = sliceAngle; |
|
522 | s->m_startAngle = sliceAngle; | |
523 | changed = true; |
|
523 | changed = true; | |
524 | } |
|
524 | } | |
525 | sliceAngle += sliceSpan; |
|
525 | sliceAngle += sliceSpan; | |
526 |
|
526 | |||
527 | if (changed) |
|
527 | if (changed) | |
528 | emit s->changed(); |
|
528 | emit s->changed(); | |
529 | } |
|
529 | } | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | #include "moc_qpieseries.cpp" |
|
532 | #include "moc_qpieseries.cpp" | |
533 |
|
533 | |||
534 | QTCOMMERCIALCHART_END_NAMESPACE |
|
534 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,375 +1,375 | |||||
1 | #include "qpieslice.h" |
|
1 | #include "qpieslice.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | #define DEFAULT_PEN_COLOR Qt::black |
|
5 | #define DEFAULT_PEN_COLOR Qt::black | |
6 | #define DEFAULT_BRUSH_COLOR Qt::white |
|
6 | #define DEFAULT_BRUSH_COLOR Qt::white | |
7 | #define DEFAULT_LABEL_ARM_LENGTH 40 |
|
7 | #define DEFAULT_LABEL_ARM_LENGTH 40 | |
8 | #define DEFAULT_EXPOLODE_DISTANCE 20 |
|
8 | #define DEFAULT_EXPOLODE_DISTANCE 20 | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \class QPieSlice |
|
11 | \class QPieSlice | |
12 | \brief Defines a slice in pie series. |
|
12 | \brief Defines a slice in pie series. | |
13 |
|
13 | |||
14 | Holds all the data of a single slice in a QPieSeries and provides the means |
|
14 | Holds all the data of a single slice in a QPieSeries and provides the means | |
15 | to modify slice data and customize the visual appearance of the slice. |
|
15 | to modify slice data and customize the visual appearance of the slice. | |
16 |
|
16 | |||
17 | It also provides the means to customize user interaction with the slice by |
|
17 | It also provides the means to customize user interaction with the slice by | |
18 | providing signals for clicking and hover events. |
|
18 | providing signals for clicking and hover events. | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \property QPieSlice::label |
|
22 | \property QPieSlice::label | |
23 |
|
23 | |||
24 | Label of the slice. |
|
24 | Label of the slice. | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \property QPieSlice::value |
|
28 | \property QPieSlice::value | |
29 |
|
29 | |||
30 | Value of the slice. |
|
30 | Value of the slice. | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | Constructs an empty slice with a \a parent. |
|
34 | Constructs an empty slice with a \a parent. | |
35 |
|
35 | |||
36 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
36 | Note that QPieSeries takes ownership of the slice when it is set/added. | |
37 |
|
37 | |||
38 | \sa QPieSeries::set(), QPieSeries::add() |
|
38 | \sa QPieSeries::set(), QPieSeries::add() | |
39 | */ |
|
39 | */ | |
40 | QPieSlice::QPieSlice(QObject *parent) |
|
40 | QPieSlice::QPieSlice(QObject *parent) | |
41 | :QObject(parent), |
|
41 | :QObject(parent), | |
42 | m_value(0), |
|
42 | m_value(0), | |
43 | m_isLabelVisible(false), |
|
43 | m_isLabelVisible(false), | |
44 | m_isExploded(false), |
|
44 | m_isExploded(false), | |
45 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), |
|
45 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), | |
46 | m_percentage(0), |
|
46 | m_percentage(0), | |
47 | m_angle(0), |
|
47 | m_startAngle(0), | |
48 | m_angleSpan(0), |
|
48 | m_angleSpan(0), | |
49 | m_pen(DEFAULT_PEN_COLOR), |
|
49 | m_pen(DEFAULT_PEN_COLOR), | |
50 | m_brush(DEFAULT_BRUSH_COLOR), |
|
50 | m_brush(DEFAULT_BRUSH_COLOR), | |
51 | m_labelPen(DEFAULT_PEN_COLOR), |
|
51 | m_labelPen(DEFAULT_PEN_COLOR), | |
52 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) |
|
52 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | |
53 | { |
|
53 | { | |
54 |
|
54 | |||
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
58 | Constructs an empty slice with given \a value, \a label and a \a parent. | |
59 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
59 | Note that QPieSeries takes ownership of the slice when it is set/added. | |
60 | \sa QPieSeries::set(), QPieSeries::add() |
|
60 | \sa QPieSeries::set(), QPieSeries::add() | |
61 | */ |
|
61 | */ | |
62 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) |
|
62 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) | |
63 | :QObject(parent), |
|
63 | :QObject(parent), | |
64 | m_value(value), |
|
64 | m_value(value), | |
65 | m_label(label), |
|
65 | m_label(label), | |
66 | m_isLabelVisible(false), |
|
66 | m_isLabelVisible(false), | |
67 | m_isExploded(false), |
|
67 | m_isExploded(false), | |
68 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), |
|
68 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), | |
69 | m_percentage(0), |
|
69 | m_percentage(0), | |
70 | m_angle(0), |
|
70 | m_startAngle(0), | |
71 | m_angleSpan(0), |
|
71 | m_angleSpan(0), | |
72 | m_pen(DEFAULT_PEN_COLOR), |
|
72 | m_pen(DEFAULT_PEN_COLOR), | |
73 | m_brush(DEFAULT_BRUSH_COLOR), |
|
73 | m_brush(DEFAULT_BRUSH_COLOR), | |
74 | m_labelPen(DEFAULT_PEN_COLOR), |
|
74 | m_labelPen(DEFAULT_PEN_COLOR), | |
75 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) |
|
75 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Destroys the slice. |
|
81 | Destroys the slice. | |
82 | User should not delete the slice if it has been added to the series. |
|
82 | User should not delete the slice if it has been added to the series. | |
83 | */ |
|
83 | */ | |
84 | QPieSlice::~QPieSlice() |
|
84 | QPieSlice::~QPieSlice() | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | Gets the value of the slice. |
|
90 | Gets the value of the slice. | |
91 | Note that all values in the series |
|
91 | Note that all values in the series | |
92 | \sa setValue() |
|
92 | \sa setValue() | |
93 | */ |
|
93 | */ | |
94 | qreal QPieSlice::value() const |
|
94 | qreal QPieSlice::value() const | |
95 | { |
|
95 | { | |
96 | return m_value; |
|
96 | return m_value; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | Gets the label of the slice. |
|
100 | Gets the label of the slice. | |
101 | \sa setLabel() |
|
101 | \sa setLabel() | |
102 | */ |
|
102 | */ | |
103 | QString QPieSlice::label() const |
|
103 | QString QPieSlice::label() const | |
104 | { |
|
104 | { | |
105 | return m_label; |
|
105 | return m_label; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | Returns true if label is set as visible. |
|
109 | Returns true if label is set as visible. | |
110 | \sa setLabelVisible() |
|
110 | \sa setLabelVisible() | |
111 | */ |
|
111 | */ | |
112 | bool QPieSlice::isLabelVisible() const |
|
112 | bool QPieSlice::isLabelVisible() const | |
113 | { |
|
113 | { | |
114 | return m_isLabelVisible; |
|
114 | return m_isLabelVisible; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | Returns true if slice is exloded from the pie. |
|
118 | Returns true if slice is exloded from the pie. | |
119 | \sa setExploded() |
|
119 | \sa setExploded() | |
120 | */ |
|
120 | */ | |
121 | bool QPieSlice::isExploded() const |
|
121 | bool QPieSlice::isExploded() const | |
122 | { |
|
122 | { | |
123 | return m_isExploded; |
|
123 | return m_isExploded; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | Returns the explosion distance of the slice. |
|
127 | Returns the explosion distance of the slice. | |
128 | Default value is 20. |
|
128 | Default value is 20. | |
129 | \sa setExplodeDistance() |
|
129 | \sa setExplodeDistance() | |
130 | */ |
|
130 | */ | |
131 | qreal QPieSlice::explodeDistance() const |
|
131 | qreal QPieSlice::explodeDistance() const | |
132 | { |
|
132 | { | |
133 | return m_explodeDistance; |
|
133 | return m_explodeDistance; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Returns the percentage of this slice compared to all slices in the same series. |
|
137 | Returns the percentage of this slice compared to all slices in the same series. | |
138 |
|
138 | |||
139 | Updated internally after the slice is added to the series. |
|
139 | Updated internally after the slice is added to the series. | |
140 | */ |
|
140 | */ | |
141 | qreal QPieSlice::percentage() const |
|
141 | qreal QPieSlice::percentage() const | |
142 | { |
|
142 | { | |
143 | return m_percentage; |
|
143 | return m_percentage; | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | Returns the starting angle of this slice in the series it belongs to. |
|
147 | Returns the starting angle of this slice in the series it belongs to. | |
148 |
|
148 | |||
149 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
149 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
150 |
|
150 | |||
151 | Updated internally after the slice is added to the series. |
|
151 | Updated internally after the slice is added to the series. | |
152 | */ |
|
152 | */ | |
153 | qreal QPieSlice::angle() const |
|
153 | qreal QPieSlice::startAngle() const | |
154 | { |
|
154 | { | |
155 | return m_angle; |
|
155 | return m_startAngle; | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 |
Returns the angle |
|
159 | Returns the end angle of this slice in the series it belongs to. | |
160 |
|
160 | |||
161 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
161 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
162 |
|
162 | |||
163 | Updated internally after the slice is added to the series. |
|
163 | Updated internally after the slice is added to the series. | |
164 | */ |
|
164 | */ | |
165 |
qreal QPieSlice:: |
|
165 | qreal QPieSlice::endAngle() const | |
166 | { |
|
166 | { | |
167 | return m_angleSpan; |
|
167 | return m_startAngle + m_angleSpan; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Returns the pen used to draw this slice. |
|
171 | Returns the pen used to draw this slice. | |
172 | \sa setPen() |
|
172 | \sa setPen() | |
173 | */ |
|
173 | */ | |
174 | QPen QPieSlice::pen() const |
|
174 | QPen QPieSlice::pen() const | |
175 | { |
|
175 | { | |
176 | return m_pen; |
|
176 | return m_pen; | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Returns the brush used to draw this slice. |
|
180 | Returns the brush used to draw this slice. | |
181 | \sa setBrush() |
|
181 | \sa setBrush() | |
182 | */ |
|
182 | */ | |
183 | QBrush QPieSlice::brush() const |
|
183 | QBrush QPieSlice::brush() const | |
184 | { |
|
184 | { | |
185 | return m_brush; |
|
185 | return m_brush; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | Returns the pen used to draw label in this slice. |
|
189 | Returns the pen used to draw label in this slice. | |
190 | \sa setLabelPen() |
|
190 | \sa setLabelPen() | |
191 | */ |
|
191 | */ | |
192 | QPen QPieSlice::labelPen() const |
|
192 | QPen QPieSlice::labelPen() const | |
193 | { |
|
193 | { | |
194 | return m_labelPen; |
|
194 | return m_labelPen; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | Returns the font used to draw label in this slice. |
|
198 | Returns the font used to draw label in this slice. | |
199 | \sa setLabelFont() |
|
199 | \sa setLabelFont() | |
200 | */ |
|
200 | */ | |
201 | QFont QPieSlice::labelFont() const |
|
201 | QFont QPieSlice::labelFont() const | |
202 | { |
|
202 | { | |
203 | return m_labelFont; |
|
203 | return m_labelFont; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Returns the label arm lenght used in this slice. |
|
207 | Returns the label arm lenght used in this slice. | |
208 | Default value is 40 pixels. |
|
208 | Default value is 40 pixels. | |
209 | \sa setLabelArmLength() |
|
209 | \sa setLabelArmLength() | |
210 | */ |
|
210 | */ | |
211 | qreal QPieSlice::labelArmLength() const |
|
211 | qreal QPieSlice::labelArmLength() const | |
212 | { |
|
212 | { | |
213 | return m_labelArmLength; |
|
213 | return m_labelArmLength; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | \fn void QPieSlice::clicked() |
|
217 | \fn void QPieSlice::clicked() | |
218 |
|
218 | |||
219 | This signal is emitted when user has clicked the slice. |
|
219 | This signal is emitted when user has clicked the slice. | |
220 |
|
220 | |||
221 | \sa QPieSeries::clicked() |
|
221 | \sa QPieSeries::clicked() | |
222 | */ |
|
222 | */ | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | \fn void QPieSlice::hoverEnter() |
|
225 | \fn void QPieSlice::hoverEnter() | |
226 |
|
226 | |||
227 | This signal is emitted when user has hovered over the slice. |
|
227 | This signal is emitted when user has hovered over the slice. | |
228 |
|
228 | |||
229 | \sa QPieSeries::hoverEnter() |
|
229 | \sa QPieSeries::hoverEnter() | |
230 | */ |
|
230 | */ | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | \fn void QPieSlice::hoverLeave() |
|
233 | \fn void QPieSlice::hoverLeave() | |
234 |
|
234 | |||
235 | This signal is emitted when user has hovered away from the slice. |
|
235 | This signal is emitted when user has hovered away from the slice. | |
236 |
|
236 | |||
237 | \sa QPieSeries::hoverLeave() |
|
237 | \sa QPieSeries::hoverLeave() | |
238 | */ |
|
238 | */ | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | \fn void QPieSlice::changed() |
|
241 | \fn void QPieSlice::changed() | |
242 |
|
242 | |||
243 | This signal emitted when something has changed in the slice. |
|
243 | This signal emitted when something has changed in the slice. | |
244 |
|
244 | |||
245 | \sa QPieSeries::changed() |
|
245 | \sa QPieSeries::changed() | |
246 | */ |
|
246 | */ | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | Sets the value of this slice. |
|
249 | Sets the value of this slice. | |
250 | \sa value() |
|
250 | \sa value() | |
251 | */ |
|
251 | */ | |
252 | void QPieSlice::setValue(qreal value) |
|
252 | void QPieSlice::setValue(qreal value) | |
253 | { |
|
253 | { | |
254 | if (m_value != value) { |
|
254 | if (m_value != value) { | |
255 | m_value = value; |
|
255 | m_value = value; | |
256 | emit changed(); |
|
256 | emit changed(); | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | /*! |
|
260 | /*! | |
261 | Sets the \a label of the slice. |
|
261 | Sets the \a label of the slice. | |
262 | \sa label() |
|
262 | \sa label() | |
263 | */ |
|
263 | */ | |
264 | void QPieSlice::setLabel(QString label) |
|
264 | void QPieSlice::setLabel(QString label) | |
265 | { |
|
265 | { | |
266 | if (m_label != label) { |
|
266 | if (m_label != label) { | |
267 | m_label = label; |
|
267 | m_label = label; | |
268 | emit changed(); |
|
268 | emit changed(); | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | /*! |
|
272 | /*! | |
273 | Sets the label \a visible in this slice. |
|
273 | Sets the label \a visible in this slice. | |
274 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() |
|
274 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() | |
275 | */ |
|
275 | */ | |
276 | void QPieSlice::setLabelVisible(bool visible) |
|
276 | void QPieSlice::setLabelVisible(bool visible) | |
277 | { |
|
277 | { | |
278 | if (m_isLabelVisible != visible) { |
|
278 | if (m_isLabelVisible != visible) { | |
279 | m_isLabelVisible = visible; |
|
279 | m_isLabelVisible = visible; | |
280 | emit changed(); |
|
280 | emit changed(); | |
281 | } |
|
281 | } | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | Sets this slice \a exploded. |
|
285 | Sets this slice \a exploded. | |
286 | \sa isExploded(), setExplodeDistance(), QPieSeries::enableClickExplodes() |
|
286 | \sa isExploded(), setExplodeDistance(), QPieSeries::enableClickExplodes() | |
287 | */ |
|
287 | */ | |
288 | void QPieSlice::setExploded(bool exploded) |
|
288 | void QPieSlice::setExploded(bool exploded) | |
289 | { |
|
289 | { | |
290 | if (m_isExploded != exploded) { |
|
290 | if (m_isExploded != exploded) { | |
291 | m_isExploded = exploded; |
|
291 | m_isExploded = exploded; | |
292 | emit changed(); |
|
292 | emit changed(); | |
293 | } |
|
293 | } | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | Sets the explosion \a distance of this slice. |
|
297 | Sets the explosion \a distance of this slice. | |
298 | It is the distance the slice is moved away from the pie center. |
|
298 | It is the distance the slice is moved away from the pie center. | |
299 | \sa explodeDistance(), isExploded(), QPieSeries::enableClickExplodes() |
|
299 | \sa explodeDistance(), isExploded(), QPieSeries::enableClickExplodes() | |
300 | */ |
|
300 | */ | |
301 | void QPieSlice::setExplodeDistance(qreal distance) |
|
301 | void QPieSlice::setExplodeDistance(qreal distance) | |
302 | { |
|
302 | { | |
303 | if (m_explodeDistance != distance) { |
|
303 | if (m_explodeDistance != distance) { | |
304 | m_explodeDistance = distance; |
|
304 | m_explodeDistance = distance; | |
305 | emit changed(); |
|
305 | emit changed(); | |
306 | } |
|
306 | } | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Sets the \a pen used to draw this slice. |
|
310 | Sets the \a pen used to draw this slice. | |
311 | Note that applying a theme will override this. |
|
311 | Note that applying a theme will override this. | |
312 | \sa pen() |
|
312 | \sa pen() | |
313 | */ |
|
313 | */ | |
314 | void QPieSlice::setPen(QPen pen) |
|
314 | void QPieSlice::setPen(QPen pen) | |
315 | { |
|
315 | { | |
316 | if (m_pen != pen) { |
|
316 | if (m_pen != pen) { | |
317 | m_pen = pen; |
|
317 | m_pen = pen; | |
318 | emit changed(); |
|
318 | emit changed(); | |
319 | } |
|
319 | } | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | /*! |
|
322 | /*! | |
323 | Sets the \a brush used to draw this slice. |
|
323 | Sets the \a brush used to draw this slice. | |
324 | Note that applying a theme will override this. |
|
324 | Note that applying a theme will override this. | |
325 | \sa brush() |
|
325 | \sa brush() | |
326 | */ |
|
326 | */ | |
327 | void QPieSlice::setBrush(QBrush brush) |
|
327 | void QPieSlice::setBrush(QBrush brush) | |
328 | { |
|
328 | { | |
329 | if (m_brush != brush) { |
|
329 | if (m_brush != brush) { | |
330 | m_brush = brush; |
|
330 | m_brush = brush; | |
331 | emit changed(); |
|
331 | emit changed(); | |
332 | } |
|
332 | } | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | /*! |
|
335 | /*! | |
336 | Sets the \a pen used to draw the label in this slice. |
|
336 | Sets the \a pen used to draw the label in this slice. | |
337 | Note that applying a theme will override this. |
|
337 | Note that applying a theme will override this. | |
338 | \sa labelPen() |
|
338 | \sa labelPen() | |
339 | */ |
|
339 | */ | |
340 | void QPieSlice::setLabelPen(QPen pen) |
|
340 | void QPieSlice::setLabelPen(QPen pen) | |
341 | { |
|
341 | { | |
342 | if (m_labelPen != pen) { |
|
342 | if (m_labelPen != pen) { | |
343 | m_labelPen = pen; |
|
343 | m_labelPen = pen; | |
344 | emit changed(); |
|
344 | emit changed(); | |
345 | } |
|
345 | } | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | /*! |
|
348 | /*! | |
349 | Sets the \a font used to draw the label in this slice. |
|
349 | Sets the \a font used to draw the label in this slice. | |
350 | Note that applying a theme will override this. |
|
350 | Note that applying a theme will override this. | |
351 | \sa labelFont() |
|
351 | \sa labelFont() | |
352 | */ |
|
352 | */ | |
353 | void QPieSlice::setLabelFont(QFont font) |
|
353 | void QPieSlice::setLabelFont(QFont font) | |
354 | { |
|
354 | { | |
355 | if (m_labelFont != font) { |
|
355 | if (m_labelFont != font) { | |
356 | m_labelFont = font; |
|
356 | m_labelFont = font; | |
357 | emit changed(); |
|
357 | emit changed(); | |
358 | } |
|
358 | } | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | /*! |
|
361 | /*! | |
362 | Sets the label arm \a length used to draw the label in this slice. |
|
362 | Sets the label arm \a length used to draw the label in this slice. | |
363 | \sa labelArmLength() |
|
363 | \sa labelArmLength() | |
364 | */ |
|
364 | */ | |
365 | void QPieSlice::setLabelArmLength(qreal length) |
|
365 | void QPieSlice::setLabelArmLength(qreal length) | |
366 | { |
|
366 | { | |
367 | if (m_labelArmLength != length) { |
|
367 | if (m_labelArmLength != length) { | |
368 | m_labelArmLength = length; |
|
368 | m_labelArmLength = length; | |
369 | emit changed(); |
|
369 | emit changed(); | |
370 | } |
|
370 | } | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | #include "moc_qpieslice.cpp" |
|
373 | #include "moc_qpieslice.cpp" | |
374 |
|
374 | |||
375 | QTCOMMERCIALCHART_END_NAMESPACE |
|
375 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,96 +1,97 | |||||
1 | #ifndef QPIESLICE_H |
|
1 | #ifndef QPIESLICE_H | |
2 | #define QPIESLICE_H |
|
2 | #define QPIESLICE_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 | #include <QBrush> |
|
7 | #include <QBrush> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject |
|
12 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed) |
|
15 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed) | |
16 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) |
|
16 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | QPieSlice(QObject *parent = 0); |
|
19 | QPieSlice(QObject *parent = 0); | |
20 | QPieSlice(qreal value, QString label, QObject *parent = 0); |
|
20 | QPieSlice(qreal value, QString label, QObject *parent = 0); | |
21 | virtual ~QPieSlice(); |
|
21 | virtual ~QPieSlice(); | |
22 |
|
22 | |||
23 | // data |
|
23 | // data | |
24 | qreal value() const; |
|
24 | qreal value() const; | |
25 | QString label() const; |
|
25 | QString label() const; | |
26 | bool isLabelVisible() const; |
|
26 | bool isLabelVisible() const; | |
27 | bool isExploded() const; |
|
27 | bool isExploded() const; | |
28 | qreal explodeDistance() const; |
|
28 | qreal explodeDistance() const; | |
29 |
|
29 | |||
30 | // generated data |
|
30 | // generated data | |
31 | qreal percentage() const; |
|
31 | qreal percentage() const; | |
32 | qreal angle() const; |
|
32 | qreal startAngle() const; | |
33 |
qreal |
|
33 | qreal endAngle() const; | |
34 |
|
34 | |||
35 | // customization |
|
35 | // customization | |
36 | QPen pen() const; |
|
36 | QPen pen() const; | |
37 | QBrush brush() const; |
|
37 | QBrush brush() const; | |
38 | QPen labelPen() const; |
|
38 | QPen labelPen() const; | |
39 | QFont labelFont() const; |
|
39 | QFont labelFont() const; | |
40 | qreal labelArmLength() const; |
|
40 | qreal labelArmLength() const; | |
41 |
|
41 | |||
42 | Q_SIGNALS: |
|
42 | Q_SIGNALS: | |
43 | void clicked(); |
|
43 | void clicked(); | |
44 | void hoverEnter(); |
|
44 | void hoverEnter(); | |
45 | void hoverLeave(); |
|
45 | void hoverLeave(); | |
46 | void changed(); |
|
46 | void changed(); | |
47 |
|
47 | |||
48 | public Q_SLOTS: |
|
48 | public Q_SLOTS: | |
49 |
|
49 | |||
50 | // data |
|
50 | // data | |
51 | void setLabel(QString label); |
|
51 | void setLabel(QString label); | |
52 | void setLabelVisible(bool visible); |
|
52 | void setLabelVisible(bool visible); | |
53 | void setValue(qreal value); |
|
53 | void setValue(qreal value); | |
54 | void setExploded(bool exploded); |
|
54 | void setExploded(bool exploded); | |
55 | void setExplodeDistance(qreal distance); |
|
55 | void setExplodeDistance(qreal distance); | |
56 |
|
56 | |||
57 | // customization |
|
57 | // customization | |
58 | void setPen(QPen pen); |
|
58 | void setPen(QPen pen); | |
59 | void setBrush(QBrush brush); |
|
59 | void setBrush(QBrush brush); | |
60 | void setLabelFont(QFont font); |
|
60 | void setLabelFont(QFont font); | |
61 | void setLabelPen(QPen pen); |
|
61 | void setLabelPen(QPen pen); | |
62 | void setLabelArmLength(qreal len); |
|
62 | void setLabelArmLength(qreal len); | |
63 |
|
63 | |||
64 | // TODO: label position in general |
|
64 | // TODO: label position in general | |
65 | // setLabelFlags(inside|outside|labelArmOn|labelArmOff|???) |
|
65 | // setLabelFlags(inside|outside|labelArmOn|labelArmOff|???) | |
66 | // setLabelOrientation(horizontal|vertical|same as slice center angle|???) |
|
66 | // setLabelOrientation(horizontal|vertical|same as slice center angle|???) | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
69 |
|
69 | |||
70 | // TODO: use private class |
|
70 | // TODO: use private class | |
71 | friend class QPieSeries; |
|
71 | friend class QPieSeries; | |
72 | friend class PiePresenter; |
|
72 | friend class PiePresenter; | |
|
73 | friend class PieSlice; | |||
73 |
|
74 | |||
74 | // data |
|
75 | // data | |
75 | qreal m_value; |
|
76 | qreal m_value; | |
76 | QString m_label; |
|
77 | QString m_label; | |
77 | bool m_isLabelVisible; |
|
78 | bool m_isLabelVisible; | |
78 | bool m_isExploded; |
|
79 | bool m_isExploded; | |
79 | qreal m_explodeDistance; |
|
80 | qreal m_explodeDistance; | |
80 |
|
81 | |||
81 | // generated data |
|
82 | // generated data | |
82 | qreal m_percentage; |
|
83 | qreal m_percentage; | |
83 | qreal m_angle; |
|
84 | qreal m_startAngle; | |
84 | qreal m_angleSpan; |
|
85 | qreal m_angleSpan; | |
85 |
|
86 | |||
86 | // customization |
|
87 | // customization | |
87 | QPen m_pen; |
|
88 | QPen m_pen; | |
88 | QBrush m_brush; |
|
89 | QBrush m_brush; | |
89 | QPen m_labelPen; |
|
90 | QPen m_labelPen; | |
90 | QFont m_labelFont; |
|
91 | QFont m_labelFont; | |
91 | qreal m_labelArmLength; |
|
92 | qreal m_labelArmLength; | |
92 | }; |
|
93 | }; | |
93 |
|
94 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | QTCOMMERCIALCHART_END_NAMESPACE | |
95 |
|
96 | |||
96 | #endif // QPIESLICE_H |
|
97 | #endif // QPIESLICE_H |
General Comments 0
You need to be logged in to leave comments.
Login now