##// END OF EJS Templates
Removed few commeneted out lines and documented few funtions
Marek Rosa -
r879:f5fdb845366c
parent child
Show More
@@ -1,446 +1,450
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QDebug>
22 22 #include "qbarseries.h"
23 23 #include "qbarset.h"
24 24 #include "barchartmodel_p.h"
25 25 #include <QAbstractItemModel>
26 26 #include <QModelIndex>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 /*!
31 31 \class QBarSeries
32 32 \brief part of QtCommercial chart API.
33 33
34 34 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
35 35 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
36 36 by QStringList.
37 37
38 38 \mainclass
39 39
40 40 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
41 41 */
42 42
43 43 /*!
44 44 \fn virtual QSeriesType QBarSeries::type() const
45 45 \brief Returns type of series.
46 46 \sa QSeries, QSeriesType
47 47 */
48 48
49 49 /*!
50 50 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
51 51 \brief \internal \a pos \a tip
52 52 */
53 53
54 54 /*!
55 55 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
56 56 QBarSeries is QObject which is a child of a \a parent.
57 57 */
58 58 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent),
59 59 m_internalModel(new BarChartModel(categories, this))
60 60 {
61 61 m_model = 0;
62 62 m_mapCategories = -1;
63 63 m_mapBarBottom = -1;
64 64 m_mapBarTop = -1;
65 65 m_mapFirst = 0;
66 66 m_mapCount = 0;
67 67 m_mapOrientation = Qt::Vertical;
68 68 }
69 69
70 70 /*!
71 71 Adds a set of bars to series. Takes ownership of \a set.
72 72 Connects the clicked(QString, Qt::MouseButtons) signal
73 73 of \a set to this series
74 74 */
75 75 void QBarSeries::appendBarSet(QBarSet *set)
76 76 {
77 77 m_internalModel->appendBarSet(set);
78 78 connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
79 79 connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
80 80 emit restructuredBars();
81 81 }
82 82
83 83 /*!
84 84 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
85 85 Disconnects the clicked(QString, Qt::MouseButtons) signal
86 86 of \a set from this series
87 87 */
88 88 void QBarSeries::removeBarSet(QBarSet *set)
89 89 {
90 90 disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
91 91 m_internalModel->removeBarSet(set);
92 92 emit restructuredBars();
93 93 }
94 94
95 95 /*!
96 96 Adds a list of barsets to series. Takes ownership of \a sets.
97 97 Connects the clicked(QString, Qt::MouseButtons) signals
98 98 of \a sets to this series
99 99 */
100 100 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
101 101 {
102 102 foreach (QBarSet* barset, sets) {
103 103 m_internalModel->appendBarSet(barset);
104 104 connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
105 105 connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
106 106 }
107 107 emit restructuredBars();
108 108 }
109 109
110 110 /*!
111 111 Removes a list of barsets from series. Releases ownership of \a set. Doesnt delete \a sets.
112 112 Disconnects the clicked(QString, Qt::MouseButtons) signal
113 113 of \a sets from this series
114 114 */
115 115 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
116 116 {
117 117 foreach (QBarSet* barset, sets) {
118 118 disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
119 119 m_internalModel->removeBarSet(barset);
120 120 }
121 121 emit restructuredBars();
122 122 }
123 123
124 124 void QBarSeries::insertBarSet(int i, QBarSet *set)
125 125 {
126 126 m_internalModel->insertBarSet(i, set);
127 127 // emit barsetChanged();
128 128 }
129 129
130 130 void QBarSeries::insertCategory(int i, QString category)
131 131 {
132 132 m_internalModel->insertCategory(i, category);
133 133 }
134 134
135 135 void QBarSeries::removeCategory(int i)
136 136 {
137 137 m_internalModel->removeCategory(i);
138 138 }
139 139
140 140 /*!
141 141 Returns number of sets in series.
142 142 */
143 143 int QBarSeries::barsetCount() const
144 144 {
145 145 // if(m_model)
146 146 // return m_mapBarTop - m_mapBarBottom;
147 147 // else
148 148 return m_internalModel->barsetCount();
149 149 }
150 150
151 151 /*!
152 152 Returns number of categories in series
153 153 */
154 154 int QBarSeries::categoryCount() const
155 155 {
156 156 return m_internalModel->categoryCount();
157 157 }
158 158
159 159 /*!
160 160 Returns a list of sets in series. Keeps ownership of sets.
161 161 */
162 162 QList<QBarSet*> QBarSeries::barSets() const
163 163 {
164 164 return m_internalModel->barSets();
165 165 }
166 166
167 167 /*!
168 168 \internal \a index
169 169 */
170 170 QBarSet* QBarSeries::barsetAt(int index)
171 171 {
172 172 return m_internalModel->barsetAt(index);
173 173 }
174 174
175 175 /*!
176 176 \internal \a category
177 177 */
178 178 QString QBarSeries::categoryName(int category)
179 179 {
180 180 return m_internalModel->categoryName(category);
181 181 }
182 182
183 183 /*!
184 184 Enables or disables tooltip depending on parameter \a enabled.
185 185 Tooltip shows the name of set, when mouse is hovering on top of bar.
186 186 Calling without parameter \a enabled, enables the tooltip
187 187 */
188 188 void QBarSeries::setToolTipEnabled(bool enabled)
189 189 {
190 190 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
191 191 if (enabled) {
192 192 for (int i=0; i<m_internalModel->barsetCount(); i++) {
193 193 QBarSet *set = m_internalModel->barsetAt(i);
194 194 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
195 195 }
196 196 } else {
197 197 for (int i=0; i<m_internalModel->barsetCount(); i++) {
198 198 QBarSet *set = m_internalModel->barsetAt(i);
199 199 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
200 200 }
201 201 }
202 202 }
203 203
204 204
205 205 /*!
206 206 \internal \a category
207 207 */
208 208 void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button)
209 209 {
210 210 emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
211 211 }
212 212
213 213 /*!
214 214 \internal
215 215 */
216 216 qreal QBarSeries::min()
217 217 {
218 218 return m_internalModel->min();
219 219 }
220 220
221 221 /*!
222 222 \internal
223 223 */
224 224 qreal QBarSeries::max()
225 225 {
226 226 return m_internalModel->max();
227 227 }
228 228
229 229 /*!
230 230 \internal \a set \a category
231 231 */
232 232 qreal QBarSeries::valueAt(int set, int category)
233 233 {
234 234 return m_internalModel->valueAt(set, category);
235 235 }
236 236
237 237 /*!
238 238 \internal \a set \a category
239 239 */
240 240 qreal QBarSeries::percentageAt(int set, int category)
241 241 {
242 242 return m_internalModel->percentageAt(set, category);
243 243 }
244 244
245 245 /*!
246 246 \internal \a category
247 247 */
248 248 qreal QBarSeries::categorySum(int category)
249 249 {
250 250 return m_internalModel->categorySum(category);
251 251 }
252 252
253 253 /*!
254 254 \internal \a category
255 255 */
256 256 qreal QBarSeries::absoluteCategorySum(int category)
257 257 {
258 258 return m_internalModel->absoluteCategorySum(category);
259 259 }
260 260
261 261 /*!
262 262 \internal
263 263 */
264 264 qreal QBarSeries::maxCategorySum()
265 265 {
266 266 return m_internalModel->maxCategorySum();
267 267 }
268 268
269 269 /*!
270 270 \internal
271 271 */
272 272 BarChartModel& QBarSeries::modelInternal()
273 273 {
274 274 return *m_internalModel;
275 275 }
276 276
277 /*!
278 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
279 Sets the \a model to be used as a data source
280 */
277 281 bool QBarSeries::setModel(QAbstractItemModel *model)
278 282 {
279 283 // disconnect signals from old model
280 284 if(m_model)
281 285 {
282 286 disconnect(m_model, 0, this, 0);
283 287 m_mapCategories = -1;
284 288 m_mapBarBottom = -1;
285 289 m_mapBarTop = -1;
286 290 m_mapFirst = 0;
287 291 m_mapCount = 0;
288 292 m_mapOrientation = Qt::Vertical;
289 293 }
290 294
291 295 // set new model
292 296 if(model)
293 297 {
294 298 m_model = model;
295 299 return true;
296 300 }
297 301 else
298 302 {
299 303 m_model = 0;
300 304 return false;
301 305 }
302 306 }
303 307
304 308 // TODO
305 309 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
306 310 {
307 311 if (!m_model)
308 312 return;
309 313
310 314 m_mapCategories = categories;
311 315 m_mapBarBottom = bottomBoundry;
312 316 m_mapBarTop = topBoundry;
313 317 // m_mapFirst = 1;
314 318 m_mapOrientation = orientation;
315 319
316 320 // connect the signals
317 321 if (m_mapOrientation == Qt::Vertical) {
318 322 m_mapCount = m_model->rowCount() - m_mapFirst;
319 323 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
320 324 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
321 325 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
322 326 this, SLOT(modelDataAdded(QModelIndex,int,int)));
323 327 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
324 328 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
325 329 } else {
326 330 m_mapCount = m_model->columnCount() - m_mapFirst;
327 331 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
328 332 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
329 333 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
330 334 this, SLOT(modelDataAdded(QModelIndex,int,int)));
331 335 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
332 336 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
333 337 }
334 338
335 339
336 340 // create the initial bars
337 341 delete m_internalModel;
338 342 if (m_mapOrientation == Qt::Vertical) {
339 343 QStringList categories;
340 344 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
341 345 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
342 346 m_internalModel = new BarChartModel(categories, this);
343 347
344 348 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
345 349 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
346 350 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
347 351 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
348 352 appendBarSet(barSet);
349 353 }
350 354 } else {
351 355 QStringList categories;
352 356 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
353 357 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
354 358 m_internalModel = new BarChartModel(categories, this);
355 359
356 360 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
357 361 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
358 362 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
359 363 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
360 364 appendBarSet(barSet);
361 365 }
362 366 }
363 367 }
364 368
365 369 void QBarSeries::setModelMappingShift(int first, int count)
366 370 {
367 371 m_mapFirst = first;
368 372 m_mapCount = count;
369 373 }
370 374
371 375 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
372 376 {
373 377 Q_UNUSED(bottomRight)
374 378
375 379 if (m_mapOrientation == Qt::Vertical)
376 380 {
377 381 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
378 382 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
379 383 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
380 384 }
381 385 else
382 386 {
383 387 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
384 388 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
385 389 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
386 390 }
387 391 }
388 392
389 393 void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
390 394 {
391 395 if (m_mapOrientation == Qt::Vertical) {
392 396 insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
393 397 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
394 398 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
395 399 }
396 400 } else {
397 401 insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
398 402 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
399 403 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
400 404 }
401 405 }
402 406 emit restructuredBars();
403 407 }
404 408
405 409 void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end)
406 410 {
407 411 Q_UNUSED(parent)
408 412 Q_UNUSED(end)
409 413
410 414 removeCategory(start - m_mapFirst);
411 415 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
412 416 {
413 417 barsetAt(i)->removeValue(start - m_mapFirst);
414 418 }
415 419 emit restructuredBars();
416 420 }
417 421
418 422 void QBarSeries::barsetChanged()
419 423 {
420 424 emit updatedBars();
421 425 }
422 426
423 427 QBarCategories QBarSeries::categories() const
424 428 {
425 429 QBarCategories categories;
426 430 int count = m_internalModel->categoryCount();
427 431 for (int i=1; i <= count; i++) {
428 432 categories.insert(i, m_internalModel->categoryName(i - 1));
429 433 }
430 434 return categories;
431 435 }
432 436
433 437 /*!
434 438 Sets the visibility of labels in series to \a visible
435 439 */
436 440 void QBarSeries::setLabelsVisible(bool visible)
437 441 {
438 442 foreach (QBarSet* s, barSets()) {
439 443 s->setLabelsVisible(visible);
440 444 }
441 445 }
442 446
443 447
444 448 #include "moc_qbarseries.cpp"
445 449
446 450 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,121 +1,120
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef BARSERIES_H
22 22 #define BARSERIES_H
23 23
24 24 #include <qseries.h>
25 25 #include <QStringList>
26 26
27 27 class QModelIndex;
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 typedef QStringList QBarCategories;
32 32
33 33 class QBarSet;
34 34 class BarChartModel;
35 35 class BarCategory;
36 36
37 37 // Container for series
38 38 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 QBarSeries(QStringList categories, QObject *parent = 0);
43 43
44 44 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
45 45
46 46 void appendBarSet(QBarSet *set); // Takes ownership of set
47 47 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
48 48 void appendBarSets(QList<QBarSet* > sets);
49 49 void removeBarSets(QList<QBarSet* > sets);
50 50 void insertBarSet(int i, QBarSet *set);
51 51 void insertCategory(int i, QString category);
52 52 void removeCategory(int i);
53 53 int barsetCount() const;
54 54 int categoryCount() const;
55 55 QList<QBarSet*> barSets() const;
56 56 QBarCategories categories() const;
57 57
58 58 void setLabelsVisible(bool visible = true);
59 59
60 60 bool setModel(QAbstractItemModel *model);
61 // QAbstractItemModel *modelExt() { return m_model; }
62 61 void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical);
63 62 void setModelMappingShift(int first, int count);
64 63
65 64 public:
66 65 // TODO: Functions below this are not part of api and will be moved
67 66 // to private implementation, when we start using it
68 67 // TODO: TO PIMPL --->
69 68 QBarSet* barsetAt(int index);
70 69 QString categoryName(int category);
71 70 qreal min();
72 71 qreal max();
73 72 qreal valueAt(int set, int category);
74 73 qreal percentageAt(int set, int category);
75 74 qreal categorySum(int category);
76 75 qreal absoluteCategorySum(int category);
77 76 qreal maxCategorySum();
78 77 BarChartModel& modelInternal();
79 78 // <--- TO PIMPL
80 79
81 80 Q_SIGNALS:
82 81 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals
83 82 void selected();
84 83 //
85 84 void updatedBars();
86 85 void restructuredBars();
87 86
88 87 // TODO: internal signals, these to private implementation.
89 88 // TODO: TO PIMPL --->
90 89 void showToolTip(QPoint pos, QString tip);
91 90 // <--- TO PIMPL
92 91
93 92 public Q_SLOTS:
94 93 void setToolTipEnabled(bool enabled = true); // enables tooltips
95 94
96 95 // TODO: TO PIMPL --->
97 96 void barsetClicked(QString category, Qt::MouseButtons button);
98 97 // <--- TO PIMPL
99 98
100 99 private Q_SLOTS:
101 100 // slots for updating bars when data in model changes
102 101 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
103 102 void modelDataAdded(QModelIndex parent, int start, int end);
104 103 void modelDataRemoved(QModelIndex parent, int start, int end);
105 104 void barsetChanged();
106 105
107 106 protected:
108 107 BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good.
109 108
110 109 // QAbstractItemModel* m_model;
111 110 int m_mapCategories;
112 111 int m_mapBarBottom;
113 112 int m_mapBarTop;
114 113 int m_mapFirst;
115 114 int m_mapCount;
116 115 Qt::Orientation m_mapOrientation;
117 116 };
118 117
119 118 QTCOMMERCIALCHART_END_NAMESPACE
120 119
121 120 #endif // BARSERIES_H
@@ -1,693 +1,697
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpieseries.h"
22 22 #include "qpieseriesprivate_p.h"
23 23 #include "qpieslice.h"
24 24 #include "pieslicedata_p.h"
25 25 #include <QAbstractItemModel>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent)
31 31 :QObject(parent),
32 32 q_ptr(parent),
33 33 m_pieRelativeHorPos(0.5),
34 34 m_pieRelativeVerPos(0.5),
35 35 m_pieRelativeSize(0.7),
36 36 m_pieStartAngle(0),
37 37 m_pieEndAngle(360),
38 38 m_total(0),
39 39 m_mapValues(0),
40 40 m_mapLabels(0),
41 41 m_mapOrientation(Qt::Horizontal)
42 42 {
43 43
44 44 }
45 45
46 46 QPieSeriesPrivate::~QPieSeriesPrivate()
47 47 {
48 48
49 49 }
50 50
51 51 void QPieSeriesPrivate::updateDerivativeData()
52 52 {
53 53 m_total = 0;
54 54
55 55 // nothing to do?
56 56 if (m_slices.count() == 0)
57 57 return;
58 58
59 59 // calculate total
60 60 foreach (QPieSlice* s, m_slices)
61 61 m_total += s->value();
62 62
63 63 // nothing to show..
64 64 if (qFuzzyIsNull(m_total))
65 65 return;
66 66
67 67 // update slice attributes
68 68 qreal sliceAngle = m_pieStartAngle;
69 69 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
70 70 QVector<QPieSlice*> changed;
71 71 foreach (QPieSlice* s, m_slices) {
72 72
73 73 PieSliceData data = PieSliceData::data(s);
74 74 data.m_percentage = s->value() / m_total;
75 75 data.m_angleSpan = pieSpan * data.m_percentage;
76 76 data.m_startAngle = sliceAngle;
77 77 sliceAngle += data.m_angleSpan;
78 78
79 79 if (PieSliceData::data(s) != data) {
80 80 PieSliceData::data(s) = data;
81 81 changed << s;
82 82 }
83 83 }
84 84
85 85 // emit signals
86 86 foreach (QPieSlice* s, changed)
87 87 PieSliceData::data(s).emitChangedSignal(s);
88 88 }
89 89
90 90 void QPieSeriesPrivate::sliceChanged()
91 91 {
92 92 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
93 93 updateDerivativeData();
94 94 }
95 95
96 96 void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons)
97 97 {
98 98 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
99 99 Q_ASSERT(m_slices.contains(slice));
100 100 Q_Q(QPieSeries);
101 101 emit q->clicked(slice, buttons);
102 102 }
103 103
104 104 void QPieSeriesPrivate::sliceHoverEnter()
105 105 {
106 106 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
107 107 Q_ASSERT(m_slices.contains(slice));
108 108 Q_Q(QPieSeries);
109 109 emit q->hoverEnter(slice);
110 110 }
111 111
112 112 void QPieSeriesPrivate::sliceHoverLeave()
113 113 {
114 114 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
115 115 Q_ASSERT(m_slices.contains(slice));
116 116 Q_Q(QPieSeries);
117 117 emit q->hoverLeave(slice);
118 118 }
119 119
120 120 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
121 121 {
122 122 Q_UNUSED(bottomRight)
123 123 Q_Q(QPieSeries);
124 124
125 125 if (m_mapOrientation == Qt::Vertical)
126 126 {
127 127 if (topLeft.column() == m_mapValues)
128 128 if (m_mapValues == m_mapLabels)
129 129 {
130 130 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
131 131 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
132 132 }
133 133 else
134 134 {
135 135 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
136 136 }
137 137 else if (topLeft.column() == m_mapLabels)
138 138 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
139 139 }
140 140 else
141 141 {
142 142 if (topLeft.row() == m_mapValues)
143 143 if (m_mapValues == m_mapLabels)
144 144 {
145 145 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
146 146 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
147 147 }
148 148 else
149 149 {
150 150 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
151 151 }
152 152 else if (topLeft.row() == m_mapLabels)
153 153 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
154 154 }
155 155 }
156 156
157 157 void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
158 158 {
159 159 Q_UNUSED(parent)
160 160 Q_UNUSED(end)
161 161 Q_Q(QPieSeries);
162 162
163 163 QPieSlice* newSlice = new QPieSlice;
164 164 newSlice->setLabelVisible(true);
165 165 if (m_mapOrientation == Qt::Vertical)
166 166 {
167 167 newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
168 168 newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
169 169 }
170 170 else
171 171 {
172 172 newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
173 173 newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
174 174 }
175 175
176 176 q->insert(start, newSlice);
177 177 }
178 178
179 179 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
180 180 {
181 181 Q_UNUSED(parent)
182 182 Q_UNUSED(end)
183 183 Q_Q(QPieSeries);
184 184 q->remove(m_slices.at(start));
185 185 }
186 186
187 187
188 188
189 189 /*!
190 190 \class QPieSeries
191 191 \brief Pie series API for QtCommercial Charts
192 192
193 193 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
194 194 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
195 195 The actual slice size is determined by that relative value.
196 196
197 197 By default the pie is defined as a full pie but it can be a partial pie.
198 198 This can be done by setting a starting angle and angle span to the series.
199 199 */
200 200
201 201 /*!
202 202 Constructs a series object which is a child of \a parent.
203 203 */
204 204 QPieSeries::QPieSeries(QObject *parent) :
205 205 QSeries(parent),
206 206 d_ptr(new QPieSeriesPrivate(this))
207 207 {
208 208
209 209 }
210 210
211 211 /*!
212 212 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
213 213 */
214 214 QPieSeries::~QPieSeries()
215 215 {
216 216 // NOTE: d_prt destroyed by QObject
217 217 }
218 218
219 219 /*!
220 220 Returns QChartSeries::SeriesTypePie.
221 221 */
222 222 QSeries::QSeriesType QPieSeries::type() const
223 223 {
224 224 return QSeries::SeriesTypePie;
225 225 }
226 226
227 227 /*!
228 228 Sets an array of \a slices to the series replacing the existing slices.
229 229 Slice ownership is passed to the series.
230 230 */
231 231 void QPieSeries::replace(QList<QPieSlice*> slices)
232 232 {
233 233 clear();
234 234 append(slices);
235 235 }
236 236
237 237 /*!
238 238 Adds an array of \a slices to the series.
239 239 Slice ownership is passed to the series.
240 240 */
241 241 void QPieSeries::append(QList<QPieSlice*> slices)
242 242 {
243 243 Q_D(QPieSeries);
244 244
245 245 foreach (QPieSlice* s, slices) {
246 246 s->setParent(this);
247 247 d->m_slices << s;
248 248 }
249 249
250 250 d->updateDerivativeData();
251 251
252 252 foreach (QPieSlice* s, slices) {
253 253 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
254 254 connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
255 255 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
256 256 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
257 257 }
258 258
259 259 emit added(slices);
260 260 }
261 261
262 262 /*!
263 263 Adds a single \a slice to the series.
264 264 Slice ownership is passed to the series.
265 265 */
266 266 void QPieSeries::append(QPieSlice* slice)
267 267 {
268 268 append(QList<QPieSlice*>() << slice);
269 269 }
270 270
271 271 /*!
272 272 Adds a single \a slice to the series and returns a reference to the series.
273 273 Slice ownership is passed to the series.
274 274 */
275 275 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
276 276 {
277 277 append(slice);
278 278 return *this;
279 279 }
280 280
281 281
282 282 /*!
283 283 Appends a single slice to the series with give \a value and \a name.
284 284 Slice ownership is passed to the series.
285 285 */
286 286 QPieSlice* QPieSeries::append(qreal value, QString name)
287 287 {
288 288 QPieSlice* slice = new QPieSlice(value, name);
289 289 append(slice);
290 290 return slice;
291 291 }
292 292
293 293 /*!
294 294 Inserts a single \a slice to the series before the slice at \a index position.
295 295 Slice ownership is passed to the series.
296 296 */
297 297 void QPieSeries::insert(int index, QPieSlice* slice)
298 298 {
299 299 Q_D(QPieSeries);
300 300 Q_ASSERT(index <= d->m_slices.count());
301 301 slice->setParent(this);
302 302 d->m_slices.insert(index, slice);
303 303
304 304 d->updateDerivativeData();
305 305
306 306 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
307 307 connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
308 308 connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
309 309 connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
310 310
311 311 emit added(QList<QPieSlice*>() << slice);
312 312 }
313 313
314 314 /*!
315 315 Removes a single \a slice from the series and deletes the slice.
316 316
317 317 Do not reference this pointer after this call.
318 318 */
319 319 void QPieSeries::remove(QPieSlice* slice)
320 320 {
321 321 Q_D(QPieSeries);
322 322 if (!d->m_slices.removeOne(slice)) {
323 323 Q_ASSERT(0); // TODO: how should this be reported?
324 324 return;
325 325 }
326 326
327 327 d->updateDerivativeData();
328 328
329 329 emit removed(QList<QPieSlice*>() << slice);
330 330
331 331 delete slice;
332 332 slice = 0;
333 333 }
334 334
335 335 /*!
336 336 Clears all slices from the series.
337 337 */
338 338 void QPieSeries::clear()
339 339 {
340 340 Q_D(QPieSeries);
341 341 if (d->m_slices.count() == 0)
342 342 return;
343 343
344 344 QList<QPieSlice*> slices = d->m_slices;
345 345 foreach (QPieSlice* s, d->m_slices) {
346 346 d->m_slices.removeOne(s);
347 347 delete s;
348 348 }
349 349
350 350 d->updateDerivativeData();
351 351
352 352 emit removed(slices);
353 353 }
354 354
355 355 /*!
356 356 Counts the number of the slices in this series.
357 357 */
358 358 int QPieSeries::count() const
359 359 {
360 360 Q_D(const QPieSeries);
361 361 return d->m_slices.count();
362 362 }
363 363
364 364 /*!
365 365 Returns true is the series is empty.
366 366 */
367 367 bool QPieSeries::isEmpty() const
368 368 {
369 369 Q_D(const QPieSeries);
370 370 return d->m_slices.isEmpty();
371 371 }
372 372
373 373 /*!
374 374 Returns a list of slices that belong to this series.
375 375 */
376 376 QList<QPieSlice*> QPieSeries::slices() const
377 377 {
378 378 Q_D(const QPieSeries);
379 379 return d->m_slices;
380 380 }
381 381
382 382 /*!
383 383 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
384 384
385 385 The factors are relative to the chart rectangle where:
386 386
387 387 \a relativeHorizontalPosition 0.0 means the absolute left.
388 388 \a relativeHorizontalPosition 1.0 means the absolute right.
389 389 \a relativeVerticalPosition 0.0 means the absolute top.
390 390 \a relativeVerticalPosition 1.0 means the absolute bottom.
391 391
392 392 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
393 393
394 394 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
395 395 */
396 396 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
397 397 {
398 398 Q_D(QPieSeries);
399 399 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
400 400 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
401 401 return;
402 402
403 403 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativeHorizontalPosition) ||
404 404 !qFuzzyIsNull(d->m_pieRelativeVerPos - relativeVerticalPosition)) {
405 405 d->m_pieRelativeHorPos = relativeHorizontalPosition;
406 406 d->m_pieRelativeVerPos = relativeVerticalPosition;
407 407 emit piePositionChanged();
408 408 }
409 409 }
410 410
411 411 /*!
412 412 Gets the horizontal position of the pie.
413 413
414 414 The returned value is relative to the chart rectangle where:
415 415
416 416 0.0 means the absolute left.
417 417 1.0 means the absolute right.
418 418
419 419 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
420 420
421 421 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
422 422 */
423 423 qreal QPieSeries::pieHorizontalPosition() const
424 424 {
425 425 Q_D(const QPieSeries);
426 426 return d->m_pieRelativeHorPos;
427 427 }
428 428
429 429 /*!
430 430 Gets the vertical position position of the pie.
431 431
432 432 The returned value is relative to the chart rectangle where:
433 433
434 434 0.0 means the absolute top.
435 435 1.0 means the absolute bottom.
436 436
437 437 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
438 438
439 439 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
440 440 */
441 441 qreal QPieSeries::pieVerticalPosition() const
442 442 {
443 443 Q_D(const QPieSeries);
444 444 return d->m_pieRelativeVerPos;
445 445 }
446 446
447 447 /*!
448 448 Sets the relative size of the pie.
449 449
450 450 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
451 451
452 452 Default value is 0.7.
453 453
454 454 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
455 455 */
456 456 void QPieSeries::setPieSize(qreal relativeSize)
457 457 {
458 458 Q_D(QPieSeries);
459 459 if (relativeSize < 0.0 || relativeSize > 1.0)
460 460 return;
461 461
462 462 if (!qFuzzyIsNull(d->m_pieRelativeSize- relativeSize)) {
463 463 d->m_pieRelativeSize = relativeSize;
464 464 emit pieSizeChanged();
465 465 }
466 466 }
467 467
468 468 /*!
469 469 Gets the relative size of the pie.
470 470
471 471 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
472 472
473 473 Default value is 0.7.
474 474
475 475 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
476 476 */
477 477 qreal QPieSeries::pieSize() const
478 478 {
479 479 Q_D(const QPieSeries);
480 480 return d->m_pieRelativeSize;
481 481 }
482 482
483 483
484 484 /*!
485 485 Sets the end angle of the pie.
486 486
487 487 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
488 488
489 489 \a angle must be less than pie end angle. Default value is 0.
490 490
491 491 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
492 492 */
493 493 void QPieSeries::setPieStartAngle(qreal angle)
494 494 {
495 495 Q_D(QPieSeries);
496 496
497 497 if (angle < 0 || angle > 360 || angle > d->m_pieEndAngle)
498 498 return;
499 499
500 500 if (!qFuzzyIsNull(angle - d->m_pieStartAngle)) {
501 501 d->m_pieStartAngle = angle;
502 502 d->updateDerivativeData();
503 503 }
504 504 }
505 505
506 506 /*!
507 507 Gets the start angle of the pie.
508 508
509 509 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
510 510
511 511 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
512 512 */
513 513 qreal QPieSeries::pieStartAngle() const
514 514 {
515 515 Q_D(const QPieSeries);
516 516 return d->m_pieStartAngle;
517 517 }
518 518
519 519 /*!
520 520 Sets the end angle of the pie.
521 521
522 522 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
523 523
524 524 \a angle must be greater than start angle.
525 525
526 526 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
527 527 */
528 528 void QPieSeries::setPieEndAngle(qreal angle)
529 529 {
530 530 Q_D(QPieSeries);
531 531
532 532 if (angle < 0 || angle > 360 || angle < d->m_pieStartAngle)
533 533 return;
534 534
535 535 if (!qFuzzyIsNull(angle - d->m_pieEndAngle)) {
536 536 d->m_pieEndAngle = angle;
537 537 d->updateDerivativeData();
538 538 }
539 539 }
540 540
541 541 /*!
542 542 Returns the end angle of the pie.
543 543
544 544 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
545 545
546 546 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
547 547 */
548 548 qreal QPieSeries::pieEndAngle() const
549 549 {
550 550 Q_D(const QPieSeries);
551 551 return d->m_pieEndAngle;
552 552 }
553 553
554 554 /*!
555 555 Sets the all the slice labels \a visible or invisible.
556 556
557 557 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
558 558 */
559 559 void QPieSeries::setLabelsVisible(bool visible)
560 560 {
561 561 Q_D(QPieSeries);
562 562 foreach (QPieSlice* s, d->m_slices)
563 563 s->setLabelVisible(visible);
564 564 }
565 565
566 566 /*!
567 567 Returns the sum of all slice values in this series.
568 568
569 569 \sa QPieSlice::value(), QPieSlice::setValue()
570 570 */
571 571 qreal QPieSeries::total() const
572 572 {
573 573 Q_D(const QPieSeries);
574 574 return d->m_total;
575 575 }
576 576
577 577 /*!
578 578 \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons)
579 579
580 580 This signal is emitted when a \a slice has been clicked with mouse \a buttons.
581 581
582 582 \sa QPieSlice::clicked()
583 583 */
584 584
585 585 /*!
586 586 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
587 587
588 588 This signal is emitted when user has hovered over a \a slice.
589 589
590 590 \sa QPieSlice::hoverEnter()
591 591 */
592 592
593 593 /*!
594 594 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
595 595
596 596 This signal is emitted when user has hovered away from a \a slice.
597 597
598 598 \sa QPieSlice::hoverLeave()
599 599 */
600 600
601 601 /*!
602 602 \fn void QPieSeries::added(QList<QPieSlice*> slices)
603 603
604 604 This signal is emitted when \a slices has been added to the series.
605 605
606 606 \sa append(), insert()
607 607 */
608 608
609 609 /*!
610 610 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
611 611
612 612 This signal is emitted when \a slices has been removed from the series.
613 613
614 614 \sa remove(), clear()
615 615 */
616 616
617 617 /*!
618 618 \fn void QPieSeries::piePositionChanged()
619 619
620 620 This signal is emitted when pie position has changed.
621 621
622 622 \sa setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
623 623 */
624 624
625 625 /*!
626 626 \fn void QPieSeries::pieSizeChanged()
627 627
628 628 This signal is emitted when pie size has changed.
629 629
630 630 \sa pieSize(), setPieSize()
631 631 */
632 632
633 /*!
634 \fn bool QPieSeries::setModel(QAbstractItemModel *model)
635 Sets the \a model to be used as a data source
636 */
633 637 bool QPieSeries::setModel(QAbstractItemModel* model)
634 638 {
635 639 Q_D(QPieSeries);
636 640 // disconnect signals from old model
637 641 if(m_model)
638 642 {
639 643 disconnect(m_model, 0, this, 0);
640 644 d->m_mapValues = -1;
641 645 d->m_mapLabels = -1;
642 646 d->m_mapOrientation = Qt::Vertical;
643 647 }
644 648
645 649 // set new model
646 650 if(model)
647 651 {
648 652 m_model = model;
649 653 return true;
650 654 }
651 655 else
652 656 {
653 657 m_model = 0;
654 658 return false;
655 659 }
656 660 }
657 661
658 662 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
659 663 {
660 664 Q_D(QPieSeries);
661 665
662 666 if (m_model == 0)
663 667 return;
664 668
665 669 d->m_mapValues = modelValuesLine;
666 670 d->m_mapLabels = modelLabelsLine;
667 671 d->m_mapOrientation = orientation;
668 672
669 673 // connect the signals
670 674 if (d->m_mapOrientation == Qt::Vertical) {
671 675 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
672 676 connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
673 677 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
674 678 } else {
675 679 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
676 680 connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
677 681 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
678 682 }
679 683
680 684 // create the initial slices set
681 685 if (d->m_mapOrientation == Qt::Vertical) {
682 686 for (int i = 0; i < m_model->rowCount(); i++)
683 687 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());
684 688 } else {
685 689 for (int i = 0; i < m_model->columnCount(); i++)
686 690 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());
687 691 }
688 692 }
689 693
690 694 #include "moc_qpieseries.cpp"
691 695 #include "moc_qpieseriesprivate_p.cpp"
692 696
693 697 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,70
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QSERIES_H
22 22 #define QSERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QObject>
26 26 //#include <QAbstractItemModel>
27 27 #include <QPen>
28 28
29 29 class QAbstractItemModel;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
34 34 {
35 35 Q_OBJECT
36 36 public:
37 37 enum QSeriesType {
38 38 SeriesTypeLine,
39 39 SeriesTypeArea,
40 40 SeriesTypeBar,
41 41 SeriesTypeStackedBar,
42 42 SeriesTypePercentBar,
43 43 SeriesTypePie,
44 44 SeriesTypeScatter,
45 45 SeriesTypeSpline
46 46 };
47 47
48 48 protected:
49 49 QSeries(QObject *parent = 0) : QObject(parent) {m_model = 0;}
50 50
51 51 public:
52 52 virtual ~QSeries() {}
53 53 virtual QSeriesType type() const = 0;
54 54 // TODO
55 55 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
56 56 QAbstractItemModel* model() const { return m_model; }
57
57 58 void setName(QString name) { m_name = name; }
58 59 QString name() const { return m_name; }
59 60
60 61 protected:
61 62 QAbstractItemModel* m_model;
62 63
63 64 private:
64 65 QString m_name;
65 66 };
66 67
67 68 QTCOMMERCIALCHART_END_NAMESPACE
68 69
69 70 #endif
@@ -1,104 +1,103
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QXYSERIES_H_
22 22 #define QXYSERIES_H_
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qseries.h>
26 26 #include <QPen>
27 27 #include <QBrush>
28 28
29 29 class QModelIndex;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
34 34 {
35 35 Q_OBJECT
36 36 protected:
37 37 QXYSeries(QObject *parent = 0);
38 38 virtual ~QXYSeries();
39 39
40 40 public:
41 41 void append(qreal x, qreal y);
42 42 void append(const QPointF &point);
43 43 void append(const QList<QPointF> points);
44 44 void replace(qreal x,qreal y);
45 45 void replace(const QPointF &point);
46 46 void remove(qreal x);
47 47 void remove(qreal x, qreal y);
48 48 void remove(const QPointF &point);
49 49 void removeAll();
50 50
51 51 int count() const;
52 52 qreal x(int pos) const;
53 53 qreal y(int pos) const;
54 54 QList<QPointF> data();
55 55
56 56 QXYSeries& operator << (const QPointF &point);
57 57 QXYSeries& operator << (const QList<QPointF> points);
58 58
59 59 void setPen(const QPen &pen);
60 60 QPen pen() const {return m_pen;}
61 61 void setBrush(const QBrush &brush);
62 62 QBrush brush() const {return m_brush;}
63 63
64 64 bool setModel(QAbstractItemModel *model);
65 // QAbstractItemModel* model() const { return m_model; }
66 65
67 66 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
68 67 virtual void setModelMappingRange(int first, int count = 0);
69 68 int mapFirst() const { return m_mapFirst; }
70 69
71 70 private Q_SLOTS:
72 71 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
73 72 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
74 73 void modelDataAdded(QModelIndex parent, int start, int end);
75 74 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
76 75 void modelDataRemoved(QModelIndex parent, int start, int end);
77 76
78 77 Q_SIGNALS:
79 78 void clicked(const QPointF &point);
80 79 void selected();
81 80 void updated();
82 81 void pointReplaced(int index);
83 82 void pointRemoved(int index);
84 83 void pointAdded(int index);
85 84
86 85 protected:
87 86 QVector<qreal> m_x;
88 87 QVector<qreal> m_y;
89 88
90 89 QPen m_pen;
91 90 QBrush m_brush;
92 91
93 92 int m_mapX;
94 93 int m_mapY;
95 94 int m_mapFirst;
96 95 int m_mapCount;
97 96 bool m_mapLimited;
98 97 Qt::Orientation m_mapOrientation;
99 98 int tempItemsRemoved;
100 99 };
101 100
102 101 QTCOMMERCIALCHART_END_NAMESPACE
103 102
104 103 #endif
General Comments 0
You need to be logged in to leave comments. Login now