##// END OF EJS Templates
rename PieSlice -> PieSliceItem
Jani Honkonen -
r673:e6252af95451
parent child
Show More
@@ -3,13 +3,13 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 5 $$PWD/qpieseries.cpp \
6 $$PWD/pieslice.cpp \
6 $$PWD/piesliceitem.cpp \
7 7 $$PWD/piechartitem.cpp \
8 8 $$PWD/qpieslice.cpp
9 9
10 10 PRIVATE_HEADERS += \
11 11 $$PWD/piechartitem_p.h \
12 $$PWD/pieslice_p.h \
12 $$PWD/piesliceitem_p.h \
13 13 $$PWD/qpiesliceprivate_p.h \
14 14 $$PWD/qpieseriesprivate_p.h
15 15
@@ -1,5 +1,5
1 1 #include "piechartitem_p.h"
2 #include "pieslice_p.h"
2 #include "piesliceitem_p.h"
3 3 #include "qpieslice.h"
4 4 #include "qpiesliceprivate_p.h"
5 5 #include "qpieseries.h"
@@ -55,12 +55,12 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
55 55 m_presenter->theme()->decorate(m_series, m_presenter->dataSet()->seriesIndex(m_series));
56 56
57 57 foreach (QPieSlice *s, slices) {
58 PieSlice* slice = new PieSlice(this);
59 m_slices.insert(s, slice);
58 PieSliceItem* item = new PieSliceItem(this);
59 m_slices.insert(s, item);
60 60 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
61 connect(slice, SIGNAL(clicked()), s, SIGNAL(clicked()));
62 connect(slice, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
63 connect(slice, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
61 connect(item, SIGNAL(clicked()), s, SIGNAL(clicked()));
62 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
63 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
64 64
65 65 PieSliceData data = sliceData(s);
66 66
@@ -129,7 +129,7 void PieChartItem::calculatePieLayout()
129 129 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
130 130 {
131 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 133 sliceData.m_radius = m_pieRadius;
134 134 sliceData.m_angleSpan = slice->endAngle() - slice->startAngle();
135 135 return sliceData;
@@ -165,22 +165,22 void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData)
165 165 void PieChartItem::setLayout(const PieLayout &layout)
166 166 {
167 167 foreach (QPieSlice *slice, layout.keys()) {
168 PieSlice *s = m_slices.value(slice);
169 Q_ASSERT(s);
170 s->setSliceData(layout.value(slice));
171 s->updateGeometry();
172 s->update();
168 PieSliceItem *item = m_slices.value(slice);
169 Q_ASSERT(item);
170 item->setSliceData(layout.value(slice));
171 item->updateGeometry();
172 item->update();
173 173 }
174 174 }
175 175
176 176 void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData)
177 177 {
178 178 // find slice
179 PieSlice *s = m_slices.value(slice);
180 Q_ASSERT(s);
181 s->setSliceData(sliceData);
182 s->updateGeometry();
183 s->update();
179 PieSliceItem *item = m_slices.value(slice);
180 Q_ASSERT(item);
181 item->setSliceData(sliceData);
182 item->updateGeometry();
183 item->update();
184 184 }
185 185
186 186 void PieChartItem::destroySlice(QPieSlice *slice)
@@ -3,7 +3,7
3 3
4 4 #include "qpieseries.h"
5 5 #include "chartitem_p.h"
6 #include "pieslice_p.h"
6 #include "piesliceitem_p.h"
7 7
8 8 class QGraphicsItem;
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -45,8 +45,8 public:
45 45 void destroySlice(QPieSlice *slice);
46 46
47 47 private:
48 friend class PieSlice;
49 QHash<QPieSlice*, PieSlice*> m_slices;
48 friend class PieSliceItem;
49 QHash<QPieSlice*, PieSliceItem*> m_slices;
50 50 QPieSeries *m_series;
51 51 QRectF m_rect;
52 52 QPointF m_pieCenter;
@@ -1,4 +1,4
1 #include "pieslice_p.h"
1 #include "piesliceitem_p.h"
2 2 #include "piechartitem_p.h"
3 3 #include "qpieseries.h"
4 4 #include "qpieslice.h"
@@ -20,7 +20,7 QPointF offset(qreal angle, qreal length)
20 20 return QPointF(dx, -dy);
21 21 }
22 22
23 PieSlice::PieSlice(QGraphicsItem* parent)
23 PieSliceItem::PieSliceItem(QGraphicsItem* parent)
24 24 :QGraphicsObject(parent)
25 25 {
26 26 setAcceptHoverEvents(true);
@@ -28,24 +28,24 PieSlice::PieSlice(QGraphicsItem* parent)
28 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 38 return m_boundingRect;
39 39 }
40 40
41 QPainterPath PieSlice::shape() const
41 QPainterPath PieSliceItem::shape() const
42 42 {
43 43 // Don't include the label and label arm.
44 44 // This is used to detect a mouse clicks. We do not want clicks from label.
45 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 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 71 emit hoverEnter();
72 72 }
73 73
74 void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
74 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
75 75 {
76 76 emit hoverLeave();
77 77 }
78 78
79 void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
79 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
80 80 {
81 81 emit clicked();
82 82 }
83 83
84 void PieSlice::setSliceData(PieSliceData sliceData)
84 void PieSliceItem::setSliceData(PieSliceData sliceData)
85 85 {
86 86 m_data = sliceData;
87 87 }
88 88
89 void PieSlice::updateGeometry()
89 void PieSliceItem::updateGeometry()
90 90 {
91 91 if (m_data.m_radius <= 0)
92 92 return;
@@ -112,7 +112,7 void PieSlice::updateGeometry()
112 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 117 if (slice->isExploded()) {
118 118 qreal centerAngle = slice->startAngle() + ((slice->endAngle() - slice->startAngle())/2);
@@ -124,7 +124,7 QPointF PieSlice::sliceCenter(QPointF point, qreal radius, QPieSlice *slice)
124 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 129 // calculate center angle
130 130 *centerAngle = startAngle + (angleSpan/2);
@@ -146,7 +146,7 QPainterPath PieSlice::slicePath(QPointF center, qreal radius, qreal startAngle,
146 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 151 qreal dx = qSin(angle*(PI/180)) * length;
152 152 qreal dy = -qCos(angle*(PI/180)) * length;
@@ -173,12 +173,12 QPainterPath PieSlice::labelArmPath(QPointF start, qreal angle, qreal length, qr
173 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 178 QFontMetricsF fm(font);
179 179 return fm.boundingRect(text);
180 180 }
181 181
182 #include "moc_pieslice_p.cpp"
182 #include "moc_piesliceitem_p.cpp"
183 183
184 184 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,5 +1,5
1 #ifndef PIESLICE_H
2 #define PIESLICE_H
1 #ifndef PIESLICEITEM_H
2 #define PIESLICEITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "charttheme_p.h"
@@ -17,13 +17,13 class PieChartItem;
17 17 class PieSliceLabel;
18 18 class QPieSlice;
19 19
20 class PieSlice : public QGraphicsObject
20 class PieSliceItem : public QGraphicsObject
21 21 {
22 22 Q_OBJECT
23 23
24 24 public:
25 PieSlice(QGraphicsItem* parent = 0);
26 ~PieSlice();
25 PieSliceItem(QGraphicsItem* parent = 0);
26 ~PieSliceItem();
27 27
28 28 public: // from QGraphicsItem
29 29 QRectF boundingRect() const;
@@ -56,4 +56,4 private:
56 56
57 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