##// END OF EJS Templates
minor fix
Marek Rosa -
r1602:1a4e98ae768d
parent child
Show More
@@ -1,617 +1,617
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 "qbarset.h"
22 22 #include "qbarset_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QBarSet
28 28 \brief Building block for different bar charts
29 29
30 30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 31 First value of set is assumed to belong to first category, second to second category and so on.
32 32 If set has fewer values than there are categories, then the missing values are assumed to be
33 33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34 34
35 35 \mainclass
36 36
37 37 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
38 38 */
39 39 /*!
40 40 \qmlclass BarSet QBarSet
41 41
42 42 BarSet represents one set of bars. Set of bars contains one data value for each category.
43 43 First value of set is assumed to belong to first category, second to second category and so on.
44 44 If set has fewer values than there are categories, then the missing values are assumed to be
45 45 at the end of set. For missing values in middle of a set, numerical value of zero is used.
46 46 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
47 47 */
48 48
49 49 /*!
50 50 \property QBarSet::label
51 51 Defines the label of the barSet.
52 52 */
53 53 /*!
54 54 \qmlproperty string BarSet::label
55 55 Defines the label of the barSet.
56 56 */
57 57
58 58 /*!
59 59 \property QBarSet::pen
60 60 \brief Defines the pen used by the barSet.
61 61 */
62 62
63 63 /*!
64 64 \property QBarSet::brush
65 65 \brief Defines the brush used by the barSet.
66 66 */
67 67
68 68 /*!
69 69 \property QBarSet::labelBrush
70 70 \brief Defines the brush used by the barSet's label.
71 71 */
72 72
73 73 /*!
74 74 \property QBarSet::labelFont
75 75 \brief Defines the font used by the barSet's label.
76 76 */
77 77
78 78 /*!
79 79 \qmlproperty Font BarSet::labelFont
80 80 Defines the font used by the barSet's label.
81 81
82 82 See the \l {Font} {QML Font Element} for detailed documentation.
83 83 */
84 84
85 85 /*!
86 86 \property QBarSet::color
87 87 The fill (brush) color of the bar set.
88 88 */
89 89 /*!
90 90 \qmlproperty color BarSet::color
91 91 The fill (brush) color of the bar set.
92 92 */
93 93
94 94 /*!
95 95 \property QBarSet::borderColor
96 96 The line (pen) color of the bar set.
97 97 */
98 98 /*!
99 99 \qmlproperty color BarSet::borderColor
100 100 The line (pen) color of the bar set.
101 101 */
102 102
103 103 /*!
104 104 \property QBarSet::labelColor
105 105 The text (label) color of the bar set.
106 106 */
107 107 /*!
108 108 \qmlproperty color BarSet::labelColor
109 109 The text (label) color of the bar set.
110 110 */
111 111
112 112 /*!
113 113 \fn void QBarSet::clicked(int index)
114 114
115 115 The signal is emitted if the user clicks with a mouse on top of barset.
116 116 Clicked bar inside set is indexed by \a index
117 117 */
118 118
119 119 /*!
120 120 \fn void QBarSet::hovered(bool status)
121 121
122 122 The signal is emitted if mouse is hovered on top of barset.
123 123 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
124 124 */
125 125
126 126
127 127 /*!
128 128 \fn void QBarSet::labelChanged()
129 129 This signal is emitted when the label of the barSet has changed.
130 130 \sa label
131 131 */
132 132 /*!
133 133 \qmlsignal BarSet::onLabelChanged()
134 134 This signal is emitted when the label of the barSet has changed.
135 135 */
136 136
137 137 /*!
138 138 \fn void QBarSet::penChanged()
139 139 This signal is emitted when the pen of the barSet has changed.
140 140 \sa pen
141 141 */
142 142
143 143 /*!
144 144 \fn void QBarSet::brushChanged()
145 145 This signal is emitted when the brush of the barSet has changed.
146 146 \sa brush
147 147 */
148 148
149 149 /*!
150 150 \fn void QBarSet::labelBrushChanged()
151 151 This signal is emitted when the brush of the barSet's label has changed.
152 152 \sa labelBrush
153 153 */
154 154
155 155 /*!
156 156 \fn void QBarSet::labelFontChanged()
157 157 This signal is emitted when the font of the barSet's label has changed.
158 158 \sa labelBrush
159 159 */
160 160
161 161 /*!
162 162 \fn void QBarSet::colorChanged(QColor)
163 163 This signal is emitted when the fill (brush) color of the set has changed to \a color.
164 164 */
165 165 /*!
166 166 \qmlsignal BarSet::onColorChanged(color color)
167 167 This signal is emitted when the fill (brush) color of the set has changed to \a color.
168 168 */
169 169
170 170 /*!
171 171 \fn void QBarSet::borderColorChanged(QColor)
172 172 This signal is emitted when the line (pen) color of the set has changed to \a color.
173 173 */
174 174 /*!
175 175 \qmlsignal BarSet::onBorderColorChanged(color color)
176 176 This signal is emitted when the line (pen) color of the set has changed to \a color.
177 177 */
178 178
179 179 /*!
180 180 \fn void QBarSet::labelColorChanged(QColor)
181 181 This signal is emitted when the text (label) color of the set has changed to \a color.
182 182 */
183 183 /*!
184 184 \qmlsignal BarSet::onLabelColorChanged(color color)
185 185 This signal is emitted when the text (label) color of the set has changed to \a color.
186 186 */
187 187
188 188 /*!
189 189 \fn void QBarSet::valuesAdded(int index, int count)
190 190 This signal is emitted when new values have been added to the set.
191 191 Parameter \a index indicates the position of the first inserted value.
192 192 Parameter \a count is the number of iserted values.
193 193 \sa append(), insert()
194 194 */
195 195 /*!
196 196 \qmlsignal BarSet::onValuesAdded(int index, int count)
197 197 This signal is emitted when new values have been added to the set.
198 198 Parameter \a index indicates the position of the first inserted value.
199 199 Parameter \a count is the number of iserted values.
200 200 */
201 201
202 202 /*!
203 203 \fn void QBarSet::valuesRemoved(int index, int count)
204 204 This signal is emitted values have been removed from the set.
205 205 Parameter \a index indicates the position of the first removed value.
206 206 Parameter \a count is the number of removed values.
207 207 \sa remove()
208 208 */
209 209 /*!
210 210 \qmlsignal BarSet::onValuesRemoved(int index, int count)
211 211 This signal is emitted values have been removed from the set.
212 212 Parameter \a index indicates the position of the first removed value.
213 213 Parameter \a count is the number of removed values.
214 214 */
215 215
216 216 /*!
217 217 \fn void QBarSet::valueChanged(int index)
218 218 This signal is emitted values the value in the set has been modified.
219 219 Parameter \a index indicates the position of the modified value.
220 220 \sa at()
221 221 */
222 222 /*!
223 223 \qmlsignal BarSet::onValueChanged(int index)
224 224 This signal is emitted values the value in the set has been modified.
225 225 Parameter \a index indicates the position of the modified value.
226 226 */
227 227
228 228 /*!
229 229 \qmlproperty int BarSet::count
230 230 The count of values on the barset
231 231 */
232 232
233 233 /*!
234 234 \qmlproperty QVariantList BarSet::values
235 235 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
236 236 reals as values, the values are automatically completed to points by using the index of a value as it's
237 237 x-coordinate. For example:
238 238 \code
239 239 myBarSet1.values = [0, 5, 1, 5];
240 240 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
241 241 \endcode
242 242 */
243 243
244 244 /*!
245 245 Constructs QBarSet with a label of \a label and with parent of \a parent
246 246 */
247 247 QBarSet::QBarSet(const QString label, QObject *parent)
248 248 : QObject(parent)
249 249 ,d_ptr(new QBarSetPrivate(label,this))
250 250 {
251 251 }
252 252
253 253 /*!
254 254 Destroys the barset
255 255 */
256 256 QBarSet::~QBarSet()
257 257 {
258 258 // NOTE: d_ptr destroyed by QObject
259 259 }
260 260
261 261 /*!
262 262 Sets new \a label for set.
263 263 */
264 264 void QBarSet::setLabel(const QString label)
265 265 {
266 266 d_ptr->m_label = label;
267 267 emit labelChanged();
268 268 }
269 269
270 270 /*!
271 271 Returns label of the set.
272 272 */
273 273 QString QBarSet::label() const
274 274 {
275 275 return d_ptr->m_label;
276 276 }
277 277
278 278 /*!
279 279 Appends new value \a value to the end of set.
280 280 */
281 281 void QBarSet::append(const qreal value)
282 282 {
283 283 // Convert to QPointF
284 284 int index = d_ptr->m_values.count();
285 285 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
286 emit valuesAdded(index,1);
286 emit valuesAdded(index, 1);
287 287 }
288 288
289 289 /*!
290 290 Appends a list of reals to set. Works like append with single real value. The \a values in list
291 291 are appended to end of barset
292 292 \sa append()
293 293 */
294 294 void QBarSet::append(const QList<qreal> &values)
295 295 {
296 296 int index = d_ptr->m_values.count();
297 297 d_ptr->append(values);
298 298 emit valuesAdded(index, values.count());
299 299 }
300 300
301 301 /*!
302 302 Convinience operator. Same as append, with real \a value.
303 303 \sa append()
304 304 */
305 305 QBarSet& QBarSet::operator << (const qreal &value)
306 306 {
307 307 append(value);
308 308 return *this;
309 309 }
310 310
311 311 /*!
312 312 Inserts new \a value on the \a index position.
313 313 The value that is currently at this postion is moved to postion index + 1
314 314 \sa remove()
315 315 */
316 316 void QBarSet::insert(const int index, const qreal value)
317 317 {
318 318 d_ptr->insert(index, value);
319 319 emit valuesAdded(index,1);
320 320 }
321 321
322 322 /*!
323 323 Removes \a count number of values from the set starting at \a index.
324 324 \sa insert()
325 325 */
326 326 void QBarSet::remove(const int index, const int count)
327 327 {
328 328 int removedCount = d_ptr->remove(index,count);
329 329 if (removedCount > 0) {
330 330 emit valuesRemoved(index,removedCount);
331 331 }
332 332 return;
333 333 }
334 334
335 335 /*!
336 336 Sets a new value \a value to set, indexed by \a index
337 337 */
338 338 void QBarSet::replace(const int index, const qreal value)
339 339 {
340 340 if (index >= 0 && index < d_ptr->m_values.count()) {
341 341 d_ptr->replace(index,value);
342 342 emit valueChanged(index);
343 343 }
344 344 }
345 345
346 346
347 347 /*!
348 348 Returns value of set indexed by \a index.
349 349 If the index is out of bounds 0.0 is returned.
350 350 */
351 351 qreal QBarSet::at(const int index) const
352 352 {
353 353 if (index < 0 || index >= d_ptr->m_values.count()) {
354 354 return 0;
355 355 }
356 356
357 357 return d_ptr->m_values.at(index).y();
358 358 }
359 359
360 360 /*!
361 361 Returns value of set indexed by \a index.
362 362 If the index is out of bounds 0.0 is returned.
363 363 */
364 364 qreal QBarSet::operator [](const int index) const
365 365 {
366 366 return at(index);
367 367 }
368 368
369 369 /*!
370 370 Returns count of values in set.
371 371 */
372 372 int QBarSet::count() const
373 373 {
374 374 return d_ptr->m_values.count();
375 375 }
376 376
377 377 /*!
378 378 Returns sum of all values in barset.
379 379 */
380 380 qreal QBarSet::sum() const
381 381 {
382 382 qreal total(0);
383 383 for (int i=0; i < d_ptr->m_values.count(); i++) {
384 384 total += d_ptr->m_values.at(i).y();
385 385 }
386 386 return total;
387 387 }
388 388
389 389 /*!
390 390 Sets pen for set. Bars of this set are drawn using \a pen
391 391 */
392 392 void QBarSet::setPen(const QPen &pen)
393 393 {
394 394 if(d_ptr->m_pen!=pen){
395 395 d_ptr->m_pen = pen;
396 396 emit d_ptr->updatedBars();
397 397 emit penChanged();
398 398 }
399 399 }
400 400
401 401 /*!
402 402 Returns pen of the set.
403 403 */
404 404 QPen QBarSet::pen() const
405 405 {
406 406 return d_ptr->m_pen;
407 407 }
408 408
409 409 /*!
410 410 Sets brush for the set. Bars of this set are drawn using \a brush
411 411 */
412 412 void QBarSet::setBrush(const QBrush &brush)
413 413 {
414 414 if(d_ptr->m_brush!=brush){
415 415 d_ptr->m_brush = brush;
416 416 emit d_ptr->updatedBars();
417 417 emit brushChanged();
418 418 }
419 419 }
420 420
421 421 /*!
422 422 Returns brush of the set.
423 423 */
424 424 QBrush QBarSet::brush() const
425 425 {
426 426 return d_ptr->m_brush;
427 427 }
428 428
429 429 /*!
430 430 Sets \a brush of the values that are drawn on top of this barset
431 431 */
432 432 void QBarSet::setLabelBrush(const QBrush &brush)
433 433 {
434 434 if(d_ptr->m_labelBrush!=brush){
435 435 d_ptr->m_labelBrush = brush;
436 436 emit d_ptr->updatedBars();
437 437 emit labelBrushChanged();
438 438 }
439 439 }
440 440
441 441 /*!
442 442 Returns brush of the values that are drawn on top of this barset
443 443 */
444 444 QBrush QBarSet::labelBrush() const
445 445 {
446 446 return d_ptr->m_labelBrush;
447 447 }
448 448
449 449 /*!
450 450 Sets the \a font for values that are drawn on top of this barset
451 451 */
452 452 void QBarSet::setLabelFont(const QFont &font)
453 453 {
454 454 if(d_ptr->m_labelFont!=font) {
455 455 d_ptr->m_labelFont = font;
456 456 emit d_ptr->updatedBars();
457 457 emit labelFontChanged();
458 458 }
459 459
460 460 }
461 461
462 462 /*!
463 463 Returns the pen for values that are drawn on top of this barset
464 464 */
465 465 QFont QBarSet::labelFont() const
466 466 {
467 467 return d_ptr->m_labelFont;
468 468 }
469 469
470 470 /*!
471 471 Returns the color of the brush of barset.
472 472 */
473 473 QColor QBarSet::color()
474 474 {
475 475 return brush().color();
476 476 }
477 477
478 478 /*!
479 479 Sets the \a color of brush for this barset
480 480 */
481 481 void QBarSet::setColor(QColor color)
482 482 {
483 483 QBrush b = brush();
484 484 if (b.color() != color) {
485 485 b.setColor(color);
486 486 setBrush(b);
487 487 emit colorChanged(color);
488 488 }
489 489 }
490 490
491 491 /*!
492 492 Returns the color of pen of this barset
493 493 */
494 494 QColor QBarSet::borderColor()
495 495 {
496 496 return pen().color();
497 497 }
498 498
499 499 /*!
500 500 Sets the color of pen for this barset
501 501 */
502 502 void QBarSet::setBorderColor(QColor color)
503 503 {
504 504 QPen p = pen();
505 505 if (p.color() != color) {
506 506 p.setColor(color);
507 507 setPen(p);
508 508 emit borderColorChanged(color);
509 509 }
510 510 }
511 511
512 512 /*!
513 513 Returns the color of labels of this barset
514 514 */
515 515 QColor QBarSet::labelColor()
516 516 {
517 517 return labelBrush().color();
518 518 }
519 519
520 520 /*!
521 521 Sets the color of labels for this barset
522 522 */
523 523 void QBarSet::setLabelColor(QColor color)
524 524 {
525 525 QBrush b = labelBrush();
526 526 if (b.color() != color) {
527 527 b.setColor(color);
528 528 setLabelBrush(b);
529 529 emit labelColorChanged(color);
530 530 }
531 531 }
532 532
533 533 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
534 534
535 535 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
536 536 q_ptr(parent),
537 537 m_label(label)
538 538 {
539 539 }
540 540
541 541 QBarSetPrivate::~QBarSetPrivate()
542 542 {
543 543 }
544 544
545 545 void QBarSetPrivate::append(QPointF value)
546 546 {
547 547 m_values.append(value);
548 548 emit restructuredBars();
549 549 }
550 550
551 551 void QBarSetPrivate::append(QList<QPointF> values)
552 552 {
553 553 for (int i=0; i<values.count(); i++) {
554 554 m_values.append(values.at(i));
555 555 }
556 556 emit restructuredBars();
557 557 }
558 558
559 559 void QBarSetPrivate::append(QList<qreal> values)
560 560 {
561 561 int index = m_values.count();
562 562 for (int i=0; i<values.count(); i++) {
563 563 m_values.append(QPointF(index,values.at(i)));
564 564 index++;
565 565 }
566 566 emit restructuredBars();
567 567 }
568 568
569 569 void QBarSetPrivate::insert(const int index, const qreal value)
570 570 {
571 571 m_values.insert(index, QPointF(index, value));
572 572 emit restructuredBars();
573 573 }
574 574
575 575 void QBarSetPrivate::insert(const int index, const QPointF value)
576 576 {
577 577 m_values.insert(index, value);
578 578 emit restructuredBars();
579 579 }
580 580
581 581 int QBarSetPrivate::remove(const int index, const int count)
582 582 {
583 583 int removeCount = count;
584 584
585 585 if ((index <0) || (m_values.count() == 0)) {
586 586 // Invalid index or not values in list, remove nothing.
587 587 return 0;
588 588 } else if ((index + count) > m_values.count()) {
589 589 // Trying to remove more items than list has. Limit amount to be removed.
590 590 removeCount = m_values.count() - index;
591 591 }
592 592
593 593 int c = 0;
594 594 while (c < removeCount) {
595 595 m_values.removeAt(index);
596 596 c++;
597 597 }
598 598 emit restructuredBars();
599 599 return removeCount;
600 600 }
601 601
602 602 void QBarSetPrivate::replace(const int index, const qreal value)
603 603 {
604 604 m_values.replace(index,QPointF(index,value));
605 605 emit updatedBars();
606 606 }
607 607
608 608 void QBarSetPrivate::replace(const int index, const QPointF value)
609 609 {
610 610 m_values.replace(index,value);
611 611 emit updatedBars();
612 612 }
613 613
614 614 #include "moc_qbarset.cpp"
615 615 #include "moc_qbarset_p.cpp"
616 616
617 617 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,614 +1,614
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 <QtCore/QString>
22 22 #include <QtTest/QtTest>
23 23
24 24 #include <qchart.h>
25 25 #include <qchartview.h>
26 26 #include <qbarseries.h>
27 27 #include <qbarset.h>
28 28 #include <qvbarmodelmapper.h>
29 29 #include <qhbarmodelmapper.h>
30 30 #include <QStandardItemModel>
31 31
32 32 QTCOMMERCIALCHART_USE_NAMESPACE
33 33
34 34 class tst_qbarmodelmapper : public QObject
35 35 {
36 36 Q_OBJECT
37 37
38 38 public:
39 39 tst_qbarmodelmapper();
40 40 void createVerticalMapper();
41 41 void createHorizontalMapper();
42 42
43 43 private Q_SLOTS:
44 44 void initTestCase();
45 45 void cleanupTestCase();
46 46 void init();
47 47 void cleanup();
48 48 void verticalMapper_data();
49 49 void verticalMapper();
50 50 void verticalMapperCustomMapping_data();
51 51 void verticalMapperCustomMapping();
52 52 void horizontalMapper_data();
53 53 void horizontalMapper();
54 54 void horizontalMapperCustomMapping_data();
55 55 void horizontalMapperCustomMapping();
56 56 void seriesUpdated();
57 57 void verticalModelInsertRows();
58 58 void verticalModelRemoveRows();
59 59 void verticalModelInsertColumns();
60 60 void verticalModelRemoveColumns();
61 61 void horizontalModelInsertRows();
62 62 void horizontalModelRemoveRows();
63 63 void horizontalModelInsertColumns();
64 64 void horizontalModelRemoveColumns();
65 65 void modelUpdateCell();
66 66
67 67 private:
68 68 QStandardItemModel *m_model;
69 69 int m_modelRowCount;
70 70 int m_modelColumnCount;
71 71
72 72 QVBarModelMapper *m_vMapper;
73 73 QHBarModelMapper *m_hMapper;
74 74
75 75 QBarSeries *m_series;
76 76 QChart *m_chart;
77 77 };
78 78
79 79 tst_qbarmodelmapper::tst_qbarmodelmapper():
80 80 m_model(0),
81 81 m_modelRowCount(10),
82 82 m_modelColumnCount(8),
83 83 m_vMapper(0),
84 84 m_hMapper(0),
85 85 m_series(0),
86 86 m_chart(0)
87 87 {
88 88 }
89 89
90 90 void tst_qbarmodelmapper::createVerticalMapper()
91 91 {
92 92 m_vMapper = new QVBarModelMapper;
93 93 QVERIFY(m_vMapper->model() == 0);
94 94 m_vMapper->setFirstBarSetColumn(0);
95 95 m_vMapper->setLastBarSetColumn(4);
96 96 m_vMapper->setModel(m_model);
97 97 m_vMapper->setSeries(m_series);
98 98 }
99 99
100 100 void tst_qbarmodelmapper::createHorizontalMapper()
101 101 {
102 102 m_hMapper = new QHBarModelMapper;
103 103 QVERIFY(m_hMapper->model() == 0);
104 104 m_hMapper->setFirstBarSetRow(0);
105 105 m_hMapper->setLastBarSetRow(4);
106 106 m_hMapper->setModel(m_model);
107 107 m_hMapper->setSeries(m_series);
108 108 }
109 109
110 110 void tst_qbarmodelmapper::init()
111 111 {
112 112 m_series = new QBarSeries;
113 113 m_chart->addSeries(m_series);
114 114
115 115 m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this);
116 116 for (int row = 0; row < m_modelRowCount; ++row) {
117 117 for (int column = 0; column < m_modelColumnCount; column++) {
118 118 m_model->setData(m_model->index(row, column), row * column);
119 119 }
120 120 }
121 121 }
122 122
123 123 void tst_qbarmodelmapper::cleanup()
124 124 {
125 125 m_chart->removeSeries(m_series);
126 126 delete m_series;
127 127 m_series = 0;
128 128
129 129 m_model->clear();
130 130 m_model->deleteLater();
131 131 m_model = 0;
132 132
133 133 if (m_vMapper) {
134 134 m_vMapper->deleteLater();
135 135 m_vMapper = 0;
136 136 }
137 137
138 138 if (m_hMapper) {
139 139 m_hMapper->deleteLater();
140 140 m_hMapper = 0;
141 141 }
142 142 }
143 143
144 144 void tst_qbarmodelmapper::initTestCase()
145 145 {
146 146 m_chart = new QChart;
147 147 QChartView *chartView = new QChartView(m_chart);
148 148 chartView->show();
149 149 }
150 150
151 151 void tst_qbarmodelmapper::cleanupTestCase()
152 152 {
153 153 }
154 154
155 155 void tst_qbarmodelmapper::verticalMapper_data()
156 156 {
157 157 QTest::addColumn<int>("firstBarSetColumn");
158 158 QTest::addColumn<int>("lastBarSetColumn");
159 159 QTest::addColumn<int>("expectedBarSetCount");
160 160 QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2;
161 161 QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1;
162 162 QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0;
163 163 QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0;
164 164 QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0;
165 165 QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0;
166 166 }
167 167
168 168 void tst_qbarmodelmapper::verticalMapper()
169 169 {
170 170 QFETCH(int, firstBarSetColumn);
171 171 QFETCH(int, lastBarSetColumn);
172 172 QFETCH(int, expectedBarSetCount);
173 173
174 174 m_series = new QBarSeries;
175 175
176 176 QVBarModelMapper *mapper = new QVBarModelMapper;
177 177 mapper->setFirstBarSetColumn(firstBarSetColumn);
178 178 mapper->setLastBarSetColumn(lastBarSetColumn);
179 179 mapper->setModel(m_model);
180 180 mapper->setSeries(m_series);
181 181
182 182 m_chart->addSeries(m_series);
183 183
184 184 QCOMPARE(m_series->count(), expectedBarSetCount);
185 185 QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn));
186 186 QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn));
187 187
188 188 delete mapper;
189 189 mapper = 0;
190 190 }
191 191
192 192 void tst_qbarmodelmapper::verticalMapperCustomMapping_data()
193 193 {
194 194 QTest::addColumn<int>("first");
195 195 QTest::addColumn<int>("countLimit");
196 196 QTest::addColumn<int>("expectedBarSetCount");
197 197 QTest::addColumn<int>("expectedCount");
198 198 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount;
199 199 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3;
200 200 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount);
201 201 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3);
202 202 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0;
203 203 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0;
204 204 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount;
205 205 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount;
206 206 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount;
207 207 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount;
208 208 }
209 209
210 210 void tst_qbarmodelmapper::verticalMapperCustomMapping()
211 211 {
212 212 QFETCH(int, first);
213 213 QFETCH(int, countLimit);
214 214 QFETCH(int, expectedBarSetCount);
215 215 QFETCH(int, expectedCount);
216 216
217 217 m_series = new QBarSeries;
218 218
219 219 QCOMPARE(m_series->count(), 0);
220 220
221 221 QVBarModelMapper *mapper = new QVBarModelMapper;
222 222 mapper->setFirstBarSetColumn(0);
223 223 mapper->setLastBarSetColumn(1);
224 224 mapper->setModel(m_model);
225 225 mapper->setSeries(m_series);
226 226 mapper->setFirstRow(first);
227 227 mapper->setRowCount(countLimit);
228 228 m_chart->addSeries(m_series);
229 229
230 230 QCOMPARE(m_series->count(), expectedBarSetCount);
231 231
232 232 if (expectedBarSetCount > 0)
233 233 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
234 234
235 235 // change values column mapping to invalid
236 236 mapper->setFirstBarSetColumn(-1);
237 237 mapper->setLastBarSetColumn(1);
238 238
239 239 QCOMPARE(m_series->count(), 0);
240 240
241 241 delete mapper;
242 242 mapper = 0;
243 243 }
244 244
245 245 void tst_qbarmodelmapper::horizontalMapper_data()
246 246 {
247 247 QTest::addColumn<int>("firstBarSetRow");
248 248 QTest::addColumn<int>("lastBarSetRow");
249 249 QTest::addColumn<int>("expectedBarSetCount");
250 250 QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2;
251 251 QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1;
252 252 QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0;
253 253 QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0;
254 254 QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0;
255 255 QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0;
256 256 }
257 257
258 258 void tst_qbarmodelmapper::horizontalMapper()
259 259 {
260 260 QFETCH(int, firstBarSetRow);
261 261 QFETCH(int, lastBarSetRow);
262 262 QFETCH(int, expectedBarSetCount);
263 263
264 264 m_series = new QBarSeries;
265 265
266 266 QHBarModelMapper *mapper = new QHBarModelMapper;
267 267 mapper->setFirstBarSetRow(firstBarSetRow);
268 268 mapper->setLastBarSetRow(lastBarSetRow);
269 269 mapper->setModel(m_model);
270 270 mapper->setSeries(m_series);
271 271
272 272 m_chart->addSeries(m_series);
273 273
274 274 QCOMPARE(m_series->count(), expectedBarSetCount);
275 275 QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow));
276 276 QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow));
277 277
278 278 delete mapper;
279 279 mapper = 0;
280 280 }
281 281
282 282 void tst_qbarmodelmapper::horizontalMapperCustomMapping_data()
283 283 {
284 284 QTest::addColumn<int>("first");
285 285 QTest::addColumn<int>("countLimit");
286 286 QTest::addColumn<int>("expectedBarSetCount");
287 287 QTest::addColumn<int>("expectedCount");
288 288 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount;
289 289 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3;
290 290 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount);
291 291 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3);
292 292 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0;
293 293 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0;
294 294 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount;
295 295 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount;
296 296 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount;
297 297 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount;
298 298 }
299 299
300 300 void tst_qbarmodelmapper::horizontalMapperCustomMapping()
301 301 {
302 302 QFETCH(int, first);
303 303 QFETCH(int, countLimit);
304 304 QFETCH(int, expectedBarSetCount);
305 305 QFETCH(int, expectedCount);
306 306
307 307 m_series = new QBarSeries;
308 308
309 309 QCOMPARE(m_series->count(), 0);
310 310
311 311 QHBarModelMapper *mapper = new QHBarModelMapper;
312 312 mapper->setFirstBarSetRow(0);
313 313 mapper->setLastBarSetRow(1);
314 314 mapper->setModel(m_model);
315 315 mapper->setSeries(m_series);
316 316 mapper->setFirstColumn(first);
317 317 mapper->setColumnCount(countLimit);
318 318 m_chart->addSeries(m_series);
319 319
320 320 QCOMPARE(m_series->count(), expectedBarSetCount);
321 321
322 322 if (expectedBarSetCount > 0)
323 323 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
324 324
325 325 // change values column mapping to invalid
326 326 mapper->setFirstBarSetRow(-1);
327 327 mapper->setLastBarSetRow(1);
328 328
329 329 QCOMPARE(m_series->count(), 0);
330 330
331 331 delete mapper;
332 332 mapper = 0;
333 333 }
334 334
335 335 void tst_qbarmodelmapper::seriesUpdated()
336 336 {
337 337 // setup the mapper
338 338 createVerticalMapper();
339 339 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
340 340 QCOMPARE(m_vMapper->rowCount(), -1);
341 341
342 342 m_series->barSets().first()->append(123);
343 343 QCOMPARE(m_model->rowCount(), m_modelRowCount + 1);
344 344 QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model
345 345
346 346 m_series->barSets().last()->remove(0, m_modelRowCount);
347 347 QCOMPARE(m_model->rowCount(), 1);
348 348 QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model
349 349
350 350 m_series->barSets().first()->replace(0, 444.0);
351 351 QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0);
352 352
353 353 m_series->barSets().first()->setLabel("Hello");
354 354 QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello"));
355 355
356 356 QList<qreal> newValues;
357 357 newValues << 15 << 27 << 35 << 49;
358 358 m_series->barSets().first()->append(newValues);
359 359 QCOMPARE(m_model->rowCount(), 1 + newValues.count());
360 360
361 361 QList<QBarSet* > newBarSets;
362 362 QBarSet* newBarSet_1 = new QBarSet("New_1");
363 363 newBarSet_1->append(101);
364 364 newBarSet_1->append(102);
365 365 newBarSet_1->append(103);
366 366 newBarSets.append(newBarSet_1);
367 367
368 QBarSet* newBarSet_2 = new QBarSet("New_1");
368 QBarSet* newBarSet_2 = new QBarSet("New_2");
369 369 newBarSet_2->append(201);
370 370 newBarSet_2->append(202);
371 371 newBarSet_2->append(203);
372 372 newBarSets.append(newBarSet_2);
373 373
374 374 m_series->append(newBarSets);
375 375 QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count());
376 376 }
377 377
378 378 void tst_qbarmodelmapper::verticalModelInsertRows()
379 379 {
380 380 // setup the mapper
381 381 createVerticalMapper();
382 382 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
383 383 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
384 384 QVERIFY(m_vMapper->model() != 0);
385 385
386 386 int insertCount = 4;
387 387 m_model->insertRows(3, insertCount);
388 388 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
389 389 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount);
390 390
391 391 int first = 3;
392 392 m_vMapper->setFirstRow(3);
393 393 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
394 394 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first);
395 395
396 396 m_model->insertRows(3, insertCount);
397 397 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
398 398 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first);
399 399
400 400 int countLimit = 6;
401 401 m_vMapper->setRowCount(countLimit);
402 402 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
403 403 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first));
404 404
405 405 m_model->insertRows(3, insertCount);
406 406 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
407 407 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first));
408 408
409 409 m_vMapper->setFirstRow(0);
410 410 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
411 411 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount));
412 412
413 413 m_vMapper->setRowCount(-1);
414 414 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
415 415 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount);
416 416 }
417 417
418 418 void tst_qbarmodelmapper::verticalModelRemoveRows()
419 419 {
420 420 // setup the mapper
421 421 createVerticalMapper();
422 422 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
423 423 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
424 424 QVERIFY(m_vMapper->model() != 0);
425 425
426 426 int removeCount = 2;
427 427 m_model->removeRows(1, removeCount);
428 428 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
429 429 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount);
430 430
431 431 int first = 1;
432 432 m_vMapper->setFirstRow(first);
433 433 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
434 434 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first);
435 435
436 436 m_model->removeRows(1, removeCount);
437 437 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
438 438 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first);
439 439
440 440 int countLimit = 3;
441 441 m_vMapper->setRowCount(countLimit);
442 442 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
443 443 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first));
444 444
445 445 m_model->removeRows(1, removeCount);
446 446 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
447 447 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first));
448 448
449 449 m_vMapper->setFirstRow(0);
450 450 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
451 451 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount));
452 452
453 453 m_vMapper->setRowCount(-1);
454 454 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
455 455 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount);
456 456 }
457 457
458 458 void tst_qbarmodelmapper::verticalModelInsertColumns()
459 459 {
460 460 // setup the mapper
461 461 createVerticalMapper();
462 462 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
463 463 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
464 464 QVERIFY(m_vMapper->model() != 0);
465 465
466 466 int insertCount = 4;
467 467 m_model->insertColumns(3, insertCount);
468 468 QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
469 469 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
470 470 }
471 471
472 472 void tst_qbarmodelmapper::verticalModelRemoveColumns()
473 473 {
474 474 // setup the mapper
475 475 createVerticalMapper();
476 476 QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1));
477 477 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
478 478 QVERIFY(m_vMapper->model() != 0);
479 479
480 480 int removeCount = m_modelColumnCount - 2;
481 481 m_model->removeColumns(0, removeCount);
482 482 QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1));
483 483 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
484 484
485 485 // leave all the columns
486 486 m_model->removeColumns(0, m_modelColumnCount - removeCount);
487 487 QCOMPARE(m_series->count(), 0);
488 488 }
489 489
490 490 void tst_qbarmodelmapper::horizontalModelInsertRows()
491 491 {
492 492 // setup the mapper
493 493 createHorizontalMapper();
494 494 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
495 495 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
496 496 QVERIFY(m_hMapper->model() != 0);
497 497
498 498 int insertCount = 4;
499 499 m_model->insertRows(3, insertCount);
500 500 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
501 501 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
502 502 }
503 503
504 504 void tst_qbarmodelmapper::horizontalModelRemoveRows()
505 505 {
506 506 // setup the mapper
507 507 createHorizontalMapper();
508 508 QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1));
509 509 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
510 510 QVERIFY(m_hMapper->model() != 0);
511 511
512 512 int removeCount = m_modelRowCount - 2;
513 513 m_model->removeRows(0, removeCount);
514 514 QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1));
515 515 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
516 516
517 517 // leave all the columns
518 518 m_model->removeRows(0, m_modelRowCount - removeCount);
519 519 QCOMPARE(m_series->count(), 0);
520 520 }
521 521
522 522 void tst_qbarmodelmapper::horizontalModelInsertColumns()
523 523 {
524 524 // setup the mapper
525 525 createHorizontalMapper();
526 526 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
527 527 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
528 528 QVERIFY(m_hMapper->model() != 0);
529 529
530 530 int insertCount = 4;
531 531 m_model->insertColumns(3, insertCount);
532 532 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
533 533 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount);
534 534
535 535 int first = 3;
536 536 m_hMapper->setFirstColumn(3);
537 537 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
538 538 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first);
539 539
540 540 m_model->insertColumns(3, insertCount);
541 541 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
542 542 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first);
543 543
544 544 int countLimit = 6;
545 545 m_hMapper->setColumnCount(countLimit);
546 546 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
547 547 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first));
548 548
549 549 m_model->insertColumns(3, insertCount);
550 550 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
551 551 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first));
552 552
553 553 m_hMapper->setFirstColumn(0);
554 554 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
555 555 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount));
556 556
557 557 m_hMapper->setColumnCount(-1);
558 558 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
559 559 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount);
560 560 }
561 561
562 562 void tst_qbarmodelmapper::horizontalModelRemoveColumns()
563 563 {
564 564 // setup the mapper
565 565 createHorizontalMapper();
566 566 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
567 567 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
568 568 QVERIFY(m_hMapper->model() != 0);
569 569
570 570 int removeCount = 2;
571 571 m_model->removeColumns(1, removeCount);
572 572 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
573 573 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount);
574 574
575 575 int first = 1;
576 576 m_hMapper->setFirstColumn(first);
577 577 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
578 578 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first);
579 579
580 580 m_model->removeColumns(1, removeCount);
581 581 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
582 582 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first);
583 583
584 584 int countLimit = 3;
585 585 m_hMapper->setColumnCount(countLimit);
586 586 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
587 587 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first));
588 588
589 589 m_model->removeColumns(1, removeCount);
590 590 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
591 591 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first));
592 592
593 593 m_hMapper->setFirstColumn(0);
594 594 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
595 595 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount));
596 596
597 597 m_hMapper->setColumnCount(-1);
598 598 QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
599 599 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount);
600 600 }
601 601
602 602 void tst_qbarmodelmapper::modelUpdateCell()
603 603 {
604 604 // setup the mapper
605 605 createVerticalMapper();
606 606
607 607 QVERIFY(m_model->setData(m_model->index(1, 0), 44));
608 608 QCOMPARE(m_series->barSets().at(0)->at(1), 44.0);
609 609 QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0);
610 610 }
611 611
612 612 QTEST_MAIN(tst_qbarmodelmapper)
613 613
614 614 #include "tst_qbarmodelmapper.moc"
General Comments 0
You need to be logged in to leave comments. Login now