##// END OF EJS Templates
Remove click exploding and hover highlighting from pie series API. User should always implement their own.
Jani Honkonen -
r436:b334955b5e36
parent child
Show More
@@ -1,38 +1,33
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <qpieslice.h>
6 #include <qpieslice.h>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
10 int main(int argc, char *argv[])
10 int main(int argc, char *argv[])
11 {
11 {
12 QApplication a(argc, argv);
12 QApplication a(argc, argv);
13
13
14 QMainWindow window;
14 QMainWindow window;
15
15
16 QChartView* chartView = new QChartView(&window);
16 QChartView* chartView = new QChartView(&window);
17
17
18 //! [1]
18 //! [1]
19 QPieSeries *series = new QPieSeries();
19 QPieSeries *series = new QPieSeries();
20 series->add(1, "Slice 1");
20 series->add(1, "Slice 1");
21 series->add(2, "Slice 2");
21 series->add(2, "Slice 2");
22 series->add(3, "Slice 3");
22 series->add(3, "Slice 3");
23 series->add(4, "Slice 4");
23 series->add(4, "Slice 4");
24 series->add(5, "Slice 5");
24 series->add(5, "Slice 5");
25 chartView->addSeries(series);
25 chartView->addSeries(series);
26 //! [1]
26 //! [1]
27
27
28 //! [2]
29 series->setHoverHighlighting();
30 series->setClickExplodes();
31 //! [2]
32
33 window.setCentralWidget(chartView);
28 window.setCentralWidget(chartView);
34 window.resize(600, 600);
29 window.resize(600, 600);
35 window.show();
30 window.show();
36
31
37 return a.exec();
32 return a.exec();
38 }
33 }
@@ -1,113 +1,111
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <qpieslice.h>
6 #include <qpieslice.h>
7 #include <QTime>
7 #include <QTime>
8
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
10
11 class DrilldownSlice : public QPieSlice
11 class DrilldownSlice : public QPieSlice
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14
14
15 public:
15 public:
16 DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries)
16 DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries)
17 :m_drilldownSeries(drilldownSeries),
17 :m_drilldownSeries(drilldownSeries),
18 m_prefix(prefix)
18 m_prefix(prefix)
19 {
19 {
20 setValue(value);
20 setValue(value);
21 setLabelVisible(true);
21 setLabelVisible(true);
22 updateLabel();
22 updateLabel();
23 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
23 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
24 }
24 }
25
25
26 QSeries* drilldownSeries() const { return m_drilldownSeries; }
26 QSeries* drilldownSeries() const { return m_drilldownSeries; }
27
27
28 public Q_SLOTS:
28 public Q_SLOTS:
29 void updateLabel()
29 void updateLabel()
30 {
30 {
31 QString label = m_prefix;
31 QString label = m_prefix;
32 label += " " + QString::number(this->value())+ "e (";
32 label += " " + QString::number(this->value())+ "e (";
33 label += QString::number(this->percentage()*100, 'f', 1) + "%)";
33 label += QString::number(this->percentage()*100, 'f', 1) + "%)";
34 setLabel(label);
34 setLabel(label);
35 }
35 }
36
36
37 private:
37 private:
38 QSeries* m_drilldownSeries;
38 QSeries* m_drilldownSeries;
39 QString m_prefix;
39 QString m_prefix;
40 };
40 };
41
41
42 class DrilldownChart : public QChartView
42 class DrilldownChart : public QChartView
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {}
46 explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {}
47
47
48 void changeSeries(QSeries* series)
48 void changeSeries(QSeries* series)
49 {
49 {
50 if (m_currentSeries)
50 if (m_currentSeries)
51 removeSeries(m_currentSeries);
51 removeSeries(m_currentSeries);
52 m_currentSeries = series;
52 m_currentSeries = series;
53 addSeries(series);
53 addSeries(series);
54 setChartTitle(series->title());
54 setChartTitle(series->title());
55 }
55 }
56
56
57 public Q_SLOTS:
57 public Q_SLOTS:
58 void handleSliceClicked(QPieSlice* slice)
58 void handleSliceClicked(QPieSlice* slice)
59 {
59 {
60 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
60 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
61 changeSeries(drilldownSlice->drilldownSeries());
61 changeSeries(drilldownSlice->drilldownSeries());
62 }
62 }
63
63
64 private:
64 private:
65 QSeries* m_currentSeries;
65 QSeries* m_currentSeries;
66 };
66 };
67
67
68 int main(int argc, char *argv[])
68 int main(int argc, char *argv[])
69 {
69 {
70 QApplication a(argc, argv);
70 QApplication a(argc, argv);
71
71
72 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
72 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
73
73
74 QMainWindow window;
74 QMainWindow window;
75
75
76 DrilldownChart* drilldownChart = new DrilldownChart(&window);
76 DrilldownChart* drilldownChart = new DrilldownChart(&window);
77 drilldownChart->setRenderHint(QPainter::Antialiasing);
77 drilldownChart->setRenderHint(QPainter::Antialiasing);
78 drilldownChart->setChartTheme(QChart::ChartThemeVanilla);
78 drilldownChart->setChartTheme(QChart::ChartThemeVanilla);
79
79
80 QPieSeries* yearSeries = new QPieSeries(drilldownChart);
80 QPieSeries* yearSeries = new QPieSeries(drilldownChart);
81 yearSeries->setTitle("Sales by year - All");
81 yearSeries->setTitle("Sales by year - All");
82 yearSeries->setHoverHighlighting();
83
82
84 QList<QString> months;
83 QList<QString> months;
85 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
84 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
86 QList<QString> names;
85 QList<QString> names;
87 names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob";
86 names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob";
88
87
89 foreach (QString name, names) {
88 foreach (QString name, names) {
90 QPieSeries* series = new QPieSeries(drilldownChart);
89 QPieSeries* series = new QPieSeries(drilldownChart);
91 series->setTitle("Sales by month - " + name);
90 series->setTitle("Sales by month - " + name);
92 series->setHoverHighlighting();
93
91
94 foreach (QString month, months)
92 foreach (QString month, months)
95 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
93 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
96
94
97 QObject::connect(series, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
95 QObject::connect(series, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
98
96
99 *yearSeries << new DrilldownSlice(series->total(), name, series);
97 *yearSeries << new DrilldownSlice(series->total(), name, series);
100 }
98 }
101
99
102 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
100 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
103
101
104 drilldownChart->changeSeries(yearSeries);
102 drilldownChart->changeSeries(yearSeries);
105
103
106 window.setCentralWidget(drilldownChart);
104 window.setCentralWidget(drilldownChart);
107 window.resize(600, 600);
105 window.resize(600, 600);
108 window.show();
106 window.show();
109
107
110 return a.exec();
108 return a.exec();
111 }
109 }
112
110
113 #include "main.moc"
111 #include "main.moc"
@@ -1,534 +1,481
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 is determined by that relative value.
109 The actual slice size is determined by that relative value.
110
110
111 By default the pie is defined as a full pie but it can be a partial pie.
111 By default the pie is defined as a full pie 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
114 To help with the most common user interaction scenarions there some convenience functions.
115 Like exploding a slice when clicked and higlighting when user hovers over a slice.
116 */
113 */
117
114
118 /*!
115 /*!
119 Constructs a series object which is a child of \a parent.
116 Constructs a series object which is a child of \a parent.
120 */
117 */
121 QPieSeries::QPieSeries(QObject *parent) :
118 QPieSeries::QPieSeries(QObject *parent) :
122 QSeries(parent),
119 QSeries(parent),
123 m_sizeFactor(1.0),
120 m_sizeFactor(1.0),
124 m_position(PiePositionMaximized),
121 m_position(PiePositionMaximized),
125 m_pieStartAngle(0),
122 m_pieStartAngle(0),
126 m_pieAngleSpan(360)
123 m_pieAngleSpan(360)
127 {
124 {
128
125
129 }
126 }
130
127
131 /*!
128 /*!
132 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
129 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
133 */
130 */
134 QPieSeries::~QPieSeries()
131 QPieSeries::~QPieSeries()
135 {
132 {
136
133
137 }
134 }
138
135
139 /*!
136 /*!
140 Returns QChartSeries::SeriesTypePie.
137 Returns QChartSeries::SeriesTypePie.
141 */
138 */
142 QSeries::QSeriesType QPieSeries::type() const
139 QSeries::QSeriesType QPieSeries::type() const
143 {
140 {
144 return QSeries::SeriesTypePie;
141 return QSeries::SeriesTypePie;
145 }
142 }
146
143
147 /*!
144 /*!
148 Sets an array of \a slices to the series replacing the existing slices.
145 Sets an array of \a slices to the series replacing the existing slices.
149 Slice ownership is passed to the series.
146 Slice ownership is passed to the series.
150 */
147 */
151 void QPieSeries::replace(QList<QPieSlice*> slices)
148 void QPieSeries::replace(QList<QPieSlice*> slices)
152 {
149 {
153 clear();
150 clear();
154 add(slices);
151 add(slices);
155 }
152 }
156
153
157 /*!
154 /*!
158 Adds an array of \a slices to the series.
155 Adds an array of \a slices to the series.
159 Slice ownership is passed to the series.
156 Slice ownership is passed to the series.
160 */
157 */
161 void QPieSeries::add(QList<QPieSlice*> slices)
158 void QPieSeries::add(QList<QPieSlice*> slices)
162 {
159 {
163 ChangeSet changeSet;
160 ChangeSet changeSet;
164 foreach (QPieSlice* s, slices) {
161 foreach (QPieSlice* s, slices) {
165 s->setParent(this);
162 s->setParent(this);
166 m_slices << s;
163 m_slices << s;
167 changeSet.appendAdded(s);
164 changeSet.appendAdded(s);
168 }
165 }
169
166
170 updateDerivativeData();
167 updateDerivativeData();
171
168
172 foreach (QPieSlice* s, slices) {
169 foreach (QPieSlice* s, slices) {
173 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
170 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
174 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
171 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
175 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
172 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
176 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
173 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
177 }
174 }
178
175
179 emit changed(changeSet);
176 emit changed(changeSet);
180 }
177 }
181
178
182 /*!
179 /*!
183 Adds a single \a slice to the series.
180 Adds a single \a slice to the series.
184 Slice ownership is passed to the series.
181 Slice ownership is passed to the series.
185 */
182 */
186 void QPieSeries::add(QPieSlice* slice)
183 void QPieSeries::add(QPieSlice* slice)
187 {
184 {
188 add(QList<QPieSlice*>() << slice);
185 add(QList<QPieSlice*>() << slice);
189 }
186 }
190
187
191 /*!
188 /*!
192 Adds a single \a slice to the series and returns a reference to the series.
189 Adds a single \a slice to the series and returns a reference to the series.
193 Slice ownership is passed to the series.
190 Slice ownership is passed to the series.
194 */
191 */
195 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
192 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
196 {
193 {
197 add(slice);
194 add(slice);
198 return *this;
195 return *this;
199 }
196 }
200
197
201
198
202 /*!
199 /*!
203 Adds a single slice to the series with give \a value and \a name.
200 Adds a single slice to the series with give \a value and \a name.
204 Slice ownership is passed to the series.
201 Slice ownership is passed to the series.
205 */
202 */
206 QPieSlice* QPieSeries::add(qreal value, QString name)
203 QPieSlice* QPieSeries::add(qreal value, QString name)
207 {
204 {
208 QPieSlice* slice = new QPieSlice(value, name);
205 QPieSlice* slice = new QPieSlice(value, name);
209 add(slice);
206 add(slice);
210 return slice;
207 return slice;
211 }
208 }
212
209
213 /*!
210 /*!
214 Removes a single \a slice from the series and deletes the slice.
211 Removes a single \a slice from the series and deletes the slice.
215
212
216 Do not reference this pointer after this call.
213 Do not reference this pointer after this call.
217 */
214 */
218 void QPieSeries::remove(QPieSlice* slice)
215 void QPieSeries::remove(QPieSlice* slice)
219 {
216 {
220 if (!m_slices.removeOne(slice)) {
217 if (!m_slices.removeOne(slice)) {
221 Q_ASSERT(0); // TODO: how should this be reported?
218 Q_ASSERT(0); // TODO: how should this be reported?
222 return;
219 return;
223 }
220 }
224
221
225 ChangeSet changeSet;
222 ChangeSet changeSet;
226 changeSet.appendRemoved(slice);
223 changeSet.appendRemoved(slice);
227 emit changed(changeSet);
224 emit changed(changeSet);
228
225
229 delete slice;
226 delete slice;
230 slice = NULL;
227 slice = NULL;
231
228
232 updateDerivativeData();
229 updateDerivativeData();
233 }
230 }
234
231
235 /*!
232 /*!
236 Clears all slices from the series.
233 Clears all slices from the series.
237 */
234 */
238 void QPieSeries::clear()
235 void QPieSeries::clear()
239 {
236 {
240 if (m_slices.count() == 0)
237 if (m_slices.count() == 0)
241 return;
238 return;
242
239
243 ChangeSet changeSet;
240 ChangeSet changeSet;
244 foreach (QPieSlice* s, m_slices) {
241 foreach (QPieSlice* s, m_slices) {
245 changeSet.appendRemoved(s);
242 changeSet.appendRemoved(s);
246 m_slices.removeOne(s);
243 m_slices.removeOne(s);
247 delete s;
244 delete s;
248 }
245 }
249 emit changed(changeSet);
246 emit changed(changeSet);
250 updateDerivativeData();
247 updateDerivativeData();
251 }
248 }
252
249
253 /*!
250 /*!
254 Counts the number of the slices in this series.
251 Counts the number of the slices in this series.
255 */
252 */
256 int QPieSeries::count() const
253 int QPieSeries::count() const
257 {
254 {
258 return m_slices.count();
255 return m_slices.count();
259 }
256 }
260
257
261 /*!
258 /*!
262 Returns a list of slices that belong to this series.
259 Returns a list of slices that belong to this series.
263 */
260 */
264 QList<QPieSlice*> QPieSeries::slices() const
261 QList<QPieSlice*> QPieSeries::slices() const
265 {
262 {
266 return m_slices;
263 return m_slices;
267 }
264 }
268
265
269 /*!
266 /*!
270 Sets the size \a factor of the pie. 1.0 is the default value.
267 Sets the size \a factor of the pie. 1.0 is the default value.
271 Note that the pie will not grow beyond its absolute maximum size.
268 Note that the pie will not grow beyond its absolute maximum size.
272 In practice its use is to make the pie appear smaller.
269 In practice its use is to make the pie appear smaller.
273 \sa sizeFactor()
270 \sa sizeFactor()
274 */
271 */
275 void QPieSeries::setSizeFactor(qreal factor)
272 void QPieSeries::setSizeFactor(qreal factor)
276 {
273 {
277 if (factor < 0.0)
274 if (factor < 0.0)
278 return;
275 return;
279
276
280 if (m_sizeFactor != factor) {
277 if (m_sizeFactor != factor) {
281 m_sizeFactor = factor;
278 m_sizeFactor = factor;
282 emit sizeFactorChanged();
279 emit sizeFactorChanged();
283 }
280 }
284 }
281 }
285
282
286 /*!
283 /*!
287 Gets the size factor of the pie.
284 Gets the size factor of the pie.
288 \sa setSizeFactor()
285 \sa setSizeFactor()
289 */
286 */
290 qreal QPieSeries::sizeFactor() const
287 qreal QPieSeries::sizeFactor() const
291 {
288 {
292 return m_sizeFactor;
289 return m_sizeFactor;
293 }
290 }
294
291
295 /*!
292 /*!
296 Sets the \a position of the pie within its bounding rectangle.
293 Sets the \a position of the pie within its bounding rectangle.
297 \sa PiePosition, position()
294 \sa PiePosition, position()
298 */
295 */
299 void QPieSeries::setPosition(PiePosition position)
296 void QPieSeries::setPosition(PiePosition position)
300 {
297 {
301 if (m_position != position) {
298 if (m_position != position) {
302 m_position = position;
299 m_position = position;
303 emit positionChanged();
300 emit positionChanged();
304 }
301 }
305 }
302 }
306
303
307 /*!
304 /*!
308 Gets the position of the pie within its bounding rectangle.
305 Gets the position of the pie within its bounding rectangle.
309 \sa PiePosition, setPosition()
306 \sa PiePosition, setPosition()
310 */
307 */
311 QPieSeries::PiePosition QPieSeries::position() const
308 QPieSeries::PiePosition QPieSeries::position() const
312 {
309 {
313 return m_position;
310 return m_position;
314 }
311 }
315
312
316
313
317 /*!
314 /*!
318 Sets the \a startAngle and \a angleSpan of this series.
315 Sets the \a startAngle and \a angleSpan of this series.
319
316
320 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
317 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
321 */
318 */
322 void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
319 void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
323 {
320 {
324 if (startAngle >= 0 && startAngle < 360 &&
321 if (startAngle >= 0 && startAngle < 360 &&
325 angleSpan > 0 && angleSpan <= 360) {
322 angleSpan > 0 && angleSpan <= 360) {
326 m_pieStartAngle = startAngle;
323 m_pieStartAngle = startAngle;
327 m_pieAngleSpan = angleSpan;
324 m_pieAngleSpan = angleSpan;
328 updateDerivativeData();
325 updateDerivativeData();
329 }
326 }
330 }
327 }
331
328
332 /*!
329 /*!
333 Sets the all the slice labels \a visible or invisible.
330 Sets the all the slice labels \a visible or invisible.
334
331
335 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
332 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
336 */
333 */
337 void QPieSeries::setLabelsVisible(bool visible)
334 void QPieSeries::setLabelsVisible(bool visible)
338 {
335 {
339 foreach (QPieSlice* s, m_slices)
336 foreach (QPieSlice* s, m_slices)
340 s->setLabelVisible(visible);
337 s->setLabelVisible(visible);
341 }
338 }
342
339
343 /*!
340 /*!
344 Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to
345 explode slices by clicking.
346
347 \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance()
348 */
349 void QPieSeries::setClickExplodes(bool enable)
350 {
351 if (enable)
352 connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*)));
353 else
354 disconnect(this, SLOT(toggleExploded(QPieSlice*)));
355 }
356
357 /*!
358 Convenience method for highlighting a slice when user hovers over the slice.
359 It changes the slice color to be lighter and shows the label of the slice.
360 Set \a enable to true to highlight a slice when user hovers on top of it.
361 */
362 void QPieSeries::setHoverHighlighting(bool enable)
363 {
364 if (enable) {
365 connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*)));
366 connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*)));
367 } else {
368 disconnect(this, SLOT(hoverEnter(QPieSlice*)));
369 disconnect(this, SLOT(hoverLeave(QPieSlice*)));
370 }
371 }
372
373 /*!
374 Returns the sum of all slice values in this series.
341 Returns the sum of all slice values in this series.
375
342
376 \sa QPieSlice::value(), QPieSlice::setValue()
343 \sa QPieSlice::value(), QPieSlice::setValue()
377 */
344 */
378 qreal QPieSeries::total() const
345 qreal QPieSeries::total() const
379 {
346 {
380 return m_total;
347 return m_total;
381 }
348 }
382
349
383 /*!
350 /*!
384 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
351 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
385
352
386 This signal emitted when something has changed in the series.
353 This signal emitted when something has changed in the series.
387 The \a changeSet contains the details of which slices have been added, changed or removed.
354 The \a changeSet contains the details of which slices have been added, changed or removed.
388
355
389 \sa QPieSeries::ChangeSet, QPieSlice::changed()
356 \sa QPieSeries::ChangeSet, QPieSlice::changed()
390 */
357 */
391
358
392 /*!
359 /*!
393 \fn void QPieSeries::clicked(QPieSlice* slice)
360 \fn void QPieSeries::clicked(QPieSlice* slice)
394
361
395 This signal is emitted when a \a slice has been clicked.
362 This signal is emitted when a \a slice has been clicked.
396
363
397 \sa QPieSlice::clicked()
364 \sa QPieSlice::clicked()
398 */
365 */
399
366
400 /*!
367 /*!
401 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
368 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
402
369
403 This signal is emitted when user has hovered over a \a slice.
370 This signal is emitted when user has hovered over a \a slice.
404
371
405 \sa QPieSlice::hoverEnter()
372 \sa QPieSlice::hoverEnter()
406 */
373 */
407
374
408 /*!
375 /*!
409 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
376 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
410
377
411 This signal is emitted when user has hovered away from a \a slice.
378 This signal is emitted when user has hovered away from a \a slice.
412
379
413 \sa QPieSlice::hoverLeave()
380 \sa QPieSlice::hoverLeave()
414 */
381 */
415
382
416 /*!
383 /*!
417 \fn void QPieSeries::sizeFactorChanged()
384 \fn void QPieSeries::sizeFactorChanged()
418
385
419 This signal is emitted when size factor has been changed.
386 This signal is emitted when size factor has been changed.
420
387
421 \sa sizeFactor(), setSizeFactor()
388 \sa sizeFactor(), setSizeFactor()
422 */
389 */
423
390
424 /*!
391 /*!
425 \fn void QPieSeries::positionChanged()
392 \fn void QPieSeries::positionChanged()
426
393
427 This signal is emitted when position of the pie has been changed.
394 This signal is emitted when position of the pie has been changed.
428
395
429 \sa position(), setPosition()
396 \sa position(), setPosition()
430 */
397 */
431
398
432 void QPieSeries::sliceChanged()
399 void QPieSeries::sliceChanged()
433 {
400 {
434 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
401 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
435 Q_ASSERT(m_slices.contains(slice));
402 Q_ASSERT(m_slices.contains(slice));
436
403
437 ChangeSet changeSet;
404 ChangeSet changeSet;
438 changeSet.appendChanged(slice);
405 changeSet.appendChanged(slice);
439 emit changed(changeSet);
406 emit changed(changeSet);
440
407
441 updateDerivativeData();
408 updateDerivativeData();
442 }
409 }
443
410
444 void QPieSeries::sliceClicked()
411 void QPieSeries::sliceClicked()
445 {
412 {
446 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
413 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
447 Q_ASSERT(m_slices.contains(slice));
414 Q_ASSERT(m_slices.contains(slice));
448 emit clicked(slice);
415 emit clicked(slice);
449 }
416 }
450
417
451 void QPieSeries::sliceHoverEnter()
418 void QPieSeries::sliceHoverEnter()
452 {
419 {
453 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
420 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
454 Q_ASSERT(m_slices.contains(slice));
421 Q_ASSERT(m_slices.contains(slice));
455 emit hoverEnter(slice);
422 emit hoverEnter(slice);
456 }
423 }
457
424
458 void QPieSeries::sliceHoverLeave()
425 void QPieSeries::sliceHoverLeave()
459 {
426 {
460 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
427 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
461 Q_ASSERT(m_slices.contains(slice));
428 Q_ASSERT(m_slices.contains(slice));
462 emit hoverLeave(slice);
429 emit hoverLeave(slice);
463 }
430 }
464
431
465 void QPieSeries::toggleExploded(QPieSlice* slice)
466 {
467 Q_ASSERT(slice);
468 slice->setExploded(!slice->isExploded());
469 }
470
471 void QPieSeries::highlightOn(QPieSlice* slice)
472 {
473 Q_ASSERT(slice);
474 QColor c = slice->brush().color().lighter();
475 slice->setBrush(c);
476 }
477
478 void QPieSeries::highlightOff(QPieSlice* slice)
479 {
480 Q_ASSERT(slice);
481 QColor c = slice->brush().color().darker(150);
482 slice->setBrush(c);
483 }
484
485 void QPieSeries::updateDerivativeData()
432 void QPieSeries::updateDerivativeData()
486 {
433 {
487 m_total = 0;
434 m_total = 0;
488
435
489 // nothing to do?
436 // nothing to do?
490 if (m_slices.count() == 0)
437 if (m_slices.count() == 0)
491 return;
438 return;
492
439
493 // calculate total
440 // calculate total
494 foreach (QPieSlice* s, m_slices)
441 foreach (QPieSlice* s, m_slices)
495 m_total += s->value();
442 m_total += s->value();
496
443
497 // we must have some values
444 // we must have some values
498 if (m_total == 0) {
445 if (m_total == 0) {
499 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
446 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
500 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
447 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
501 }
448 }
502
449
503 // update slice attributes
450 // update slice attributes
504 qreal sliceAngle = m_pieStartAngle;
451 qreal sliceAngle = m_pieStartAngle;
505 foreach (QPieSlice* s, m_slices) {
452 foreach (QPieSlice* s, m_slices) {
506
453
507 bool changed = false;
454 bool changed = false;
508
455
509 qreal percentage = s->value() / m_total;
456 qreal percentage = s->value() / m_total;
510 if (s->m_percentage != percentage) {
457 if (s->m_percentage != percentage) {
511 s->m_percentage = percentage;
458 s->m_percentage = percentage;
512 changed = true;
459 changed = true;
513 }
460 }
514
461
515 qreal sliceSpan = m_pieAngleSpan * percentage;
462 qreal sliceSpan = m_pieAngleSpan * percentage;
516 if (s->m_angleSpan != sliceSpan) {
463 if (s->m_angleSpan != sliceSpan) {
517 s->m_angleSpan = sliceSpan;
464 s->m_angleSpan = sliceSpan;
518 changed = true;
465 changed = true;
519 }
466 }
520
467
521 if (s->m_startAngle != sliceAngle) {
468 if (s->m_startAngle != sliceAngle) {
522 s->m_startAngle = sliceAngle;
469 s->m_startAngle = sliceAngle;
523 changed = true;
470 changed = true;
524 }
471 }
525 sliceAngle += sliceSpan;
472 sliceAngle += sliceSpan;
526
473
527 if (changed)
474 if (changed)
528 emit s->changed();
475 emit s->changed();
529 }
476 }
530 }
477 }
531
478
532 #include "moc_qpieseries.cpp"
479 #include "moc_qpieseries.cpp"
533
480
534 QTCOMMERCIALCHART_END_NAMESPACE
481 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,132 +1,127
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qseries.h"
4 #include "qseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8 #include <QPen>
8 #include <QPen>
9 #include <QBrush>
9 #include <QBrush>
10 #include <QSignalMapper>
10 #include <QSignalMapper>
11
11
12 class QGraphicsObject;
12 class QGraphicsObject;
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 class PiePresenter;
14 class PiePresenter;
15 class PieSlice;
15 class PieSlice;
16 class QPieSlice;
16 class QPieSlice;
17
17
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
19 {
19 {
20 Q_OBJECT
20 Q_OBJECT
21
21
22 public:
22 public:
23 enum PiePosition {
23 enum PiePosition {
24 PiePositionMaximized = 0,
24 PiePositionMaximized = 0,
25 PiePositionTopLeft,
25 PiePositionTopLeft,
26 PiePositionTopRight,
26 PiePositionTopRight,
27 PiePositionBottomLeft,
27 PiePositionBottomLeft,
28 PiePositionBottomRight
28 PiePositionBottomRight
29 };
29 };
30
30
31 class ChangeSet
31 class ChangeSet
32 {
32 {
33 public:
33 public:
34
34
35 // TODO: these should not really be exposed to the public API
35 // TODO: these should not really be exposed to the public API
36 void appendAdded(QPieSlice* slice);
36 void appendAdded(QPieSlice* slice);
37 void appendAdded(QList<QPieSlice*> slices);
37 void appendAdded(QList<QPieSlice*> slices);
38 void appendChanged(QPieSlice* slice);
38 void appendChanged(QPieSlice* slice);
39 void appendRemoved(QPieSlice* slice);
39 void appendRemoved(QPieSlice* slice);
40
40
41 QList<QPieSlice*> added() const;
41 QList<QPieSlice*> added() const;
42 QList<QPieSlice*> changed() const;
42 QList<QPieSlice*> changed() const;
43 QList<QPieSlice*> removed() const;
43 QList<QPieSlice*> removed() const;
44
44
45 bool isEmpty() const;
45 bool isEmpty() const;
46
46
47 private:
47 private:
48 QList<QPieSlice*> m_added;
48 QList<QPieSlice*> m_added;
49 QList<QPieSlice*> m_changed;
49 QList<QPieSlice*> m_changed;
50 QList<QPieSlice*> m_removed;
50 QList<QPieSlice*> m_removed;
51 };
51 };
52
52
53 public:
53 public:
54 QPieSeries(QObject *parent = 0);
54 QPieSeries(QObject *parent = 0);
55 virtual ~QPieSeries();
55 virtual ~QPieSeries();
56
56
57 public: // from QChartSeries
57 public: // from QChartSeries
58 QSeriesType type() const;
58 QSeriesType type() const;
59
59
60 public:
60 public:
61 void replace(QList<QPieSlice*> slices);
61 void replace(QList<QPieSlice*> slices);
62 void add(QList<QPieSlice*> slices);
62 void add(QList<QPieSlice*> slices);
63 void add(QPieSlice* slice);
63 void add(QPieSlice* slice);
64 QPieSlice* add(qreal value, QString name);
64 QPieSlice* add(qreal value, QString name);
65 QPieSeries& operator << (QPieSlice* slice);
65 QPieSeries& operator << (QPieSlice* slice);
66 void remove(QPieSlice* slice);
66 void remove(QPieSlice* slice);
67 void clear();
67 void clear();
68
68
69 int count() const;
69 int count() const;
70 QList<QPieSlice*> slices() const;
70 QList<QPieSlice*> slices() const;
71
71
72 void setSizeFactor(qreal sizeFactor);
72 void setSizeFactor(qreal sizeFactor);
73 qreal sizeFactor() const;
73 qreal sizeFactor() const;
74 void setPosition(PiePosition position);
74 void setPosition(PiePosition position);
75 PiePosition position() const;
75 PiePosition position() const;
76 void setSpan(qreal startAngle, qreal angleSpan);
76 void setSpan(qreal startAngle, qreal angleSpan);
77
77
78 void setLabelsVisible(bool visible = true);
78 void setLabelsVisible(bool visible = true);
79 void setClickExplodes(bool enable = true);
80 void setHoverHighlighting(bool enable = true);
81
79
82 qreal total() const;
80 qreal total() const;
83
81
84 // TODO: find slices?
82 // TODO: find slices?
85 // QList<QPieSlice*> findByValue(qreal value);
83 // QList<QPieSlice*> findByValue(qreal value);
86 // ...
84 // ...
87
85
88 // TODO: sorting slices?
86 // TODO: sorting slices?
89 // void sort(QPieSeries::SortByValue|label|??)
87 // void sort(QPieSeries::SortByValue|label|??)
90
88
91 // TODO: general graphics customization
89 // TODO: general graphics customization
92 // setDrawStyle(2d|3d)
90 // setDrawStyle(2d|3d)
93 // setDropShadows(bool)
91 // setDropShadows(bool)
94
92
95 Q_SIGNALS:
93 Q_SIGNALS:
96 void changed(const QPieSeries::ChangeSet& changeSet);
94 void changed(const QPieSeries::ChangeSet& changeSet);
97 void clicked(QPieSlice* slice);
95 void clicked(QPieSlice* slice);
98 void hoverEnter(QPieSlice* slice);
96 void hoverEnter(QPieSlice* slice);
99 void hoverLeave(QPieSlice* slice);
97 void hoverLeave(QPieSlice* slice);
100 void sizeFactorChanged();
98 void sizeFactorChanged();
101 void positionChanged();
99 void positionChanged();
102
100
103 private Q_SLOTS: // TODO: should be private and not visible in the interface at all
101 private Q_SLOTS: // TODO: should be private and not visible in the interface at all
104 void sliceChanged();
102 void sliceChanged();
105 void sliceClicked();
103 void sliceClicked();
106 void sliceHoverEnter();
104 void sliceHoverEnter();
107 void sliceHoverLeave();
105 void sliceHoverLeave();
108 void toggleExploded(QPieSlice* slice);
109 void highlightOn(QPieSlice* slice);
110 void highlightOff(QPieSlice* slice);
111
106
112 private:
107 private:
113 void updateDerivativeData();
108 void updateDerivativeData();
114
109
115 private:
110 private:
116 Q_DISABLE_COPY(QPieSeries)
111 Q_DISABLE_COPY(QPieSeries)
117
112
118 // TODO: use PIML
113 // TODO: use PIML
119 friend class PiePresenter;
114 friend class PiePresenter;
120 friend class PieSlice;
115 friend class PieSlice;
121
116
122 QList<QPieSlice*> m_slices;
117 QList<QPieSlice*> m_slices;
123 qreal m_sizeFactor;
118 qreal m_sizeFactor;
124 PiePosition m_position;
119 PiePosition m_position;
125 qreal m_total;
120 qreal m_total;
126 qreal m_pieStartAngle;
121 qreal m_pieStartAngle;
127 qreal m_pieAngleSpan;
122 qreal m_pieAngleSpan;
128 };
123 };
129
124
130 QTCOMMERCIALCHART_END_NAMESPACE
125 QTCOMMERCIALCHART_END_NAMESPACE
131
126
132 #endif // PIESERIES_H
127 #endif // PIESERIES_H
@@ -1,376 +1,376
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::replace(), QPieSeries::add()
38 \sa QPieSeries::replace(), 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_startAngle(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::replace(), QPieSeries::add()
60 \sa QPieSeries::replace(), 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_startAngle(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 The returned value ranges from 0 to 1.0.
138 The returned value ranges from 0 to 1.0.
139
139
140 Updated internally after the slice is added to the series.
140 Updated internally after the slice is added to the series.
141 */
141 */
142 qreal QPieSlice::percentage() const
142 qreal QPieSlice::percentage() const
143 {
143 {
144 return m_percentage;
144 return m_percentage;
145 }
145 }
146
146
147 /*!
147 /*!
148 Returns the starting angle of this slice in the series it belongs to.
148 Returns the starting angle of this slice in the series it belongs to.
149
149
150 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
150 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
151
151
152 Updated internally after the slice is added to the series.
152 Updated internally after the slice is added to the series.
153 */
153 */
154 qreal QPieSlice::startAngle() const
154 qreal QPieSlice::startAngle() const
155 {
155 {
156 return m_startAngle;
156 return m_startAngle;
157 }
157 }
158
158
159 /*!
159 /*!
160 Returns the end angle of this slice in the series it belongs to.
160 Returns the end angle of this slice in the series it belongs to.
161
161
162 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
162 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
163
163
164 Updated internally after the slice is added to the series.
164 Updated internally after the slice is added to the series.
165 */
165 */
166 qreal QPieSlice::endAngle() const
166 qreal QPieSlice::endAngle() const
167 {
167 {
168 return m_startAngle + m_angleSpan;
168 return m_startAngle + m_angleSpan;
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns the pen used to draw this slice.
172 Returns the pen used to draw this slice.
173 \sa setPen()
173 \sa setPen()
174 */
174 */
175 QPen QPieSlice::pen() const
175 QPen QPieSlice::pen() const
176 {
176 {
177 return m_pen;
177 return m_pen;
178 }
178 }
179
179
180 /*!
180 /*!
181 Returns the brush used to draw this slice.
181 Returns the brush used to draw this slice.
182 \sa setBrush()
182 \sa setBrush()
183 */
183 */
184 QBrush QPieSlice::brush() const
184 QBrush QPieSlice::brush() const
185 {
185 {
186 return m_brush;
186 return m_brush;
187 }
187 }
188
188
189 /*!
189 /*!
190 Returns the pen used to draw label in this slice.
190 Returns the pen used to draw label in this slice.
191 \sa setLabelPen()
191 \sa setLabelPen()
192 */
192 */
193 QPen QPieSlice::labelPen() const
193 QPen QPieSlice::labelPen() const
194 {
194 {
195 return m_labelPen;
195 return m_labelPen;
196 }
196 }
197
197
198 /*!
198 /*!
199 Returns the font used to draw label in this slice.
199 Returns the font used to draw label in this slice.
200 \sa setLabelFont()
200 \sa setLabelFont()
201 */
201 */
202 QFont QPieSlice::labelFont() const
202 QFont QPieSlice::labelFont() const
203 {
203 {
204 return m_labelFont;
204 return m_labelFont;
205 }
205 }
206
206
207 /*!
207 /*!
208 Returns the label arm lenght used in this slice.
208 Returns the label arm lenght used in this slice.
209 Default value is 40 pixels.
209 Default value is 40 pixels.
210 \sa setLabelArmLength()
210 \sa setLabelArmLength()
211 */
211 */
212 qreal QPieSlice::labelArmLength() const
212 qreal QPieSlice::labelArmLength() const
213 {
213 {
214 return m_labelArmLength;
214 return m_labelArmLength;
215 }
215 }
216
216
217 /*!
217 /*!
218 \fn void QPieSlice::clicked()
218 \fn void QPieSlice::clicked()
219
219
220 This signal is emitted when user has clicked the slice.
220 This signal is emitted when user has clicked the slice.
221
221
222 \sa QPieSeries::clicked()
222 \sa QPieSeries::clicked()
223 */
223 */
224
224
225 /*!
225 /*!
226 \fn void QPieSlice::hoverEnter()
226 \fn void QPieSlice::hoverEnter()
227
227
228 This signal is emitted when user has hovered over the slice.
228 This signal is emitted when user has hovered over the slice.
229
229
230 \sa QPieSeries::hoverEnter()
230 \sa QPieSeries::hoverEnter()
231 */
231 */
232
232
233 /*!
233 /*!
234 \fn void QPieSlice::hoverLeave()
234 \fn void QPieSlice::hoverLeave()
235
235
236 This signal is emitted when user has hovered away from the slice.
236 This signal is emitted when user has hovered away from the slice.
237
237
238 \sa QPieSeries::hoverLeave()
238 \sa QPieSeries::hoverLeave()
239 */
239 */
240
240
241 /*!
241 /*!
242 \fn void QPieSlice::changed()
242 \fn void QPieSlice::changed()
243
243
244 This signal emitted when something has changed in the slice.
244 This signal emitted when something has changed in the slice.
245
245
246 \sa QPieSeries::changed()
246 \sa QPieSeries::changed()
247 */
247 */
248
248
249 /*!
249 /*!
250 Sets the value of this slice.
250 Sets the value of this slice.
251 \sa value()
251 \sa value()
252 */
252 */
253 void QPieSlice::setValue(qreal value)
253 void QPieSlice::setValue(qreal value)
254 {
254 {
255 if (m_value != value) {
255 if (m_value != value) {
256 m_value = value;
256 m_value = value;
257 emit changed();
257 emit changed();
258 }
258 }
259 }
259 }
260
260
261 /*!
261 /*!
262 Sets the \a label of the slice.
262 Sets the \a label of the slice.
263 \sa label()
263 \sa label()
264 */
264 */
265 void QPieSlice::setLabel(QString label)
265 void QPieSlice::setLabel(QString label)
266 {
266 {
267 if (m_label != label) {
267 if (m_label != label) {
268 m_label = label;
268 m_label = label;
269 emit changed();
269 emit changed();
270 }
270 }
271 }
271 }
272
272
273 /*!
273 /*!
274 Sets the label \a visible in this slice.
274 Sets the label \a visible in this slice.
275 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
275 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
276 */
276 */
277 void QPieSlice::setLabelVisible(bool visible)
277 void QPieSlice::setLabelVisible(bool visible)
278 {
278 {
279 if (m_isLabelVisible != visible) {
279 if (m_isLabelVisible != visible) {
280 m_isLabelVisible = visible;
280 m_isLabelVisible = visible;
281 emit changed();
281 emit changed();
282 }
282 }
283 }
283 }
284
284
285 /*!
285 /*!
286 Sets this slice \a exploded.
286 Sets this slice \a exploded.
287 \sa isExploded(), setExplodeDistance(), QPieSeries::setClickExplodes()
287 \sa isExploded(), setExplodeDistance()
288 */
288 */
289 void QPieSlice::setExploded(bool exploded)
289 void QPieSlice::setExploded(bool exploded)
290 {
290 {
291 if (m_isExploded != exploded) {
291 if (m_isExploded != exploded) {
292 m_isExploded = exploded;
292 m_isExploded = exploded;
293 emit changed();
293 emit changed();
294 }
294 }
295 }
295 }
296
296
297 /*!
297 /*!
298 Sets the explosion \a distance of this slice.
298 Sets the explosion \a distance of this slice.
299 It is the distance the slice is moved away from the pie center.
299 It is the distance the slice is moved away from the pie center.
300 \sa explodeDistance(), isExploded(), QPieSeries::setClickExplodes()
300 \sa explodeDistance(), isExploded()
301 */
301 */
302 void QPieSlice::setExplodeDistance(qreal distance)
302 void QPieSlice::setExplodeDistance(qreal distance)
303 {
303 {
304 if (m_explodeDistance != distance) {
304 if (m_explodeDistance != distance) {
305 m_explodeDistance = distance;
305 m_explodeDistance = distance;
306 emit changed();
306 emit changed();
307 }
307 }
308 }
308 }
309
309
310 /*!
310 /*!
311 Sets the \a pen used to draw this slice.
311 Sets the \a pen used to draw this slice.
312 Note that applying a theme will override this.
312 Note that applying a theme will override this.
313 \sa pen()
313 \sa pen()
314 */
314 */
315 void QPieSlice::setPen(QPen pen)
315 void QPieSlice::setPen(QPen pen)
316 {
316 {
317 if (m_pen != pen) {
317 if (m_pen != pen) {
318 m_pen = pen;
318 m_pen = pen;
319 emit changed();
319 emit changed();
320 }
320 }
321 }
321 }
322
322
323 /*!
323 /*!
324 Sets the \a brush used to draw this slice.
324 Sets the \a brush used to draw this slice.
325 Note that applying a theme will override this.
325 Note that applying a theme will override this.
326 \sa brush()
326 \sa brush()
327 */
327 */
328 void QPieSlice::setBrush(QBrush brush)
328 void QPieSlice::setBrush(QBrush brush)
329 {
329 {
330 if (m_brush != brush) {
330 if (m_brush != brush) {
331 m_brush = brush;
331 m_brush = brush;
332 emit changed();
332 emit changed();
333 }
333 }
334 }
334 }
335
335
336 /*!
336 /*!
337 Sets the \a pen used to draw the label in this slice.
337 Sets the \a pen used to draw the label in this slice.
338 Note that applying a theme will override this.
338 Note that applying a theme will override this.
339 \sa labelPen()
339 \sa labelPen()
340 */
340 */
341 void QPieSlice::setLabelPen(QPen pen)
341 void QPieSlice::setLabelPen(QPen pen)
342 {
342 {
343 if (m_labelPen != pen) {
343 if (m_labelPen != pen) {
344 m_labelPen = pen;
344 m_labelPen = pen;
345 emit changed();
345 emit changed();
346 }
346 }
347 }
347 }
348
348
349 /*!
349 /*!
350 Sets the \a font used to draw the label in this slice.
350 Sets the \a font used to draw the label in this slice.
351 Note that applying a theme will override this.
351 Note that applying a theme will override this.
352 \sa labelFont()
352 \sa labelFont()
353 */
353 */
354 void QPieSlice::setLabelFont(QFont font)
354 void QPieSlice::setLabelFont(QFont font)
355 {
355 {
356 if (m_labelFont != font) {
356 if (m_labelFont != font) {
357 m_labelFont = font;
357 m_labelFont = font;
358 emit changed();
358 emit changed();
359 }
359 }
360 }
360 }
361
361
362 /*!
362 /*!
363 Sets the label arm \a length used to draw the label in this slice.
363 Sets the label arm \a length used to draw the label in this slice.
364 \sa labelArmLength()
364 \sa labelArmLength()
365 */
365 */
366 void QPieSlice::setLabelArmLength(qreal length)
366 void QPieSlice::setLabelArmLength(qreal length)
367 {
367 {
368 if (m_labelArmLength != length) {
368 if (m_labelArmLength != length) {
369 m_labelArmLength = length;
369 m_labelArmLength = length;
370 emit changed();
370 emit changed();
371 }
371 }
372 }
372 }
373
373
374 #include "moc_qpieslice.cpp"
374 #include "moc_qpieslice.cpp"
375
375
376 QTCOMMERCIALCHART_END_NAMESPACE
376 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now