@@ -1,713 +1,713 | |||||
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 "qpieseriesprivate_p.h" |
|
22 | #include "qpieseriesprivate_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 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) |
|
30 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
31 | :QObject(parent), |
|
31 | :QObject(parent), | |
32 | q_ptr(parent), |
|
32 | q_ptr(parent), | |
33 | m_pieRelativeHorPos(0.5), |
|
33 | m_pieRelativeHorPos(0.5), | |
34 | m_pieRelativeVerPos(0.5), |
|
34 | m_pieRelativeVerPos(0.5), | |
35 | m_pieRelativeSize(0.7), |
|
35 | m_pieRelativeSize(0.7), | |
36 | m_pieStartAngle(0), |
|
36 | m_pieStartAngle(0), | |
37 | m_pieEndAngle(360), |
|
37 | m_pieEndAngle(360), | |
38 | m_total(0), |
|
38 | m_total(0), | |
39 | m_mapValues(0), |
|
39 | m_mapValues(0), | |
40 | m_mapLabels(0), |
|
40 | m_mapLabels(0), | |
41 | m_mapOrientation(Qt::Horizontal) |
|
41 | m_mapOrientation(Qt::Horizontal) | |
42 | { |
|
42 | { | |
43 |
|
43 | |||
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
46 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
47 | { |
|
47 | { | |
48 |
|
48 | |||
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void QPieSeriesPrivate::updateDerivativeData() |
|
51 | void QPieSeriesPrivate::updateDerivativeData() | |
52 | { |
|
52 | { | |
53 | m_total = 0; |
|
53 | m_total = 0; | |
54 |
|
54 | |||
55 | // nothing to do? |
|
55 | // nothing to do? | |
56 | if (m_slices.count() == 0) |
|
56 | if (m_slices.count() == 0) | |
57 | return; |
|
57 | return; | |
58 |
|
58 | |||
59 | // calculate total |
|
59 | // calculate total | |
60 | foreach (QPieSlice* s, m_slices) |
|
60 | foreach (QPieSlice* s, m_slices) | |
61 | m_total += s->value(); |
|
61 | m_total += s->value(); | |
62 |
|
62 | |||
63 | // nothing to show.. |
|
63 | // nothing to show.. | |
64 | if (qFuzzyIsNull(m_total)) |
|
64 | if (qFuzzyIsNull(m_total)) | |
65 | return; |
|
65 | return; | |
66 |
|
66 | |||
67 | // update slice attributes |
|
67 | // update slice attributes | |
68 | qreal sliceAngle = m_pieStartAngle; |
|
68 | qreal sliceAngle = m_pieStartAngle; | |
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
70 | QVector<QPieSlice*> changed; |
|
70 | QVector<QPieSlice*> changed; | |
71 | foreach (QPieSlice* s, m_slices) { |
|
71 | foreach (QPieSlice* s, m_slices) { | |
72 |
|
72 | |||
73 | PieSliceData data = PieSliceData::data(s); |
|
73 | PieSliceData data = PieSliceData::data(s); | |
74 | data.m_percentage = s->value() / m_total; |
|
74 | data.m_percentage = s->value() / m_total; | |
75 | data.m_angleSpan = pieSpan * data.m_percentage; |
|
75 | data.m_angleSpan = pieSpan * data.m_percentage; | |
76 | data.m_startAngle = sliceAngle; |
|
76 | data.m_startAngle = sliceAngle; | |
77 | sliceAngle += data.m_angleSpan; |
|
77 | sliceAngle += data.m_angleSpan; | |
78 |
|
78 | |||
79 | if (PieSliceData::data(s) != data) { |
|
79 | if (PieSliceData::data(s) != data) { | |
80 | PieSliceData::data(s) = data; |
|
80 | PieSliceData::data(s) = data; | |
81 | changed << s; |
|
81 | changed << s; | |
82 | } |
|
82 | } | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // emit signals |
|
85 | // emit signals | |
86 | foreach (QPieSlice* s, changed) |
|
86 | foreach (QPieSlice* s, changed) | |
87 | PieSliceData::data(s).emitChangedSignal(s); |
|
87 | PieSliceData::data(s).emitChangedSignal(s); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void QPieSeriesPrivate::sliceChanged() |
|
90 | void QPieSeriesPrivate::sliceChanged() | |
91 | { |
|
91 | { | |
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
93 | updateDerivativeData(); |
|
93 | updateDerivativeData(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) |
|
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
97 | { |
|
97 | { | |
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
99 | Q_ASSERT(m_slices.contains(slice)); |
|
99 | Q_ASSERT(m_slices.contains(slice)); | |
100 | Q_Q(QPieSeries); |
|
100 | Q_Q(QPieSeries); | |
101 | emit q->clicked(slice, buttons); |
|
101 | emit q->clicked(slice, buttons); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void QPieSeriesPrivate::sliceHoverEnter() |
|
104 | void QPieSeriesPrivate::sliceHoverEnter() | |
105 | { |
|
105 | { | |
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
107 | Q_ASSERT(m_slices.contains(slice)); |
|
107 | Q_ASSERT(m_slices.contains(slice)); | |
108 | Q_Q(QPieSeries); |
|
108 | Q_Q(QPieSeries); | |
109 | emit q->hoverEnter(slice); |
|
109 | emit q->hoverEnter(slice); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void QPieSeriesPrivate::sliceHoverLeave() |
|
112 | void QPieSeriesPrivate::sliceHoverLeave() | |
113 | { |
|
113 | { | |
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
115 | Q_ASSERT(m_slices.contains(slice)); |
|
115 | Q_ASSERT(m_slices.contains(slice)); | |
116 | Q_Q(QPieSeries); |
|
116 | Q_Q(QPieSeries); | |
117 | emit q->hoverLeave(slice); |
|
117 | emit q->hoverLeave(slice); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
121 | { |
|
121 | { | |
122 | Q_UNUSED(bottomRight) |
|
122 | Q_UNUSED(bottomRight) | |
123 | Q_Q(QPieSeries); |
|
123 | Q_Q(QPieSeries); | |
124 |
|
124 | |||
125 | if (m_mapOrientation == Qt::Vertical) |
|
125 | if (m_mapOrientation == Qt::Vertical) | |
126 | { |
|
126 | { | |
127 | if (topLeft.column() == m_mapValues) |
|
127 | if (topLeft.column() == m_mapValues) | |
128 | if (m_mapValues == m_mapLabels) |
|
128 | if (m_mapValues == m_mapLabels) | |
129 | { |
|
129 | { | |
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
132 | } |
|
132 | } | |
133 | else |
|
133 | else | |
134 | { |
|
134 | { | |
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
136 | } |
|
136 | } | |
137 | else if (topLeft.column() == m_mapLabels) |
|
137 | else if (topLeft.column() == m_mapLabels) | |
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
139 | } |
|
139 | } | |
140 | else |
|
140 | else | |
141 | { |
|
141 | { | |
142 | if (topLeft.row() == m_mapValues) |
|
142 | if (topLeft.row() == m_mapValues) | |
143 | if (m_mapValues == m_mapLabels) |
|
143 | if (m_mapValues == m_mapLabels) | |
144 | { |
|
144 | { | |
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
147 | } |
|
147 | } | |
148 | else |
|
148 | else | |
149 | { |
|
149 | { | |
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
151 | } |
|
151 | } | |
152 | else if (topLeft.row() == m_mapLabels) |
|
152 | else if (topLeft.row() == m_mapLabels) | |
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
158 | { |
|
158 | { | |
159 | Q_UNUSED(parent) |
|
159 | Q_UNUSED(parent) | |
160 | Q_UNUSED(end) |
|
160 | Q_UNUSED(end) | |
161 | Q_Q(QPieSeries); |
|
161 | Q_Q(QPieSeries); | |
162 |
|
162 | |||
163 | QPieSlice* newSlice = new QPieSlice; |
|
163 | QPieSlice* newSlice = new QPieSlice; | |
164 | newSlice->setLabelVisible(true); |
|
164 | newSlice->setLabelVisible(true); | |
165 | if (m_mapOrientation == Qt::Vertical) |
|
165 | if (m_mapOrientation == Qt::Vertical) | |
166 | { |
|
166 | { | |
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); |
|
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); |
|
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
169 | } |
|
169 | } | |
170 | else |
|
170 | else | |
171 | { |
|
171 | { | |
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); |
|
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); |
|
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | q->insert(start, newSlice); |
|
176 | q->insert(start, newSlice); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
180 | { |
|
180 | { | |
181 | Q_UNUSED(parent) |
|
181 | Q_UNUSED(parent) | |
182 | Q_UNUSED(end) |
|
182 | Q_UNUSED(end) | |
183 | Q_Q(QPieSeries); |
|
183 | Q_Q(QPieSeries); | |
184 | q->remove(m_slices.at(start)); |
|
184 | q->remove(m_slices.at(start)); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) |
|
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
188 | { |
|
188 | { | |
189 | // Remove rounding errors |
|
189 | // Remove rounding errors | |
190 | qreal roundedValue = newValue; |
|
190 | qreal roundedValue = newValue; | |
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) |
|
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
192 | roundedValue = 0.0; |
|
192 | roundedValue = 0.0; | |
193 | else if (qFuzzyCompare(newValue, max)) |
|
193 | else if (qFuzzyCompare(newValue, max)) | |
194 | roundedValue = max; |
|
194 | roundedValue = max; | |
195 | else if (qFuzzyCompare(newValue, min)) |
|
195 | else if (qFuzzyCompare(newValue, min)) | |
196 | roundedValue = min; |
|
196 | roundedValue = min; | |
197 |
|
197 | |||
198 | // Check if the position is valid after removing the rounding errors |
|
198 | // Check if the position is valid after removing the rounding errors | |
199 | if (roundedValue < min || roundedValue > max) { |
|
199 | if (roundedValue < min || roundedValue > max) { | |
200 | qWarning("QPieSeries: Illegal value"); |
|
200 | qWarning("QPieSeries: Illegal value"); | |
201 | return false; |
|
201 | return false; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | if (!qFuzzyIsNull(value - roundedValue)) { |
|
204 | if (!qFuzzyIsNull(value - roundedValue)) { | |
205 | value = roundedValue; |
|
205 | value = roundedValue; | |
206 | return true; |
|
206 | return true; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | // The change was so small it is considered a rounding error |
|
209 | // The change was so small it is considered a rounding error | |
210 | return false; |
|
210 | return false; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 |
|
213 | |||
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | \class QPieSeries |
|
216 | \class QPieSeries | |
217 | \brief Pie series API for QtCommercial Charts |
|
217 | \brief Pie series API for QtCommercial Charts | |
218 |
|
218 | |||
219 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
219 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
220 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
220 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
221 | The actual slice size is determined by that relative value. |
|
221 | The actual slice size is determined by that relative value. | |
222 |
|
222 | |||
223 | By default the pie is defined as a full pie but it can be a partial pie. |
|
223 | By default the pie is defined as a full pie but it can be a partial pie. | |
224 | This can be done by setting a starting angle and angle span to the series. |
|
224 | This can be done by setting a starting angle and angle span to the series. | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Constructs a series object which is a child of \a parent. |
|
228 | Constructs a series object which is a child of \a parent. | |
229 | */ |
|
229 | */ | |
230 | QPieSeries::QPieSeries(QObject *parent) : |
|
230 | QPieSeries::QPieSeries(QObject *parent) : | |
231 | QSeries(parent), |
|
231 | QSeries(parent), | |
232 | d_ptr(new QPieSeriesPrivate(this)) |
|
232 | d_ptr(new QPieSeriesPrivate(this)) | |
233 | { |
|
233 | { | |
234 |
|
234 | |||
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
238 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
239 | */ |
|
239 | */ | |
240 | QPieSeries::~QPieSeries() |
|
240 | QPieSeries::~QPieSeries() | |
241 | { |
|
241 | { | |
242 | // NOTE: d_prt destroyed by QObject |
|
242 | // NOTE: d_prt destroyed by QObject | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | /*! |
|
245 | /*! | |
246 | Returns QChartSeries::SeriesTypePie. |
|
246 | Returns QChartSeries::SeriesTypePie. | |
247 | */ |
|
247 | */ | |
248 | QSeries::QSeriesType QPieSeries::type() const |
|
248 | QSeries::QSeriesType QPieSeries::type() const | |
249 | { |
|
249 | { | |
250 | return QSeries::SeriesTypePie; |
|
250 | return QSeries::SeriesTypePie; | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Sets an array of \a slices to the series replacing the existing slices. |
|
254 | Sets an array of \a slices to the series replacing the existing slices. | |
255 | Slice ownership is passed to the series. |
|
255 | Slice ownership is passed to the series. | |
256 | */ |
|
256 | */ | |
257 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
257 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
258 | { |
|
258 | { | |
259 | clear(); |
|
259 | clear(); | |
260 | append(slices); |
|
260 | append(slices); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | /*! |
|
263 | /*! | |
264 | Adds an array of \a slices to the series. |
|
264 | Adds an array of \a slices to the series. | |
265 | Slice ownership is passed to the series. |
|
265 | Slice ownership is passed to the series. | |
266 | */ |
|
266 | */ | |
267 | void QPieSeries::append(QList<QPieSlice*> slices) |
|
267 | void QPieSeries::append(QList<QPieSlice*> slices) | |
268 | { |
|
268 | { | |
269 | Q_D(QPieSeries); |
|
269 | Q_D(QPieSeries); | |
270 |
|
270 | |||
271 | foreach (QPieSlice* s, slices) { |
|
271 | foreach (QPieSlice* s, slices) { | |
272 | s->setParent(this); |
|
272 | s->setParent(this); | |
273 | d->m_slices << s; |
|
273 | d->m_slices << s; | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | d->updateDerivativeData(); |
|
276 | d->updateDerivativeData(); | |
277 |
|
277 | |||
278 | foreach (QPieSlice* s, slices) { |
|
278 | foreach (QPieSlice* s, slices) { | |
279 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
279 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
280 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
280 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
281 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
281 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
282 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
282 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | emit added(slices); |
|
285 | emit added(slices); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Adds a single \a slice to the series. |
|
289 | Adds a single \a slice to the series. | |
290 | Slice ownership is passed to the series. |
|
290 | Slice ownership is passed to the series. | |
291 | */ |
|
291 | */ | |
292 | void QPieSeries::append(QPieSlice* slice) |
|
292 | void QPieSeries::append(QPieSlice* slice) | |
293 | { |
|
293 | { | |
294 | append(QList<QPieSlice*>() << slice); |
|
294 | append(QList<QPieSlice*>() << slice); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Adds a single \a slice to the series and returns a reference to the series. |
|
298 | Adds a single \a slice to the series and returns a reference to the series. | |
299 | Slice ownership is passed to the series. |
|
299 | Slice ownership is passed to the series. | |
300 | */ |
|
300 | */ | |
301 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
301 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
302 | { |
|
302 | { | |
303 | append(slice); |
|
303 | append(slice); | |
304 | return *this; |
|
304 | return *this; | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Appends a single slice to the series with give \a value and \a name. |
|
309 | Appends a single slice to the series with give \a value and \a name. | |
310 | Slice ownership is passed to the series. |
|
310 | Slice ownership is passed to the series. | |
311 | */ |
|
311 | */ | |
312 | QPieSlice* QPieSeries::append(qreal value, QString name) |
|
312 | QPieSlice* QPieSeries::append(qreal value, QString name) | |
313 | { |
|
313 | { | |
314 | QPieSlice* slice = new QPieSlice(value, name); |
|
314 | QPieSlice* slice = new QPieSlice(value, name); | |
315 | append(slice); |
|
315 | append(slice); | |
316 | return slice; |
|
316 | return slice; | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | /*! |
|
319 | /*! | |
320 | Inserts a single \a slice to the series before the slice at \a index position. |
|
320 | Inserts a single \a slice to the series before the slice at \a index position. | |
321 | Slice ownership is passed to the series. |
|
321 | Slice ownership is passed to the series. | |
322 | */ |
|
322 | */ | |
323 | void QPieSeries::insert(int index, QPieSlice* slice) |
|
323 | void QPieSeries::insert(int index, QPieSlice* slice) | |
324 | { |
|
324 | { | |
325 | Q_D(QPieSeries); |
|
325 | Q_D(QPieSeries); | |
326 | Q_ASSERT(index <= d->m_slices.count()); |
|
326 | Q_ASSERT(index <= d->m_slices.count()); | |
327 | slice->setParent(this); |
|
327 | slice->setParent(this); | |
328 | d->m_slices.insert(index, slice); |
|
328 | d->m_slices.insert(index, slice); | |
329 |
|
329 | |||
330 | d->updateDerivativeData(); |
|
330 | d->updateDerivativeData(); | |
331 |
|
331 | |||
332 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
332 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
333 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
333 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
334 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
334 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
335 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
335 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
336 |
|
336 | |||
337 | emit added(QList<QPieSlice*>() << slice); |
|
337 | emit added(QList<QPieSlice*>() << slice); | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Removes a single \a slice from the series and deletes the slice. |
|
341 | Removes a single \a slice from the series and deletes the slice. | |
342 |
|
342 | |||
343 | Do not reference this pointer after this call. |
|
343 | Do not reference this pointer after this call. | |
344 | */ |
|
344 | */ | |
345 | void QPieSeries::remove(QPieSlice* slice) |
|
345 | void QPieSeries::remove(QPieSlice* slice) | |
346 | { |
|
346 | { | |
347 | Q_D(QPieSeries); |
|
347 | Q_D(QPieSeries); | |
348 | if (!d->m_slices.removeOne(slice)) { |
|
348 | if (!d->m_slices.removeOne(slice)) { | |
349 | Q_ASSERT(0); // TODO: how should this be reported? |
|
349 | Q_ASSERT(0); // TODO: how should this be reported? | |
350 | return; |
|
350 | return; | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | d->updateDerivativeData(); |
|
353 | d->updateDerivativeData(); | |
354 |
|
354 | |||
355 | emit removed(QList<QPieSlice*>() << slice); |
|
355 | emit removed(QList<QPieSlice*>() << slice); | |
356 |
|
356 | |||
357 | delete slice; |
|
357 | delete slice; | |
358 | slice = 0; |
|
358 | slice = 0; | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | /*! |
|
361 | /*! | |
362 | Clears all slices from the series. |
|
362 | Clears all slices from the series. | |
363 | */ |
|
363 | */ | |
364 | void QPieSeries::clear() |
|
364 | void QPieSeries::clear() | |
365 | { |
|
365 | { | |
366 | Q_D(QPieSeries); |
|
366 | Q_D(QPieSeries); | |
367 | if (d->m_slices.count() == 0) |
|
367 | if (d->m_slices.count() == 0) | |
368 | return; |
|
368 | return; | |
369 |
|
369 | |||
370 | QList<QPieSlice*> slices = d->m_slices; |
|
370 | QList<QPieSlice*> slices = d->m_slices; | |
371 | foreach (QPieSlice* s, d->m_slices) { |
|
371 | foreach (QPieSlice* s, d->m_slices) { | |
372 | d->m_slices.removeOne(s); |
|
372 | d->m_slices.removeOne(s); | |
373 | delete s; |
|
373 | delete s; | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | d->updateDerivativeData(); |
|
376 | d->updateDerivativeData(); | |
377 |
|
377 | |||
378 | emit removed(slices); |
|
378 | emit removed(slices); | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | /*! |
|
381 | /*! | |
382 | Counts the number of the slices in this series. |
|
382 | Counts the number of the slices in this series. | |
383 | */ |
|
383 | */ | |
384 | int QPieSeries::count() const |
|
384 | int QPieSeries::count() const | |
385 | { |
|
385 | { | |
386 | Q_D(const QPieSeries); |
|
386 | Q_D(const QPieSeries); | |
387 | return d->m_slices.count(); |
|
387 | return d->m_slices.count(); | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | /*! |
|
390 | /*! | |
391 | Returns true is the series is empty. |
|
391 | Returns true is the series is empty. | |
392 | */ |
|
392 | */ | |
393 | bool QPieSeries::isEmpty() const |
|
393 | bool QPieSeries::isEmpty() const | |
394 | { |
|
394 | { | |
395 | Q_D(const QPieSeries); |
|
395 | Q_D(const QPieSeries); | |
396 | return d->m_slices.isEmpty(); |
|
396 | return d->m_slices.isEmpty(); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | /*! |
|
399 | /*! | |
400 | Returns a list of slices that belong to this series. |
|
400 | Returns a list of slices that belong to this series. | |
401 | */ |
|
401 | */ | |
402 | QList<QPieSlice*> QPieSeries::slices() const |
|
402 | QList<QPieSlice*> QPieSeries::slices() const | |
403 | { |
|
403 | { | |
404 | Q_D(const QPieSeries); |
|
404 | Q_D(const QPieSeries); | |
405 | return d->m_slices; |
|
405 | return d->m_slices; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Sets the horizontal center position of the pie to \relativePosition. If \relativePosition is |
|
409 | Sets the horizontal center position of the pie to \relativePosition. If \relativePosition is | |
410 | set to 0.0 the pie is drawn on the left side of the chart and if it's set to 1.0 the pie is |
|
410 | set to 0.0 the pie is drawn on the left side of the chart and if it's set to 1.0 the pie is | |
411 | drawn on right side of the chart. The default value 0.5 puts the pie in the middle. |
|
411 | drawn on right side of the chart. The default value 0.5 puts the pie in the middle. | |
412 |
|
412 | |||
413 | \sa setHorizontalPosition(), setPieSize() |
|
413 | \sa setHorizontalPosition(), setPieSize() | |
414 | */ |
|
414 | */ | |
415 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
415 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
416 | { |
|
416 | { | |
417 | Q_D(QPieSeries); |
|
417 | Q_D(QPieSeries); | |
418 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) |
|
418 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) | |
419 | emit piePositionChanged(); |
|
419 | emit piePositionChanged(); | |
420 | } |
|
420 | } | |
421 |
|
421 | |||
422 | /*! |
|
422 | /*! | |
423 | Sets the vertical center position of the pie to \relativePosition. If \relativePosition is |
|
423 | Sets the vertical center position of the pie to \relativePosition. If \relativePosition is | |
424 | set to 0.0 the pie is drawn on the top of the chart and if it's set to 1.0 the pie is drawn |
|
424 | set to 0.0 the pie is drawn on the top of the chart and if it's set to 1.0 the pie is drawn | |
425 | on bottom of the chart. The default value 0.5 puts the pie in the middle. |
|
425 | on bottom of the chart. The default value 0.5 puts the pie in the middle. | |
426 |
|
426 | |||
427 | \sa setVerticalPosition(), setPieSize() |
|
427 | \sa setVerticalPosition(), setPieSize() | |
428 | */ |
|
428 | */ | |
429 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
429 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
430 | { |
|
430 | { | |
431 | Q_D(QPieSeries); |
|
431 | Q_D(QPieSeries); | |
432 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) |
|
432 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) | |
433 | emit piePositionChanged(); |
|
433 | emit piePositionChanged(); | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | /*! |
|
436 | /*! | |
437 | Gets the horizontal position of the pie. |
|
437 | Gets the horizontal position of the pie. | |
438 |
|
438 | |||
439 | The returned value is relative to the chart rectangle where: |
|
439 | The returned value is relative to the chart rectangle where: | |
440 |
|
440 | |||
441 | 0.0 means the absolute left. |
|
441 | 0.0 means the absolute left. | |
442 | 1.0 means the absolute right. |
|
442 | 1.0 means the absolute right. | |
443 |
|
443 | |||
444 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. |
|
444 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. | |
445 |
|
445 | |||
446 | \sa verticalPosition(), setPieSize() |
|
446 | \sa verticalPosition(), setPieSize() | |
447 | */ |
|
447 | */ | |
448 | qreal QPieSeries::horizontalPosition() const |
|
448 | qreal QPieSeries::horizontalPosition() const | |
449 | { |
|
449 | { | |
450 | Q_D(const QPieSeries); |
|
450 | Q_D(const QPieSeries); | |
451 | return d->m_pieRelativeHorPos; |
|
451 | return d->m_pieRelativeHorPos; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | /*! |
|
454 | /*! | |
455 | Gets the vertical position position of the pie. |
|
455 | Gets the vertical position position of the pie. | |
456 |
|
456 | |||
457 | The returned value is relative to the chart rectangle where: |
|
457 | The returned value is relative to the chart rectangle where: | |
458 |
|
458 | |||
459 | 0.0 means the absolute top. |
|
459 | 0.0 means the absolute top. | |
460 | 1.0 means the absolute bottom. |
|
460 | 1.0 means the absolute bottom. | |
461 |
|
461 | |||
462 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. |
|
462 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. | |
463 |
|
463 | |||
464 | \sa horizontalPosition(), setPieSize() |
|
464 | \sa horizontalPosition(), setPieSize() | |
465 | */ |
|
465 | */ | |
466 | qreal QPieSeries::verticalPosition() const |
|
466 | qreal QPieSeries::verticalPosition() const | |
467 | { |
|
467 | { | |
468 | Q_D(const QPieSeries); |
|
468 | Q_D(const QPieSeries); | |
469 | return d->m_pieRelativeVerPos; |
|
469 | return d->m_pieRelativeVerPos; | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | /*! |
|
472 | /*! | |
473 | Sets the relative size of the pie. |
|
473 | Sets the relative size of the pie. | |
474 |
|
474 | |||
475 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
475 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
476 |
|
476 | |||
477 | Default value is 0.7. |
|
477 | Default value is 0.7. | |
478 |
|
478 | |||
479 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
479 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
480 | */ |
|
480 | */ | |
481 | void QPieSeries::setPieSize(qreal relativeSize) |
|
481 | void QPieSeries::setPieSize(qreal relativeSize) | |
482 | { |
|
482 | { | |
483 | Q_D(QPieSeries); |
|
483 | Q_D(QPieSeries); | |
484 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) |
|
484 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) | |
485 | emit pieSizeChanged(); |
|
485 | emit pieSizeChanged(); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | /*! |
|
488 | /*! | |
489 | Gets the relative size of the pie. |
|
489 | Gets the relative size of the pie. | |
490 |
|
490 | |||
491 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
491 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
492 |
|
492 | |||
493 | Default value is 0.7. |
|
493 | Default value is 0.7. | |
494 |
|
494 | |||
495 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
495 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
496 | */ |
|
496 | */ | |
497 | qreal QPieSeries::pieSize() const |
|
497 | qreal QPieSeries::pieSize() const | |
498 | { |
|
498 | { | |
499 | Q_D(const QPieSeries); |
|
499 | Q_D(const QPieSeries); | |
500 | return d->m_pieRelativeSize; |
|
500 | return d->m_pieRelativeSize; | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 |
|
503 | |||
504 | /*! |
|
504 | /*! | |
505 | Sets the end angle of the pie. |
|
505 | Sets the end angle of the pie. | |
506 |
|
506 | |||
507 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
507 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
508 |
|
508 | |||
509 | \a angle must be less than pie end angle. Default value is 0. |
|
509 | \a angle must be less than pie end angle. Default value is 0. | |
510 |
|
510 | |||
511 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
511 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() | |
512 | */ |
|
512 | */ | |
513 | void QPieSeries::setPieStartAngle(qreal angle) |
|
513 | void QPieSeries::setPieStartAngle(qreal angle) | |
514 | { |
|
514 | { | |
515 | Q_D(QPieSeries); |
|
515 | Q_D(QPieSeries); | |
516 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) |
|
516 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) | |
517 | d->updateDerivativeData(); |
|
517 | d->updateDerivativeData(); | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | /*! |
|
520 | /*! | |
521 | Gets the start angle of the pie. |
|
521 | Gets the start angle of the pie. | |
522 |
|
522 | |||
523 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. |
|
523 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. | |
524 |
|
524 | |||
525 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
525 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() | |
526 | */ |
|
526 | */ | |
527 | qreal QPieSeries::pieStartAngle() const |
|
527 | qreal QPieSeries::pieStartAngle() const | |
528 | { |
|
528 | { | |
529 | Q_D(const QPieSeries); |
|
529 | Q_D(const QPieSeries); | |
530 | return d->m_pieStartAngle; |
|
530 | return d->m_pieStartAngle; | |
531 | } |
|
531 | } | |
532 |
|
532 | |||
533 | /*! |
|
533 | /*! | |
534 | Sets the end angle of the pie. |
|
534 | Sets the end angle of the pie. | |
535 |
|
535 | |||
536 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
536 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
537 |
|
537 | |||
538 | \a angle must be greater than start angle. |
|
538 | \a angle must be greater than start angle. | |
539 |
|
539 | |||
540 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
540 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
541 | */ |
|
541 | */ | |
542 | void QPieSeries::setPieEndAngle(qreal angle) |
|
542 | void QPieSeries::setPieEndAngle(qreal angle) | |
543 | { |
|
543 | { | |
544 | Q_D(QPieSeries); |
|
544 | Q_D(QPieSeries); | |
545 |
|
545 | |||
546 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) |
|
546 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) | |
547 | d->updateDerivativeData(); |
|
547 | d->updateDerivativeData(); | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | /*! |
|
550 | /*! | |
551 | Returns the end angle of the pie. |
|
551 | Returns the end angle of the pie. | |
552 |
|
552 | |||
553 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
553 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
554 |
|
554 | |||
555 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
555 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
556 | */ |
|
556 | */ | |
557 | qreal QPieSeries::pieEndAngle() const |
|
557 | qreal QPieSeries::pieEndAngle() const | |
558 | { |
|
558 | { | |
559 | Q_D(const QPieSeries); |
|
559 | Q_D(const QPieSeries); | |
560 | return d->m_pieEndAngle; |
|
560 | return d->m_pieEndAngle; | |
561 | } |
|
561 | } | |
562 |
|
562 | |||
563 | /*! |
|
563 | /*! | |
564 | Sets the all the slice labels \a visible or invisible. |
|
564 | Sets the all the slice labels \a visible or invisible. | |
565 |
|
565 | |||
566 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
566 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
567 | */ |
|
567 | */ | |
568 | void QPieSeries::setLabelsVisible(bool visible) |
|
568 | void QPieSeries::setLabelsVisible(bool visible) | |
569 | { |
|
569 | { | |
570 | Q_D(QPieSeries); |
|
570 | Q_D(QPieSeries); | |
571 | foreach (QPieSlice* s, d->m_slices) |
|
571 | foreach (QPieSlice* s, d->m_slices) | |
572 | s->setLabelVisible(visible); |
|
572 | s->setLabelVisible(visible); | |
573 | } |
|
573 | } | |
574 |
|
574 | |||
575 | /*! |
|
575 | /*! | |
576 | Returns the sum of all slice values in this series. |
|
576 | Returns the sum of all slice values in this series. | |
577 |
|
577 | |||
578 | \sa QPieSlice::value(), QPieSlice::setValue() |
|
578 | \sa QPieSlice::value(), QPieSlice::setValue() | |
579 | */ |
|
579 | */ | |
580 | qreal QPieSeries::total() const |
|
580 | qreal QPieSeries::total() const | |
581 | { |
|
581 | { | |
582 | Q_D(const QPieSeries); |
|
582 | Q_D(const QPieSeries); | |
583 | return d->m_total; |
|
583 | return d->m_total; | |
584 | } |
|
584 | } | |
585 |
|
585 | |||
586 | /*! |
|
586 | /*! | |
587 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
587 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
588 |
|
588 | |||
589 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. |
|
589 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. | |
590 |
|
590 | |||
591 | \sa QPieSlice::clicked() |
|
591 | \sa QPieSlice::clicked() | |
592 | */ |
|
592 | */ | |
593 |
|
593 | |||
594 | /*! |
|
594 | /*! | |
595 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
595 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
596 |
|
596 | |||
597 | This signal is emitted when user has hovered over a \a slice. |
|
597 | This signal is emitted when user has hovered over a \a slice. | |
598 |
|
598 | |||
599 | \sa QPieSlice::hoverEnter() |
|
599 | \sa QPieSlice::hoverEnter() | |
600 | */ |
|
600 | */ | |
601 |
|
601 | |||
602 | /*! |
|
602 | /*! | |
603 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
603 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
604 |
|
604 | |||
605 | This signal is emitted when user has hovered away from a \a slice. |
|
605 | This signal is emitted when user has hovered away from a \a slice. | |
606 |
|
606 | |||
607 | \sa QPieSlice::hoverLeave() |
|
607 | \sa QPieSlice::hoverLeave() | |
608 | */ |
|
608 | */ | |
609 |
|
609 | |||
610 | /*! |
|
610 | /*! | |
611 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
611 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
612 |
|
612 | |||
613 | This signal is emitted when \a slices has been added to the series. |
|
613 | This signal is emitted when \a slices has been added to the series. | |
614 |
|
614 | |||
615 | \sa append(), insert() |
|
615 | \sa append(), insert() | |
616 | */ |
|
616 | */ | |
617 |
|
617 | |||
618 | /*! |
|
618 | /*! | |
619 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
619 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
620 |
|
620 | |||
621 | This signal is emitted when \a slices has been removed from the series. |
|
621 | This signal is emitted when \a slices has been removed from the series. | |
622 |
|
622 | |||
623 | \sa remove(), clear() |
|
623 | \sa remove(), clear() | |
624 | */ |
|
624 | */ | |
625 |
|
625 | |||
626 | /*! |
|
626 | /*! | |
627 | \fn void QPieSeries::piePositionChanged() |
|
627 | \fn void QPieSeries::piePositionChanged() | |
628 |
|
628 | |||
629 | This signal is emitted when pie position has changed. |
|
629 | This signal is emitted when pie position has changed. | |
630 |
|
630 | |||
631 |
\sa |
|
631 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() | |
632 | */ |
|
632 | */ | |
633 |
|
633 | |||
634 | /*! |
|
634 | /*! | |
635 | \fn void QPieSeries::pieSizeChanged() |
|
635 | \fn void QPieSeries::pieSizeChanged() | |
636 |
|
636 | |||
637 | This signal is emitted when pie size has changed. |
|
637 | This signal is emitted when pie size has changed. | |
638 |
|
638 | |||
639 | \sa pieSize(), setPieSize() |
|
639 | \sa pieSize(), setPieSize() | |
640 | */ |
|
640 | */ | |
641 |
|
641 | |||
642 | /*! |
|
642 | /*! | |
643 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) |
|
643 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) | |
644 | Sets the \a model to be used as a data source |
|
644 | Sets the \a model to be used as a data source | |
645 | */ |
|
645 | */ | |
646 | bool QPieSeries::setModel(QAbstractItemModel* model) |
|
646 | bool QPieSeries::setModel(QAbstractItemModel* model) | |
647 | { |
|
647 | { | |
648 | Q_D(QPieSeries); |
|
648 | Q_D(QPieSeries); | |
649 | // disconnect signals from old model |
|
649 | // disconnect signals from old model | |
650 | if(m_model) |
|
650 | if(m_model) | |
651 | { |
|
651 | { | |
652 | disconnect(m_model, 0, this, 0); |
|
652 | disconnect(m_model, 0, this, 0); | |
653 | d->m_mapValues = -1; |
|
653 | d->m_mapValues = -1; | |
654 | d->m_mapLabels = -1; |
|
654 | d->m_mapLabels = -1; | |
655 | d->m_mapOrientation = Qt::Vertical; |
|
655 | d->m_mapOrientation = Qt::Vertical; | |
656 | } |
|
656 | } | |
657 |
|
657 | |||
658 | // set new model |
|
658 | // set new model | |
659 | if(model) |
|
659 | if(model) | |
660 | { |
|
660 | { | |
661 | m_model = model; |
|
661 | m_model = model; | |
662 | return true; |
|
662 | return true; | |
663 | } |
|
663 | } | |
664 | else |
|
664 | else | |
665 | { |
|
665 | { | |
666 | m_model = 0; |
|
666 | m_model = 0; | |
667 | return false; |
|
667 | return false; | |
668 | } |
|
668 | } | |
669 | } |
|
669 | } | |
670 |
|
670 | |||
671 | /*! |
|
671 | /*! | |
672 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
672 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
673 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. |
|
673 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. | |
674 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. |
|
674 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. | |
675 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. |
|
675 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. | |
676 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
676 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
677 | */ |
|
677 | */ | |
678 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
678 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
679 | { |
|
679 | { | |
680 | Q_D(QPieSeries); |
|
680 | Q_D(QPieSeries); | |
681 |
|
681 | |||
682 | if (m_model == 0) |
|
682 | if (m_model == 0) | |
683 | return; |
|
683 | return; | |
684 |
|
684 | |||
685 | d->m_mapValues = modelValuesLine; |
|
685 | d->m_mapValues = modelValuesLine; | |
686 | d->m_mapLabels = modelLabelsLine; |
|
686 | d->m_mapLabels = modelLabelsLine; | |
687 | d->m_mapOrientation = orientation; |
|
687 | d->m_mapOrientation = orientation; | |
688 |
|
688 | |||
689 | // connect the signals |
|
689 | // connect the signals | |
690 | if (d->m_mapOrientation == Qt::Vertical) { |
|
690 | if (d->m_mapOrientation == Qt::Vertical) { | |
691 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
691 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
692 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
692 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
693 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
693 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
694 | } else { |
|
694 | } else { | |
695 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
695 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
696 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
696 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
697 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
697 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
698 | } |
|
698 | } | |
699 |
|
699 | |||
700 | // create the initial slices set |
|
700 | // create the initial slices set | |
701 | if (d->m_mapOrientation == Qt::Vertical) { |
|
701 | if (d->m_mapOrientation == Qt::Vertical) { | |
702 | for (int i = 0; i < m_model->rowCount(); i++) |
|
702 | for (int i = 0; i < m_model->rowCount(); i++) | |
703 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); |
|
703 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
704 | } else { |
|
704 | } else { | |
705 | for (int i = 0; i < m_model->columnCount(); i++) |
|
705 | for (int i = 0; i < m_model->columnCount(); i++) | |
706 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); |
|
706 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
707 | } |
|
707 | } | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | #include "moc_qpieseries.cpp" |
|
710 | #include "moc_qpieseries.cpp" | |
711 | #include "moc_qpieseriesprivate_p.cpp" |
|
711 | #include "moc_qpieseriesprivate_p.cpp" | |
712 |
|
712 | |||
713 | QTCOMMERCIALCHART_END_NAMESPACE |
|
713 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,382 +1,382 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include <QGraphicsScene> |
|
23 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
24 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChart::ChartTheme |
|
29 | \enum QChart::ChartTheme | |
30 |
|
30 | |||
31 | This enum describes the theme used by the chart. |
|
31 | This enum describes the theme used by the chart. | |
32 |
|
32 | |||
33 | \value ChartThemeLight The default theme |
|
33 | \value ChartThemeLight The default theme | |
34 | \value ChartThemeBlueCerulean |
|
34 | \value ChartThemeBlueCerulean | |
35 | \value ChartThemeDark |
|
35 | \value ChartThemeDark | |
36 | \value ChartThemeBrownSand |
|
36 | \value ChartThemeBrownSand | |
37 | \value ChartThemeBlueNcs |
|
37 | \value ChartThemeBlueNcs | |
38 | \value ChartThemeHighContrast |
|
38 | \value ChartThemeHighContrast | |
39 | \value ChartThemeBlueIcy |
|
39 | \value ChartThemeBlueIcy | |
40 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
40 | \value ChartThemeCount Not really a theme; the total count of themes. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \enum QChart::AnimationOption |
|
44 | \enum QChart::AnimationOption | |
45 |
|
45 | |||
46 | For enabling/disabling animations. Defaults to NoAnimation. |
|
46 | For enabling/disabling animations. Defaults to NoAnimation. | |
47 |
|
47 | |||
48 | \value NoAnimation |
|
48 | \value NoAnimation | |
49 | \value GridAxisAnimations |
|
49 | \value GridAxisAnimations | |
50 | \value SeriesAnimations |
|
50 | \value SeriesAnimations | |
51 | \value AllAnimations |
|
51 | \value AllAnimations | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \class QChart |
|
55 | \class QChart | |
56 | \brief QtCommercial chart API. |
|
56 | \brief QtCommercial chart API. | |
57 |
|
57 | |||
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
59 | representation of different types of QChartSeries and other chart related objects like |
|
59 | representation of different types of QChartSeries and other chart related objects like | |
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
61 | convenience class QChartView instead of QChart. |
|
61 | convenience class QChartView instead of QChart. | |
62 | \sa QChartView |
|
62 | \sa QChartView | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
67 | */ |
|
67 | */ | |
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
69 | d_ptr(new QChartPrivate()) |
|
69 | d_ptr(new QChartPrivate()) | |
70 | { |
|
70 | { | |
71 | d_ptr->m_legend = new ScrolledQLegend(this); |
|
71 | d_ptr->m_legend = new ScrolledQLegend(this); | |
72 | d_ptr->m_legend->setVisible(false); |
|
72 | d_ptr->m_legend->setVisible(false); | |
73 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | d_ptr->m_dataset = new ChartDataSet(this); | |
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
75 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
75 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
76 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
77 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
77 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
82 | */ |
|
82 | */ | |
83 | QChart::~QChart() |
|
83 | QChart::~QChart() | |
84 | { |
|
84 | { | |
85 | //delete first presenter , since this is a root of all the graphical items |
|
85 | //delete first presenter , since this is a root of all the graphical items | |
86 | delete d_ptr->m_presenter; |
|
86 | delete d_ptr->m_presenter; | |
87 | d_ptr->m_presenter=0; |
|
87 | d_ptr->m_presenter=0; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
93 | the y axis). |
|
93 | the y axis). | |
94 | */ |
|
94 | */ | |
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
96 | { |
|
96 | { | |
97 | Q_ASSERT(series); |
|
97 | Q_ASSERT(series); | |
98 | d_ptr->m_dataset->addSeries(series, axisY); |
|
98 | d_ptr->m_dataset->addSeries(series, axisY); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | Removes the \a series specified in a perameter from the QChartView. |
|
102 | Removes the \a series specified in a perameter from the QChartView. | |
103 | It releses its ownership of the specified QChartSeries object. |
|
103 | It releses its ownership of the specified QChartSeries object. | |
104 | It does not delete the pointed QChartSeries data object |
|
104 | It does not delete the pointed QChartSeries data object | |
105 | \sa addSeries(), removeAllSeries() |
|
105 | \sa addSeries(), removeAllSeries() | |
106 | */ |
|
106 | */ | |
107 | void QChart::removeSeries(QSeries* series) |
|
107 | void QChart::removeSeries(QSeries* series) | |
108 | { |
|
108 | { | |
109 | Q_ASSERT(series); |
|
109 | Q_ASSERT(series); | |
110 | d_ptr->m_dataset->removeSeries(series); |
|
110 | d_ptr->m_dataset->removeSeries(series); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Removes all the QChartSeries that have been added to the QChartView |
|
114 | Removes all the QChartSeries that have been added to the QChartView | |
115 | It also deletes the pointed QChartSeries data objects |
|
115 | It also deletes the pointed QChartSeries data objects | |
116 | \sa addSeries(), removeSeries() |
|
116 | \sa addSeries(), removeSeries() | |
117 | */ |
|
117 | */ | |
118 | void QChart::removeAllSeries() |
|
118 | void QChart::removeAllSeries() | |
119 | { |
|
119 | { | |
120 | d_ptr->m_dataset->removeAllSeries(); |
|
120 | d_ptr->m_dataset->removeAllSeries(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Sets the \a brush that is used for painting the background of the chart area. |
|
124 | Sets the \a brush that is used for painting the background of the chart area. | |
125 | */ |
|
125 | */ | |
126 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
126 | void QChart::setBackgroundBrush(const QBrush& brush) | |
127 | { |
|
127 | { | |
128 | //TODO: refactor me |
|
128 | //TODO: refactor me | |
129 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
129 | d_ptr->m_presenter->createChartBackgroundItem(); | |
130 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
130 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
131 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
131 | d_ptr->m_presenter->m_backgroundItem->update(); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | QBrush QChart::backgroundBrush() const |
|
134 | QBrush QChart::backgroundBrush() const | |
135 | { |
|
135 | { | |
136 | //TODO: refactor me |
|
136 | //TODO: refactor me | |
137 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
137 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
138 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
138 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | Sets the \a pen that is used for painting the background of the chart area. |
|
142 | Sets the \a pen that is used for painting the background of the chart area. | |
143 | */ |
|
143 | */ | |
144 | void QChart::setBackgroundPen(const QPen& pen) |
|
144 | void QChart::setBackgroundPen(const QPen& pen) | |
145 | { |
|
145 | { | |
146 | //TODO: refactor me |
|
146 | //TODO: refactor me | |
147 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
147 | d_ptr->m_presenter->createChartBackgroundItem(); | |
148 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
148 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
149 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
149 | d_ptr->m_presenter->m_backgroundItem->update(); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | QPen QChart::backgroundPen() const |
|
152 | QPen QChart::backgroundPen() const | |
153 | { |
|
153 | { | |
154 | //TODO: refactor me |
|
154 | //TODO: refactor me | |
155 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
155 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
156 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
156 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Sets the chart \a title. The description text that is drawn above the chart. |
|
160 | Sets the chart \a title. The description text that is drawn above the chart. | |
161 | */ |
|
161 | */ | |
162 | void QChart::setTitle(const QString& title) |
|
162 | void QChart::setTitle(const QString& title) | |
163 | { |
|
163 | { | |
164 | //TODO: refactor me |
|
164 | //TODO: refactor me | |
165 | d_ptr->m_presenter->createChartTitleItem(); |
|
165 | d_ptr->m_presenter->createChartTitleItem(); | |
166 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
166 | d_ptr->m_presenter->m_titleItem->setText(title); | |
167 | d_ptr->m_presenter->updateLayout(); |
|
167 | d_ptr->m_presenter->updateLayout(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Returns the chart title. The description text that is drawn above the chart. |
|
171 | Returns the chart title. The description text that is drawn above the chart. | |
172 | */ |
|
172 | */ | |
173 | QString QChart::title() const |
|
173 | QString QChart::title() const | |
174 | { |
|
174 | { | |
175 | //TODO: refactor me |
|
175 | //TODO: refactor me | |
176 | if (d_ptr->m_presenter->m_titleItem) |
|
176 | if (d_ptr->m_presenter->m_titleItem) | |
177 | return d_ptr->m_presenter->m_titleItem->text(); |
|
177 | return d_ptr->m_presenter->m_titleItem->text(); | |
178 | else |
|
178 | else | |
179 | return QString(); |
|
179 | return QString(); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
183 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
184 | */ |
|
184 | */ | |
185 | void QChart::setTitleFont(const QFont& font) |
|
185 | void QChart::setTitleFont(const QFont& font) | |
186 | { |
|
186 | { | |
187 | //TODO: refactor me |
|
187 | //TODO: refactor me | |
188 | d_ptr->m_presenter->createChartTitleItem(); |
|
188 | d_ptr->m_presenter->createChartTitleItem(); | |
189 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
189 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
190 | d_ptr->m_presenter->updateLayout(); |
|
190 | d_ptr->m_presenter->updateLayout(); | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | QFont QChart::titleFont() const |
|
193 | QFont QChart::titleFont() const | |
194 | { |
|
194 | { | |
195 | if (d_ptr->m_presenter->m_titleItem) |
|
195 | if (d_ptr->m_presenter->m_titleItem) | |
196 | return d_ptr->m_presenter->m_titleItem->font(); |
|
196 | return d_ptr->m_presenter->m_titleItem->font(); | |
197 | else |
|
197 | else | |
198 | return QFont(); |
|
198 | return QFont(); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | Sets the \a brush used for rendering the title text. |
|
202 | Sets the \a brush used for rendering the title text. | |
203 | */ |
|
203 | */ | |
204 | void QChart::setTitleBrush(const QBrush &brush) |
|
204 | void QChart::setTitleBrush(const QBrush &brush) | |
205 | { |
|
205 | { | |
206 | //TODO: refactor me |
|
206 | //TODO: refactor me | |
207 | d_ptr->m_presenter->createChartTitleItem(); |
|
207 | d_ptr->m_presenter->createChartTitleItem(); | |
208 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
208 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
209 | d_ptr->m_presenter->updateLayout(); |
|
209 | d_ptr->m_presenter->updateLayout(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Returns the brush used for rendering the title text. |
|
213 | Returns the brush used for rendering the title text. | |
214 | */ |
|
214 | */ | |
215 | QBrush QChart::titleBrush() const |
|
215 | QBrush QChart::titleBrush() const | |
216 | { |
|
216 | { | |
217 | //TODO: refactor me |
|
217 | //TODO: refactor me | |
218 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
218 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
219 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
219 | return d_ptr->m_presenter->m_titleItem->brush(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
223 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
224 | \sa ChartTheme, chartTheme() |
|
224 | \sa theme() | |
225 | */ |
|
225 | */ | |
226 | void QChart::setTheme(QChart::ChartTheme theme) |
|
226 | void QChart::setTheme(QChart::ChartTheme theme) | |
227 | { |
|
227 | { | |
228 | d_ptr->m_presenter->setTheme(theme); |
|
228 | d_ptr->m_presenter->setTheme(theme); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Returns the theme enum used by the chart. |
|
232 | Returns the theme enum used by the chart. | |
233 |
\sa ChartTheme, set |
|
233 | \sa ChartTheme, setTheme() | |
234 | */ |
|
234 | */ | |
235 | QChart::ChartTheme QChart::theme() const |
|
235 | QChart::ChartTheme QChart::theme() const | |
236 | { |
|
236 | { | |
237 | return d_ptr->m_presenter->theme(); |
|
237 | return d_ptr->m_presenter->theme(); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | Zooms in the view by a factor of 2 |
|
241 | Zooms in the view by a factor of 2 | |
242 | */ |
|
242 | */ | |
243 | void QChart::zoomIn() |
|
243 | void QChart::zoomIn() | |
244 | { |
|
244 | { | |
245 | d_ptr->m_presenter->zoomIn(); |
|
245 | d_ptr->m_presenter->zoomIn(); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
249 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
250 | */ |
|
250 | */ | |
251 | void QChart::zoomIn(const QRectF& rect) |
|
251 | void QChart::zoomIn(const QRectF& rect) | |
252 | { |
|
252 | { | |
253 | if (!rect.isValid()) return; |
|
253 | if (!rect.isValid()) return; | |
254 | d_ptr->m_presenter->zoomIn(rect); |
|
254 | d_ptr->m_presenter->zoomIn(rect); | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | /*! |
|
257 | /*! | |
258 | Restores the view zoom level to the previous one. |
|
258 | Restores the view zoom level to the previous one. | |
259 | */ |
|
259 | */ | |
260 | void QChart::zoomOut() |
|
260 | void QChart::zoomOut() | |
261 | { |
|
261 | { | |
262 | d_ptr->m_presenter->zoomOut(); |
|
262 | d_ptr->m_presenter->zoomOut(); | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | /*! |
|
265 | /*! | |
266 | Returns the pointer to the x axis object of the chart |
|
266 | Returns the pointer to the x axis object of the chart | |
267 | */ |
|
267 | */ | |
268 | QChartAxis* QChart::axisX() const |
|
268 | QChartAxis* QChart::axisX() const | |
269 | { |
|
269 | { | |
270 | return d_ptr->m_dataset->axisX(); |
|
270 | return d_ptr->m_dataset->axisX(); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | /*! |
|
273 | /*! | |
274 | Returns the pointer to the y axis object of the chart |
|
274 | Returns the pointer to the y axis object of the chart | |
275 | */ |
|
275 | */ | |
276 | QChartAxis* QChart::axisY(QSeries* series) const |
|
276 | QChartAxis* QChart::axisY(QSeries* series) const | |
277 | { |
|
277 | { | |
278 | return d_ptr->m_dataset->axisY(series); |
|
278 | return d_ptr->m_dataset->axisY(series); | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | /*! |
|
281 | /*! | |
282 | Returns the legend object of the chart. Ownership stays in chart. |
|
282 | Returns the legend object of the chart. Ownership stays in chart. | |
283 | */ |
|
283 | */ | |
284 | QLegend* QChart::legend() const |
|
284 | QLegend* QChart::legend() const | |
285 | { |
|
285 | { | |
286 | return d_ptr->m_legend; |
|
286 | return d_ptr->m_legend; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | QRectF QChart::margins() const |
|
289 | QRectF QChart::margins() const | |
290 | { |
|
290 | { | |
291 | return d_ptr->m_presenter->margins(); |
|
291 | return d_ptr->m_presenter->margins(); | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 |
|
294 | |||
295 | /*! |
|
295 | /*! | |
296 | Resizes and updates the chart area using the \a event data |
|
296 | Resizes and updates the chart area using the \a event data | |
297 | */ |
|
297 | */ | |
298 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
298 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
299 | { |
|
299 | { | |
300 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
300 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
301 | QGraphicsWidget::resizeEvent(event); |
|
301 | QGraphicsWidget::resizeEvent(event); | |
302 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
302 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | Sets animation \a options for the chart |
|
306 | Sets animation \a options for the chart | |
307 | */ |
|
307 | */ | |
308 | void QChart::setAnimationOptions(AnimationOptions options) |
|
308 | void QChart::setAnimationOptions(AnimationOptions options) | |
309 | { |
|
309 | { | |
310 | d_ptr->m_presenter->setAnimationOptions(options); |
|
310 | d_ptr->m_presenter->setAnimationOptions(options); | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | /*! |
|
313 | /*! | |
314 | Returns animation options for the chart |
|
314 | Returns animation options for the chart | |
315 | */ |
|
315 | */ | |
316 | QChart::AnimationOptions QChart::animationOptions() const |
|
316 | QChart::AnimationOptions QChart::animationOptions() const | |
317 | { |
|
317 | { | |
318 | return d_ptr->m_presenter->animationOptions(); |
|
318 | return d_ptr->m_presenter->animationOptions(); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | void QChart::scrollLeft() |
|
321 | void QChart::scrollLeft() | |
322 | { |
|
322 | { | |
323 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
323 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | void QChart::scrollRight() |
|
326 | void QChart::scrollRight() | |
327 | { |
|
327 | { | |
328 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
328 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | void QChart::scrollUp() |
|
331 | void QChart::scrollUp() | |
332 | { |
|
332 | { | |
333 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
333 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | void QChart::scrollDown() |
|
336 | void QChart::scrollDown() | |
337 | { |
|
337 | { | |
338 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
338 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | void QChart::setBackgroundVisible(bool visible) |
|
341 | void QChart::setBackgroundVisible(bool visible) | |
342 | { |
|
342 | { | |
343 | //TODO: refactor me |
|
343 | //TODO: refactor me | |
344 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
344 | d_ptr->m_presenter->createChartBackgroundItem(); | |
345 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
345 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | bool QChart::isBackgroundVisible() const |
|
348 | bool QChart::isBackgroundVisible() const | |
349 | { |
|
349 | { | |
350 | //TODO: refactor me |
|
350 | //TODO: refactor me | |
351 | if (!d_ptr->m_presenter->m_backgroundItem) return false; |
|
351 | if (!d_ptr->m_presenter->m_backgroundItem) return false; | |
352 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
352 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
356 |
|
356 | |||
357 | QChartPrivate::QChartPrivate(): |
|
357 | QChartPrivate::QChartPrivate(): | |
358 | m_legend(0), |
|
358 | m_legend(0), | |
359 | m_dataset(0), |
|
359 | m_dataset(0), | |
360 | m_presenter(0) |
|
360 | m_presenter(0) | |
361 | { |
|
361 | { | |
362 |
|
362 | |||
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | QChartPrivate::~QChartPrivate() |
|
365 | QChartPrivate::~QChartPrivate() | |
366 | { |
|
366 | { | |
367 |
|
367 | |||
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | void QChartPrivate::createConnections() |
|
370 | void QChartPrivate::createConnections() | |
371 | { |
|
371 | { | |
372 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
372 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
373 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
373 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
374 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
374 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
375 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); |
|
375 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); | |
376 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
376 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
377 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); |
|
377 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | #include "moc_qchart.cpp" |
|
380 | #include "moc_qchart.cpp" | |
381 |
|
381 | |||
382 | QTCOMMERCIALCHART_END_NAMESPACE |
|
382 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,246 +1,249 | |||||
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 "qchartview.h" |
|
21 | #include "qchartview.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qchartview_p.h" |
|
23 | #include "qchartview_p.h" | |
24 | #include <QGraphicsScene> |
|
24 | #include <QGraphicsScene> | |
25 | #include <QRubberBand> |
|
25 | #include <QRubberBand> | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChartView::RubberBandPolicy |
|
29 | \enum QChartView::RubberBandPolicy | |
30 |
|
30 | |||
31 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
31 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
32 |
|
32 | |||
33 | \value NoRubberBand |
|
33 | \value NoRubberBand | |
34 | \value VerticalRubberBand |
|
34 | \value VerticalRubberBand | |
35 | \value HorizonalRubberBand |
|
35 | \value HorizonalRubberBand | |
36 | \value RectangleRubberBand |
|
36 | \value RectangleRubberBand | |
37 | */ |
|
37 | */ | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \class QChartView |
|
40 | \class QChartView | |
41 | \brief Standalone charting widget. |
|
41 | \brief Standalone charting widget. | |
42 |
|
42 | |||
43 | QChartView is a standalone widget that can display charts. It does not require separate |
|
43 | QChartView is a standalone widget that can display charts. It does not require separate | |
44 | QGraphicsScene to work. It manages the graphical representation of different types of |
|
44 | QGraphicsScene to work. It manages the graphical representation of different types of | |
45 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to |
|
45 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to | |
46 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
46 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
47 |
|
47 | |||
48 | \sa QChart |
|
48 | \sa QChart | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | Constructs a chartView object which is a child of a\a parent. |
|
54 | Constructs a chartView object which is a child of a\a parent. | |
55 | */ |
|
55 | */ | |
56 | QChartView::QChartView(QChart *chart,QWidget *parent) : |
|
56 | QChartView::QChartView(QChart *chart,QWidget *parent) : | |
57 | QGraphicsView(parent), |
|
57 | QGraphicsView(parent), | |
58 | d_ptr(new QChartViewPrivate()) |
|
58 | d_ptr(new QChartViewPrivate()) | |
59 | { |
|
59 | { | |
60 | Q_ASSERT(chart); |
|
60 | Q_ASSERT(chart); | |
61 | d_ptr->m_scene = new QGraphicsScene(this); |
|
61 | d_ptr->m_scene = new QGraphicsScene(this); | |
62 | d_ptr->m_chart = chart; |
|
62 | d_ptr->m_chart = chart; | |
63 | setFrameShape(QFrame::NoFrame); |
|
63 | setFrameShape(QFrame::NoFrame); | |
64 | setBackgroundRole(QPalette::Window); |
|
64 | setBackgroundRole(QPalette::Window); | |
65 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
65 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
66 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
66 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
67 | setScene(d_ptr->m_scene); |
|
67 | setScene(d_ptr->m_scene); | |
68 | d_ptr->m_scene->addItem(chart); |
|
68 | d_ptr->m_scene->addItem(chart); | |
69 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
69 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
74 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
75 | */ |
|
75 | */ | |
76 | QChartView::~QChartView() |
|
76 | QChartView::~QChartView() | |
77 | { |
|
77 | { | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
|
80 | /*! | |||
|
81 | Returns the pointer to the associated chart | |||
|
82 | */ | |||
80 | QChart* QChartView::chart() const |
|
83 | QChart* QChartView::chart() const | |
81 | { |
|
84 | { | |
82 | return d_ptr->m_chart; |
|
85 | return d_ptr->m_chart; | |
83 | } |
|
86 | } | |
84 |
|
87 | |||
85 | /*! |
|
88 | /*! | |
86 |
Sets the RubberBandPlicy to \a |
|
89 | Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed. | |
87 | */ |
|
90 | */ | |
88 | void QChartView::setRubberBand(const RubberBands& rubberBand) |
|
91 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
89 | { |
|
92 | { | |
90 | d_ptr->m_rubberBandFlags=rubberBand; |
|
93 | d_ptr->m_rubberBandFlags=rubberBand; | |
91 |
|
94 | |||
92 | if (!d_ptr->m_rubberBandFlags) { |
|
95 | if (!d_ptr->m_rubberBandFlags) { | |
93 | delete d_ptr->m_rubberBand; |
|
96 | delete d_ptr->m_rubberBand; | |
94 | d_ptr->m_rubberBand=0; |
|
97 | d_ptr->m_rubberBand=0; | |
95 | return; |
|
98 | return; | |
96 | } |
|
99 | } | |
97 |
|
100 | |||
98 | if (!d_ptr->m_rubberBand) { |
|
101 | if (!d_ptr->m_rubberBand) { | |
99 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
102 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
100 | d_ptr->m_rubberBand->setEnabled(true); |
|
103 | d_ptr->m_rubberBand->setEnabled(true); | |
101 | } |
|
104 | } | |
102 | } |
|
105 | } | |
103 |
|
106 | |||
104 | /*! |
|
107 | /*! | |
105 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
108 | Returns the RubberBandPolicy that is currently being used by the widget. | |
106 | */ |
|
109 | */ | |
107 | QChartView::RubberBands QChartView::rubberBand() const |
|
110 | QChartView::RubberBands QChartView::rubberBand() const | |
108 | { |
|
111 | { | |
109 | return d_ptr->m_rubberBandFlags; |
|
112 | return d_ptr->m_rubberBandFlags; | |
110 | } |
|
113 | } | |
111 |
|
114 | |||
112 | /*! |
|
115 | /*! | |
113 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. |
|
116 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
114 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. |
|
117 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
115 | */ |
|
118 | */ | |
116 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
119 | void QChartView::mousePressEvent(QMouseEvent *event) | |
117 | { |
|
120 | { | |
118 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
121 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
119 |
|
122 | |||
120 | int padding = d_ptr->m_chart->margins().top(); |
|
123 | int padding = d_ptr->m_chart->margins().top(); | |
121 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
124 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
122 |
|
125 | |||
123 | if (rect.contains(event->pos())) { |
|
126 | if (rect.contains(event->pos())) { | |
124 | d_ptr->m_rubberBandOrigin = event->pos(); |
|
127 | d_ptr->m_rubberBandOrigin = event->pos(); | |
125 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); |
|
128 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
126 | d_ptr->m_rubberBand->show(); |
|
129 | d_ptr->m_rubberBand->show(); | |
127 | event->accept(); |
|
130 | event->accept(); | |
128 | } |
|
131 | } | |
129 | } |
|
132 | } | |
130 | else { |
|
133 | else { | |
131 | QGraphicsView::mousePressEvent(event); |
|
134 | QGraphicsView::mousePressEvent(event); | |
132 | } |
|
135 | } | |
133 | } |
|
136 | } | |
134 |
|
137 | |||
135 | /*! |
|
138 | /*! | |
136 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
139 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
137 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
140 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
138 | */ |
|
141 | */ | |
139 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
142 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
140 | { |
|
143 | { | |
141 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
144 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
142 | QRectF margins = d_ptr->m_chart->margins(); |
|
145 | QRectF margins = d_ptr->m_chart->margins(); | |
143 | QRectF geometry = d_ptr->m_chart->geometry(); |
|
146 | QRectF geometry = d_ptr->m_chart->geometry(); | |
144 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); |
|
147 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); | |
145 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
148 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
146 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); |
|
149 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
147 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { |
|
150 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
148 | d_ptr->m_rubberBandOrigin.setY(rect.top()); |
|
151 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
149 | height = rect.height(); |
|
152 | height = rect.height(); | |
150 | } |
|
153 | } | |
151 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { |
|
154 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
152 | d_ptr->m_rubberBandOrigin.setX(rect.left()); |
|
155 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
153 | width= rect.width(); |
|
156 | width= rect.width(); | |
154 | } |
|
157 | } | |
155 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); |
|
158 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); | |
156 | } |
|
159 | } | |
157 | else { |
|
160 | else { | |
158 | QGraphicsView::mouseMoveEvent(event); |
|
161 | QGraphicsView::mouseMoveEvent(event); | |
159 | } |
|
162 | } | |
160 | } |
|
163 | } | |
161 |
|
164 | |||
162 | /*! |
|
165 | /*! | |
163 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand |
|
166 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
164 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
167 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
165 | */ |
|
168 | */ | |
166 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
169 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
167 | { |
|
170 | { | |
168 | if(d_ptr->m_rubberBand) { |
|
171 | if(d_ptr->m_rubberBand) { | |
169 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { |
|
172 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
170 | d_ptr->m_rubberBand->hide(); |
|
173 | d_ptr->m_rubberBand->hide(); | |
171 | QRect rect = d_ptr->m_rubberBand->geometry(); |
|
174 | QRect rect = d_ptr->m_rubberBand->geometry(); | |
172 | d_ptr->m_chart->zoomIn(rect); |
|
175 | d_ptr->m_chart->zoomIn(rect); | |
173 | event->accept(); |
|
176 | event->accept(); | |
174 | } |
|
177 | } | |
175 |
|
178 | |||
176 | if(event->button()==Qt::RightButton){ |
|
179 | if(event->button()==Qt::RightButton){ | |
177 | d_ptr->m_chart->zoomOut(); |
|
180 | d_ptr->m_chart->zoomOut(); | |
178 | event->accept(); |
|
181 | event->accept(); | |
179 | } |
|
182 | } | |
180 | } |
|
183 | } | |
181 | else { |
|
184 | else { | |
182 | QGraphicsView::mouseReleaseEvent(event); |
|
185 | QGraphicsView::mouseReleaseEvent(event); | |
183 | } |
|
186 | } | |
184 | } |
|
187 | } | |
185 |
|
188 | |||
186 | /*! |
|
189 | /*! | |
187 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
190 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
188 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
191 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
189 | */ |
|
192 | */ | |
190 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
193 | void QChartView::keyPressEvent(QKeyEvent *event) | |
191 | { |
|
194 | { | |
192 | switch (event->key()) { |
|
195 | switch (event->key()) { | |
193 | case Qt::Key_Plus: |
|
196 | case Qt::Key_Plus: | |
194 | d_ptr->m_chart->zoomIn(); |
|
197 | d_ptr->m_chart->zoomIn(); | |
195 | break; |
|
198 | break; | |
196 | case Qt::Key_Minus: |
|
199 | case Qt::Key_Minus: | |
197 | d_ptr->m_chart->zoomOut(); |
|
200 | d_ptr->m_chart->zoomOut(); | |
198 | break; |
|
201 | break; | |
199 | case Qt::Key_Left: |
|
202 | case Qt::Key_Left: | |
200 | d_ptr->m_chart->scrollLeft(); |
|
203 | d_ptr->m_chart->scrollLeft(); | |
201 | break; |
|
204 | break; | |
202 | case Qt::Key_Right: |
|
205 | case Qt::Key_Right: | |
203 | d_ptr->m_chart->scrollRight(); |
|
206 | d_ptr->m_chart->scrollRight(); | |
204 | break; |
|
207 | break; | |
205 | case Qt::Key_Up: |
|
208 | case Qt::Key_Up: | |
206 | d_ptr->m_chart->scrollUp(); |
|
209 | d_ptr->m_chart->scrollUp(); | |
207 | break; |
|
210 | break; | |
208 | case Qt::Key_Down: |
|
211 | case Qt::Key_Down: | |
209 | d_ptr->m_chart->scrollDown(); |
|
212 | d_ptr->m_chart->scrollDown(); | |
210 | break; |
|
213 | break; | |
211 | default: |
|
214 | default: | |
212 | QGraphicsView::keyPressEvent(event); |
|
215 | QGraphicsView::keyPressEvent(event); | |
213 | break; |
|
216 | break; | |
214 | } |
|
217 | } | |
215 | } |
|
218 | } | |
216 |
|
219 | |||
217 | /*! |
|
220 | /*! | |
218 | Resizes and updates the chart area using the \a event data |
|
221 | Resizes and updates the chart area using the \a event data | |
219 | */ |
|
222 | */ | |
220 | void QChartView::resizeEvent(QResizeEvent *event) |
|
223 | void QChartView::resizeEvent(QResizeEvent *event) | |
221 | { |
|
224 | { | |
222 | QGraphicsView::resizeEvent(event); |
|
225 | QGraphicsView::resizeEvent(event); | |
223 | d_ptr->m_chart->resize(size()); |
|
226 | d_ptr->m_chart->resize(size()); | |
224 | setSceneRect(d_ptr->m_chart->geometry()); |
|
227 | setSceneRect(d_ptr->m_chart->geometry()); | |
225 | } |
|
228 | } | |
226 |
|
229 | |||
227 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
230 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
228 |
|
231 | |||
229 | QChartViewPrivate::QChartViewPrivate(): |
|
232 | QChartViewPrivate::QChartViewPrivate(): | |
230 | m_scene(0), |
|
233 | m_scene(0), | |
231 | m_chart(0), |
|
234 | m_chart(0), | |
232 | m_presenter(0), |
|
235 | m_presenter(0), | |
233 | m_rubberBand(0), |
|
236 | m_rubberBand(0), | |
234 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
237 | m_rubberBandFlags(QChartView::NoRubberBand) | |
235 | { |
|
238 | { | |
236 |
|
239 | |||
237 | } |
|
240 | } | |
238 |
|
241 | |||
239 | QChartViewPrivate::~QChartViewPrivate() |
|
242 | QChartViewPrivate::~QChartViewPrivate() | |
240 | { |
|
243 | { | |
241 |
|
244 | |||
242 | } |
|
245 | } | |
243 |
|
246 | |||
244 | #include "moc_qchartview.cpp" |
|
247 | #include "moc_qchartview.cpp" | |
245 |
|
248 | |||
246 | QTCOMMERCIALCHART_END_NAMESPACE |
|
249 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,559 +1,557 | |||||
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 "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include <QAbstractItemModel> |
|
22 | #include <QAbstractItemModel> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QXYSeries |
|
27 | \class QXYSeries | |
28 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
28 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
29 | */ |
|
29 | */ | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \fn QPen QXYSeries::pen() const |
|
32 | \fn QPen QXYSeries::pen() const | |
33 | \brief Returns pen used to draw points for series. |
|
33 | \brief Returns pen used to draw points for series. | |
34 | \sa setPen() |
|
34 | \sa setPen() | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \fn QBrush QXYSeries::brush() const |
|
38 | \fn QBrush QXYSeries::brush() const | |
39 | \brief Returns brush used to draw points for series. |
|
39 | \brief Returns brush used to draw points for series. | |
40 | \sa setBrush() |
|
40 | \sa setBrush() | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \fn void QXYSeries::clicked(const QPointF& point) |
|
44 | \fn void QXYSeries::clicked(const QPointF& point) | |
45 | \brief Signal is emitted when user clicks the \a point on chart. |
|
45 | \brief Signal is emitted when user clicks the \a point on chart. | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn void QXYSeries::pointReplaced(int index) |
|
49 | \fn void QXYSeries::pointReplaced(int index) | |
50 | \brief \internal \a index |
|
50 | \brief \internal \a index | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \fn void QXYSeries::pointAdded(int index) |
|
54 | \fn void QXYSeries::pointAdded(int index) | |
55 | \brief \internal \a index |
|
55 | \brief \internal \a index | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QXYSeries::pointRemoved(int index) |
|
59 | \fn void QXYSeries::pointRemoved(int index) | |
60 | \brief \internal \a index |
|
60 | \brief \internal \a index | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \fn void QXYSeries::updated() |
|
64 | \fn void QXYSeries::updated() | |
65 | \brief \internal |
|
65 | \brief \internal | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \fn int QXYSeries::mapFirst() const |
|
69 | \fn int QXYSeries::mapFirst() const | |
70 | Returns the index of the model's item that is used as a first one for the series. |
|
70 | Returns the index of the model's item that is used as a first one for the series. | |
71 | \sa mapCount() |
|
71 | \sa mapCount() | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \fn int QXYSeries::mapCount() const |
|
75 | \fn int QXYSeries::mapCount() const | |
76 | Returns the number of the items that are taken from the model. |
|
76 | Returns the number of the items that are taken from the model. | |
77 | If -1 it means all the items of the model following the first one are used. |
|
77 | If -1 it means all the items of the model following the first one are used. | |
78 | \sa mapFirst() |
|
78 | \sa mapFirst() | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Constructs empty series object which is a child of \a parent. |
|
82 | Constructs empty series object which is a child of \a parent. | |
83 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
83 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
84 | */ |
|
84 | */ | |
85 | QXYSeries::QXYSeries(QObject *parent):QSeries(parent) |
|
85 | QXYSeries::QXYSeries(QObject *parent):QSeries(parent) | |
86 | { |
|
86 | { | |
87 | m_mapX = -1; |
|
87 | m_mapX = -1; | |
88 | m_mapY = -1; |
|
88 | m_mapY = -1; | |
89 | m_mapFirst = 0; |
|
89 | m_mapFirst = 0; | |
90 | m_mapCount = 0; |
|
90 | m_mapCount = 0; | |
91 | m_mapLimited = false; |
|
91 | m_mapLimited = false; | |
92 | m_mapOrientation = Qt::Vertical; |
|
92 | m_mapOrientation = Qt::Vertical; | |
93 | // m_mapYOrientation = Qt::Vertical; |
|
93 | // m_mapYOrientation = Qt::Vertical; | |
94 | } |
|
94 | } | |
95 | /*! |
|
95 | /*! | |
96 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
96 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
97 | and are deleted when mentioned object are destroyed. |
|
97 | and are deleted when mentioned object are destroyed. | |
98 | */ |
|
98 | */ | |
99 | QXYSeries::~QXYSeries() |
|
99 | QXYSeries::~QXYSeries() | |
100 | { |
|
100 | { | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
104 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
105 | */ |
|
105 | */ | |
106 | void QXYSeries::append(qreal x,qreal y) |
|
106 | void QXYSeries::append(qreal x,qreal y) | |
107 | { |
|
107 | { | |
108 | Q_ASSERT(m_x.size() == m_y.size()); |
|
108 | Q_ASSERT(m_x.size() == m_y.size()); | |
109 | m_x<<x; |
|
109 | m_x<<x; | |
110 | m_y<<y; |
|
110 | m_y<<y; | |
111 | emit pointAdded(m_x.size()-1); |
|
111 | emit pointAdded(m_x.size()-1); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | This is an overloaded function. |
|
115 | This is an overloaded function. | |
116 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
116 | Adds data \a point to the series. Points are connected with lines on the chart. | |
117 | */ |
|
117 | */ | |
118 | void QXYSeries::append(const QPointF &point) |
|
118 | void QXYSeries::append(const QPointF &point) | |
119 | { |
|
119 | { | |
120 | append(point.x(),point.y()); |
|
120 | append(point.x(),point.y()); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | This is an overloaded function. |
|
124 | This is an overloaded function. | |
125 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
125 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
126 | */ |
|
126 | */ | |
127 | void QXYSeries::append(const QList<QPointF> points) |
|
127 | void QXYSeries::append(const QList<QPointF> points) | |
128 | { |
|
128 | { | |
129 | foreach(const QPointF& point , points) { |
|
129 | foreach(const QPointF& point , points) { | |
130 | append(point.x(),point.y()); |
|
130 | append(point.x(),point.y()); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Modifies \a y value for given \a x a value. |
|
135 | Modifies \a y value for given \a x a value. | |
136 | */ |
|
136 | */ | |
137 | void QXYSeries::replace(qreal x,qreal y) |
|
137 | void QXYSeries::replace(qreal x,qreal y) | |
138 | { |
|
138 | { | |
139 | int index = m_x.indexOf(x); |
|
139 | int index = m_x.indexOf(x); | |
140 | m_x[index] = x; |
|
140 | m_x[index] = x; | |
141 | m_y[index] = y; |
|
141 | m_y[index] = y; | |
142 | emit pointReplaced(index); |
|
142 | emit pointReplaced(index); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | This is an overloaded function. |
|
146 | This is an overloaded function. | |
147 | Replaces current y value of for given \a point x value with \a point y value. |
|
147 | Replaces current y value of for given \a point x value with \a point y value. | |
148 | */ |
|
148 | */ | |
149 | void QXYSeries::replace(const QPointF &point) |
|
149 | void QXYSeries::replace(const QPointF &point) | |
150 | { |
|
150 | { | |
151 | replace(point.x(),point.y()); |
|
151 | replace(point.x(),point.y()); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | Removes first \a x value and related y value. |
|
155 | Removes first \a x value and related y value. | |
156 | */ |
|
156 | */ | |
157 | void QXYSeries::remove(qreal x) |
|
157 | void QXYSeries::remove(qreal x) | |
158 | { |
|
158 | { | |
159 | int index = m_x.indexOf(x); |
|
159 | int index = m_x.indexOf(x); | |
160 |
|
160 | |||
161 | if (index == -1) return; |
|
161 | if (index == -1) return; | |
162 |
|
162 | |||
163 | m_x.remove(index); |
|
163 | m_x.remove(index); | |
164 | m_y.remove(index); |
|
164 | m_y.remove(index); | |
165 |
|
165 | |||
166 | emit pointRemoved(index); |
|
166 | emit pointRemoved(index); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | Removes current \a x and \a y value. |
|
170 | Removes current \a x and \a y value. | |
171 | */ |
|
171 | */ | |
172 | void QXYSeries::remove(qreal x,qreal y) |
|
172 | void QXYSeries::remove(qreal x,qreal y) | |
173 | { |
|
173 | { | |
174 | int index =-1; |
|
174 | int index =-1; | |
175 | do { |
|
175 | do { | |
176 | index = m_x.indexOf(x,index+1); |
|
176 | index = m_x.indexOf(x,index+1); | |
177 | } while (index !=-1 && m_y.at(index)!=y); |
|
177 | } while (index !=-1 && m_y.at(index)!=y); | |
178 |
|
178 | |||
179 | if (index==-1) return; |
|
179 | if (index==-1) return; | |
180 |
|
180 | |||
181 | m_x.remove(index); |
|
181 | m_x.remove(index); | |
182 | m_y.remove(index); |
|
182 | m_y.remove(index); | |
183 | emit pointRemoved(index); |
|
183 | emit pointRemoved(index); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | Removes current \a point x value. Note \a point y value is ignored. |
|
187 | Removes current \a point x value. Note \a point y value is ignored. | |
188 | */ |
|
188 | */ | |
189 | void QXYSeries::remove(const QPointF &point) |
|
189 | void QXYSeries::remove(const QPointF &point) | |
190 | { |
|
190 | { | |
191 | remove(point.x(),point.y()); |
|
191 | remove(point.x(),point.y()); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Removes all data points from the series. |
|
195 | Removes all data points from the series. | |
196 | */ |
|
196 | */ | |
197 | void QXYSeries::removeAll() |
|
197 | void QXYSeries::removeAll() | |
198 | { |
|
198 | { | |
199 | m_x.clear(); |
|
199 | m_x.clear(); | |
200 | m_y.clear(); |
|
200 | m_y.clear(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \internal \a pos |
|
204 | \internal \a pos | |
205 | */ |
|
205 | */ | |
206 | qreal QXYSeries::x(int pos) const |
|
206 | qreal QXYSeries::x(int pos) const | |
207 | { |
|
207 | { | |
208 | if (m_model) { |
|
208 | if (m_model) { | |
209 | if (m_mapOrientation == Qt::Vertical) |
|
209 | if (m_mapOrientation == Qt::Vertical) | |
210 | // consecutive data is read from model's column |
|
210 | // consecutive data is read from model's column | |
211 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble(); |
|
211 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble(); | |
212 | else |
|
212 | else | |
213 | // consecutive data is read from model's row |
|
213 | // consecutive data is read from model's row | |
214 | return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble(); |
|
214 | return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble(); | |
215 | } else { |
|
215 | } else { | |
216 | // model is not specified, return the data from series' internal data store |
|
216 | // model is not specified, return the data from series' internal data store | |
217 | return m_x.at(pos); |
|
217 | return m_x.at(pos); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \internal \a pos |
|
222 | \internal \a pos | |
223 | */ |
|
223 | */ | |
224 | qreal QXYSeries::y(int pos) const |
|
224 | qreal QXYSeries::y(int pos) const | |
225 | { |
|
225 | { | |
226 | if (m_model) { |
|
226 | if (m_model) { | |
227 | if (m_mapOrientation == Qt::Vertical) |
|
227 | if (m_mapOrientation == Qt::Vertical) | |
228 | // consecutive data is read from model's column |
|
228 | // consecutive data is read from model's column | |
229 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble(); |
|
229 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble(); | |
230 | else |
|
230 | else | |
231 | // consecutive data is read from model's row |
|
231 | // consecutive data is read from model's row | |
232 | return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble(); |
|
232 | return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble(); | |
233 | } else { |
|
233 | } else { | |
234 | // model is not specified, return the data from series' internal data store |
|
234 | // model is not specified, return the data from series' internal data store | |
235 | return m_y.at(pos); |
|
235 | return m_y.at(pos); | |
236 | } |
|
236 | } | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Returns number of data points within series. |
|
240 | Returns number of data points within series. | |
241 | */ |
|
241 | */ | |
242 | int QXYSeries::count() const |
|
242 | int QXYSeries::count() const | |
243 | { |
|
243 | { | |
244 | Q_ASSERT(m_x.size() == m_y.size()); |
|
244 | Q_ASSERT(m_x.size() == m_y.size()); | |
245 |
|
245 | |||
246 | if (m_model) { |
|
246 | if (m_model) { | |
247 | if (m_mapOrientation == Qt::Vertical) { |
|
247 | if (m_mapOrientation == Qt::Vertical) { | |
248 | // data is in a column. Return the number of mapped items if the model's column have enough items |
|
248 | // data is in a column. Return the number of mapped items if the model's column have enough items | |
249 | // or the number of items that can be mapped |
|
249 | // or the number of items that can be mapped | |
250 | if (m_mapLimited) |
|
250 | if (m_mapLimited) | |
251 | return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0)); |
|
251 | return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0)); | |
252 | else |
|
252 | else | |
253 | return qMax(m_model->rowCount() - m_mapFirst, 0); |
|
253 | return qMax(m_model->rowCount() - m_mapFirst, 0); | |
254 | } else { |
|
254 | } else { | |
255 | // data is in a row. Return the number of mapped items if the model's row have enough items |
|
255 | // data is in a row. Return the number of mapped items if the model's row have enough items | |
256 | // or the number of items that can be mapped |
|
256 | // or the number of items that can be mapped | |
257 | if (m_mapLimited) |
|
257 | if (m_mapLimited) | |
258 | return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0)); |
|
258 | return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0)); | |
259 | else |
|
259 | else | |
260 | return qMax(m_model->columnCount() - m_mapFirst, 0); |
|
260 | return qMax(m_model->columnCount() - m_mapFirst, 0); | |
261 | } |
|
261 | } | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | // model is not specified, return the number of points in the series internal data store |
|
264 | // model is not specified, return the number of points in the series internal data store | |
265 | return m_x.size(); |
|
265 | return m_x.size(); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | /*! |
|
268 | /*! | |
269 | Returns the data points of the series. |
|
269 | Returns the data points of the series. | |
270 | */ |
|
270 | */ | |
271 | QList<QPointF> QXYSeries::data() |
|
271 | QList<QPointF> QXYSeries::data() | |
272 | { |
|
272 | { | |
273 | QList<QPointF> data; |
|
273 | QList<QPointF> data; | |
274 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) |
|
274 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) | |
275 | data.append(QPointF(m_x.at(i), m_y.at(i))); |
|
275 | data.append(QPointF(m_x.at(i), m_y.at(i))); | |
276 | return data; |
|
276 | return data; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 |
|
279 | |||
280 | /*! |
|
280 | /*! | |
281 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
281 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
282 | pen from chart theme is used. |
|
282 | pen from chart theme is used. | |
283 |
\sa QChart::set |
|
283 | \sa QChart::setTheme() | |
284 | */ |
|
284 | */ | |
285 | void QXYSeries::setPen(const QPen &pen) |
|
285 | void QXYSeries::setPen(const QPen &pen) | |
286 | { |
|
286 | { | |
287 | if (pen != m_pen) { |
|
287 | if (pen != m_pen) { | |
288 | m_pen = pen; |
|
288 | m_pen = pen; | |
289 | emit updated(); |
|
289 | emit updated(); | |
290 | } |
|
290 | } | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | /*! |
|
293 | /*! | |
294 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
294 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
295 | from chart theme setting is used. |
|
295 | from chart theme setting is used. | |
296 |
\sa QChart::set |
|
296 | \sa QChart::setTheme() | |
297 | */ |
|
297 | */ | |
298 |
|
||||
299 | void QXYSeries::setBrush(const QBrush &brush) |
|
298 | void QXYSeries::setBrush(const QBrush &brush) | |
300 | { |
|
299 | { | |
301 | if (brush != m_brush) { |
|
300 | if (brush != m_brush) { | |
302 | m_brush = brush; |
|
301 | m_brush = brush; | |
303 | emit updated(); |
|
302 | emit updated(); | |
304 | } |
|
303 | } | |
305 | } |
|
304 | } | |
306 |
|
305 | |||
307 |
|
306 | |||
308 | /*! |
|
307 | /*! | |
309 | Stream operator for adding a data \a point to the series. |
|
308 | Stream operator for adding a data \a point to the series. | |
310 | \sa append() |
|
309 | \sa append() | |
311 | */ |
|
310 | */ | |
312 |
|
||||
313 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
311 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
314 | { |
|
312 | { | |
315 | append(point); |
|
313 | append(point); | |
316 | return *this; |
|
314 | return *this; | |
317 | } |
|
315 | } | |
318 |
|
316 | |||
319 |
|
317 | |||
320 | /*! |
|
318 | /*! | |
321 | Stream operator for adding a list of \a points to the series. |
|
319 | Stream operator for adding a list of \a points to the series. | |
322 | \sa append() |
|
320 | \sa append() | |
323 | */ |
|
321 | */ | |
324 |
|
322 | |||
325 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) |
|
323 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) | |
326 | { |
|
324 | { | |
327 | append(points); |
|
325 | append(points); | |
328 | return *this; |
|
326 | return *this; | |
329 | } |
|
327 | } | |
330 |
|
328 | |||
331 | /*! |
|
329 | /*! | |
332 | \internal |
|
330 | \internal | |
333 | */ |
|
331 | */ | |
334 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
332 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
335 | { |
|
333 | { | |
336 | Q_UNUSED(bottomRight) |
|
334 | Q_UNUSED(bottomRight) | |
337 |
|
335 | |||
338 | if (m_mapOrientation == Qt::Vertical) { |
|
336 | if (m_mapOrientation == Qt::Vertical) { | |
339 | if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount)) |
|
337 | if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount)) | |
340 | emit pointReplaced(topLeft.row() - m_mapFirst); |
|
338 | emit pointReplaced(topLeft.row() - m_mapFirst); | |
341 | } else { |
|
339 | } else { | |
342 | if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount)) |
|
340 | if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount)) | |
343 | emit pointReplaced(topLeft.column() - m_mapFirst); |
|
341 | emit pointReplaced(topLeft.column() - m_mapFirst); | |
344 | } |
|
342 | } | |
345 | } |
|
343 | } | |
346 |
|
344 | |||
347 | /*! |
|
345 | /*! | |
348 | \internal |
|
346 | \internal | |
349 | */ |
|
347 | */ | |
350 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) |
|
348 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |
351 | { |
|
349 | { | |
352 | Q_UNUSED(parent) |
|
350 | Q_UNUSED(parent) | |
353 | // Q_UNUSED(end) |
|
351 | // Q_UNUSED(end) | |
354 |
|
352 | |||
355 | if (m_mapLimited) { |
|
353 | if (m_mapLimited) { | |
356 | if (start >= m_mapFirst + m_mapCount) { |
|
354 | if (start >= m_mapFirst + m_mapCount) { | |
357 | // the added data is below mapped area |
|
355 | // the added data is below mapped area | |
358 | // therefore it has no relevance |
|
356 | // therefore it has no relevance | |
359 | return; |
|
357 | return; | |
360 | } else { |
|
358 | } else { | |
361 | // the added data is in the mapped area or before it and update is needed |
|
359 | // the added data is in the mapped area or before it and update is needed | |
362 |
|
360 | |||
363 | // check how many mapped items there is currently (before new items are added) |
|
361 | // check how many mapped items there is currently (before new items are added) | |
364 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem |
|
362 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem | |
365 | // internal storage before new ones can be added |
|
363 | // internal storage before new ones can be added | |
366 |
|
364 | |||
367 | int itemsToRemove = qMin(count() - qMax(start - m_mapFirst, 0), end - start + 1); |
|
365 | int itemsToRemove = qMin(count() - qMax(start - m_mapFirst, 0), end - start + 1); | |
368 | if (m_mapCount == count()) { |
|
366 | if (m_mapCount == count()) { | |
369 | for (int i = 0; i < itemsToRemove; i++) |
|
367 | for (int i = 0; i < itemsToRemove; i++) | |
370 | emit pointRemoved(qMin(end, count()) - i); |
|
368 | emit pointRemoved(qMin(end, count()) - i); | |
371 | } |
|
369 | } | |
372 | } |
|
370 | } | |
373 | } else { |
|
371 | } else { | |
374 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) |
|
372 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) | |
375 | // nothing to do |
|
373 | // nothing to do | |
376 | // emit pointAdded(qMax(start - m_mapFirst, 0)); |
|
374 | // emit pointAdded(qMax(start - m_mapFirst, 0)); | |
377 | } |
|
375 | } | |
378 | } |
|
376 | } | |
379 |
|
377 | |||
380 | /*! |
|
378 | /*! | |
381 | \internal |
|
379 | \internal | |
382 | */ |
|
380 | */ | |
383 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
381 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
384 | { |
|
382 | { | |
385 | Q_UNUSED(parent) |
|
383 | Q_UNUSED(parent) | |
386 | // Q_UNUSED(end) |
|
384 | // Q_UNUSED(end) | |
387 |
|
385 | |||
388 | if (m_mapLimited) { |
|
386 | if (m_mapLimited) { | |
389 | if (start >= m_mapFirst + m_mapCount) { |
|
387 | if (start >= m_mapFirst + m_mapCount) { | |
390 | // the added data is below mapped area |
|
388 | // the added data is below mapped area | |
391 | // therefore it has no relevance |
|
389 | // therefore it has no relevance | |
392 | return; |
|
390 | return; | |
393 | } else { |
|
391 | } else { | |
394 | // the added data is in the mapped area or before it |
|
392 | // the added data is in the mapped area or before it | |
395 | // update needed |
|
393 | // update needed | |
396 | if (count() > 0) { |
|
394 | if (count() > 0) { | |
397 | int toBeAdded = qMin(m_mapCount - (start - m_mapFirst), end - start + 1); |
|
395 | int toBeAdded = qMin(m_mapCount - (start - m_mapFirst), end - start + 1); | |
398 | for (int i = 0; i < toBeAdded; i++) |
|
396 | for (int i = 0; i < toBeAdded; i++) | |
399 | if (start + i >= m_mapFirst) |
|
397 | if (start + i >= m_mapFirst) | |
400 | emit pointAdded(start + i); |
|
398 | emit pointAdded(start + i); | |
401 | } |
|
399 | } | |
402 | } |
|
400 | } | |
403 | } else { |
|
401 | } else { | |
404 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
402 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
405 | for (int i = 0; i < end - start + 1; i++) |
|
403 | for (int i = 0; i < end - start + 1; i++) | |
406 | emit pointAdded(start + i); |
|
404 | emit pointAdded(start + i); | |
407 | } |
|
405 | } | |
408 | } |
|
406 | } | |
409 |
|
407 | |||
410 | /*! |
|
408 | /*! | |
411 | \internal |
|
409 | \internal | |
412 | */ |
|
410 | */ | |
413 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) |
|
411 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) | |
414 | { |
|
412 | { | |
415 | Q_UNUSED(parent) |
|
413 | Q_UNUSED(parent) | |
416 | // Q_UNUSED(end) |
|
414 | // Q_UNUSED(end) | |
417 |
|
415 | |||
418 | if (m_mapLimited) { |
|
416 | if (m_mapLimited) { | |
419 | if (start >= m_mapFirst + m_mapCount) { |
|
417 | if (start >= m_mapFirst + m_mapCount) { | |
420 | // the removed data is below mapped area |
|
418 | // the removed data is below mapped area | |
421 | // therefore it has no relevance |
|
419 | // therefore it has no relevance | |
422 | return; |
|
420 | return; | |
423 | } else { |
|
421 | } else { | |
424 | // the removed data is in the mapped area or before it |
|
422 | // the removed data is in the mapped area or before it | |
425 | // update needed |
|
423 | // update needed | |
426 |
|
424 | |||
427 | // check how many items need to be removed from the xychartitem storage |
|
425 | // check how many items need to be removed from the xychartitem storage | |
428 | // the number equals the number of items that are removed and that lay before |
|
426 | // the number equals the number of items that are removed and that lay before | |
429 | // or in the mapped area. Items that lay beyond the map do not count |
|
427 | // or in the mapped area. Items that lay beyond the map do not count | |
430 | // the max is the current number of items in storage (count()) |
|
428 | // the max is the current number of items in storage (count()) | |
431 | int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); |
|
429 | int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); | |
432 | for (int i = 0; i < itemsToRemove; i++) |
|
430 | for (int i = 0; i < itemsToRemove; i++) | |
433 | emit pointRemoved(start); |
|
431 | emit pointRemoved(start); | |
434 | } |
|
432 | } | |
435 | } else { |
|
433 | } else { | |
436 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
434 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
437 | for (int i = 0; i < end - start + 1; i++) |
|
435 | for (int i = 0; i < end - start + 1; i++) | |
438 | emit pointRemoved(start); |
|
436 | emit pointRemoved(start); | |
439 | } |
|
437 | } | |
440 | } |
|
438 | } | |
441 |
|
439 | |||
442 | /*! |
|
440 | /*! | |
443 | \internal |
|
441 | \internal | |
444 | */ |
|
442 | */ | |
445 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
443 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
446 | { |
|
444 | { | |
447 | Q_UNUSED(parent) |
|
445 | Q_UNUSED(parent) | |
448 | Q_UNUSED(end) |
|
446 | Q_UNUSED(end) | |
449 |
|
447 | |||
450 | // how many items there were before data was removed |
|
448 | // how many items there were before data was removed | |
451 | // int oldCount = count() - 1; |
|
449 | // int oldCount = count() - 1; | |
452 |
|
450 | |||
453 | if (m_mapLimited) { |
|
451 | if (m_mapLimited) { | |
454 | if (start >= m_mapFirst + m_mapCount) { |
|
452 | if (start >= m_mapFirst + m_mapCount) { | |
455 | // the removed data is below mapped area |
|
453 | // the removed data is below mapped area | |
456 | // therefore it has no relevance |
|
454 | // therefore it has no relevance | |
457 | return; |
|
455 | return; | |
458 | } else { |
|
456 | } else { | |
459 | // if the current items count in the whole model is bigger than the index of the last item |
|
457 | // if the current items count in the whole model is bigger than the index of the last item | |
460 | // that was removed than it means there are some extra items available |
|
458 | // that was removed than it means there are some extra items available | |
461 |
|
459 | |||
462 | int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); |
|
460 | int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); | |
463 | int extraItemsAvailable = 0; |
|
461 | int extraItemsAvailable = 0; | |
464 | if (m_mapOrientation == Qt::Vertical) { |
|
462 | if (m_mapOrientation == Qt::Vertical) { | |
465 | extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); |
|
463 | extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); | |
466 | } else { |
|
464 | } else { | |
467 | extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); |
|
465 | extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); | |
468 | } |
|
466 | } | |
469 |
|
467 | |||
470 | // if there are excess items available (below the mapped area) use them to repopulate mapped area |
|
468 | // if there are excess items available (below the mapped area) use them to repopulate mapped area | |
471 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); |
|
469 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); | |
472 | for (int k = 0; k < toBeAdded; k++) |
|
470 | for (int k = 0; k < toBeAdded; k++) | |
473 | emit pointAdded(m_mapFirst + m_mapCount - removedItemsCount + k); |
|
471 | emit pointAdded(m_mapFirst + m_mapCount - removedItemsCount + k); | |
474 | } |
|
472 | } | |
475 | } else { |
|
473 | } else { | |
476 | // data was removed from XYSeries interal storage. Nothing more to do |
|
474 | // data was removed from XYSeries interal storage. Nothing more to do | |
477 | } |
|
475 | } | |
478 | } |
|
476 | } | |
479 |
|
477 | |||
480 | /*! |
|
478 | /*! | |
481 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) |
|
479 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) | |
482 | Sets the \a model to be used as a data source |
|
480 | Sets the \a model to be used as a data source | |
483 | \sa setModelMapping(), setModelMappingRange() |
|
481 | \sa setModelMapping(), setModelMappingRange() | |
484 | */ |
|
482 | */ | |
485 | bool QXYSeries::setModel(QAbstractItemModel *model) { |
|
483 | bool QXYSeries::setModel(QAbstractItemModel *model) { | |
486 |
|
484 | |||
487 | // disconnect signals from old model |
|
485 | // disconnect signals from old model | |
488 | if (m_model) { |
|
486 | if (m_model) { | |
489 | disconnect(m_model, 0, this, 0); |
|
487 | disconnect(m_model, 0, this, 0); | |
490 | m_mapX = -1; |
|
488 | m_mapX = -1; | |
491 | m_mapY = -1; |
|
489 | m_mapY = -1; | |
492 | m_mapFirst = 0; |
|
490 | m_mapFirst = 0; | |
493 | m_mapCount = 0; |
|
491 | m_mapCount = 0; | |
494 | m_mapLimited = false; |
|
492 | m_mapLimited = false; | |
495 | m_mapOrientation = Qt::Vertical; |
|
493 | m_mapOrientation = Qt::Vertical; | |
496 | } |
|
494 | } | |
497 |
|
495 | |||
498 | // set new model |
|
496 | // set new model | |
499 | if (model) { |
|
497 | if (model) { | |
500 | m_model = model; |
|
498 | m_model = model; | |
501 | return true; |
|
499 | return true; | |
502 | } else { |
|
500 | } else { | |
503 | m_model = 0; |
|
501 | m_model = 0; | |
504 | return false; |
|
502 | return false; | |
505 | } |
|
503 | } | |
506 | } |
|
504 | } | |
507 |
|
505 | |||
508 | /*! |
|
506 | /*! | |
509 | \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
507 | \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
510 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used |
|
508 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used | |
511 | as a data source for y coordinate. The \a orientation paramater specifies whether the data |
|
509 | as a data source for y coordinate. The \a orientation paramater specifies whether the data | |
512 | is in columns or in rows. |
|
510 | is in columns or in rows. | |
513 | \sa setModel(), setModelMappingRange() |
|
511 | \sa setModel(), setModelMappingRange() | |
514 | */ |
|
512 | */ | |
515 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
513 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
516 | { |
|
514 | { | |
517 | if (m_model == 0) |
|
515 | if (m_model == 0) | |
518 | return; |
|
516 | return; | |
519 | m_mapX = modelX; |
|
517 | m_mapX = modelX; | |
520 | m_mapY = modelY; |
|
518 | m_mapY = modelY; | |
521 | m_mapFirst = 0; |
|
519 | m_mapFirst = 0; | |
522 | m_mapOrientation = orientation; |
|
520 | m_mapOrientation = orientation; | |
523 | if (m_mapOrientation == Qt::Vertical) { |
|
521 | if (m_mapOrientation == Qt::Vertical) { | |
524 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
522 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
525 | connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); |
|
523 | connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
526 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
524 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
527 | connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); |
|
525 | connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
528 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
526 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
529 | } else { |
|
527 | } else { | |
530 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
528 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
531 | connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); |
|
529 | connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
532 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
530 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
533 | connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); |
|
531 | connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
534 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
532 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
535 | } |
|
533 | } | |
536 | } |
|
534 | } | |
537 |
|
535 | |||
538 | /*! |
|
536 | /*! | |
539 | \fn bool QXYSeries::setModelMappingRange(int first, int count) |
|
537 | \fn bool QXYSeries::setModelMappingRange(int first, int count) | |
540 | Allows limiting the model mapping. |
|
538 | Allows limiting the model mapping. | |
541 | Parameter \a first specifies which element of the model should be used as a first one of the series. |
|
539 | Parameter \a first specifies which element of the model should be used as a first one of the series. | |
542 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) |
|
540 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) | |
543 | then all the items following \a first item in a model are used. |
|
541 | then all the items following \a first item in a model are used. | |
544 | \sa setModel(), setModelMapping() |
|
542 | \sa setModel(), setModelMapping() | |
545 | */ |
|
543 | */ | |
546 | void QXYSeries::setModelMappingRange(int first, int count) |
|
544 | void QXYSeries::setModelMappingRange(int first, int count) | |
547 | { |
|
545 | { | |
548 | m_mapFirst = first; |
|
546 | m_mapFirst = first; | |
549 | if (count == 0) { |
|
547 | if (count == 0) { | |
550 | m_mapLimited = false; |
|
548 | m_mapLimited = false; | |
551 | } else { |
|
549 | } else { | |
552 | m_mapCount = count; |
|
550 | m_mapCount = count; | |
553 | m_mapLimited = true; |
|
551 | m_mapLimited = true; | |
554 | } |
|
552 | } | |
555 | } |
|
553 | } | |
556 |
|
554 | |||
557 | #include "moc_qxyseries.cpp" |
|
555 | #include "moc_qxyseries.cpp" | |
558 |
|
556 | |||
559 | QTCOMMERCIALCHART_END_NAMESPACE |
|
557 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now