@@ -1,77 +1,77 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "drilldownchart.h" |
|
21 | #include "drilldownchart.h" | |
22 | #include "drilldownslice.h" |
|
22 | #include "drilldownslice.h" | |
23 | #include <QtGui/QApplication> |
|
23 | #include <QtGui/QApplication> | |
24 | #include <QMainWindow> |
|
24 | #include <QMainWindow> | |
25 | #include <QTime> |
|
25 | #include <QTime> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QLegend> |
|
27 | #include <QLegend> | |
28 | #include <QPieSeries> |
|
28 | #include <QPieSeries> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | int main(int argc, char *argv[]) |
|
32 | int main(int argc, char *argv[]) | |
33 | { |
|
33 | { | |
34 | QApplication a(argc, argv); |
|
34 | QApplication a(argc, argv); | |
35 |
|
35 | |||
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
37 |
|
37 | |||
38 | QMainWindow window; |
|
38 | QMainWindow window; | |
39 |
|
39 | |||
40 | DrilldownChart* chart = new DrilldownChart(); |
|
40 | DrilldownChart* chart = new DrilldownChart(); | |
41 | chart->setTheme(QChart::ChartThemeLight); |
|
41 | chart->setTheme(QChart::ChartThemeLight); | |
42 | chart->setAnimationOptions(QChart::AllAnimations); |
|
42 | chart->setAnimationOptions(QChart::AllAnimations); | |
43 | chart->legend()->setVisible(true); |
|
43 | chart->legend()->setVisible(true); | |
44 | chart->legend()->setAlignment(QLegend::AlignmentRight); |
|
44 | chart->legend()->setAlignment(QLegend::AlignmentRight); | |
45 |
|
45 | |||
46 | QPieSeries* yearSeries = new QPieSeries(&window); |
|
46 | QPieSeries* yearSeries = new QPieSeries(&window); | |
47 | yearSeries->setName("Sales by year - All"); |
|
47 | yearSeries->setName("Sales by year - All"); | |
48 |
|
48 | |||
49 | QList<QString> months; |
|
49 | QList<QString> months; | |
50 | months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
50 | months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
51 | QList<QString> names; |
|
51 | QList<QString> names; | |
52 | names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob"; |
|
52 | names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob"; | |
53 |
|
53 | |||
54 | foreach (QString name, names) { |
|
54 | foreach (QString name, names) { | |
55 | QPieSeries* series = new QPieSeries(&window); |
|
55 | QPieSeries* series = new QPieSeries(&window); | |
56 | series->setName("Sales by month - " + name); |
|
56 | series->setName("Sales by month - " + name); | |
57 |
|
57 | |||
58 | foreach (QString month, months) |
|
58 | foreach (QString month, months) | |
59 | *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); |
|
59 | *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); | |
60 |
|
60 | |||
61 | QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); |
|
61 | QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); | |
62 |
|
62 | |||
63 |
*yearSeries << new DrilldownSlice(series-> |
|
63 | *yearSeries << new DrilldownSlice(series->sum(), name, series); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); |
|
66 | QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); | |
67 |
|
67 | |||
68 | chart->changeSeries(yearSeries); |
|
68 | chart->changeSeries(yearSeries); | |
69 |
|
69 | |||
70 | QChartView* chartView = new QChartView(chart); |
|
70 | QChartView* chartView = new QChartView(chart); | |
71 | chartView->setRenderHint(QPainter::Antialiasing); |
|
71 | chartView->setRenderHint(QPainter::Antialiasing); | |
72 | window.setCentralWidget(chartView); |
|
72 | window.setCentralWidget(chartView); | |
73 | window.resize(800, 500); |
|
73 | window.resize(800, 500); | |
74 | window.show(); |
|
74 | window.show(); | |
75 |
|
75 | |||
76 | return a.exec(); |
|
76 | return a.exec(); | |
77 | } |
|
77 | } |
@@ -1,701 +1,701 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "pieslicedata_p.h" |
|
24 | #include "pieslicedata_p.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QPieSeries |
|
31 | \class QPieSeries | |
32 | \brief Pie series API for QtCommercial Charts |
|
32 | \brief Pie series API for QtCommercial Charts | |
33 |
|
33 | |||
34 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
34 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
35 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
35 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
36 | The actual slice size is determined by that relative value. |
|
36 | The actual slice size is determined by that relative value. | |
37 |
|
37 | |||
38 | By default the pie is defined as a full pie but it can be a partial pie. |
|
38 | By default the pie is defined as a full pie but it can be a partial pie. | |
39 | This can be done by setting a starting angle and angle span to the series. |
|
39 | This can be done by setting a starting angle and angle span to the series. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \property QPieSeries::horizontalPosition |
|
43 | \property QPieSeries::horizontalPosition | |
44 | \brief Defines the horizontal position of the pie. |
|
44 | \brief Defines the horizontal position of the pie. | |
45 |
|
45 | |||
46 | The value is a relative value to the chart rectangle where: |
|
46 | The value is a relative value to the chart rectangle where: | |
47 |
|
47 | |||
48 | \list |
|
48 | \list | |
49 | \o 0.0 is the absolute left. |
|
49 | \o 0.0 is the absolute left. | |
50 | \o 1.0 is the absolute right. |
|
50 | \o 1.0 is the absolute right. | |
51 | \endlist |
|
51 | \endlist | |
52 |
|
52 | |||
53 | Default value is 0.5 (center). |
|
53 | Default value is 0.5 (center). | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \property QPieSeries::verticalPosition |
|
57 | \property QPieSeries::verticalPosition | |
58 | \brief Defines the vertical position of the pie. |
|
58 | \brief Defines the vertical position of the pie. | |
59 |
|
59 | |||
60 | The value is a relative value to the chart rectangle where: |
|
60 | The value is a relative value to the chart rectangle where: | |
61 |
|
61 | |||
62 | \list |
|
62 | \list | |
63 | \o 0.0 is the absolute top. |
|
63 | \o 0.0 is the absolute top. | |
64 | \o 1.0 is the absolute bottom. |
|
64 | \o 1.0 is the absolute bottom. | |
65 | \endlist |
|
65 | \endlist | |
66 |
|
66 | |||
67 | Default value is 0.5 (center). |
|
67 | Default value is 0.5 (center). | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \property QPieSeries::size |
|
71 | \property QPieSeries::size | |
72 | \brief Defines the pie size. |
|
72 | \brief Defines the pie size. | |
73 |
|
73 | |||
74 | The value is a relative value to the chart rectangle where: |
|
74 | The value is a relative value to the chart rectangle where: | |
75 |
|
75 | |||
76 | \list |
|
76 | \list | |
77 | \o 0.0 is the minumum size (pie not drawn). |
|
77 | \o 0.0 is the minumum size (pie not drawn). | |
78 | \o 1.0 is the maximum size that can fit the chart. |
|
78 | \o 1.0 is the maximum size that can fit the chart. | |
79 | \endlist |
|
79 | \endlist | |
80 |
|
80 | |||
81 | Default value is 0.7. |
|
81 | Default value is 0.7. | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \property QPieSeries::startAngle |
|
85 | \property QPieSeries::startAngle | |
86 | \brief Defines the starting angle of the pie. |
|
86 | \brief Defines the starting angle of the pie. | |
87 |
|
87 | |||
88 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
88 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
89 |
|
89 | |||
90 | Default is value is 0. |
|
90 | Default is value is 0. | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QPieSeries::endAngle |
|
94 | \property QPieSeries::endAngle | |
95 | \brief Defines the ending angle of the pie. |
|
95 | \brief Defines the ending angle of the pie. | |
96 |
|
96 | |||
97 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
97 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
98 |
|
98 | |||
99 | Default is value is 360. |
|
99 | Default is value is 360. | |
100 | */ |
|
100 | */ | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | Constructs a series object which is a child of \a parent. |
|
104 | Constructs a series object which is a child of \a parent. | |
105 | */ |
|
105 | */ | |
106 | QPieSeries::QPieSeries(QObject *parent) : |
|
106 | QPieSeries::QPieSeries(QObject *parent) : | |
107 | QSeries(*new QPieSeriesPrivate(this),parent) |
|
107 | QSeries(*new QPieSeriesPrivate(this),parent) | |
108 | { |
|
108 | { | |
109 |
|
109 | |||
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Destroys the series and its slices. |
|
113 | Destroys the series and its slices. | |
114 | */ |
|
114 | */ | |
115 | QPieSeries::~QPieSeries() |
|
115 | QPieSeries::~QPieSeries() | |
116 | { |
|
116 | { | |
117 | // NOTE: d_prt destroyed by QObject |
|
117 | // NOTE: d_prt destroyed by QObject | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Returns QChartSeries::SeriesTypePie. |
|
121 | Returns QChartSeries::SeriesTypePie. | |
122 | */ |
|
122 | */ | |
123 | QSeries::QSeriesType QPieSeries::type() const |
|
123 | QSeries::QSeriesType QPieSeries::type() const | |
124 | { |
|
124 | { | |
125 | return QSeries::SeriesTypePie; |
|
125 | return QSeries::SeriesTypePie; | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Sets an array of \a slices to the series replacing the existing slices. |
|
129 | Sets an array of \a slices to the series replacing the existing slices. | |
130 | Slice ownership is passed to the series. |
|
130 | Slice ownership is passed to the series. | |
131 | */ |
|
131 | */ | |
132 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
132 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
133 | { |
|
133 | { | |
134 | clear(); |
|
134 | clear(); | |
135 | append(slices); |
|
135 | append(slices); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Appends an array of \a slices to the series. |
|
139 | Appends an array of \a slices to the series. | |
140 | Slice ownership is passed to the series. |
|
140 | Slice ownership is passed to the series. | |
141 | */ |
|
141 | */ | |
142 | void QPieSeries::append(QList<QPieSlice*> slices) |
|
142 | void QPieSeries::append(QList<QPieSlice*> slices) | |
143 | { |
|
143 | { | |
144 | Q_D(QPieSeries); |
|
144 | Q_D(QPieSeries); | |
145 |
|
145 | |||
146 | foreach (QPieSlice* s, slices) { |
|
146 | foreach (QPieSlice* s, slices) { | |
147 | s->setParent(this); |
|
147 | s->setParent(this); | |
148 | d->m_slices << s; |
|
148 | d->m_slices << s; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | d->updateDerivativeData(); |
|
151 | d->updateDerivativeData(); | |
152 |
|
152 | |||
153 | foreach (QPieSlice* s, slices) { |
|
153 | foreach (QPieSlice* s, slices) { | |
154 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
154 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
155 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
155 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
156 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
156 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
157 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
157 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | emit added(slices); |
|
160 | emit added(slices); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | Appends a single \a slice to the series. |
|
164 | Appends a single \a slice to the series. | |
165 | Slice ownership is passed to the series. |
|
165 | Slice ownership is passed to the series. | |
166 | */ |
|
166 | */ | |
167 | void QPieSeries::append(QPieSlice* slice) |
|
167 | void QPieSeries::append(QPieSlice* slice) | |
168 | { |
|
168 | { | |
169 | append(QList<QPieSlice*>() << slice); |
|
169 | append(QList<QPieSlice*>() << slice); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Appends a single \a slice to the series and returns a reference to the series. |
|
173 | Appends a single \a slice to the series and returns a reference to the series. | |
174 | Slice ownership is passed to the series. |
|
174 | Slice ownership is passed to the series. | |
175 | */ |
|
175 | */ | |
176 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
176 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
177 | { |
|
177 | { | |
178 | append(slice); |
|
178 | append(slice); | |
179 | return *this; |
|
179 | return *this; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | Appends a single slice to the series with give \a value and \a name. |
|
184 | Appends a single slice to the series with give \a value and \a name. | |
185 | Slice ownership is passed to the series. |
|
185 | Slice ownership is passed to the series. | |
186 | */ |
|
186 | */ | |
187 | QPieSlice* QPieSeries::append(qreal value, QString name) |
|
187 | QPieSlice* QPieSeries::append(qreal value, QString name) | |
188 | { |
|
188 | { | |
189 | QPieSlice* slice = new QPieSlice(value, name); |
|
189 | QPieSlice* slice = new QPieSlice(value, name); | |
190 | append(slice); |
|
190 | append(slice); | |
191 | return slice; |
|
191 | return slice; | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Inserts a single \a slice to the series before the slice at \a index position. |
|
195 | Inserts a single \a slice to the series before the slice at \a index position. | |
196 | Slice ownership is passed to the series. |
|
196 | Slice ownership is passed to the series. | |
197 | */ |
|
197 | */ | |
198 | void QPieSeries::insert(int index, QPieSlice* slice) |
|
198 | void QPieSeries::insert(int index, QPieSlice* slice) | |
199 | { |
|
199 | { | |
200 | Q_D(QPieSeries); |
|
200 | Q_D(QPieSeries); | |
201 | Q_ASSERT(index <= d->m_slices.count()); |
|
201 | Q_ASSERT(index <= d->m_slices.count()); | |
202 | slice->setParent(this); |
|
202 | slice->setParent(this); | |
203 | d->m_slices.insert(index, slice); |
|
203 | d->m_slices.insert(index, slice); | |
204 |
|
204 | |||
205 | d->updateDerivativeData(); |
|
205 | d->updateDerivativeData(); | |
206 |
|
206 | |||
207 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
207 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
208 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
208 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
209 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
209 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
210 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
210 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
211 |
|
211 | |||
212 | emit added(QList<QPieSlice*>() << slice); |
|
212 | emit added(QList<QPieSlice*>() << slice); | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | Removes a single \a slice from the series and deletes the slice. |
|
216 | Removes a single \a slice from the series and deletes the slice. | |
217 |
|
217 | |||
218 | Do not reference this pointer after this call. |
|
218 | Do not reference this pointer after this call. | |
219 | */ |
|
219 | */ | |
220 | void QPieSeries::remove(QPieSlice* slice) |
|
220 | void QPieSeries::remove(QPieSlice* slice) | |
221 | { |
|
221 | { | |
222 | Q_D(QPieSeries); |
|
222 | Q_D(QPieSeries); | |
223 | if (!d->m_slices.removeOne(slice)) { |
|
223 | if (!d->m_slices.removeOne(slice)) { | |
224 | Q_ASSERT(0); // TODO: how should this be reported? |
|
224 | Q_ASSERT(0); // TODO: how should this be reported? | |
225 | return; |
|
225 | return; | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | d->updateDerivativeData(); |
|
228 | d->updateDerivativeData(); | |
229 |
|
229 | |||
230 | emit removed(QList<QPieSlice*>() << slice); |
|
230 | emit removed(QList<QPieSlice*>() << slice); | |
231 |
|
231 | |||
232 | delete slice; |
|
232 | delete slice; | |
233 | slice = 0; |
|
233 | slice = 0; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | Clears all slices from the series. |
|
237 | Clears all slices from the series. | |
238 | */ |
|
238 | */ | |
239 | void QPieSeries::clear() |
|
239 | void QPieSeries::clear() | |
240 | { |
|
240 | { | |
241 | Q_D(QPieSeries); |
|
241 | Q_D(QPieSeries); | |
242 | if (d->m_slices.count() == 0) |
|
242 | if (d->m_slices.count() == 0) | |
243 | return; |
|
243 | return; | |
244 |
|
244 | |||
245 | QList<QPieSlice*> slices = d->m_slices; |
|
245 | QList<QPieSlice*> slices = d->m_slices; | |
246 | foreach (QPieSlice* s, d->m_slices) { |
|
246 | foreach (QPieSlice* s, d->m_slices) { | |
247 | d->m_slices.removeOne(s); |
|
247 | d->m_slices.removeOne(s); | |
248 | delete s; |
|
248 | delete s; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | d->updateDerivativeData(); |
|
251 | d->updateDerivativeData(); | |
252 |
|
252 | |||
253 | emit removed(slices); |
|
253 | emit removed(slices); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | /*! |
|
256 | /*! | |
257 | returns the number of the slices in this series. |
|
257 | returns the number of the slices in this series. | |
258 | */ |
|
258 | */ | |
259 | int QPieSeries::count() const |
|
259 | int QPieSeries::count() const | |
260 | { |
|
260 | { | |
261 | Q_D(const QPieSeries); |
|
261 | Q_D(const QPieSeries); | |
262 | return d->m_slices.count(); |
|
262 | return d->m_slices.count(); | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | /*! |
|
265 | /*! | |
266 | Returns true is the series is empty. |
|
266 | Returns true is the series is empty. | |
267 | */ |
|
267 | */ | |
268 | bool QPieSeries::isEmpty() const |
|
268 | bool QPieSeries::isEmpty() const | |
269 | { |
|
269 | { | |
270 | Q_D(const QPieSeries); |
|
270 | Q_D(const QPieSeries); | |
271 | return d->m_slices.isEmpty(); |
|
271 | return d->m_slices.isEmpty(); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | /*! |
|
274 | /*! | |
275 | Returns a list of slices that belong to this series. |
|
275 | Returns a list of slices that belong to this series. | |
276 | */ |
|
276 | */ | |
277 | QList<QPieSlice*> QPieSeries::slices() const |
|
277 | QList<QPieSlice*> QPieSeries::slices() const | |
278 | { |
|
278 | { | |
279 | Q_D(const QPieSeries); |
|
279 | Q_D(const QPieSeries); | |
280 | return d->m_slices; |
|
280 | return d->m_slices; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
283 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
284 | { |
|
284 | { | |
285 | Q_D(QPieSeries); |
|
285 | Q_D(QPieSeries); | |
286 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) |
|
286 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) | |
287 | emit piePositionChanged(); |
|
287 | emit piePositionChanged(); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
290 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
291 | { |
|
291 | { | |
292 | Q_D(QPieSeries); |
|
292 | Q_D(QPieSeries); | |
293 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) |
|
293 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) | |
294 | emit piePositionChanged(); |
|
294 | emit piePositionChanged(); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | qreal QPieSeries::horizontalPosition() const |
|
297 | qreal QPieSeries::horizontalPosition() const | |
298 | { |
|
298 | { | |
299 | Q_D(const QPieSeries); |
|
299 | Q_D(const QPieSeries); | |
300 | return d->m_pieRelativeHorPos; |
|
300 | return d->m_pieRelativeHorPos; | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | qreal QPieSeries::verticalPosition() const |
|
303 | qreal QPieSeries::verticalPosition() const | |
304 | { |
|
304 | { | |
305 | Q_D(const QPieSeries); |
|
305 | Q_D(const QPieSeries); | |
306 | return d->m_pieRelativeVerPos; |
|
306 | return d->m_pieRelativeVerPos; | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void QPieSeries::setPieSize(qreal relativeSize) |
|
309 | void QPieSeries::setPieSize(qreal relativeSize) | |
310 | { |
|
310 | { | |
311 | Q_D(QPieSeries); |
|
311 | Q_D(QPieSeries); | |
312 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) |
|
312 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) | |
313 | emit pieSizeChanged(); |
|
313 | emit pieSizeChanged(); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | qreal QPieSeries::pieSize() const |
|
316 | qreal QPieSeries::pieSize() const | |
317 | { |
|
317 | { | |
318 | Q_D(const QPieSeries); |
|
318 | Q_D(const QPieSeries); | |
319 | return d->m_pieRelativeSize; |
|
319 | return d->m_pieRelativeSize; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 |
|
322 | |||
323 | void QPieSeries::setPieStartAngle(qreal angle) |
|
323 | void QPieSeries::setPieStartAngle(qreal angle) | |
324 | { |
|
324 | { | |
325 | Q_D(QPieSeries); |
|
325 | Q_D(QPieSeries); | |
326 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) |
|
326 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) | |
327 | d->updateDerivativeData(); |
|
327 | d->updateDerivativeData(); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | qreal QPieSeries::pieStartAngle() const |
|
330 | qreal QPieSeries::pieStartAngle() const | |
331 | { |
|
331 | { | |
332 | Q_D(const QPieSeries); |
|
332 | Q_D(const QPieSeries); | |
333 | return d->m_pieStartAngle; |
|
333 | return d->m_pieStartAngle; | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | /*! |
|
336 | /*! | |
337 | Sets the end angle of the pie. |
|
337 | Sets the end angle of the pie. | |
338 |
|
338 | |||
339 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
339 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
340 |
|
340 | |||
341 | \a angle must be greater than start angle. |
|
341 | \a angle must be greater than start angle. | |
342 |
|
342 | |||
343 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
343 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
344 | */ |
|
344 | */ | |
345 | void QPieSeries::setPieEndAngle(qreal angle) |
|
345 | void QPieSeries::setPieEndAngle(qreal angle) | |
346 | { |
|
346 | { | |
347 | Q_D(QPieSeries); |
|
347 | Q_D(QPieSeries); | |
348 |
|
348 | |||
349 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) |
|
349 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) | |
350 | d->updateDerivativeData(); |
|
350 | d->updateDerivativeData(); | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | /*! |
|
353 | /*! | |
354 | Returns the end angle of the pie. |
|
354 | Returns the end angle of the pie. | |
355 |
|
355 | |||
356 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
356 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
357 |
|
357 | |||
358 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
358 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
359 | */ |
|
359 | */ | |
360 | qreal QPieSeries::pieEndAngle() const |
|
360 | qreal QPieSeries::pieEndAngle() const | |
361 | { |
|
361 | { | |
362 | Q_D(const QPieSeries); |
|
362 | Q_D(const QPieSeries); | |
363 | return d->m_pieEndAngle; |
|
363 | return d->m_pieEndAngle; | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | /*! |
|
366 | /*! | |
367 | Sets the all the slice labels \a visible or invisible. |
|
367 | Sets the all the slice labels \a visible or invisible. | |
368 |
|
368 | |||
369 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
369 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
370 | */ |
|
370 | */ | |
371 | void QPieSeries::setLabelsVisible(bool visible) |
|
371 | void QPieSeries::setLabelsVisible(bool visible) | |
372 | { |
|
372 | { | |
373 | Q_D(QPieSeries); |
|
373 | Q_D(QPieSeries); | |
374 | foreach (QPieSlice* s, d->m_slices) |
|
374 | foreach (QPieSlice* s, d->m_slices) | |
375 | s->setLabelVisible(visible); |
|
375 | s->setLabelVisible(visible); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Returns the sum of all slice values in this series. |
|
379 | Returns the sum of all slice values in this series. | |
380 |
|
380 | |||
381 | \sa QPieSlice::value(), QPieSlice::setValue() |
|
381 | \sa QPieSlice::value(), QPieSlice::setValue() | |
382 | */ |
|
382 | */ | |
383 |
qreal QPieSeries:: |
|
383 | qreal QPieSeries::sum() const | |
384 | { |
|
384 | { | |
385 | Q_D(const QPieSeries); |
|
385 | Q_D(const QPieSeries); | |
386 |
return d->m_ |
|
386 | return d->m_sum; | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | /*! |
|
389 | /*! | |
390 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
390 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
391 |
|
391 | |||
392 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. |
|
392 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. | |
393 |
|
393 | |||
394 | \sa QPieSlice::clicked() |
|
394 | \sa QPieSlice::clicked() | |
395 | */ |
|
395 | */ | |
396 |
|
396 | |||
397 | /*! |
|
397 | /*! | |
398 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
398 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
399 |
|
399 | |||
400 | This signal is emitted when user has hovered over a \a slice. |
|
400 | This signal is emitted when user has hovered over a \a slice. | |
401 |
|
401 | |||
402 | \sa QPieSlice::hoverEnter() |
|
402 | \sa QPieSlice::hoverEnter() | |
403 | */ |
|
403 | */ | |
404 |
|
404 | |||
405 | /*! |
|
405 | /*! | |
406 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
406 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
407 |
|
407 | |||
408 | This signal is emitted when user has hovered away from a \a slice. |
|
408 | This signal is emitted when user has hovered away from a \a slice. | |
409 |
|
409 | |||
410 | \sa QPieSlice::hoverLeave() |
|
410 | \sa QPieSlice::hoverLeave() | |
411 | */ |
|
411 | */ | |
412 |
|
412 | |||
413 | /*! |
|
413 | /*! | |
414 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
414 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
415 |
|
415 | |||
416 | This signal is emitted when \a slices has been added to the series. |
|
416 | This signal is emitted when \a slices has been added to the series. | |
417 |
|
417 | |||
418 | \sa append(), insert() |
|
418 | \sa append(), insert() | |
419 | */ |
|
419 | */ | |
420 |
|
420 | |||
421 | /*! |
|
421 | /*! | |
422 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
422 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
423 |
|
423 | |||
424 | This signal is emitted when \a slices has been removed from the series. |
|
424 | This signal is emitted when \a slices has been removed from the series. | |
425 |
|
425 | |||
426 | \sa remove(), clear() |
|
426 | \sa remove(), clear() | |
427 | */ |
|
427 | */ | |
428 |
|
428 | |||
429 | /*! |
|
429 | /*! | |
430 | \fn void QPieSeries::piePositionChanged() |
|
430 | \fn void QPieSeries::piePositionChanged() | |
431 |
|
431 | |||
432 | This signal is emitted when pie position has changed. |
|
432 | This signal is emitted when pie position has changed. | |
433 |
|
433 | |||
434 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() |
|
434 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() | |
435 | */ |
|
435 | */ | |
436 |
|
436 | |||
437 | /*! |
|
437 | /*! | |
438 | \fn void QPieSeries::pieSizeChanged() |
|
438 | \fn void QPieSeries::pieSizeChanged() | |
439 |
|
439 | |||
440 | This signal is emitted when pie size has changed. |
|
440 | This signal is emitted when pie size has changed. | |
441 |
|
441 | |||
442 | \sa pieSize(), setPieSize() |
|
442 | \sa pieSize(), setPieSize() | |
443 | */ |
|
443 | */ | |
444 |
|
444 | |||
445 | /*! |
|
445 | /*! | |
446 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) |
|
446 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) | |
447 | Sets the \a model to be used as a data source |
|
447 | Sets the \a model to be used as a data source | |
448 | */ |
|
448 | */ | |
449 | bool QPieSeries::setModel(QAbstractItemModel* model) |
|
449 | bool QPieSeries::setModel(QAbstractItemModel* model) | |
450 | { |
|
450 | { | |
451 | Q_D(QPieSeries); |
|
451 | Q_D(QPieSeries); | |
452 | // disconnect signals from old model |
|
452 | // disconnect signals from old model | |
453 | if(d->m_model) |
|
453 | if(d->m_model) | |
454 | { |
|
454 | { | |
455 | disconnect(d->m_model, 0, this, 0); |
|
455 | disconnect(d->m_model, 0, this, 0); | |
456 | d->m_mapValues = -1; |
|
456 | d->m_mapValues = -1; | |
457 | d->m_mapLabels = -1; |
|
457 | d->m_mapLabels = -1; | |
458 | d->m_mapOrientation = Qt::Vertical; |
|
458 | d->m_mapOrientation = Qt::Vertical; | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | // set new model |
|
461 | // set new model | |
462 | if(model) |
|
462 | if(model) | |
463 | { |
|
463 | { | |
464 | d->m_model = model; |
|
464 | d->m_model = model; | |
465 | return true; |
|
465 | return true; | |
466 | } |
|
466 | } | |
467 | else |
|
467 | else | |
468 | { |
|
468 | { | |
469 | d->m_model = 0; |
|
469 | d->m_model = 0; | |
470 | return false; |
|
470 | return false; | |
471 | } |
|
471 | } | |
472 | } |
|
472 | } | |
473 |
|
473 | |||
474 | /*! |
|
474 | /*! | |
475 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
475 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
476 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. |
|
476 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. | |
477 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. |
|
477 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. | |
478 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. |
|
478 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. | |
479 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
479 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
480 | */ |
|
480 | */ | |
481 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
481 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
482 | { |
|
482 | { | |
483 | Q_D(QPieSeries); |
|
483 | Q_D(QPieSeries); | |
484 |
|
484 | |||
485 | if (d->m_model == 0) |
|
485 | if (d->m_model == 0) | |
486 | return; |
|
486 | return; | |
487 |
|
487 | |||
488 | d->m_mapValues = modelValuesLine; |
|
488 | d->m_mapValues = modelValuesLine; | |
489 | d->m_mapLabels = modelLabelsLine; |
|
489 | d->m_mapLabels = modelLabelsLine; | |
490 | d->m_mapOrientation = orientation; |
|
490 | d->m_mapOrientation = orientation; | |
491 |
|
491 | |||
492 | // connect the signals |
|
492 | // connect the signals | |
493 | if (d->m_mapOrientation == Qt::Vertical) { |
|
493 | if (d->m_mapOrientation == Qt::Vertical) { | |
494 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
494 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
495 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
495 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
496 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
496 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
497 | } else { |
|
497 | } else { | |
498 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
498 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
499 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
499 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
500 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
500 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | // create the initial slices set |
|
503 | // create the initial slices set | |
504 | if (d->m_mapOrientation == Qt::Vertical) { |
|
504 | if (d->m_mapOrientation == Qt::Vertical) { | |
505 | for (int i = 0; i < d->m_model->rowCount(); i++) |
|
505 | for (int i = 0; i < d->m_model->rowCount(); i++) | |
506 | append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); |
|
506 | append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
507 | } else { |
|
507 | } else { | |
508 | for (int i = 0; i < d->m_model->columnCount(); i++) |
|
508 | for (int i = 0; i < d->m_model->columnCount(); i++) | |
509 | append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); |
|
509 | append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
510 | } |
|
510 | } | |
511 | } |
|
511 | } | |
512 |
|
512 | |||
513 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
513 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
514 |
|
514 | |||
515 |
|
515 | |||
516 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) |
|
516 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
517 | :QSeriesPrivate(parent), |
|
517 | :QSeriesPrivate(parent), | |
518 | m_pieRelativeHorPos(0.5), |
|
518 | m_pieRelativeHorPos(0.5), | |
519 | m_pieRelativeVerPos(0.5), |
|
519 | m_pieRelativeVerPos(0.5), | |
520 | m_pieRelativeSize(0.7), |
|
520 | m_pieRelativeSize(0.7), | |
521 | m_pieStartAngle(0), |
|
521 | m_pieStartAngle(0), | |
522 | m_pieEndAngle(360), |
|
522 | m_pieEndAngle(360), | |
523 |
m_ |
|
523 | m_sum(0), | |
524 | m_mapValues(0), |
|
524 | m_mapValues(0), | |
525 | m_mapLabels(0), |
|
525 | m_mapLabels(0), | |
526 | m_mapOrientation(Qt::Horizontal) |
|
526 | m_mapOrientation(Qt::Horizontal) | |
527 | { |
|
527 | { | |
528 |
|
528 | |||
529 | } |
|
529 | } | |
530 |
|
530 | |||
531 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
531 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
532 | { |
|
532 | { | |
533 |
|
533 | |||
534 | } |
|
534 | } | |
535 |
|
535 | |||
536 | void QPieSeriesPrivate::updateDerivativeData() |
|
536 | void QPieSeriesPrivate::updateDerivativeData() | |
537 | { |
|
537 | { | |
538 |
m_ |
|
538 | m_sum = 0; | |
539 |
|
539 | |||
540 | // nothing to do? |
|
540 | // nothing to do? | |
541 | if (m_slices.count() == 0) |
|
541 | if (m_slices.count() == 0) | |
542 | return; |
|
542 | return; | |
543 |
|
543 | |||
544 |
// calculate |
|
544 | // calculate sum of all slices | |
545 | foreach (QPieSlice* s, m_slices) |
|
545 | foreach (QPieSlice* s, m_slices) | |
546 |
m_ |
|
546 | m_sum += s->value(); | |
547 |
|
547 | |||
548 | // nothing to show.. |
|
548 | // nothing to show.. | |
549 |
if (qFuzzyIsNull(m_ |
|
549 | if (qFuzzyIsNull(m_sum)) | |
550 | return; |
|
550 | return; | |
551 |
|
551 | |||
552 | // update slice attributes |
|
552 | // update slice attributes | |
553 | qreal sliceAngle = m_pieStartAngle; |
|
553 | qreal sliceAngle = m_pieStartAngle; | |
554 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
554 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
555 | QVector<QPieSlice*> changed; |
|
555 | QVector<QPieSlice*> changed; | |
556 | foreach (QPieSlice* s, m_slices) { |
|
556 | foreach (QPieSlice* s, m_slices) { | |
557 |
|
557 | |||
558 | PieSliceData data = PieSliceData::data(s); |
|
558 | PieSliceData data = PieSliceData::data(s); | |
559 |
data.m_percentage = s->value() / m_ |
|
559 | data.m_percentage = s->value() / m_sum; | |
560 | data.m_angleSpan = pieSpan * data.m_percentage; |
|
560 | data.m_angleSpan = pieSpan * data.m_percentage; | |
561 | data.m_startAngle = sliceAngle; |
|
561 | data.m_startAngle = sliceAngle; | |
562 | sliceAngle += data.m_angleSpan; |
|
562 | sliceAngle += data.m_angleSpan; | |
563 |
|
563 | |||
564 | if (PieSliceData::data(s) != data) { |
|
564 | if (PieSliceData::data(s) != data) { | |
565 | PieSliceData::data(s) = data; |
|
565 | PieSliceData::data(s) = data; | |
566 | changed << s; |
|
566 | changed << s; | |
567 | } |
|
567 | } | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | // emit signals |
|
570 | // emit signals | |
571 | foreach (QPieSlice* s, changed) |
|
571 | foreach (QPieSlice* s, changed) | |
572 | PieSliceData::data(s).emitChangedSignal(s); |
|
572 | PieSliceData::data(s).emitChangedSignal(s); | |
573 | } |
|
573 | } | |
574 |
|
574 | |||
575 | void QPieSeriesPrivate::sliceChanged() |
|
575 | void QPieSeriesPrivate::sliceChanged() | |
576 | { |
|
576 | { | |
577 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
577 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
578 | updateDerivativeData(); |
|
578 | updateDerivativeData(); | |
579 | } |
|
579 | } | |
580 |
|
580 | |||
581 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) |
|
581 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
582 | { |
|
582 | { | |
583 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
583 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
584 | Q_ASSERT(m_slices.contains(slice)); |
|
584 | Q_ASSERT(m_slices.contains(slice)); | |
585 | Q_Q(QPieSeries); |
|
585 | Q_Q(QPieSeries); | |
586 | emit q->clicked(slice, buttons); |
|
586 | emit q->clicked(slice, buttons); | |
587 | } |
|
587 | } | |
588 |
|
588 | |||
589 | void QPieSeriesPrivate::sliceHoverEnter() |
|
589 | void QPieSeriesPrivate::sliceHoverEnter() | |
590 | { |
|
590 | { | |
591 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
591 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
592 | Q_ASSERT(m_slices.contains(slice)); |
|
592 | Q_ASSERT(m_slices.contains(slice)); | |
593 | Q_Q(QPieSeries); |
|
593 | Q_Q(QPieSeries); | |
594 | emit q->hoverEnter(slice); |
|
594 | emit q->hoverEnter(slice); | |
595 | } |
|
595 | } | |
596 |
|
596 | |||
597 | void QPieSeriesPrivate::sliceHoverLeave() |
|
597 | void QPieSeriesPrivate::sliceHoverLeave() | |
598 | { |
|
598 | { | |
599 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
599 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
600 | Q_ASSERT(m_slices.contains(slice)); |
|
600 | Q_ASSERT(m_slices.contains(slice)); | |
601 | Q_Q(QPieSeries); |
|
601 | Q_Q(QPieSeries); | |
602 | emit q->hoverLeave(slice); |
|
602 | emit q->hoverLeave(slice); | |
603 | } |
|
603 | } | |
604 |
|
604 | |||
605 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
605 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
606 | { |
|
606 | { | |
607 | Q_UNUSED(bottomRight) |
|
607 | Q_UNUSED(bottomRight) | |
608 |
|
608 | |||
609 | if (m_mapOrientation == Qt::Vertical) |
|
609 | if (m_mapOrientation == Qt::Vertical) | |
610 | { |
|
610 | { | |
611 | if (topLeft.column() == m_mapValues) |
|
611 | if (topLeft.column() == m_mapValues) | |
612 | if (m_mapValues == m_mapLabels) |
|
612 | if (m_mapValues == m_mapLabels) | |
613 | { |
|
613 | { | |
614 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
614 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
615 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
615 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
616 | } |
|
616 | } | |
617 | else |
|
617 | else | |
618 | { |
|
618 | { | |
619 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
619 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
620 | } |
|
620 | } | |
621 | else if (topLeft.column() == m_mapLabels) |
|
621 | else if (topLeft.column() == m_mapLabels) | |
622 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
622 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
623 | } |
|
623 | } | |
624 | else |
|
624 | else | |
625 | { |
|
625 | { | |
626 | if (topLeft.row() == m_mapValues) |
|
626 | if (topLeft.row() == m_mapValues) | |
627 | if (m_mapValues == m_mapLabels) |
|
627 | if (m_mapValues == m_mapLabels) | |
628 | { |
|
628 | { | |
629 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
629 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
630 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
630 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
631 | } |
|
631 | } | |
632 | else |
|
632 | else | |
633 | { |
|
633 | { | |
634 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
634 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
635 | } |
|
635 | } | |
636 | else if (topLeft.row() == m_mapLabels) |
|
636 | else if (topLeft.row() == m_mapLabels) | |
637 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
637 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
638 | } |
|
638 | } | |
639 | } |
|
639 | } | |
640 |
|
640 | |||
641 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
641 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
642 | { |
|
642 | { | |
643 | Q_UNUSED(parent) |
|
643 | Q_UNUSED(parent) | |
644 | Q_UNUSED(end) |
|
644 | Q_UNUSED(end) | |
645 | Q_Q(QPieSeries); |
|
645 | Q_Q(QPieSeries); | |
646 |
|
646 | |||
647 | QPieSlice* newSlice = new QPieSlice; |
|
647 | QPieSlice* newSlice = new QPieSlice; | |
648 | newSlice->setLabelVisible(true); |
|
648 | newSlice->setLabelVisible(true); | |
649 | if (m_mapOrientation == Qt::Vertical) |
|
649 | if (m_mapOrientation == Qt::Vertical) | |
650 | { |
|
650 | { | |
651 | newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); |
|
651 | newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
652 | newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); |
|
652 | newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
653 | } |
|
653 | } | |
654 | else |
|
654 | else | |
655 | { |
|
655 | { | |
656 | newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); |
|
656 | newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
657 | newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); |
|
657 | newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
658 | } |
|
658 | } | |
659 |
|
659 | |||
660 | q->insert(start, newSlice); |
|
660 | q->insert(start, newSlice); | |
661 | } |
|
661 | } | |
662 |
|
662 | |||
663 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
663 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
664 | { |
|
664 | { | |
665 | Q_UNUSED(parent) |
|
665 | Q_UNUSED(parent) | |
666 | Q_UNUSED(end) |
|
666 | Q_UNUSED(end) | |
667 | Q_Q(QPieSeries); |
|
667 | Q_Q(QPieSeries); | |
668 | q->remove(m_slices.at(start)); |
|
668 | q->remove(m_slices.at(start)); | |
669 | } |
|
669 | } | |
670 |
|
670 | |||
671 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) |
|
671 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
672 | { |
|
672 | { | |
673 | // Remove rounding errors |
|
673 | // Remove rounding errors | |
674 | qreal roundedValue = newValue; |
|
674 | qreal roundedValue = newValue; | |
675 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) |
|
675 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
676 | roundedValue = 0.0; |
|
676 | roundedValue = 0.0; | |
677 | else if (qFuzzyCompare(newValue, max)) |
|
677 | else if (qFuzzyCompare(newValue, max)) | |
678 | roundedValue = max; |
|
678 | roundedValue = max; | |
679 | else if (qFuzzyCompare(newValue, min)) |
|
679 | else if (qFuzzyCompare(newValue, min)) | |
680 | roundedValue = min; |
|
680 | roundedValue = min; | |
681 |
|
681 | |||
682 | // Check if the position is valid after removing the rounding errors |
|
682 | // Check if the position is valid after removing the rounding errors | |
683 | if (roundedValue < min || roundedValue > max) { |
|
683 | if (roundedValue < min || roundedValue > max) { | |
684 | qWarning("QPieSeries: Illegal value"); |
|
684 | qWarning("QPieSeries: Illegal value"); | |
685 | return false; |
|
685 | return false; | |
686 | } |
|
686 | } | |
687 |
|
687 | |||
688 | if (!qFuzzyIsNull(value - roundedValue)) { |
|
688 | if (!qFuzzyIsNull(value - roundedValue)) { | |
689 | value = roundedValue; |
|
689 | value = roundedValue; | |
690 | return true; |
|
690 | return true; | |
691 | } |
|
691 | } | |
692 |
|
692 | |||
693 | // The change was so small it is considered a rounding error |
|
693 | // The change was so small it is considered a rounding error | |
694 | return false; |
|
694 | return false; | |
695 | } |
|
695 | } | |
696 |
|
696 | |||
697 |
|
697 | |||
698 | #include "moc_qpieseries.cpp" |
|
698 | #include "moc_qpieseries.cpp" | |
699 | #include "moc_qpieseries_p.cpp" |
|
699 | #include "moc_qpieseries_p.cpp" | |
700 |
|
700 | |||
701 | QTCOMMERCIALCHART_END_NAMESPACE |
|
701 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,101 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef PIESERIES_H |
|
21 | #ifndef PIESERIES_H | |
22 | #define PIESERIES_H |
|
22 | #define PIESERIES_H | |
23 |
|
23 | |||
24 | #include <qseries.h> |
|
24 | #include <qseries.h> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 | class QPieSeriesPrivate; |
|
27 | class QPieSeriesPrivate; | |
28 | class QPieSlice; |
|
28 | class QPieSlice; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries |
|
30 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) |
|
33 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) | |
34 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) |
|
34 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) | |
35 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) |
|
35 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) | |
36 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) |
|
36 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) | |
37 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) |
|
37 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | QPieSeries(QObject *parent = 0); |
|
40 | QPieSeries(QObject *parent = 0); | |
41 | virtual ~QPieSeries(); |
|
41 | virtual ~QPieSeries(); | |
42 |
|
42 | |||
43 | public: // from QChartSeries |
|
43 | public: // from QChartSeries | |
44 | QSeriesType type() const; |
|
44 | QSeriesType type() const; | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 |
|
47 | |||
48 | // slice setters |
|
48 | // slice setters | |
49 | void append(QPieSlice* slice); |
|
49 | void append(QPieSlice* slice); | |
50 | void append(QList<QPieSlice*> slices); |
|
50 | void append(QList<QPieSlice*> slices); | |
51 | void insert(int index, QPieSlice* slice); |
|
51 | void insert(int index, QPieSlice* slice); | |
52 | void replace(QList<QPieSlice*> slices); |
|
52 | void replace(QList<QPieSlice*> slices); | |
53 | void remove(QPieSlice* slice); |
|
53 | void remove(QPieSlice* slice); | |
54 | void clear(); |
|
54 | void clear(); | |
55 |
|
55 | |||
56 | // slice getters |
|
56 | // slice getters | |
57 | QList<QPieSlice*> slices() const; |
|
57 | QList<QPieSlice*> slices() const; | |
58 |
|
58 | |||
59 | // calculated data |
|
59 | // calculated data | |
60 | int count() const; |
|
60 | int count() const; | |
61 | bool isEmpty() const; |
|
61 | bool isEmpty() const; | |
62 |
qreal |
|
62 | qreal sum() const; | |
63 |
|
63 | |||
64 | // pie customization |
|
64 | // pie customization | |
65 | void setHorizontalPosition(qreal relativePosition); |
|
65 | void setHorizontalPosition(qreal relativePosition); | |
66 | qreal horizontalPosition() const; |
|
66 | qreal horizontalPosition() const; | |
67 | void setVerticalPosition(qreal relativePosition); |
|
67 | void setVerticalPosition(qreal relativePosition); | |
68 | qreal verticalPosition() const; |
|
68 | qreal verticalPosition() const; | |
69 | void setPieSize(qreal relativeSize); |
|
69 | void setPieSize(qreal relativeSize); | |
70 | qreal pieSize() const; |
|
70 | qreal pieSize() const; | |
71 | void setPieStartAngle(qreal startAngle); |
|
71 | void setPieStartAngle(qreal startAngle); | |
72 | qreal pieStartAngle() const; |
|
72 | qreal pieStartAngle() const; | |
73 | void setPieEndAngle(qreal endAngle); |
|
73 | void setPieEndAngle(qreal endAngle); | |
74 | qreal pieEndAngle() const; |
|
74 | qreal pieEndAngle() const; | |
75 |
|
75 | |||
76 | // convenience function |
|
76 | // convenience function | |
77 | QPieSeries& operator << (QPieSlice* slice); |
|
77 | QPieSeries& operator << (QPieSlice* slice); | |
78 | QPieSlice* append(qreal value, QString name); |
|
78 | QPieSlice* append(qreal value, QString name); | |
79 | void setLabelsVisible(bool visible = true); |
|
79 | void setLabelsVisible(bool visible = true); | |
80 |
|
80 | |||
81 | // data from model |
|
81 | // data from model | |
82 | bool setModel(QAbstractItemModel* model); |
|
82 | bool setModel(QAbstractItemModel* model); | |
83 | void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical); |
|
83 | void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical); | |
84 |
|
84 | |||
85 | Q_SIGNALS: |
|
85 | Q_SIGNALS: | |
86 | void clicked(QPieSlice* slice, Qt::MouseButtons buttons); |
|
86 | void clicked(QPieSlice* slice, Qt::MouseButtons buttons); | |
87 | void hoverEnter(QPieSlice* slice); |
|
87 | void hoverEnter(QPieSlice* slice); | |
88 | void hoverLeave(QPieSlice* slice); |
|
88 | void hoverLeave(QPieSlice* slice); | |
89 | void added(QList<QPieSlice*> slices); |
|
89 | void added(QList<QPieSlice*> slices); | |
90 | void removed(QList<QPieSlice*> slices); |
|
90 | void removed(QList<QPieSlice*> slices); | |
91 | void piePositionChanged(); |
|
91 | void piePositionChanged(); | |
92 | void pieSizeChanged(); |
|
92 | void pieSizeChanged(); | |
93 |
|
93 | |||
94 | private: |
|
94 | private: | |
95 | Q_DECLARE_PRIVATE(QPieSeries) |
|
95 | Q_DECLARE_PRIVATE(QPieSeries) | |
96 | Q_DISABLE_COPY(QPieSeries) |
|
96 | Q_DISABLE_COPY(QPieSeries) | |
97 | }; |
|
97 | }; | |
98 |
|
98 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
99 | QTCOMMERCIALCHART_END_NAMESPACE | |
100 |
|
100 | |||
101 | #endif // PIESERIES_H |
|
101 | #endif // PIESERIES_H |
@@ -1,70 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QPIESERIES_P_H |
|
21 | #ifndef QPIESERIES_P_H | |
22 | #define QPIESERIES_P_H |
|
22 | #define QPIESERIES_P_H | |
23 |
|
23 | |||
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qseries_p.h" |
|
25 | #include "qseries_p.h" | |
26 |
|
26 | |||
27 | class QModelIndex; |
|
27 | class QModelIndex; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QPieSeriesPrivate : public QSeriesPrivate |
|
31 | class QPieSeriesPrivate : public QSeriesPrivate | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | QPieSeriesPrivate(QPieSeries *parent); |
|
36 | QPieSeriesPrivate(QPieSeries *parent); | |
37 | ~QPieSeriesPrivate(); |
|
37 | ~QPieSeriesPrivate(); | |
38 |
|
38 | |||
39 | void updateDerivativeData(); |
|
39 | void updateDerivativeData(); | |
40 |
|
40 | |||
41 | public Q_SLOTS: |
|
41 | public Q_SLOTS: | |
42 | void sliceChanged(); |
|
42 | void sliceChanged(); | |
43 | void sliceClicked(Qt::MouseButtons buttons); |
|
43 | void sliceClicked(Qt::MouseButtons buttons); | |
44 | void sliceHoverEnter(); |
|
44 | void sliceHoverEnter(); | |
45 | void sliceHoverLeave(); |
|
45 | void sliceHoverLeave(); | |
46 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
46 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
47 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
47 | void modelDataAdded(QModelIndex parent, int start, int end); | |
48 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
48 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
49 | bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0); |
|
49 | bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0); | |
50 |
|
50 | |||
51 | public: |
|
51 | public: | |
52 | QList<QPieSlice*> m_slices; |
|
52 | QList<QPieSlice*> m_slices; | |
53 | qreal m_pieRelativeHorPos; |
|
53 | qreal m_pieRelativeHorPos; | |
54 | qreal m_pieRelativeVerPos; |
|
54 | qreal m_pieRelativeVerPos; | |
55 | qreal m_pieRelativeSize; |
|
55 | qreal m_pieRelativeSize; | |
56 | qreal m_pieStartAngle; |
|
56 | qreal m_pieStartAngle; | |
57 | qreal m_pieEndAngle; |
|
57 | qreal m_pieEndAngle; | |
58 |
qreal m_ |
|
58 | qreal m_sum; | |
59 |
|
59 | |||
60 | // model map |
|
60 | // model map | |
61 | int m_mapValues; |
|
61 | int m_mapValues; | |
62 | int m_mapLabels; |
|
62 | int m_mapLabels; | |
63 | Qt::Orientation m_mapOrientation; |
|
63 | Qt::Orientation m_mapOrientation; | |
64 | private: |
|
64 | private: | |
65 | Q_DECLARE_PUBLIC(QPieSeries) |
|
65 | Q_DECLARE_PUBLIC(QPieSeries) | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
69 | |||
70 | #endif // QPIESERIES_P_H |
|
70 | #endif // QPIESERIES_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now