##// END OF EJS Templates
Fix vs2010 build
Jani Honkonen -
r605:c0502398e154
parent child
Show More
@@ -1,241 +1,242
1 1 #include <QDebug>
2 2 #include "qbarseries.h"
3 3 #include "qbarset.h"
4 4 #include "barchartmodel_p.h"
5 5
6 6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7
8 8 /*!
9 9 \class QBarSeries
10 10 \brief part of QtCommercial chart API.
11 11
12 12 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
13 13 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
14 14 by QStringList.
15 15
16 16 \mainclass
17 17
18 18 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
19 19 */
20 20
21 21 /*!
22 22 \fn virtual QSeriesType QBarSeries::type() const
23 23 \brief Returns type of series.
24 24 \sa QSeries, QSeriesType
25 25 */
26 26
27 27 /*!
28 28 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
29 29 \brief \internal \a pos \a tip
30 30 */
31 31
32 32 /*!
33 33 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
34 34 QBarSeries is QObject which is a child of a \a parent.
35 35 */
36 36 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
37 37 : QSeries(parent)
38 38 ,mModel(new BarChartModel(categories, this))
39 39 {
40 40 m_model = NULL;
41 41 m_mapCategories = -1;
42 42 m_mapBarBottom - 1;
43 43 m_mapBarTop - 1;
44 44 }
45 45
46 46 /*!
47 47 Adds a set of bars to series. Takes ownership of \a set.
48 48 Connects the clicked(QString) and rightClicked(QString) signals
49 49 of \a set to this series
50 50 */
51 51 void QBarSeries::addBarSet(QBarSet *set)
52 52 {
53 53 mModel->addBarSet(set);
54 54 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
55 55 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
56 56 }
57 57
58 58 /*!
59 59 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
60 60 Disconnects the clicked(QString) and rightClicked(QString) signals
61 61 of \a set from this series
62 62 */
63 63 void QBarSeries::removeBarSet(QBarSet *set)
64 64 {
65 65 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
66 66 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
67 67 mModel->removeBarSet(set);
68 68 }
69 69
70 70 /*!
71 71 Returns number of sets in series.
72 72 */
73 73 int QBarSeries::barsetCount()
74 74 {
75 75 if(m_model)
76 76 return m_mapBarTop - m_mapBarBottom;
77 77 else
78 78 return mModel->barsetCount();
79 79 }
80 80
81 81 /*!
82 82 Returns number of categories in series
83 83 */
84 84 int QBarSeries::categoryCount()
85 85 {
86 86 return mModel->categoryCount();
87 87 }
88 88
89 89 /*!
90 90 Returns a list of sets in series. Keeps ownership of sets.
91 91 */
92 92 QList<QBarSet*> QBarSeries::barSets()
93 93 {
94 94 return mModel->barSets();
95 95 }
96 96
97 97 /*!
98 98 \internal \a index
99 99 */
100 100 QBarSet* QBarSeries::barsetAt(int index)
101 101 {
102 102 return mModel->setAt(index);
103 103 }
104 104
105 105 /*!
106 106 \internal \a category
107 107 */
108 108 QString QBarSeries::categoryName(int category)
109 109 {
110 110 return mModel->categoryName(category);
111 111 }
112 112
113 113 /*!
114 114 Enables or disables tooltip depending on parameter \a enabled.
115 115 Tooltip shows the name of set, when mouse is hovering on top of bar.
116 116 Calling without parameter \a enabled, enables the tooltip
117 117 */
118 118 void QBarSeries::setToolTipEnabled(bool enabled)
119 119 {
120 120 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
121 121 if (enabled) {
122 122 for (int i=0; i<mModel->barsetCount(); i++) {
123 123 QBarSet *set = mModel->setAt(i);
124 124 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
125 125 }
126 126 } else {
127 127 for (int i=0; i<mModel->barsetCount(); i++) {
128 128 QBarSet *set = mModel->setAt(i);
129 129 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
130 130 }
131 131 }
132 132 }
133 133
134 134 /*!
135 135 Enables or disables separators depending on parameter \a enabled.
136 136 Separators are visual elements that are drawn between categories.
137 137 Calling without parameter \a enabled, enables the separators
138 138 */
139 139 void QBarSeries::setSeparatorsVisible(bool visible)
140 140 {
141 141 mSeparatorsVisible = visible;
142 142 emit enableSeparators(visible);
143 143 }
144 144
145 145
146 146 /*!
147 147 \internal \a category
148 148 */
149 149 void QBarSeries::barsetClicked(QString category)
150 150 {
151 151 emit clicked(qobject_cast<QBarSet*>(sender()), category);
152 152 }
153 153
154 154 /*!
155 155 \internal \a category
156 156 */
157 157 void QBarSeries::barsetRightClicked(QString category)
158 158 {
159 159 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
160 160 }
161 161
162 162
163 163 /*!
164 164 \internal
165 165 */
166 166 qreal QBarSeries::min()
167 167 {
168 168 return mModel->min();
169 169 }
170 170
171 171 /*!
172 172 \internal
173 173 */
174 174 qreal QBarSeries::max()
175 175 {
176 176 return mModel->max();
177 177 }
178 178
179 179 /*!
180 180 \internal \a set \a category
181 181 */
182 182 qreal QBarSeries::valueAt(int set, int category)
183 183 {
184 184 return mModel->valueAt(set,category);
185 185 }
186 186
187 187 /*!
188 188 \internal \a set \a category
189 189 */
190 190 qreal QBarSeries::percentageAt(int set, int category)
191 191 {
192 192 return mModel->percentageAt(set,category);
193 193 }
194 194
195 195 /*!
196 196 \internal \a category
197 197 */
198 198 qreal QBarSeries::categorySum(int category)
199 199 {
200 200 return mModel->categorySum(category);
201 201 }
202 202
203 203 /*!
204 204 \internal
205 205 */
206 206 qreal QBarSeries::maxCategorySum()
207 207 {
208 208 return mModel->maxCategorySum();
209 209 }
210 210
211 211 /*!
212 212 \internal
213 213 */
214 214 BarChartModel& QBarSeries::model()
215 215 {
216 216 return *mModel;
217 217 }
218 218
219 219 bool QBarSeries::separatorsVisible()
220 220 {
221 221 return mSeparatorsVisible;
222 222 }
223 223
224 224 bool QBarSeries::setModel(QAbstractItemModel* model)
225 225 {
226 226 m_model = model;
227 return true;
227 228 }
228 229
229 230 void QBarSeries::setModelMappingCategories(int modelColumn)
230 231 {
231 232 //
232 233 }
233 234
234 235 void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry)
235 236 {
236 237 //
237 238 }
238 239
239 240 #include "moc_qbarseries.cpp"
240 241
241 242 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,634 +1,636
1 1 #include "qpieseries.h"
2 2 #include "qpieslice.h"
3 3 #include <QDebug>
4 4
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7
8 8 /*!
9 9 \class QPieSeries::ChangeSet
10 10 \brief Defines the changes in the series.
11 11
12 12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
13 13
14 14 \sa QPieSeries::changed()
15 15 */
16 16
17 17 /*!
18 18 \internal
19 19 */
20 20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
21 21 {
22 22 if (!m_added.contains(slice))
23 23 m_added << slice;
24 24 }
25 25
26 26 /*!
27 27 \internal
28 28 */
29 29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
30 30 {
31 31 foreach (QPieSlice* s, slices)
32 32 appendAdded(s);
33 33 }
34 34
35 35 /*!
36 36 \internal
37 37 */
38 38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
39 39 {
40 40 if (!m_changed.contains(slice))
41 41 m_changed << slice;
42 42 }
43 43
44 44 /*!
45 45 \internal
46 46 */
47 47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
48 48 {
49 49 if (!m_removed.contains(slice))
50 50 m_removed << slice;
51 51 }
52 52
53 53 /*!
54 54 Returns a list of slices that have been added to the series.
55 55 \sa QPieSeries::changed()
56 56 */
57 57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
58 58 {
59 59 return m_added;
60 60 }
61 61
62 62 /*!
63 63 Returns a list of slices that have been changed in the series.
64 64 \sa QPieSeries::changed()
65 65 */
66 66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
67 67 {
68 68 return m_changed;
69 69 }
70 70
71 71 /*!
72 72 Returns a list of slices that have been removed from the series.
73 73 \sa QPieSeries::changed()
74 74 */
75 75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
76 76 {
77 77 return m_removed;
78 78 }
79 79
80 80
81 81 /*!
82 82 Returns true if there are no added/changed or removed slices in the change set.
83 83 */
84 84 bool QPieSeries::ChangeSet::isEmpty() const
85 85 {
86 86 if (m_added.count() || m_changed.count() || m_removed.count())
87 87 return false;
88 88 return true;
89 89 }
90 90
91 91 /*!
92 92 \class QPieSeries
93 93 \brief Pie series API for QtCommercial Charts
94 94
95 95 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
96 96 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
97 97 The actual slice size is determined by that relative value.
98 98
99 99 By default the pie is defined as a full pie but it can be a partial pie.
100 100 This can be done by setting a starting angle and angle span to the series.
101 101 */
102 102
103 103 /*!
104 104 Constructs a series object which is a child of \a parent.
105 105 */
106 106 QPieSeries::QPieSeries(QObject *parent) :
107 107 QSeries(parent),
108 108 m_pieRelativeHorPos(0.5),
109 109 m_pieRelativeVerPos(0.5),
110 110 m_pieRelativeSize(0.7),
111 111 m_pieStartAngle(0),
112 112 m_pieEndAngle(360),
113 113 m_total(0)
114 114 {
115 115
116 116 }
117 117
118 118 /*!
119 119 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
120 120 */
121 121 QPieSeries::~QPieSeries()
122 122 {
123 123
124 124 }
125 125
126 126 /*!
127 127 Returns QChartSeries::SeriesTypePie.
128 128 */
129 129 QSeries::QSeriesType QPieSeries::type() const
130 130 {
131 131 return QSeries::SeriesTypePie;
132 132 }
133 133
134 134 /*!
135 135 Sets an array of \a slices to the series replacing the existing slices.
136 136 Slice ownership is passed to the series.
137 137 */
138 138 void QPieSeries::replace(QList<QPieSlice*> slices)
139 139 {
140 140 clear();
141 141 add(slices);
142 142 }
143 143
144 144 /*!
145 145 Adds an array of \a slices to the series.
146 146 Slice ownership is passed to the series.
147 147 */
148 148 void QPieSeries::add(QList<QPieSlice*> slices)
149 149 {
150 150 foreach (QPieSlice* s, slices) {
151 151 s->setParent(this);
152 152 m_slices << s;
153 153 }
154 154
155 155 updateDerivativeData();
156 156
157 157 foreach (QPieSlice* s, slices) {
158 158 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
159 159 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
160 160 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
161 161 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
162 162 }
163 163
164 164 emit changed();
165 165 }
166 166
167 167 /*!
168 168 Adds a single \a slice to the series.
169 169 Slice ownership is passed to the series.
170 170 */
171 171 void QPieSeries::add(QPieSlice* slice)
172 172 {
173 173 add(QList<QPieSlice*>() << slice);
174 174 }
175 175
176 176 /*!
177 177 Adds a single \a slice to the series and returns a reference to the series.
178 178 Slice ownership is passed to the series.
179 179 */
180 180 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
181 181 {
182 182 add(slice);
183 183 return *this;
184 184 }
185 185
186 186
187 187 /*!
188 188 Adds a single slice to the series with give \a value and \a name.
189 189 Slice ownership is passed to the series.
190 190 */
191 191 QPieSlice* QPieSeries::add(qreal value, QString name)
192 192 {
193 193 QPieSlice* slice = new QPieSlice(value, name);
194 194 add(slice);
195 195 return slice;
196 196 }
197 197
198 198 void QPieSeries::insert(int i, QPieSlice* slice)
199 199 {
200 200 Q_ASSERT(i <= m_slices.count());
201 201 slice->setParent(this);
202 202 m_slices.insert(i, slice);
203 203
204 204 updateDerivativeData();
205 205
206 206 connect(slice, SIGNAL(changed()), this, SLOT(sliceChanged()));
207 207 connect(slice, SIGNAL(clicked()), this, SLOT(sliceClicked()));
208 208 connect(slice, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
209 209 connect(slice, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
210 210
211 211 emit changed();
212 212 }
213 213
214 214 /*!
215 215 Removes a single \a slice from the series and deletes the slice.
216 216
217 217 Do not reference this pointer after this call.
218 218 */
219 219 void QPieSeries::remove(QPieSlice* slice)
220 220 {
221 221 if (!m_slices.removeOne(slice)) {
222 222 Q_ASSERT(0); // TODO: how should this be reported?
223 223 return;
224 224 }
225 225 emit changed();
226 226
227 227 updateDerivativeData();
228 228
229 229 delete slice;
230 230 slice = NULL;
231 231 }
232 232
233 233 /*!
234 234 Clears all slices from the series.
235 235 */
236 236 void QPieSeries::clear()
237 237 {
238 238 if (m_slices.count() == 0)
239 239 return;
240 240
241 241 foreach (QPieSlice* s, m_slices) {
242 242 m_slices.removeOne(s);
243 243 delete s;
244 244 }
245 245
246 246 emit changed();
247 247
248 248 updateDerivativeData();
249 249 }
250 250
251 251 /*!
252 252 Counts the number of the slices in this series.
253 253 */
254 254 int QPieSeries::count() const
255 255 {
256 256 return m_slices.count();
257 257 }
258 258
259 259 /*!
260 260 Returns a list of slices that belong to this series.
261 261 */
262 262 QList<QPieSlice*> QPieSeries::slices() const
263 263 {
264 264 return m_slices;
265 265 }
266 266
267 267 /*!
268 268 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
269 269
270 270 The factors are relative to the chart rectangle where:
271 271
272 272 \a relativeHorizontalPosition 0.0 means the absolute left.
273 273 \a relativeHorizontalPosition 1.0 means the absolute right.
274 274 \a relativeVerticalPosition 0.0 means the absolute top.
275 275 \a relativeVerticalPosition 1.0 means the absolute bottom.
276 276
277 277 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
278 278
279 279 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
280 280 */
281 281 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
282 282 {
283 283 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
284 284 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
285 285 return;
286 286
287 287 if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) {
288 288 m_pieRelativeHorPos = relativeHorizontalPosition;
289 289 m_pieRelativeVerPos = relativeVerticalPosition;
290 290 emit changed();
291 291 }
292 292 }
293 293
294 294 /*!
295 295 Gets the horizontal position of the pie.
296 296
297 297 The returned value is relative to the chart rectangle where:
298 298
299 299 0.0 means the absolute left.
300 300 1.0 means the absolute right.
301 301
302 302 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
303 303
304 304 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
305 305 */
306 306 qreal QPieSeries::pieHorizontalPosition() const
307 307 {
308 308 return m_pieRelativeHorPos;
309 309 }
310 310
311 311 /*!
312 312 Gets the vertical position position of the pie.
313 313
314 314 The returned value is relative to the chart rectangle where:
315 315
316 316 0.0 means the absolute top.
317 317 1.0 means the absolute bottom.
318 318
319 319 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
320 320
321 321 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
322 322 */
323 323 qreal QPieSeries::pieVerticalPosition() const
324 324 {
325 325 return m_pieRelativeVerPos;
326 326 }
327 327
328 328 /*!
329 329 Sets the relative size of the pie.
330 330
331 331 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
332 332
333 333 Default value is 0.7.
334 334
335 335 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
336 336 */
337 337 void QPieSeries::setPieSize(qreal relativeSize)
338 338 {
339 339 if (relativeSize < 0.0 || relativeSize > 1.0)
340 340 return;
341 341
342 342 if (m_pieRelativeSize != relativeSize) {
343 343 m_pieRelativeSize = relativeSize;
344 344 emit changed();
345 345 }
346 346 }
347 347
348 348 /*!
349 349 Gets the relative size of the pie.
350 350
351 351 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
352 352
353 353 Default value is 0.7.
354 354
355 355 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
356 356 */
357 357 qreal QPieSeries::pieSize() const
358 358 {
359 359 return m_pieRelativeSize;
360 360 }
361 361
362 362
363 363 /*!
364 364 Sets the end angle of the pie.
365 365
366 366 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
367 367
368 368 \a angle must be less than pie end angle. Default value is 0.
369 369
370 370 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
371 371 */
372 372 void QPieSeries::setPieStartAngle(qreal angle)
373 373 {
374 374 if (angle >= 0 && angle <= 360 && angle != m_pieStartAngle && angle <= m_pieEndAngle) {
375 375 m_pieStartAngle = angle;
376 376 updateDerivativeData();
377 377 }
378 378 }
379 379
380 380 /*!
381 381 Gets the start angle of the pie.
382 382
383 383 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
384 384
385 385 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
386 386 */
387 387 qreal QPieSeries::pieStartAngle() const
388 388 {
389 389 return m_pieStartAngle;
390 390 }
391 391
392 392 /*!
393 393 Sets the end angle of the pie.
394 394
395 395 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
396 396
397 397 \a angle must be greater than start angle.
398 398
399 399 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
400 400 */
401 401 void QPieSeries::setPieEndAngle(qreal angle)
402 402 {
403 403 if (angle >= 0 && angle <= 360 && angle != m_pieEndAngle && angle >= m_pieStartAngle) {
404 404 m_pieEndAngle = angle;
405 405 updateDerivativeData();
406 406 }
407 407 }
408 408
409 409 /*!
410 410 Returns the end angle of the pie.
411 411
412 412 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
413 413
414 414 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
415 415 */
416 416 qreal QPieSeries::pieEndAngle() const
417 417 {
418 418 return m_pieEndAngle;
419 419 }
420 420
421 421 /*!
422 422 Sets the all the slice labels \a visible or invisible.
423 423
424 424 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
425 425 */
426 426 void QPieSeries::setLabelsVisible(bool visible)
427 427 {
428 428 foreach (QPieSlice* s, m_slices)
429 429 s->setLabelVisible(visible);
430 430 }
431 431
432 432 /*!
433 433 Returns the sum of all slice values in this series.
434 434
435 435 \sa QPieSlice::value(), QPieSlice::setValue()
436 436 */
437 437 qreal QPieSeries::total() const
438 438 {
439 439 return m_total;
440 440 }
441 441
442 442 /*!
443 443 \fn void QPieSeries::changed()
444 444
445 445 This signal emitted when something has changed in the series.
446 446
447 447 \sa QPieSeries::ChangeSet, QPieSlice::changed()
448 448 */
449 449
450 450 /*!
451 451 \fn void QPieSeries::clicked(QPieSlice* slice)
452 452
453 453 This signal is emitted when a \a slice has been clicked.
454 454
455 455 \sa QPieSlice::clicked()
456 456 */
457 457
458 458 /*!
459 459 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
460 460
461 461 This signal is emitted when user has hovered over a \a slice.
462 462
463 463 \sa QPieSlice::hoverEnter()
464 464 */
465 465
466 466 /*!
467 467 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
468 468
469 469 This signal is emitted when user has hovered away from a \a slice.
470 470
471 471 \sa QPieSlice::hoverLeave()
472 472 */
473 473
474 474 void QPieSeries::sliceChanged()
475 475 {
476 476 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
477 477 Q_ASSERT(m_slices.contains(slice));
478 478 updateDerivativeData();
479 479 }
480 480
481 481 void QPieSeries::sliceClicked()
482 482 {
483 483 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
484 484 Q_ASSERT(m_slices.contains(slice));
485 485 emit clicked(slice);
486 486 }
487 487
488 488 void QPieSeries::sliceHoverEnter()
489 489 {
490 490 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
491 491 Q_ASSERT(m_slices.contains(slice));
492 492 emit hoverEnter(slice);
493 493 }
494 494
495 495 void QPieSeries::sliceHoverLeave()
496 496 {
497 497 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
498 498 Q_ASSERT(m_slices.contains(slice));
499 499 emit hoverLeave(slice);
500 500 }
501 501
502 502 void QPieSeries::updateDerivativeData()
503 503 {
504 504 m_total = 0;
505 505
506 506 // nothing to do?
507 507 if (m_slices.count() == 0)
508 508 return;
509 509
510 510 // calculate total
511 511 foreach (QPieSlice* s, m_slices)
512 512 m_total += s->value();
513 513
514 514 // we must have some values
515 515 if (m_total == 0) {
516 516 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
517 517 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
518 518 }
519 519
520 520 // update slice attributes
521 521 qreal sliceAngle = m_pieStartAngle;
522 522 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
523 523 foreach (QPieSlice* s, m_slices) {
524 524
525 525 bool changed = false;
526 526
527 527 qreal percentage = s->value() / m_total;
528 528 if (s->m_percentage != percentage) {
529 529 s->m_percentage = percentage;
530 530 changed = true;
531 531 }
532 532
533 533 qreal sliceSpan = pieSpan * percentage;
534 534 if (s->m_angleSpan != sliceSpan) {
535 535 s->m_angleSpan = sliceSpan;
536 536 changed = true;
537 537 }
538 538
539 539 if (s->m_startAngle != sliceAngle) {
540 540 s->m_startAngle = sliceAngle;
541 541 changed = true;
542 542 }
543 543 sliceAngle += sliceSpan;
544 544
545 545 if (changed)
546 546 emit s->changed();
547 547 }
548 548 }
549 549
550 550 bool QPieSeries::setModel(QAbstractItemModel* model)
551 551 {
552 552 // disconnect signals from old model
553 553 if(m_model)
554 554 {
555 555 disconnect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0, 0);
556 556 disconnect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), 0, 0);
557 557 disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), 0, 0);
558 558 }
559 559
560 560 // set new model if not NULL and connect necessary signals from it
561 561 if(model)
562 562 {
563 563 m_model = model;
564 564 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
565 565 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
566 566 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
567 567 }
568
569 return true;
568 570 }
569 571
570 572 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
571 573 {
572 574 m_mapValues = modelValuesLine;
573 575 m_mapLabels = modelLabelsLine;
574 576 m_mapOrientation = orientation;
575 577
576 578 if (m_model == NULL)
577 579 return;
578 580
579 581 if (m_mapOrientation == Qt::Vertical)
580 582 for (int i = 0; i < m_model->rowCount(); i++)
581 583 add(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
582 584 else
583 585 for (int i = 0; i < m_model->columnCount(); i++)
584 586 add(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString());
585 587
586 588
587 589 }
588 590
589 591 void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
590 592 {
591 593 if (m_mapOrientation == Qt::Vertical)
592 594 {
593 595 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
594 596 if (topLeft.column() == m_mapValues)
595 597 slices().at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
596 598 else if (topLeft.column() == m_mapLabels)
597 599 slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
598 600 }
599 601 else
600 602 {
601 603 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
602 604 if (topLeft.column() == m_mapValues)
603 605 slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
604 606 else if (topLeft.column() == m_mapLabels)
605 607 slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
606 608 }
607 609 }
608 610
609 611 void QPieSeries::modelDataAdded(QModelIndex parent, int start, int end)
610 612 {
611 613 QPieSlice* newSlice = new QPieSlice;
612 614 newSlice->setLabelVisible(true);
613 615 if (m_mapOrientation == Qt::Vertical)
614 616 {
615 617 newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
616 618 newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
617 619 }
618 620 else
619 621 {
620 622 newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
621 623 newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
622 624 }
623 625
624 626 insert(start, newSlice);
625 627 }
626 628
627 629 void QPieSeries::modelDataRemoved(QModelIndex parent, int start, int end)
628 630 {
629 631 remove(slices().at(start));
630 632 }
631 633
632 634 #include "moc_qpieseries.cpp"
633 635
634 636 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,154 +1,155
1 1 #include "qsplineseries.h"
2 2
3 3 /*!
4 4 \class QSplineSeries
5 5 \brief Series type used to store data needed to draw a spline.
6 6
7 7 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
8 8 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
9 9 */
10 10
11 11 /*!
12 12 \fn QSeriesType QSplineSeries::type() const
13 13 Returns the type of the series
14 14 */
15 15
16 16 /*!
17 17 \fn QSeriesType QSplineSeries::controlPoint(int index) const
18 18 Returns the control point specified by \a index
19 19 */
20 20
21 21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
22 22
23 23 /*!
24 24 Constructs empty series object which is a child of \a parent.
25 25 When series object is added to QChartView or QChart instance then the ownerships is transfered.
26 26 */
27 27
28 28 QSplineSeries::QSplineSeries(QObject *parent) :
29 29 QLineSeries(parent)
30 30 {
31 31 connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
32 32 connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
33 33 connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
34 34 }
35 35
36 36 /*!
37 37 \internal
38 38 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
39 39 */
40 40 void QSplineSeries::calculateControlPoints()
41 41 {
42 42
43 43 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
44 44 // CPOL License
45 45
46 46 int n = count() - 1;
47 47 if (n == 1)
48 48 { // Special case: Bezier curve should be a straight line.
49 49 // firstControlPoints = new Point[1];
50 50 // 3P1 = 2P0 + P3
51 51 m_controlPoints.append(QPointF((2 * x(0) + x(1)) / 3, (2 * y(0) + y(1)) / 3));
52 52
53 53 // P2 = 2P1 P0
54 54 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - x(0), 2 * m_controlPoints[0].y() - y(0)));
55 55 return;
56 56 }
57 57
58 58 // Calculate first Bezier control points
59 59 // Right hand side vector
60 60 // Set of equations for P0 to Pn points.
61 61 //
62 62 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
63 63 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
64 64 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
65 65 // | . . . . . . . . . . . . | | ... | | ... |
66 66 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
67 67 // | . . . . . . . . . . . . | | ... | | ... |
68 68 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
69 69 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
70 70 //
71 71 QList<qreal> rhs;
72 72 rhs.append(x(0) + 2 * x(1));
73 73
74 74 // Set right hand side X values
75 75 for (int i = 1; i < n - 1; ++i)
76 76 rhs.append(4 * x(i) + 2 * x(i + 1));
77 77
78 78 rhs.append((8 * x(n - 1) + x(n)) / 2.0);
79 79 // Get first control points X-values
80 80 QList<qreal> xControl = getFirstControlPoints(rhs);
81 81 rhs[0] = y(0) + 2 * y(1);
82 82
83 83 // Set right hand side Y values
84 84 for (int i = 1; i < n - 1; ++i)
85 85 rhs[i] = 4 * y(i) + 2 * y(i + 1);
86 86
87 87 rhs[n - 1] = (8 * y(n - 1) + y(n)) / 2.0;
88 88 // Get first control points Y-values
89 89 QList<qreal> yControl = getFirstControlPoints(rhs);
90 90
91 91 // Fill output arrays.
92 92 for (int i = 0; i < n; ++i)
93 93 {
94 94 // First control point
95 95 m_controlPoints.append(QPointF(xControl[i], yControl[i]));
96 96 // Second control point
97 97 if (i < n - 1)
98 98 m_controlPoints.append(QPointF(2 * x(i + 1) - xControl[i + 1], 2 * y(i + 1) - yControl[i + 1]));
99 99 else
100 100 m_controlPoints.append(QPointF((x(n) + xControl[n - 1]) / 2, (y(n) + yControl[n - 1]) / 2));
101 101 }
102 102 }
103 103
104 104 /*!
105 105 \internal
106 106 */
107 107 QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs)
108 108 {
109 109 QList<qreal> x; // Solution vector.
110 110 QList<qreal> tmp; // Temp workspace.
111 111
112 112 qreal b = 2.0;
113 113 x.append(rhs[0] / b);
114 114 tmp.append(0);
115 115 for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution.
116 116 {
117 117 tmp.append(1 / b);
118 118 b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
119 119 x.append((rhs[i] - x[i - 1]) / b);
120 120 }
121 121 for (int i = 1; i < rhs.size(); i++)
122 122 x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
123 123
124 124 return x;
125 125 }
126 126
127 127 /*!
128 128 \internal
129 129 Updates the control points, besed on currently avaiable knots.
130 130 */
131 131 void QSplineSeries::updateControlPoints()
132 132 {
133 133 if(count() > 1)
134 134 {
135 135 m_controlPoints.clear();
136 136 calculateControlPoints();
137 137 }
138 138 }
139 139
140 140 bool QSplineSeries::setModel(QAbstractItemModel* model)
141 141 {
142 142 QXYSeries::setModel(model);
143 143 // calculateControlPoints();
144 return true;
144 145 }
145 146
146 147 void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
147 148 {
148 149 QLineSeries::setModelMapping(modelX, modelY, orientation);
149 150 calculateControlPoints();
150 151 }
151 152
152 153 #include "moc_qsplineseries.cpp"
153 154
154 155 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,131 +1,132
1 1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 2 TARGET = QtCommercialChart
3 3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 4 TEMPLATE = lib
5 5 QT += core \
6 6 gui
7 win32: LIBS += User32.lib
7 8 CONFIG += debug_and_release
8 9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 10 SOURCES += \
10 11 chartdataset.cpp \
11 12 chartpresenter.cpp \
12 13 charttheme.cpp \
13 14 domain.cpp \
14 15 qchart.cpp \
15 16 qchartview.cpp \
16 17 qseries.cpp \
17 18 qlegend.cpp \
18 19 legendmarker.cpp
19 20 PRIVATE_HEADERS += \
20 21 chartdataset_p.h \
21 22 chartitem_p.h \
22 23 chartpresenter_p.h \
23 24 charttheme_p.h \
24 25 domain_p.h \
25 26 legendmarker_p.h
26 27 PUBLIC_HEADERS += \
27 28 qchart.h \
28 29 qchartglobal.h \
29 30 qseries.h \
30 31 qchartview.h \
31 32 qlegend.h
32 33
33 34 include(animations/animations.pri)
34 35 include(axis/axis.pri)
35 36 include(xychart/xychart.pri)
36 37 include(linechart/linechart.pri)
37 38 include(areachart/areachart.pri)
38 39 include(barchart/barchart.pri)
39 40 include(piechart/piechart.pri)
40 41 include(scatterseries/scatter.pri)
41 42 include(splinechart/splinechart.pri)
42 43
43 44 THEMES += themes/chartthemedefault_p.h \
44 45 themes/chartthemeicy_p.h \
45 46 themes/chartthemegrayscale_p.h \
46 47 themes/chartthemescientific_p.h \
47 48 themes/chartthemevanilla_p.h \
48 49 themes/chartthemebluecerulean_p.h \
49 50 themes/chartthemelight_p.h
50 51
51 52 HEADERS += $$PUBLIC_HEADERS
52 53 HEADERS += $$PRIVATE_HEADERS
53 54 HEADERS += $$THEMES
54 55 INCLUDEPATH += linechart \
55 56 barchart \
56 57 themes \
57 58 .
58 59 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
59 60 MOC_DIR = $$CHART_BUILD_DIR/lib
60 61 UI_DIR = $$CHART_BUILD_DIR/lib
61 62 RCC_DIR = $$CHART_BUILD_DIR/lib
62 63 DEFINES += QTCOMMERCIALCHART_LIBRARY
63 64
64 65 #qt public headers
65 66 #this is very primitive and lame parser , TODO: make perl script insted
66 67 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR)
67 68 {
68 69 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
69 70 }
70 71
71 72 for(file, PUBLIC_HEADERS) {
72 73 name = $$split(file,'/')
73 74 name = $$last(name)
74 75 class = "$$cat($$file)"
75 76 class = $$find(class,class)
76 77 !isEmpty(class){
77 78 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
78 79 class = $$member(class,1)
79 80 class = $$split(class,' ')
80 81 class = $$replace(class,' ','')
81 82 class = $$member(class,0)
82 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
83 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
83 84 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
84 85 system($$command)
85 86 }
86 87 }
87 88
88 89 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
89 90 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
90 91
91 92 target.path = $$[QT_INSTALL_LIBS]
92 93 INSTALLS += target public_headers
93 94
94 95 install_build_public_headers.name = build_public_headers
95 96 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
96 97 install_build_public_headers.input = PUBLIC_HEADERS
97 98 install_build_public_headers.commands = $$QMAKE_COPY \
98 99 ${QMAKE_FILE_NAME} \
99 100 $$CHART_BUILD_PUBLIC_HEADER_DIR
100 101 install_build_public_headers.CONFIG += target_predeps \
101 102 no_link
102 103
103 104 install_build_private_headers.name = buld_private_headers
104 105 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
105 106 install_build_private_headers.input = PRIVATE_HEADERS
106 107 install_build_private_headers.commands = $$QMAKE_COPY \
107 108 ${QMAKE_FILE_NAME} \
108 109 $$CHART_BUILD_PRIVATE_HEADER_DIR
109 110 install_build_private_headers.CONFIG += target_predeps \
110 111 no_link
111 112
112 113 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
113 114 install_build_private_headers \
114 115
115 116 chartversion.target = qchartversion_p.h
116 117 chartversion.commands = @echo \
117 118 "build_time" \
118 119 > \
119 120 $$chartversion.target;
120 121 chartversion.depends = $$HEADERS \
121 122 $$SOURCES
122 123 PRE_TARGETDEPS += qchartversion_p.h
123 124 QMAKE_CLEAN += qchartversion_p.h
124 125 QMAKE_EXTRA_TARGETS += chartversion
125 126 unix:QMAKE_DISTCLEAN += -r \
126 127 $$CHART_BUILD_HEADER_DIR \
127 128 $$CHART_BUILD_LIB_DIR
128 129 win32:QMAKE_DISTCLEAN += /Q \
129 130 $$CHART_BUILD_HEADER_DIR \
130 131 $$CHART_BUILD_LIB_DIR
131 132
@@ -1,310 +1,311
1 1 #include "qxyseries.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 /*!
6 6 \class QXYSeries
7 7 \brief The QXYSeries class is a base class for line, spline and scatter series.
8 8 */
9 9
10 10 /*!
11 11 \fn QPen QXYSeries::pen() const
12 12 \brief Returns pen used to draw points for series.
13 13 \sa setPen()
14 14 */
15 15
16 16 /*!
17 17 \fn QBrush QXYSeries::brush() const
18 18 \brief Returns brush used to draw points for series.
19 19 \sa setBrush()
20 20 */
21 21
22 22 /*!
23 23 \fn void QXYSeries::clicked(const QPointF& point)
24 24 \brief Signal is emitted when user clicks the \a point on chart.
25 25 */
26 26
27 27 /*!
28 28 \fn void QXYSeries::pointReplaced(int index)
29 29 \brief \internal \a index
30 30 */
31 31
32 32 /*!
33 33 \fn void QXYSeries::pointAdded(int index)
34 34 \brief \internal \a index
35 35 */
36 36
37 37 /*!
38 38 \fn void QXYSeries::pointRemoved(int index)
39 39 \brief \internal \a index
40 40 */
41 41
42 42 /*!
43 43 \fn void QXYSeries::updated()
44 44 \brief \internal
45 45 */
46 46
47 47 /*!
48 48 Constructs empty series object which is a child of \a parent.
49 49 When series object is added to QChartView or QChart instance ownerships is transfered.
50 50 */
51 51 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
52 52 {
53 53 m_mapX = -1;
54 54 m_mapY = -1;
55 55 m_mapOrientation = Qt::Vertical;
56 56 // m_mapYOrientation = Qt::Vertical;
57 57 }
58 58 /*!
59 59 Destroys the object. Series added to QChartView or QChart instances are owned by those,
60 60 and are deleted when mentioned object are destroyed.
61 61 */
62 62 QXYSeries::~QXYSeries()
63 63 {
64 64 }
65 65
66 66 /*!
67 67 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
68 68 */
69 69 void QXYSeries::add(qreal x,qreal y)
70 70 {
71 71 Q_ASSERT(m_x.size() == m_y.size());
72 72 m_x<<x;
73 73 m_y<<y;
74 74 emit pointAdded(m_x.size()-1);
75 75 }
76 76
77 77 /*!
78 78 This is an overloaded function.
79 79 Adds data \a point to the series. Points are connected with lines on the chart.
80 80 */
81 81 void QXYSeries::add(const QPointF& point)
82 82 {
83 83 add(point.x(),point.y());
84 84 }
85 85
86 86 /*!
87 87 This is an overloaded function.
88 88 Adds list of data \a points to the series. Points are connected with lines on the chart.
89 89 */
90 90 void QXYSeries::add(const QList<QPointF> points)
91 91 {
92 92 foreach(const QPointF& point , points) {
93 93 add(point.x(),point.y());
94 94 }
95 95 }
96 96
97 97 /*!
98 98 Modifies \a y value for given \a x a value.
99 99 */
100 100 void QXYSeries::replace(qreal x,qreal y)
101 101 {
102 102 int index = m_x.indexOf(x);
103 103 m_x[index]=x;
104 104 m_y[index]=y;
105 105 emit pointReplaced(index);
106 106 }
107 107
108 108 /*!
109 109 This is an overloaded function.
110 110 Replaces current y value of for given \a point x value with \a point y value.
111 111 */
112 112 void QXYSeries::replace(const QPointF& point)
113 113 {
114 114 replace(point.x(),point.y());
115 115 }
116 116
117 117 /*!
118 118 Removes current \a x and \a y value.
119 119 */
120 120 void QXYSeries::remove(qreal x,qreal y)
121 121 {
122 122 int index =-1;
123 123 do{
124 124 index = m_x.indexOf(x,index+1);
125 125 }while(index !=-1 && m_y.at(index)!=y);
126 126
127 127 if(index==-1) return;
128 128
129 129 m_x.remove(index);
130 130 m_y.remove(index);
131 131 emit pointRemoved(index);
132 132 }
133 133
134 134 /*!
135 135 Removes current \a point x value. Note \a point y value is ignored.
136 136 */
137 137 void QXYSeries::remove(const QPointF& point)
138 138 {
139 139 remove(point.x(),point.y());
140 140 }
141 141
142 142 /*!
143 143 Removes all data points from the series.
144 144 */
145 145 void QXYSeries::removeAll()
146 146 {
147 147 m_x.clear();
148 148 m_y.clear();
149 149 }
150 150
151 151 /*!
152 152 \internal \a pos
153 153 */
154 154 qreal QXYSeries::x(int pos) const
155 155 {
156 156 if (m_model)
157 157 if (m_mapOrientation == Qt::Vertical)
158 158 // consecutive data is read from model's column
159 159 return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble();
160 160 else
161 161 // consecutive data is read from model's row
162 162 return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble();
163 163 else
164 164 // model is not specified, return the data from series' internal data store
165 165 return m_x.at(pos);
166 166 }
167 167
168 168 /*!
169 169 \internal \a pos
170 170 */
171 171 qreal QXYSeries::y(int pos) const
172 172 {
173 173 if (m_model)
174 174 if (m_mapOrientation == Qt::Vertical)
175 175 // consecutive data is read from model's column
176 176 return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble();
177 177 else
178 178 // consecutive data is read from model's row
179 179 return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble();
180 180 else
181 181 // model is not specified, return the data from series' internal data store
182 182 return m_y.at(pos);
183 183 }
184 184
185 185 /*!
186 186 Returns number of data points within series.
187 187 */
188 188 int QXYSeries::count() const
189 189 {
190 190 Q_ASSERT(m_x.size() == m_y.size());
191 191
192 192 if (m_model)
193 193 if (m_mapOrientation == Qt::Vertical)
194 194 // data is in a column, so return the number of items in single column
195 195 return m_model->rowCount();
196 196 else
197 197 // data is in a row, so return the number of items in single row
198 198 m_model->columnCount();
199 199 else
200 200 // model is not specified, return the number of points in the series internal data store
201 201 return m_x.size();
202 202 }
203 203
204 204 /*!
205 205 Returns the data points of the series.
206 206 */
207 207 QList<QPointF> QXYSeries::data()
208 208 {
209 209 QList<QPointF> data;
210 210 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
211 211 data.append(QPointF(m_x.at(i), m_y.at(i)));
212 212 return data;
213 213 }
214 214
215 215
216 216 /*!
217 217 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
218 218 pen from chart theme is used.
219 219 \sa QChart::setChartTheme()
220 220 */
221 221 void QXYSeries::setPen(const QPen& pen)
222 222 {
223 223 if(pen!=m_pen){
224 224 m_pen=pen;
225 225 emit updated();
226 226 }
227 227 }
228 228
229 229 /*!
230 230 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
231 231 from chart theme setting is used.
232 232 \sa QChart::setChartTheme()
233 233 */
234 234
235 235 void QXYSeries::setBrush(const QBrush& brush)
236 236 {
237 237 if(brush!=m_brush){
238 238 m_brush=brush;
239 239 emit updated();
240 240 }
241 241 }
242 242
243 243
244 244 /*!
245 245 Stream operator for adding a data \a point to the series.
246 246 \sa add()
247 247 */
248 248
249 249 QXYSeries& QXYSeries::operator<< (const QPointF &point)
250 250 {
251 251 add(point);
252 252 return *this;
253 253 }
254 254
255 255
256 256 /*!
257 257 Stream operator for adding a list of \a points to the series.
258 258 \sa add()
259 259 */
260 260
261 261 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
262 262 {
263 263 add(points);
264 264 return *this;
265 265 }
266 266
267 267
268 268 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
269 269 {
270 270 if (m_mapOrientation == Qt::Vertical)
271 271 emit pointReplaced(topLeft.row());
272 272 else
273 273 emit pointReplaced(topLeft.column());
274 274 }
275 275
276 276 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
277 277 {
278 278 emit pointAdded(start);
279 279 }
280 280
281 281 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
282 282 {
283 283 emit pointRemoved(start);
284 284 }
285 285
286 286 bool QXYSeries::setModel(QAbstractItemModel* model) {
287 287 m_model = model;
288 288 // for (int i = 0; i < m_model->rowCount(); i++)
289 289 // emit pointAdded(i);
290 290 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
291 291 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
292 292 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
293 return true;
293 294 }
294 295
295 296 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
296 297 {
297 298 m_mapX = modelX;
298 299 m_mapY = modelY;
299 300 m_mapOrientation = orientation;
300 301 }
301 302
302 303 //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation)
303 304 //{
304 305 // m_mapY = modelLineIndex;
305 306 // m_mapYOrientation = orientation;
306 307 //}
307 308
308 309 #include "moc_qxyseries.cpp"
309 310
310 311 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now