@@ -3,13 +3,13 DEPENDPATH += $$PWD | |||||
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/qpieseries.cpp \ |
|
5 | $$PWD/qpieseries.cpp \ | |
6 | $$PWD/pieslice.cpp \ |
|
6 | $$PWD/piesliceitem.cpp \ | |
7 | $$PWD/piechartitem.cpp \ |
|
7 | $$PWD/piechartitem.cpp \ | |
8 | $$PWD/qpieslice.cpp |
|
8 | $$PWD/qpieslice.cpp | |
9 |
|
9 | |||
10 | PRIVATE_HEADERS += \ |
|
10 | PRIVATE_HEADERS += \ | |
11 | $$PWD/piechartitem_p.h \ |
|
11 | $$PWD/piechartitem_p.h \ | |
12 | $$PWD/pieslice_p.h \ |
|
12 | $$PWD/piesliceitem_p.h \ | |
13 | $$PWD/qpiesliceprivate_p.h \ |
|
13 | $$PWD/qpiesliceprivate_p.h \ | |
14 | $$PWD/qpieseriesprivate_p.h |
|
14 | $$PWD/qpieseriesprivate_p.h | |
15 |
|
15 |
@@ -1,5 +1,5 | |||||
1 | #include "piechartitem_p.h" |
|
1 | #include "piechartitem_p.h" | |
2 | #include "pieslice_p.h" |
|
2 | #include "piesliceitem_p.h" | |
3 | #include "qpieslice.h" |
|
3 | #include "qpieslice.h" | |
4 | #include "qpiesliceprivate_p.h" |
|
4 | #include "qpiesliceprivate_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
@@ -55,12 +55,12 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||||
55 | m_presenter->theme()->decorate(m_series, m_presenter->dataSet()->seriesIndex(m_series)); |
|
55 | m_presenter->theme()->decorate(m_series, m_presenter->dataSet()->seriesIndex(m_series)); | |
56 |
|
56 | |||
57 | foreach (QPieSlice *s, slices) { |
|
57 | foreach (QPieSlice *s, slices) { | |
58 |
PieSlice* |
|
58 | PieSliceItem* item = new PieSliceItem(this); | |
59 |
m_slices.insert(s, |
|
59 | m_slices.insert(s, item); | |
60 | connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged())); |
|
60 | connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged())); | |
61 |
connect( |
|
61 | connect(item, SIGNAL(clicked()), s, SIGNAL(clicked())); | |
62 |
connect( |
|
62 | connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter())); | |
63 |
connect( |
|
63 | connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave())); | |
64 |
|
64 | |||
65 | PieSliceData data = sliceData(s); |
|
65 | PieSliceData data = sliceData(s); | |
66 |
|
66 | |||
@@ -129,7 +129,7 void PieChartItem::calculatePieLayout() | |||||
129 | PieSliceData PieChartItem::sliceData(QPieSlice *slice) |
|
129 | PieSliceData PieChartItem::sliceData(QPieSlice *slice) | |
130 | { |
|
130 | { | |
131 | PieSliceData sliceData = slice->d_ptr->m_data; |
|
131 | PieSliceData sliceData = slice->d_ptr->m_data; | |
132 | sliceData.m_center = PieSlice::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
132 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
133 | sliceData.m_radius = m_pieRadius; |
|
133 | sliceData.m_radius = m_pieRadius; | |
134 | sliceData.m_angleSpan = slice->endAngle() - slice->startAngle(); |
|
134 | sliceData.m_angleSpan = slice->endAngle() - slice->startAngle(); | |
135 | return sliceData; |
|
135 | return sliceData; | |
@@ -165,22 +165,22 void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData) | |||||
165 | void PieChartItem::setLayout(const PieLayout &layout) |
|
165 | void PieChartItem::setLayout(const PieLayout &layout) | |
166 | { |
|
166 | { | |
167 | foreach (QPieSlice *slice, layout.keys()) { |
|
167 | foreach (QPieSlice *slice, layout.keys()) { | |
168 |
PieSlice * |
|
168 | PieSliceItem *item = m_slices.value(slice); | |
169 |
Q_ASSERT( |
|
169 | Q_ASSERT(item); | |
170 |
|
|
170 | item->setSliceData(layout.value(slice)); | |
171 |
|
|
171 | item->updateGeometry(); | |
172 |
|
|
172 | item->update(); | |
173 | } |
|
173 | } | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData) |
|
176 | void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData) | |
177 | { |
|
177 | { | |
178 | // find slice |
|
178 | // find slice | |
179 |
PieSlice * |
|
179 | PieSliceItem *item = m_slices.value(slice); | |
180 |
Q_ASSERT( |
|
180 | Q_ASSERT(item); | |
181 |
|
|
181 | item->setSliceData(sliceData); | |
182 |
|
|
182 | item->updateGeometry(); | |
183 |
|
|
183 | item->update(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void PieChartItem::destroySlice(QPieSlice *slice) |
|
186 | void PieChartItem::destroySlice(QPieSlice *slice) |
@@ -3,7 +3,7 | |||||
3 |
|
3 | |||
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include "pieslice_p.h" |
|
6 | #include "piesliceitem_p.h" | |
7 |
|
7 | |||
8 | class QGraphicsItem; |
|
8 | class QGraphicsItem; | |
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -45,8 +45,8 public: | |||||
45 | void destroySlice(QPieSlice *slice); |
|
45 | void destroySlice(QPieSlice *slice); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | friend class PieSlice; |
|
48 | friend class PieSliceItem; | |
49 | QHash<QPieSlice*, PieSlice*> m_slices; |
|
49 | QHash<QPieSlice*, PieSliceItem*> m_slices; | |
50 | QPieSeries *m_series; |
|
50 | QPieSeries *m_series; | |
51 | QRectF m_rect; |
|
51 | QRectF m_rect; | |
52 | QPointF m_pieCenter; |
|
52 | QPointF m_pieCenter; |
@@ -1,4 +1,4 | |||||
1 | #include "pieslice_p.h" |
|
1 | #include "piesliceitem_p.h" | |
2 | #include "piechartitem_p.h" |
|
2 | #include "piechartitem_p.h" | |
3 | #include "qpieseries.h" |
|
3 | #include "qpieseries.h" | |
4 | #include "qpieslice.h" |
|
4 | #include "qpieslice.h" | |
@@ -20,7 +20,7 QPointF offset(qreal angle, qreal length) | |||||
20 | return QPointF(dx, -dy); |
|
20 | return QPointF(dx, -dy); | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | PieSlice::PieSlice(QGraphicsItem* parent) |
|
23 | PieSliceItem::PieSliceItem(QGraphicsItem* parent) | |
24 | :QGraphicsObject(parent) |
|
24 | :QGraphicsObject(parent) | |
25 | { |
|
25 | { | |
26 | setAcceptHoverEvents(true); |
|
26 | setAcceptHoverEvents(true); | |
@@ -28,24 +28,24 PieSlice::PieSlice(QGraphicsItem* parent) | |||||
28 | setZValue(ChartPresenter::PieSeriesZValue); |
|
28 | setZValue(ChartPresenter::PieSeriesZValue); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | PieSlice::~PieSlice() |
|
31 | PieSliceItem::~PieSliceItem() | |
32 | { |
|
32 | { | |
33 |
|
33 | |||
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | QRectF PieSlice::boundingRect() const |
|
36 | QRectF PieSliceItem::boundingRect() const | |
37 | { |
|
37 | { | |
38 | return m_boundingRect; |
|
38 | return m_boundingRect; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QPainterPath PieSlice::shape() const |
|
41 | QPainterPath PieSliceItem::shape() const | |
42 | { |
|
42 | { | |
43 | // Don't include the label and label arm. |
|
43 | // Don't include the label and label arm. | |
44 | // This is used to detect a mouse clicks. We do not want clicks from label. |
|
44 | // This is used to detect a mouse clicks. We do not want clicks from label. | |
45 | return m_slicePath; |
|
45 | return m_slicePath; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) |
|
48 | void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
49 | { |
|
49 | { | |
50 | painter->setClipRect(parentItem()->boundingRect()); |
|
50 | painter->setClipRect(parentItem()->boundingRect()); | |
51 |
|
51 | |||
@@ -66,27 +66,27 void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option | |||||
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
69 | void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) | |
70 | { |
|
70 | { | |
71 | emit hoverEnter(); |
|
71 | emit hoverEnter(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
74 | void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | |
75 | { |
|
75 | { | |
76 | emit hoverLeave(); |
|
76 | emit hoverLeave(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) |
|
79 | void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) | |
80 | { |
|
80 | { | |
81 | emit clicked(); |
|
81 | emit clicked(); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void PieSlice::setSliceData(PieSliceData sliceData) |
|
84 | void PieSliceItem::setSliceData(PieSliceData sliceData) | |
85 | { |
|
85 | { | |
86 | m_data = sliceData; |
|
86 | m_data = sliceData; | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void PieSlice::updateGeometry() |
|
89 | void PieSliceItem::updateGeometry() | |
90 | { |
|
90 | { | |
91 | if (m_data.m_radius <= 0) |
|
91 | if (m_data.m_radius <= 0) | |
92 | return; |
|
92 | return; | |
@@ -112,7 +112,7 void PieSlice::updateGeometry() | |||||
112 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); |
|
112 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | QPointF PieSlice::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) |
|
115 | QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |
116 | { |
|
116 | { | |
117 | if (slice->isExploded()) { |
|
117 | if (slice->isExploded()) { | |
118 | qreal centerAngle = slice->startAngle() + ((slice->endAngle() - slice->startAngle())/2); |
|
118 | qreal centerAngle = slice->startAngle() + ((slice->endAngle() - slice->startAngle())/2); | |
@@ -124,7 +124,7 QPointF PieSlice::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |||||
124 | return point; |
|
124 | return point; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | QPainterPath PieSlice::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal* centerAngle, QPointF* armStart) |
|
127 | QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal* centerAngle, QPointF* armStart) | |
128 | { |
|
128 | { | |
129 | // calculate center angle |
|
129 | // calculate center angle | |
130 | *centerAngle = startAngle + (angleSpan/2); |
|
130 | *centerAngle = startAngle + (angleSpan/2); | |
@@ -146,7 +146,7 QPainterPath PieSlice::slicePath(QPointF center, qreal radius, qreal startAngle, | |||||
146 | return path; |
|
146 | return path; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | QPainterPath PieSlice::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF* textStart) |
|
149 | QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF* textStart) | |
150 | { |
|
150 | { | |
151 | qreal dx = qSin(angle*(PI/180)) * length; |
|
151 | qreal dx = qSin(angle*(PI/180)) * length; | |
152 | qreal dy = -qCos(angle*(PI/180)) * length; |
|
152 | qreal dy = -qCos(angle*(PI/180)) * length; | |
@@ -173,12 +173,12 QPainterPath PieSlice::labelArmPath(QPointF start, qreal angle, qreal length, qr | |||||
173 | return path; |
|
173 | return path; | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QRectF PieSlice::labelTextRect(QFont font, QString text) |
|
176 | QRectF PieSliceItem::labelTextRect(QFont font, QString text) | |
177 | { |
|
177 | { | |
178 | QFontMetricsF fm(font); |
|
178 | QFontMetricsF fm(font); | |
179 | return fm.boundingRect(text); |
|
179 | return fm.boundingRect(text); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | #include "moc_pieslice_p.cpp" |
|
182 | #include "moc_piesliceitem_p.cpp" | |
183 |
|
183 | |||
184 | QTCOMMERCIALCHART_END_NAMESPACE |
|
184 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,5 +1,5 | |||||
1 | #ifndef PIESLICE_H |
|
1 | #ifndef PIESLICEITEM_H | |
2 | #define PIESLICE_H |
|
2 | #define PIESLICEITEM_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
@@ -17,13 +17,13 class PieChartItem; | |||||
17 | class PieSliceLabel; |
|
17 | class PieSliceLabel; | |
18 | class QPieSlice; |
|
18 | class QPieSlice; | |
19 |
|
19 | |||
20 | class PieSlice : public QGraphicsObject |
|
20 | class PieSliceItem : public QGraphicsObject | |
21 | { |
|
21 | { | |
22 | Q_OBJECT |
|
22 | Q_OBJECT | |
23 |
|
23 | |||
24 | public: |
|
24 | public: | |
25 | PieSlice(QGraphicsItem* parent = 0); |
|
25 | PieSliceItem(QGraphicsItem* parent = 0); | |
26 | ~PieSlice(); |
|
26 | ~PieSliceItem(); | |
27 |
|
27 | |||
28 | public: // from QGraphicsItem |
|
28 | public: // from QGraphicsItem | |
29 | QRectF boundingRect() const; |
|
29 | QRectF boundingRect() const; | |
@@ -56,4 +56,4 private: | |||||
56 |
|
56 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
58 | |||
59 | #endif // PIESLICE_H |
|
59 | #endif // PIESLICEITEM_H |
General Comments 0
You need to be logged in to leave comments.
Login now