##// END OF EJS Templates
Update candlestick chart model mappers API...
Alexander Mishin -
r2897:f5164ec8f20d dev
parent child
Show More
@@ -57,7 +57,7 CandlestickChartItem::CandlestickChartItem(QCandlestickSeries *series, QGraphics
57
57
58 setZValue(ChartPresenter::CandlestickSeriesZValue);
58 setZValue(ChartPresenter::CandlestickSeriesZValue);
59
59
60 handleCandlestickSetsAdd(m_series->candlestickSets());
60 handleCandlestickSetsAdd(m_series->sets());
61 }
61 }
62
62
63 CandlestickChartItem::~CandlestickChartItem()
63 CandlestickChartItem::~CandlestickChartItem()
@@ -233,7 +233,7 void CandlestickChartItem::handleDataStructureChanged()
233 updateTimePeriod();
233 updateTimePeriod();
234
234
235 for (int i = 0; i < m_series->count(); ++i) {
235 for (int i = 0; i < m_series->count(); ++i) {
236 QCandlestickSet *set = m_series->candlestickSets().at(i);
236 QCandlestickSet *set = m_series->sets().at(i);
237 Candlestick *item = m_candlesticks.value(set);
237 Candlestick *item = m_candlesticks.value(set);
238
238
239 updateCandlestickGeometry(item, i);
239 updateCandlestickGeometry(item, i);
@@ -252,7 +252,7 bool CandlestickChartItem::updateCandlestickGeometry(Candlestick *item, int inde
252 {
252 {
253 bool changed = false;
253 bool changed = false;
254
254
255 QCandlestickSet *set = m_series->candlestickSets().at(index);
255 QCandlestickSet *set = m_series->sets().at(index);
256 CandlestickData &data = item->m_data;
256 CandlestickData &data = item->m_data;
257
257
258 if ((data.m_open != set->open())
258 if ((data.m_open != set->open())
@@ -310,19 +310,19 int QCandlestickModelMapper::close() const
310
310
311 /*!
311 /*!
312 Sets the section of the model that is used as the data source for the first candlestick set.
312 Sets the section of the model that is used as the data source for the first candlestick set.
313 Parameter \a firstCandlestickSetSection specifies the section of the model. Default value is -1.
313 Parameter \a firstSetSection specifies the section of the model. Default value is -1.
314 */
314 */
315 void QCandlestickModelMapper::setFirstCandlestickSetSection(int firstCandlestickSetSection)
315 void QCandlestickModelMapper::setFirstSetSection(int firstSetSection)
316 {
316 {
317 Q_D(QCandlestickModelMapper);
317 Q_D(QCandlestickModelMapper);
318
318
319 firstCandlestickSetSection = qMax(firstCandlestickSetSection, -1);
319 firstSetSection = qMax(firstSetSection, -1);
320
320
321 if (d->m_firstCandlestickSetSection == firstCandlestickSetSection)
321 if (d->m_firstSetSection == firstSetSection)
322 return;
322 return;
323
323
324 d->m_firstCandlestickSetSection = firstCandlestickSetSection;
324 d->m_firstSetSection = firstSetSection;
325 emit d->firstCandlestickSetSectionChanged();
325 emit d->firstSetSectionChanged();
326 d->initializeCandlestickFromModel();
326 d->initializeCandlestickFromModel();
327 }
327 }
328
328
@@ -330,28 +330,28 void QCandlestickModelMapper::setFirstCandlestickSetSection(int firstCandlestick
330 Returns the section of the model that is used as the data source for the first candlestick set.
330 Returns the section of the model that is used as the data source for the first candlestick set.
331 Default value is -1 (invalid mapping).
331 Default value is -1 (invalid mapping).
332 */
332 */
333 int QCandlestickModelMapper::firstCandlestickSetSection() const
333 int QCandlestickModelMapper::firstSetSection() const
334 {
334 {
335 Q_D(const QCandlestickModelMapper);
335 Q_D(const QCandlestickModelMapper);
336
336
337 return d->m_firstCandlestickSetSection;
337 return d->m_firstSetSection;
338 }
338 }
339
339
340 /*!
340 /*!
341 Sets the section of the model that is used as the data source for the last candlestick set.
341 Sets the section of the model that is used as the data source for the last candlestick set.
342 Parameter \a lastCandlestickSetSection specifies the section of the model. Default value is -1.
342 Parameter \a lastSetSection specifies the section of the model. Default value is -1.
343 */
343 */
344 void QCandlestickModelMapper::setLastCandlestickSetSection(int lastCandlestickSetSection)
344 void QCandlestickModelMapper::setLastSetSection(int lastSetSection)
345 {
345 {
346 Q_D(QCandlestickModelMapper);
346 Q_D(QCandlestickModelMapper);
347
347
348 lastCandlestickSetSection = qMax(lastCandlestickSetSection, -1);
348 lastSetSection = qMax(lastSetSection, -1);
349
349
350 if (d->m_lastCandlestickSetSection == lastCandlestickSetSection)
350 if (d->m_lastSetSection == lastSetSection)
351 return;
351 return;
352
352
353 d->m_lastCandlestickSetSection = lastCandlestickSetSection;
353 d->m_lastSetSection = lastSetSection;
354 emit d->lastCandlestickSetSectionChanged();
354 emit d->lastSetSectionChanged();
355 d->initializeCandlestickFromModel();
355 d->initializeCandlestickFromModel();
356 }
356 }
357
357
@@ -359,11 +359,11 void QCandlestickModelMapper::setLastCandlestickSetSection(int lastCandlestickSe
359 Returns the section of the model that is used as the data source for the last candlestick set.
359 Returns the section of the model that is used as the data source for the last candlestick set.
360 Default value is -1 (invalid mapping).
360 Default value is -1 (invalid mapping).
361 */
361 */
362 int QCandlestickModelMapper::lastCandlestickSetSection() const
362 int QCandlestickModelMapper::lastSetSection() const
363 {
363 {
364 Q_D(const QCandlestickModelMapper);
364 Q_D(const QCandlestickModelMapper);
365
365
366 return d->m_lastCandlestickSetSection;
366 return d->m_lastSetSection;
367 }
367 }
368
368
369 ////////////////////////////////////////////////////////////////////////////////////////////////////
369 ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -377,8 +377,8 QCandlestickModelMapperPrivate::QCandlestickModelMapperPrivate(QCandlestickModel
377 m_high(-1),
377 m_high(-1),
378 m_low(-1),
378 m_low(-1),
379 m_close(-1),
379 m_close(-1),
380 m_firstCandlestickSetSection(-1),
380 m_firstSetSection(-1),
381 m_lastCandlestickSetSection(-1),
381 m_lastSetSection(-1),
382 m_modelSignalsBlock(false),
382 m_modelSignalsBlock(false),
383 m_seriesSignalsBlock(false),
383 m_seriesSignalsBlock(false),
384 q_ptr(q)
384 q_ptr(q)
@@ -393,11 +393,11 void QCandlestickModelMapperPrivate::initializeCandlestickFromModel()
393 blockSeriesSignals();
393 blockSeriesSignals();
394 // clear current content
394 // clear current content
395 m_series->clear();
395 m_series->clear();
396 m_candlestickSets.clear();
396 m_sets.clear();
397
397
398 // create the initial candlestick sets
398 // create the initial candlestick sets
399 QList<QCandlestickSet *> candlestickSets;
399 QList<QCandlestickSet *> sets;
400 for (int i = m_firstCandlestickSetSection; i <= m_lastCandlestickSetSection; ++i) {
400 for (int i = m_firstSetSection; i <= m_lastSetSection; ++i) {
401 QModelIndex timestampIndex = candlestickModelIndex(i, m_timestamp);
401 QModelIndex timestampIndex = candlestickModelIndex(i, m_timestamp);
402 QModelIndex openIndex = candlestickModelIndex(i, m_open);
402 QModelIndex openIndex = candlestickModelIndex(i, m_open);
403 QModelIndex highIndex = candlestickModelIndex(i, m_high);
403 QModelIndex highIndex = candlestickModelIndex(i, m_high);
@@ -421,13 +421,13 void QCandlestickModelMapperPrivate::initializeCandlestickFromModel()
421 connect(set, SIGNAL(lowChanged()), this, SLOT(candlestickSetChanged()));
421 connect(set, SIGNAL(lowChanged()), this, SLOT(candlestickSetChanged()));
422 connect(set, SIGNAL(closeChanged()), this, SLOT(candlestickSetChanged()));
422 connect(set, SIGNAL(closeChanged()), this, SLOT(candlestickSetChanged()));
423
423
424 candlestickSets.append(set);
424 sets.append(set);
425 } else {
425 } else {
426 break;
426 break;
427 }
427 }
428 }
428 }
429 m_series->append(candlestickSets);
429 m_series->append(sets);
430 m_candlestickSets.append(candlestickSets);
430 m_sets.append(sets);
431 blockSeriesSignals(false);
431 blockSeriesSignals(false);
432 }
432 }
433
433
@@ -485,7 +485,7 void QCandlestickModelMapperPrivate::modelRowsInserted(QModelIndex parent, int s
485 blockSeriesSignals();
485 blockSeriesSignals();
486 if (q->orientation() == Qt::Vertical)
486 if (q->orientation() == Qt::Vertical)
487 insertData(start, end);
487 insertData(start, end);
488 else if (start <= m_firstCandlestickSetSection || start <= m_lastCandlestickSetSection)
488 else if (start <= m_firstSetSection || start <= m_lastSetSection)
489 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
489 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
490 blockSeriesSignals(false);
490 blockSeriesSignals(false);
491 }
491 }
@@ -502,7 +502,7 void QCandlestickModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int st
502 blockSeriesSignals();
502 blockSeriesSignals();
503 if (q->orientation() == Qt::Vertical)
503 if (q->orientation() == Qt::Vertical)
504 removeData(start, end);
504 removeData(start, end);
505 else if (start <= m_firstCandlestickSetSection || start <= m_lastCandlestickSetSection)
505 else if (start <= m_firstSetSection || start <= m_lastSetSection)
506 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
506 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
507 blockSeriesSignals(false);
507 blockSeriesSignals(false);
508 }
508 }
@@ -519,7 +519,7 void QCandlestickModelMapperPrivate::modelColumnsInserted(QModelIndex parent, in
519 blockSeriesSignals();
519 blockSeriesSignals();
520 if (q->orientation() == Qt::Horizontal)
520 if (q->orientation() == Qt::Horizontal)
521 insertData(start, end);
521 insertData(start, end);
522 else if (start <= m_firstCandlestickSetSection || start <= m_lastCandlestickSetSection)
522 else if (start <= m_firstSetSection || start <= m_lastSetSection)
523 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
523 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
524 blockSeriesSignals(false);
524 blockSeriesSignals(false);
525 }
525 }
@@ -536,7 +536,7 void QCandlestickModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int
536 blockSeriesSignals();
536 blockSeriesSignals();
537 if (q->orientation() == Qt::Horizontal)
537 if (q->orientation() == Qt::Horizontal)
538 removeData(start, end);
538 removeData(start, end);
539 else if (start <= m_firstCandlestickSetSection || start <= m_lastCandlestickSetSection)
539 else if (start <= m_firstSetSection || start <= m_lastSetSection)
540 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
540 initializeCandlestickFromModel(); // if the changes affect the map - reinitialize
541 blockSeriesSignals(false);
541 blockSeriesSignals(false);
542 }
542 }
@@ -556,20 +556,20 void QCandlestickModelMapperPrivate::candlestickSetsAdded(const QList<QCandlesti
556 if (sets.isEmpty())
556 if (sets.isEmpty())
557 return;
557 return;
558
558
559 int firstIndex = m_series->candlestickSets().indexOf(sets.at(0));
559 int firstIndex = m_series->sets().indexOf(sets.at(0));
560 if (firstIndex == -1)
560 if (firstIndex == -1)
561 return;
561 return;
562
562
563 m_lastCandlestickSetSection += sets.count();
563 m_lastSetSection += sets.count();
564
564
565 blockModelSignals();
565 blockModelSignals();
566 if (q->orientation() == Qt::Vertical)
566 if (q->orientation() == Qt::Vertical)
567 m_model->insertColumns(firstIndex + m_firstCandlestickSetSection, sets.count());
567 m_model->insertColumns(firstIndex + m_firstSetSection, sets.count());
568 else
568 else
569 m_model->insertRows(firstIndex + m_firstCandlestickSetSection, sets.count());
569 m_model->insertRows(firstIndex + m_firstSetSection, sets.count());
570
570
571 for (int i = 0; i < sets.count(); ++i) {
571 for (int i = 0; i < sets.count(); ++i) {
572 int section = i + firstIndex + m_firstCandlestickSetSection;
572 int section = i + firstIndex + m_firstSetSection;
573 m_model->setData(candlestickModelIndex(section, m_timestamp), sets.at(i)->timestamp());
573 m_model->setData(candlestickModelIndex(section, m_timestamp), sets.at(i)->timestamp());
574 m_model->setData(candlestickModelIndex(section, m_open), sets.at(i)->open());
574 m_model->setData(candlestickModelIndex(section, m_open), sets.at(i)->open());
575 m_model->setData(candlestickModelIndex(section, m_high), sets.at(i)->high());
575 m_model->setData(candlestickModelIndex(section, m_high), sets.at(i)->high());
@@ -590,20 +590,20 void QCandlestickModelMapperPrivate::candlestickSetsRemoved(const QList<QCandles
590 if (sets.isEmpty())
590 if (sets.isEmpty())
591 return;
591 return;
592
592
593 int firstIndex = m_candlestickSets.indexOf(sets.at(0));
593 int firstIndex = m_sets.indexOf(sets.at(0));
594 if (firstIndex == -1)
594 if (firstIndex == -1)
595 return;
595 return;
596
596
597 m_lastCandlestickSetSection -= sets.count();
597 m_lastSetSection -= sets.count();
598
598
599 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; --i)
599 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; --i)
600 m_candlestickSets.removeAt(i);
600 m_sets.removeAt(i);
601
601
602 blockModelSignals();
602 blockModelSignals();
603 if (q->orientation() == Qt::Vertical)
603 if (q->orientation() == Qt::Vertical)
604 m_model->removeColumns(firstIndex + m_firstCandlestickSetSection, sets.count());
604 m_model->removeColumns(firstIndex + m_firstSetSection, sets.count());
605 else
605 else
606 m_model->removeRows(firstIndex + m_firstCandlestickSetSection, sets.count());
606 m_model->removeRows(firstIndex + m_firstSetSection, sets.count());
607 blockModelSignals(false);
607 blockModelSignals(false);
608 initializeCandlestickFromModel();
608 initializeCandlestickFromModel();
609 }
609 }
@@ -617,11 +617,11 void QCandlestickModelMapperPrivate::candlestickSetChanged()
617 if (!set)
617 if (!set)
618 return;
618 return;
619
619
620 int section = m_series->candlestickSets().indexOf(set);
620 int section = m_series->sets().indexOf(set);
621 if (section < 0)
621 if (section < 0)
622 return;
622 return;
623
623
624 section += m_firstCandlestickSetSection;
624 section += m_firstSetSection;
625
625
626 blockModelSignals();
626 blockModelSignals();
627 m_model->setData(candlestickModelIndex(section, m_timestamp), set->timestamp());
627 m_model->setData(candlestickModelIndex(section, m_timestamp), set->timestamp());
@@ -647,20 +647,20 QCandlestickSet *QCandlestickModelMapperPrivate::candlestickSet(QModelIndex inde
647 int section = (q->orientation() == Qt::Vertical) ? index.column() : index.row();
647 int section = (q->orientation() == Qt::Vertical) ? index.column() : index.row();
648 int pos = (q->orientation() == Qt::Vertical) ? index.row() : index.column();
648 int pos = (q->orientation() == Qt::Vertical) ? index.row() : index.column();
649
649
650 if (section < m_firstCandlestickSetSection || section > m_lastCandlestickSetSection)
650 if (section < m_firstSetSection || section > m_lastSetSection)
651 return 0; // This part of model has not been mapped to any candlestick set.
651 return 0; // This part of model has not been mapped to any candlestick set.
652
652
653 if (pos != m_timestamp && pos != m_open && pos != m_high && pos != m_low && pos != m_close)
653 if (pos != m_timestamp && pos != m_open && pos != m_high && pos != m_low && pos != m_close)
654 return 0; // This part of model has not been mapped to any candlestick set.
654 return 0; // This part of model has not been mapped to any candlestick set.
655
655
656 return m_series->candlestickSets().at(section - m_firstCandlestickSetSection);
656 return m_series->sets().at(section - m_firstSetSection);
657 }
657 }
658
658
659 QModelIndex QCandlestickModelMapperPrivate::candlestickModelIndex(int section, int pos)
659 QModelIndex QCandlestickModelMapperPrivate::candlestickModelIndex(int section, int pos)
660 {
660 {
661 Q_Q(QCandlestickModelMapper);
661 Q_Q(QCandlestickModelMapper);
662
662
663 if (section < m_firstCandlestickSetSection || section > m_lastCandlestickSetSection)
663 if (section < m_firstSetSection || section > m_lastSetSection)
664 return QModelIndex(); // invalid
664 return QModelIndex(); // invalid
665
665
666 if (pos != m_timestamp && pos != m_open && pos != m_high && pos != m_low && pos != m_close)
666 if (pos != m_timestamp && pos != m_open && pos != m_high && pos != m_low && pos != m_close)
@@ -79,11 +79,11 protected:
79 void setClose(int close);
79 void setClose(int close);
80 int close() const;
80 int close() const;
81
81
82 void setFirstCandlestickSetSection(int firstCandlestickSetSection);
82 void setFirstSetSection(int firstSetSection);
83 int firstCandlestickSetSection() const;
83 int firstSetSection() const;
84
84
85 void setLastCandlestickSetSection(int lastCandlestickSetSection);
85 void setLastSetSection(int lastSetSection);
86 int lastCandlestickSetSection() const;
86 int lastSetSection() const;
87
87
88 protected:
88 protected:
89 QCandlestickModelMapperPrivate * const d_ptr;
89 QCandlestickModelMapperPrivate * const d_ptr;
@@ -63,8 +63,8 Q_SIGNALS:
63 void highChanged();
63 void highChanged();
64 void lowChanged();
64 void lowChanged();
65 void closeChanged();
65 void closeChanged();
66 void firstCandlestickSetSectionChanged();
66 void firstSetSectionChanged();
67 void lastCandlestickSetSectionChanged();
67 void lastSetSectionChanged();
68
68
69 private Q_SLOTS:
69 private Q_SLOTS:
70 void initializeCandlestickFromModel();
70 void initializeCandlestickFromModel();
@@ -100,9 +100,9 private:
100 int m_high;
100 int m_high;
101 int m_low;
101 int m_low;
102 int m_close;
102 int m_close;
103 int m_firstCandlestickSetSection;
103 int m_firstSetSection;
104 int m_lastCandlestickSetSection;
104 int m_lastSetSection;
105 QList<QCandlestickSet *> m_candlestickSets;
105 QList<QCandlestickSet *> m_sets;
106 bool m_modelSignalsBlock;
106 bool m_modelSignalsBlock;
107 bool m_seriesSignalsBlock;
107 bool m_seriesSignalsBlock;
108
108
@@ -602,7 +602,7 void QCandlestickSeries::clear()
602 {
602 {
603 Q_D(QCandlestickSeries);
603 Q_D(QCandlestickSeries);
604
604
605 QList<QCandlestickSet *> sets = candlestickSets();
605 QList<QCandlestickSet *> sets = this->sets();
606
606
607 bool success = d->remove(sets);
607 bool success = d->remove(sets);
608 if (success) {
608 if (success) {
@@ -616,11 +616,11 void QCandlestickSeries::clear()
616 /*!
616 /*!
617 Returns the list of sets in the series. Ownership of the sets is unchanged.
617 Returns the list of sets in the series. Ownership of the sets is unchanged.
618 */
618 */
619 QList<QCandlestickSet *> QCandlestickSeries::candlestickSets() const
619 QList<QCandlestickSet *> QCandlestickSeries::sets() const
620 {
620 {
621 Q_D(const QCandlestickSeries);
621 Q_D(const QCandlestickSeries);
622
622
623 return d->m_candlestickSets;
623 return d->m_sets;
624 }
624 }
625
625
626 /*!
626 /*!
@@ -628,7 +628,7 QList<QCandlestickSet *> QCandlestickSeries::candlestickSets() const
628 */
628 */
629 int QCandlestickSeries::count() const
629 int QCandlestickSeries::count() const
630 {
630 {
631 return candlestickSets().count();
631 return sets().count();
632 }
632 }
633
633
634 /*!
634 /*!
@@ -918,20 +918,20 void QCandlestickSeriesPrivate::initializeDomain()
918 qreal minY(domain()->minY());
918 qreal minY(domain()->minY());
919 qreal maxY(domain()->maxY());
919 qreal maxY(domain()->maxY());
920
920
921 if (m_candlestickSets.count()) {
921 if (m_sets.count()) {
922 QCandlestickSet *set = m_candlestickSets.first();
922 QCandlestickSet *set = m_sets.first();
923 minX = set->timestamp();
923 minX = set->timestamp();
924 maxX = set->timestamp();
924 maxX = set->timestamp();
925 minY = set->low();
925 minY = set->low();
926 maxY = set->high();
926 maxY = set->high();
927 for (int i = 1; i < m_candlestickSets.count(); ++i) {
927 for (int i = 1; i < m_sets.count(); ++i) {
928 set = m_candlestickSets.at(i);
928 set = m_sets.at(i);
929 minX = qMin(minX, qreal(set->timestamp()));
929 minX = qMin(minX, qreal(set->timestamp()));
930 maxX = qMax(maxX, qreal(set->timestamp()));
930 maxX = qMax(maxX, qreal(set->timestamp()));
931 minY = qMin(minY, set->low());
931 minY = qMin(minY, set->low());
932 maxY = qMax(maxY, set->high());
932 maxY = qMax(maxY, set->high());
933 }
933 }
934 qreal extra = (maxX - minX) / m_candlestickSets.count() / 2;
934 qreal extra = (maxX - minX) / m_sets.count() / 2;
935 minX = minX - extra;
935 minX = minX - extra;
936 maxX = maxX + extra;
936 maxX = maxX + extra;
937 }
937 }
@@ -1039,14 +1039,14 QAbstractAxis* QCandlestickSeriesPrivate::createDefaultAxis(Qt::Orientation orie
1039 bool QCandlestickSeriesPrivate::append(const QList<QCandlestickSet *> &sets)
1039 bool QCandlestickSeriesPrivate::append(const QList<QCandlestickSet *> &sets)
1040 {
1040 {
1041 foreach (QCandlestickSet *set, sets) {
1041 foreach (QCandlestickSet *set, sets) {
1042 if ((set == 0) || m_candlestickSets.contains(set) || set->d_ptr->m_series)
1042 if ((set == 0) || m_sets.contains(set) || set->d_ptr->m_series)
1043 return false; // Fail if any of the sets is null or is already appended.
1043 return false; // Fail if any of the sets is null or is already appended.
1044 if (sets.count(set) != 1)
1044 if (sets.count(set) != 1)
1045 return false; // Also fail if the same set occurs more than once in the given list.
1045 return false; // Also fail if the same set occurs more than once in the given list.
1046 }
1046 }
1047
1047
1048 foreach (QCandlestickSet *set, sets) {
1048 foreach (QCandlestickSet *set, sets) {
1049 m_candlestickSets.append(set);
1049 m_sets.append(set);
1050 connect(set->d_func(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
1050 connect(set->d_func(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
1051 connect(set->d_func(), SIGNAL(updatedCandlestick()), this, SIGNAL(updatedCandlesticks()));
1051 connect(set->d_func(), SIGNAL(updatedCandlestick()), this, SIGNAL(updatedCandlesticks()));
1052 set->d_ptr->m_series = this;
1052 set->d_ptr->m_series = this;
@@ -1061,7 +1061,7 bool QCandlestickSeriesPrivate::remove(const QList<QCandlestickSet *> &sets)
1061 return false;
1061 return false;
1062
1062
1063 foreach (QCandlestickSet *set, sets) {
1063 foreach (QCandlestickSet *set, sets) {
1064 if ((set == 0) || (!m_candlestickSets.contains(set)))
1064 if ((set == 0) || (!m_sets.contains(set)))
1065 return false; // Fail if any of the sets is null or is not in series.
1065 return false; // Fail if any of the sets is null or is not in series.
1066 if (sets.count(set) != 1)
1066 if (sets.count(set) != 1)
1067 return false; // Also fail if the same set occurs more than once in the given list.
1067 return false; // Also fail if the same set occurs more than once in the given list.
@@ -1069,7 +1069,7 bool QCandlestickSeriesPrivate::remove(const QList<QCandlestickSet *> &sets)
1069
1069
1070 foreach (QCandlestickSet *set, sets) {
1070 foreach (QCandlestickSet *set, sets) {
1071 set->d_ptr->m_series = nullptr;
1071 set->d_ptr->m_series = nullptr;
1072 m_candlestickSets.removeOne(set);
1072 m_sets.removeOne(set);
1073 disconnect(set->d_func(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
1073 disconnect(set->d_func(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
1074 disconnect(set->d_func(), SIGNAL(updatedCandlestick()),this, SIGNAL(updatedCandlesticks()));
1074 disconnect(set->d_func(), SIGNAL(updatedCandlestick()),this, SIGNAL(updatedCandlesticks()));
1075 }
1075 }
@@ -1079,10 +1079,10 bool QCandlestickSeriesPrivate::remove(const QList<QCandlestickSet *> &sets)
1079
1079
1080 bool QCandlestickSeriesPrivate::insert(int index, QCandlestickSet *set)
1080 bool QCandlestickSeriesPrivate::insert(int index, QCandlestickSet *set)
1081 {
1081 {
1082 if ((m_candlestickSets.contains(set)) || (set == 0) || set->d_ptr->m_series)
1082 if ((m_sets.contains(set)) || (set == 0) || set->d_ptr->m_series)
1083 return false; // Fail if set is already in list or set is null.
1083 return false; // Fail if set is already in list or set is null.
1084
1084
1085 m_candlestickSets.insert(index, set);
1085 m_sets.insert(index, set);
1086 connect(set->d_func(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
1086 connect(set->d_func(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
1087 connect(set->d_func(), SIGNAL(updatedCandlestick()), this, SIGNAL(updatedCandlesticks()));
1087 connect(set->d_func(), SIGNAL(updatedCandlestick()), this, SIGNAL(updatedCandlesticks()));
1088 set->d_ptr->m_series = this;
1088 set->d_ptr->m_series = this;
@@ -1123,8 +1123,8 void QCandlestickSeriesPrivate::populateBarCategories(QBarCategoryAxis *axis)
1123 {
1123 {
1124 if (axis->categories().isEmpty()) {
1124 if (axis->categories().isEmpty()) {
1125 QStringList categories;
1125 QStringList categories;
1126 for (int i = 0; i < m_candlestickSets.count(); ++i) {
1126 for (int i = 0; i < m_sets.count(); ++i) {
1127 const qint64 timestamp = qRound64(m_candlestickSets.at(i)->timestamp());
1127 const qint64 timestamp = qRound64(m_sets.at(i)->timestamp());
1128 const QString timestampFormat = m_chart->locale().dateTimeFormat(QLocale::ShortFormat);
1128 const QString timestampFormat = m_chart->locale().dateTimeFormat(QLocale::ShortFormat);
1129 categories << QDateTime::fromMSecsSinceEpoch(timestamp).toString(timestampFormat);
1129 categories << QDateTime::fromMSecsSinceEpoch(timestamp).toString(timestampFormat);
1130 }
1130 }
@@ -64,7 +64,7 public:
64 bool take(QCandlestickSet *set);
64 bool take(QCandlestickSet *set);
65 void clear();
65 void clear();
66
66
67 QList<QCandlestickSet *> candlestickSets() const;
67 QList<QCandlestickSet *> sets() const;
68 int count() const;
68 int count() const;
69
69
70 QAbstractSeries::SeriesType type() const;
70 QAbstractSeries::SeriesType type() const;
@@ -89,7 +89,7 private:
89 void populateBarCategories(QBarCategoryAxis *axis);
89 void populateBarCategories(QBarCategoryAxis *axis);
90
90
91 protected:
91 protected:
92 QList<QCandlestickSet *> m_candlestickSets;
92 QList<QCandlestickSet *> m_sets;
93 qreal m_maximumColumnWidth;
93 qreal m_maximumColumnWidth;
94 qreal m_minimumColumnWidth;
94 qreal m_minimumColumnWidth;
95 qreal m_bodyWidth;
95 qreal m_bodyWidth;
@@ -71,8 +71,8 QT_CHARTS_BEGIN_NAMESPACE
71 highColumn: 3
71 highColumn: 3
72 lowColumn: 4
72 lowColumn: 4
73 closeColumn: 5
73 closeColumn: 5
74 firstCandlestickSetRow: 1
74 firstSetRow: 1
75 lastCandlestickSetRow: 3
75 lastSetRow: 3
76 }
76 }
77 }
77 }
78 \endqml
78 \endqml
@@ -158,25 +158,25 QT_CHARTS_BEGIN_NAMESPACE
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QHCandlestickModelMapper::firstCandlestickSetRow
161 \property QHCandlestickModelMapper::firstSetRow
162 \brief Defines the row of the model that is used as the data source for the first set. Default
162 \brief Defines the row of the model that is used as the data source for the first set. Default
163 value is -1 (invalid mapping).
163 value is -1 (invalid mapping).
164 */
164 */
165
165
166 /*!
166 /*!
167 \qmlproperty int HCandlestickModelMapper::firstCandlestickSetRow
167 \qmlproperty int HCandlestickModelMapper::firstSetRow
168 \brief Defines the row of the model that is used as the data source for the first set. Default
168 \brief Defines the row of the model that is used as the data source for the first set. Default
169 value is -1 (invalid mapping).
169 value is -1 (invalid mapping).
170 */
170 */
171
171
172 /*!
172 /*!
173 \property QHCandlestickModelMapper::lastCandlestickSetRow
173 \property QHCandlestickModelMapper::lastSetRow
174 \brief Defines the row of the model that is used as the data source for the last set. Default
174 \brief Defines the row of the model that is used as the data source for the last set. Default
175 value is -1 (invalid mapping).
175 value is -1 (invalid mapping).
176 */
176 */
177
177
178 /*!
178 /*!
179 \qmlproperty int HCandlestickModelMapper::lastCandlestickSetRow
179 \qmlproperty int HCandlestickModelMapper::lastSetRow
180 \brief Defines the row of the model that is used as the data source for the last set. Default
180 \brief Defines the row of the model that is used as the data source for the last set. Default
181 value is -1 (invalid mapping).
181 value is -1 (invalid mapping).
182 */
182 */
@@ -211,15 +211,15 QT_CHARTS_BEGIN_NAMESPACE
211 */
211 */
212
212
213 /*!
213 /*!
214 \fn void QHCandlestickModelMapper::firstCandlestickSetRowChanged()
214 \fn void QHCandlestickModelMapper::firstSetRowChanged()
215 \brief Emitted when the row of the model that contains the data of the first set is changed.
215 \brief Emitted when the row of the model that contains the data of the first set is changed.
216 \sa firstCandlestickSetRow
216 \sa firstSetRow
217 */
217 */
218
218
219 /*!
219 /*!
220 \fn void QHCandlestickModelMapper::lastCandlestickSetRowChanged()
220 \fn void QHCandlestickModelMapper::lastSetRowChanged()
221 \brief Emitted when the row of the model that contains the data of the last set is changed.
221 \brief Emitted when the row of the model that contains the data of the last set is changed.
222 \sa lastCandlestickSetRow
222 \sa lastSetRow
223 */
223 */
224
224
225 /*!
225 /*!
@@ -233,10 +233,8 QHCandlestickModelMapper::QHCandlestickModelMapper(QObject *parent)
233 connect(d_ptr, SIGNAL(highChanged()), this, SIGNAL(highColumnChanged()));
233 connect(d_ptr, SIGNAL(highChanged()), this, SIGNAL(highColumnChanged()));
234 connect(d_ptr, SIGNAL(lowChanged()), this, SIGNAL(lowColumnChanged()));
234 connect(d_ptr, SIGNAL(lowChanged()), this, SIGNAL(lowColumnChanged()));
235 connect(d_ptr, SIGNAL(closeChanged()), this, SIGNAL(closeColumnChanged()));
235 connect(d_ptr, SIGNAL(closeChanged()), this, SIGNAL(closeColumnChanged()));
236 connect(d_ptr, SIGNAL(firstCandlestickSetSectionChanged()),
236 connect(d_ptr, SIGNAL(firstSetSectionChanged()), this, SIGNAL(firstSetRowChanged()));
237 this, SIGNAL(firstCandlestickSetRowChanged()));
237 connect(d_ptr, SIGNAL(lastSetSectionChanged()), this, SIGNAL(lastSetRowChanged()));
238 connect(d_ptr, SIGNAL(lastCandlestickSetSectionChanged()),
239 this, SIGNAL(lastCandlestickSetRowChanged()));
240 }
238 }
241
239
242 /*!
240 /*!
@@ -297,24 +295,24 int QHCandlestickModelMapper::closeColumn() const
297 return QCandlestickModelMapper::close();
295 return QCandlestickModelMapper::close();
298 }
296 }
299
297
300 void QHCandlestickModelMapper::setFirstCandlestickSetRow(int firstCandlestickSetRow)
298 void QHCandlestickModelMapper::setFirstSetRow(int firstSetRow)
301 {
299 {
302 QCandlestickModelMapper::setFirstCandlestickSetSection(firstCandlestickSetRow);
300 QCandlestickModelMapper::setFirstSetSection(firstSetRow);
303 }
301 }
304
302
305 int QHCandlestickModelMapper::firstCandlestickSetRow() const
303 int QHCandlestickModelMapper::firstSetRow() const
306 {
304 {
307 return QCandlestickModelMapper::firstCandlestickSetSection();
305 return QCandlestickModelMapper::firstSetSection();
308 }
306 }
309
307
310 void QHCandlestickModelMapper::setLastCandlestickSetRow(int lastCandlestickSetRow)
308 void QHCandlestickModelMapper::setLastSetRow(int lastSetRow)
311 {
309 {
312 QCandlestickModelMapper::setLastCandlestickSetSection(lastCandlestickSetRow);
310 QCandlestickModelMapper::setLastSetSection(lastSetRow);
313 }
311 }
314
312
315 int QHCandlestickModelMapper::lastCandlestickSetRow() const
313 int QHCandlestickModelMapper::lastSetRow() const
316 {
314 {
317 return QCandlestickModelMapper::lastCandlestickSetSection();
315 return QCandlestickModelMapper::lastSetSection();
318 }
316 }
319
317
320 #include "moc_qhcandlestickmodelmapper.cpp"
318 #include "moc_qhcandlestickmodelmapper.cpp"
@@ -42,8 +42,8 class QT_CHARTS_EXPORT QHCandlestickModelMapper : public QCandlestickModelMapper
42 Q_PROPERTY(int highColumn READ highColumn WRITE setHighColumn NOTIFY highColumnChanged)
42 Q_PROPERTY(int highColumn READ highColumn WRITE setHighColumn NOTIFY highColumnChanged)
43 Q_PROPERTY(int lowColumn READ lowColumn WRITE setLowColumn NOTIFY lowColumnChanged)
43 Q_PROPERTY(int lowColumn READ lowColumn WRITE setLowColumn NOTIFY lowColumnChanged)
44 Q_PROPERTY(int closeColumn READ closeColumn WRITE setCloseColumn NOTIFY closeColumnChanged)
44 Q_PROPERTY(int closeColumn READ closeColumn WRITE setCloseColumn NOTIFY closeColumnChanged)
45 Q_PROPERTY(int firstCandlestickSetRow READ firstCandlestickSetRow WRITE setFirstCandlestickSetRow NOTIFY firstCandlestickSetRowChanged)
45 Q_PROPERTY(int firstSetRow READ firstSetRow WRITE setFirstSetRow NOTIFY firstSetRowChanged)
46 Q_PROPERTY(int lastCandlestickSetRow READ lastCandlestickSetRow WRITE setLastCandlestickSetRow NOTIFY lastCandlestickSetRowChanged)
46 Q_PROPERTY(int lastSetRow READ lastSetRow WRITE setLastSetRow NOTIFY lastSetRowChanged)
47
47
48 public:
48 public:
49 explicit QHCandlestickModelMapper(QObject *parent = nullptr);
49 explicit QHCandlestickModelMapper(QObject *parent = nullptr);
@@ -65,11 +65,11 public:
65 void setCloseColumn(int closeColumn);
65 void setCloseColumn(int closeColumn);
66 int closeColumn() const;
66 int closeColumn() const;
67
67
68 void setFirstCandlestickSetRow(int firstCandlestickSetRow);
68 void setFirstSetRow(int firstSetRow);
69 int firstCandlestickSetRow() const;
69 int firstSetRow() const;
70
70
71 void setLastCandlestickSetRow(int lastCandlestickSetRow);
71 void setLastSetRow(int lastSetRow);
72 int lastCandlestickSetRow() const;
72 int lastSetRow() const;
73
73
74 Q_SIGNALS:
74 Q_SIGNALS:
75 void timestampColumnChanged();
75 void timestampColumnChanged();
@@ -77,8 +77,8 Q_SIGNALS:
77 void highColumnChanged();
77 void highColumnChanged();
78 void lowColumnChanged();
78 void lowColumnChanged();
79 void closeColumnChanged();
79 void closeColumnChanged();
80 void firstCandlestickSetRowChanged();
80 void firstSetRowChanged();
81 void lastCandlestickSetRowChanged();
81 void lastSetRowChanged();
82 };
82 };
83
83
84 QT_CHARTS_END_NAMESPACE
84 QT_CHARTS_END_NAMESPACE
@@ -71,8 +71,8 QT_CHARTS_BEGIN_NAMESPACE
71 highRow: 3
71 highRow: 3
72 lowRow: 4
72 lowRow: 4
73 closeRow: 5
73 closeRow: 5
74 firstCandlestickSetColumn: 1
74 firstSetColumn: 1
75 lastCandlestickSetColumn: 3
75 lastSetColumn: 3
76 }
76 }
77 }
77 }
78 \endqml
78 \endqml
@@ -158,25 +158,25 QT_CHARTS_BEGIN_NAMESPACE
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QVCandlestickModelMapper::firstCandlestickSetColumn
161 \property QVCandlestickModelMapper::firstSetColumn
162 \brief Defines the column of the model that is used as the data source for the first set.
162 \brief Defines the column of the model that is used as the data source for the first set.
163 Default value is -1 (invalid mapping).
163 Default value is -1 (invalid mapping).
164 */
164 */
165
165
166 /*!
166 /*!
167 \qmlproperty int VCandlestickModelMapper::firstCandlestickSetColumn
167 \qmlproperty int VCandlestickModelMapper::firstSetColumn
168 \brief Defines the column of the model that is used as the data source for the first set.
168 \brief Defines the column of the model that is used as the data source for the first set.
169 Default value is -1 (invalid mapping).
169 Default value is -1 (invalid mapping).
170 */
170 */
171
171
172 /*!
172 /*!
173 \property QVCandlestickModelMapper::lastCandlestickSetColumn
173 \property QVCandlestickModelMapper::lastSetColumn
174 \brief Defines the column of the model that is used as the data source for the last set. Default
174 \brief Defines the column of the model that is used as the data source for the last set. Default
175 value is -1 (invalid mapping).
175 value is -1 (invalid mapping).
176 */
176 */
177
177
178 /*!
178 /*!
179 \qmlproperty int VCandlestickModelMapper::lastCandlestickSetColumn
179 \qmlproperty int VCandlestickModelMapper::lastSetColumn
180 \brief Defines the column of the model that is used as the data source for the last set. Default
180 \brief Defines the column of the model that is used as the data source for the last set. Default
181 value is -1 (invalid mapping).
181 value is -1 (invalid mapping).
182 */
182 */
@@ -212,15 +212,15 QT_CHARTS_BEGIN_NAMESPACE
212 */
212 */
213
213
214 /*!
214 /*!
215 \fn void QVCandlestickModelMapper::firstCandlestickSetColumnChanged()
215 \fn void QVCandlestickModelMapper::firstSetColumnChanged()
216 \brief Emitted when the column of the model that contains the data of the first set is changed.
216 \brief Emitted when the column of the model that contains the data of the first set is changed.
217 \sa firstCandlestickSetColumn
217 \sa firstSetColumn
218 */
218 */
219
219
220 /*!
220 /*!
221 \fn void QVCandlestickModelMapper::lastCandlestickSetColumnChanged()
221 \fn void QVCandlestickModelMapper::lastSetColumnChanged()
222 \brief Emitted when the column of the model that contains the data of the last set is changed.
222 \brief Emitted when the column of the model that contains the data of the last set is changed.
223 \sa lastCandlestickSetColumn
223 \sa lastSetColumn
224 */
224 */
225
225
226 /*!
226 /*!
@@ -234,10 +234,8 QVCandlestickModelMapper::QVCandlestickModelMapper(QObject *parent)
234 connect(d_ptr, SIGNAL(highChanged()), this, SIGNAL(highRowChanged()));
234 connect(d_ptr, SIGNAL(highChanged()), this, SIGNAL(highRowChanged()));
235 connect(d_ptr, SIGNAL(lowChanged()), this, SIGNAL(lowRowChanged()));
235 connect(d_ptr, SIGNAL(lowChanged()), this, SIGNAL(lowRowChanged()));
236 connect(d_ptr, SIGNAL(closeChanged()), this, SIGNAL(closeRowChanged()));
236 connect(d_ptr, SIGNAL(closeChanged()), this, SIGNAL(closeRowChanged()));
237 connect(d_ptr, SIGNAL(firstCandlestickSetSectionChanged()),
237 connect(d_ptr, SIGNAL(firstSetSectionChanged()), this, SIGNAL(firstSetColumnChanged()));
238 this, SIGNAL(firstCandlestickSetColumnChanged()));
238 connect(d_ptr, SIGNAL(lastSetSectionChanged()), this, SIGNAL(lastSetColumnChanged()));
239 connect(d_ptr, SIGNAL(lastCandlestickSetSectionChanged()),
240 this, SIGNAL(lastCandlestickSetColumnChanged()));
241 }
239 }
242
240
243 /*!
241 /*!
@@ -298,24 +296,24 int QVCandlestickModelMapper::closeRow() const
298 return QCandlestickModelMapper::close();
296 return QCandlestickModelMapper::close();
299 }
297 }
300
298
301 void QVCandlestickModelMapper::setFirstCandlestickSetColumn(int firstCandlestickSetColumn)
299 void QVCandlestickModelMapper::setFirstSetColumn(int firstSetColumn)
302 {
300 {
303 QCandlestickModelMapper::setFirstCandlestickSetSection(firstCandlestickSetColumn);
301 QCandlestickModelMapper::setFirstSetSection(firstSetColumn);
304 }
302 }
305
303
306 int QVCandlestickModelMapper::firstCandlestickSetColumn() const
304 int QVCandlestickModelMapper::firstSetColumn() const
307 {
305 {
308 return QCandlestickModelMapper::firstCandlestickSetSection();
306 return QCandlestickModelMapper::firstSetSection();
309 }
307 }
310
308
311 void QVCandlestickModelMapper::setLastCandlestickSetColumn(int lastCandlestickSetColumn)
309 void QVCandlestickModelMapper::setLastSetColumn(int lastSetColumn)
312 {
310 {
313 QCandlestickModelMapper::setLastCandlestickSetSection(lastCandlestickSetColumn);
311 QCandlestickModelMapper::setLastSetSection(lastSetColumn);
314 }
312 }
315
313
316 int QVCandlestickModelMapper::lastCandlestickSetColumn() const
314 int QVCandlestickModelMapper::lastSetColumn() const
317 {
315 {
318 return QCandlestickModelMapper::lastCandlestickSetSection();
316 return QCandlestickModelMapper::lastSetSection();
319 }
317 }
320
318
321 #include "moc_qvcandlestickmodelmapper.cpp"
319 #include "moc_qvcandlestickmodelmapper.cpp"
@@ -42,8 +42,8 class QT_CHARTS_EXPORT QVCandlestickModelMapper : public QCandlestickModelMapper
42 Q_PROPERTY(int highRow READ highRow WRITE setHighRow NOTIFY highRowChanged)
42 Q_PROPERTY(int highRow READ highRow WRITE setHighRow NOTIFY highRowChanged)
43 Q_PROPERTY(int lowRow READ lowRow WRITE setLowRow NOTIFY lowRowChanged)
43 Q_PROPERTY(int lowRow READ lowRow WRITE setLowRow NOTIFY lowRowChanged)
44 Q_PROPERTY(int closeRow READ closeRow WRITE setCloseRow NOTIFY closeRowChanged)
44 Q_PROPERTY(int closeRow READ closeRow WRITE setCloseRow NOTIFY closeRowChanged)
45 Q_PROPERTY(int firstCandlestickSetColumn READ firstCandlestickSetColumn WRITE setFirstCandlestickSetColumn NOTIFY firstCandlestickSetColumnChanged)
45 Q_PROPERTY(int firstSetColumn READ firstSetColumn WRITE setFirstSetColumn NOTIFY firstSetColumnChanged)
46 Q_PROPERTY(int lastCandlestickSetColumn READ lastCandlestickSetColumn WRITE setLastCandlestickSetColumn NOTIFY lastCandlestickSetColumnChanged)
46 Q_PROPERTY(int lastSetColumn READ lastSetColumn WRITE setLastSetColumn NOTIFY lastSetColumnChanged)
47
47
48 public:
48 public:
49 explicit QVCandlestickModelMapper(QObject *parent = nullptr);
49 explicit QVCandlestickModelMapper(QObject *parent = nullptr);
@@ -65,11 +65,11 public:
65 void setCloseRow(int closeRow);
65 void setCloseRow(int closeRow);
66 int closeRow() const;
66 int closeRow() const;
67
67
68 void setFirstCandlestickSetColumn(int firstCandlestickSetColumn);
68 void setFirstSetColumn(int firstSetColumn);
69 int firstCandlestickSetColumn() const;
69 int firstSetColumn() const;
70
70
71 void setLastCandlestickSetColumn(int lastCandlestickSetColumn);
71 void setLastSetColumn(int lastSetColumn);
72 int lastCandlestickSetColumn() const;
72 int lastSetColumn() const;
73
73
74 Q_SIGNALS:
74 Q_SIGNALS:
75 void timestampRowChanged();
75 void timestampRowChanged();
@@ -77,8 +77,8 Q_SIGNALS:
77 void highRowChanged();
77 void highRowChanged();
78 void lowRowChanged();
78 void lowRowChanged();
79 void closeRowChanged();
79 void closeRowChanged();
80 void firstCandlestickSetColumnChanged();
80 void firstSetColumnChanged();
81 void lastCandlestickSetColumnChanged();
81 void lastSetColumnChanged();
82 };
82 };
83
83
84 QT_CHARTS_END_NAMESPACE
84 QT_CHARTS_END_NAMESPACE
@@ -126,7 +126,7 QString DeclarativeCandlestickSeries::brushFilename() const
126
126
127 DeclarativeCandlestickSet *DeclarativeCandlestickSeries::at(int index)
127 DeclarativeCandlestickSet *DeclarativeCandlestickSeries::at(int index)
128 {
128 {
129 QList<QCandlestickSet *> sets = candlestickSets();
129 QList<QCandlestickSet *> sets = this->sets();
130 if (index >= 0 && index < sets.count())
130 if (index >= 0 && index < sets.count())
131 return qobject_cast<DeclarativeCandlestickSet *>(sets[index]);
131 return qobject_cast<DeclarativeCandlestickSet *>(sets[index]);
132
132
@@ -158,7 +158,7 bool DeclarativeCandlestickSeries::append(qreal open, qreal high, qreal low, qre
158 bool DeclarativeCandlestickSeries::remove(qreal timestamp)
158 bool DeclarativeCandlestickSeries::remove(qreal timestamp)
159 {
159 {
160 for (int i = 0; i < count(); ++i) {
160 for (int i = 0; i < count(); ++i) {
161 QCandlestickSet *set = candlestickSets().at(i);
161 QCandlestickSet *set = sets().at(i);
162 if (set->timestamp() == timestamp)
162 if (set->timestamp() == timestamp)
163 return QCandlestickSeries::remove(set);
163 return QCandlestickSeries::remove(set);
164 }
164 }
@@ -110,8 +110,8 void tst_qcandlestickmodelmapper::createHorizontalMapper()
110 m_hMapper->setHighColumn(3);
110 m_hMapper->setHighColumn(3);
111 m_hMapper->setLowColumn(5);
111 m_hMapper->setLowColumn(5);
112 m_hMapper->setCloseColumn(6);
112 m_hMapper->setCloseColumn(6);
113 m_hMapper->setFirstCandlestickSetRow(0);
113 m_hMapper->setFirstSetRow(0);
114 m_hMapper->setLastCandlestickSetRow(4);
114 m_hMapper->setLastSetRow(4);
115 m_hMapper->setModel(m_model);
115 m_hMapper->setModel(m_model);
116 m_hMapper->setSeries(m_series);
116 m_hMapper->setSeries(m_series);
117 }
117 }
@@ -125,8 +125,8 void tst_qcandlestickmodelmapper::createVerticalMapper()
125 m_vMapper->setHighRow(3);
125 m_vMapper->setHighRow(3);
126 m_vMapper->setLowRow(5);
126 m_vMapper->setLowRow(5);
127 m_vMapper->setCloseRow(6);
127 m_vMapper->setCloseRow(6);
128 m_vMapper->setFirstCandlestickSetColumn(0);
128 m_vMapper->setFirstSetColumn(0);
129 m_vMapper->setLastCandlestickSetColumn(4);
129 m_vMapper->setLastSetColumn(4);
130 m_vMapper->setModel(m_model);
130 m_vMapper->setModel(m_model);
131 m_vMapper->setSeries(m_series);
131 m_vMapper->setSeries(m_series);
132 }
132 }
@@ -179,9 +179,9 void tst_qcandlestickmodelmapper::cleanup()
179
179
180 void tst_qcandlestickmodelmapper::verticalMapper_data()
180 void tst_qcandlestickmodelmapper::verticalMapper_data()
181 {
181 {
182 QTest::addColumn<int>("firstCandlestickSetColumn");
182 QTest::addColumn<int>("firstSetColumn");
183 QTest::addColumn<int>("lastCandlestickSetColumn");
183 QTest::addColumn<int>("lastSetColumn");
184 QTest::addColumn<int>("expectedCandlestickSetCount");
184 QTest::addColumn<int>("expectedSetCount");
185
185
186 QTest::newRow("last column greater than first column") << 0 << 1 << 2;
186 QTest::newRow("last column greater than first column") << 0 << 1 << 2;
187 QTest::newRow("last column equal to first column") << 1 << 1 << 1;
187 QTest::newRow("last column equal to first column") << 1 << 1 << 1;
@@ -193,21 +193,21 void tst_qcandlestickmodelmapper::verticalMapper_data()
193
193
194 void tst_qcandlestickmodelmapper::verticalMapper()
194 void tst_qcandlestickmodelmapper::verticalMapper()
195 {
195 {
196 QFETCH(int, firstCandlestickSetColumn);
196 QFETCH(int, firstSetColumn);
197 QFETCH(int, lastCandlestickSetColumn);
197 QFETCH(int, lastSetColumn);
198 QFETCH(int, expectedCandlestickSetCount);
198 QFETCH(int, expectedSetCount);
199
199
200 QCandlestickSeries *series = new QCandlestickSeries();
200 QCandlestickSeries *series = new QCandlestickSeries();
201 m_chart->addSeries(series);
201 m_chart->addSeries(series);
202
202
203 createVerticalMapper();
203 createVerticalMapper();
204 m_vMapper->setFirstCandlestickSetColumn(firstCandlestickSetColumn);
204 m_vMapper->setFirstSetColumn(firstSetColumn);
205 m_vMapper->setLastCandlestickSetColumn(lastCandlestickSetColumn);
205 m_vMapper->setLastSetColumn(lastSetColumn);
206 m_vMapper->setSeries(series);
206 m_vMapper->setSeries(series);
207
207
208 QCOMPARE(m_vMapper->firstCandlestickSetColumn(), qMax(firstCandlestickSetColumn, -1));
208 QCOMPARE(m_vMapper->firstSetColumn(), qMax(firstSetColumn, -1));
209 QCOMPARE(m_vMapper->lastCandlestickSetColumn(), qMax(lastCandlestickSetColumn, -1));
209 QCOMPARE(m_vMapper->lastSetColumn(), qMax(lastSetColumn, -1));
210 QCOMPARE(series->count(), expectedCandlestickSetCount);
210 QCOMPARE(series->count(), expectedSetCount);
211
211
212 m_chart->removeSeries(series);
212 m_chart->removeSeries(series);
213 delete series;
213 delete series;
@@ -272,14 +272,14 void tst_qcandlestickmodelmapper::verticalMapperCustomMapping()
272 && (m_vMapper->highRow() >= 0 && m_vMapper->highRow() < m_modelRowCount)
272 && (m_vMapper->highRow() >= 0 && m_vMapper->highRow() < m_modelRowCount)
273 && (m_vMapper->lowRow() >= 0 && m_vMapper->lowRow() < m_modelRowCount)
273 && (m_vMapper->lowRow() >= 0 && m_vMapper->lowRow() < m_modelRowCount)
274 && (m_vMapper->closeRow() >= 0 && m_vMapper->closeRow() < m_modelRowCount))
274 && (m_vMapper->closeRow() >= 0 && m_vMapper->closeRow() < m_modelRowCount))
275 count = m_vMapper->lastCandlestickSetColumn() - m_vMapper->firstCandlestickSetColumn() + 1;
275 count = m_vMapper->lastSetColumn() - m_vMapper->firstSetColumn() + 1;
276 else
276 else
277 count = 0;
277 count = 0;
278 QCOMPARE(series->count(), count);
278 QCOMPARE(series->count(), count);
279
279
280 // change values column mapping to invalid
280 // change values column mapping to invalid
281 m_vMapper->setFirstCandlestickSetColumn(-1);
281 m_vMapper->setFirstSetColumn(-1);
282 m_vMapper->setLastCandlestickSetColumn(1);
282 m_vMapper->setLastSetColumn(1);
283 QCOMPARE(series->count(), 0);
283 QCOMPARE(series->count(), 0);
284
284
285 m_chart->removeSeries(series);
285 m_chart->removeSeries(series);
@@ -288,9 +288,9 void tst_qcandlestickmodelmapper::verticalMapperCustomMapping()
288
288
289 void tst_qcandlestickmodelmapper::horizontalMapper_data()
289 void tst_qcandlestickmodelmapper::horizontalMapper_data()
290 {
290 {
291 QTest::addColumn<int>("firstCandlestickSetRow");
291 QTest::addColumn<int>("firstSetRow");
292 QTest::addColumn<int>("lastCandlestickSetRow");
292 QTest::addColumn<int>("lastSetRow");
293 QTest::addColumn<int>("expectedCandlestickSetCount");
293 QTest::addColumn<int>("expectedSetCount");
294
294
295 QTest::newRow("last row greater than first row") << 0 << 1 << 2;
295 QTest::newRow("last row greater than first row") << 0 << 1 << 2;
296 QTest::newRow("last row equal to first row") << 1 << 1 << 1;
296 QTest::newRow("last row equal to first row") << 1 << 1 << 1;
@@ -302,21 +302,21 void tst_qcandlestickmodelmapper::horizontalMapper_data()
302
302
303 void tst_qcandlestickmodelmapper::horizontalMapper()
303 void tst_qcandlestickmodelmapper::horizontalMapper()
304 {
304 {
305 QFETCH(int, firstCandlestickSetRow);
305 QFETCH(int, firstSetRow);
306 QFETCH(int, lastCandlestickSetRow);
306 QFETCH(int, lastSetRow);
307 QFETCH(int, expectedCandlestickSetCount);
307 QFETCH(int, expectedSetCount);
308
308
309 QCandlestickSeries *series = new QCandlestickSeries();
309 QCandlestickSeries *series = new QCandlestickSeries();
310 m_chart->addSeries(series);
310 m_chart->addSeries(series);
311
311
312 createHorizontalMapper();
312 createHorizontalMapper();
313 m_hMapper->setFirstCandlestickSetRow(firstCandlestickSetRow);
313 m_hMapper->setFirstSetRow(firstSetRow);
314 m_hMapper->setLastCandlestickSetRow(lastCandlestickSetRow);
314 m_hMapper->setLastSetRow(lastSetRow);
315 m_hMapper->setSeries(series);
315 m_hMapper->setSeries(series);
316
316
317 QCOMPARE(m_hMapper->firstCandlestickSetRow(), qMax(firstCandlestickSetRow, -1));
317 QCOMPARE(m_hMapper->firstSetRow(), qMax(firstSetRow, -1));
318 QCOMPARE(m_hMapper->lastCandlestickSetRow(), qMax(lastCandlestickSetRow, -1));
318 QCOMPARE(m_hMapper->lastSetRow(), qMax(lastSetRow, -1));
319 QCOMPARE(series->count(), expectedCandlestickSetCount);
319 QCOMPARE(series->count(), expectedSetCount);
320
320
321 m_chart->removeSeries(series);
321 m_chart->removeSeries(series);
322 delete series;
322 delete series;
@@ -381,14 +381,14 void tst_qcandlestickmodelmapper::horizontalMapperCustomMapping()
381 && (m_hMapper->highColumn() >= 0 && m_hMapper->highColumn() < m_modelColumnCount)
381 && (m_hMapper->highColumn() >= 0 && m_hMapper->highColumn() < m_modelColumnCount)
382 && (m_hMapper->lowColumn() >= 0 && m_hMapper->lowColumn() < m_modelColumnCount)
382 && (m_hMapper->lowColumn() >= 0 && m_hMapper->lowColumn() < m_modelColumnCount)
383 && (m_hMapper->closeColumn() >= 0 && m_hMapper->closeColumn() < m_modelColumnCount))
383 && (m_hMapper->closeColumn() >= 0 && m_hMapper->closeColumn() < m_modelColumnCount))
384 count = m_hMapper->lastCandlestickSetRow() - m_hMapper->firstCandlestickSetRow() + 1;
384 count = m_hMapper->lastSetRow() - m_hMapper->firstSetRow() + 1;
385 else
385 else
386 count = 0;
386 count = 0;
387 QCOMPARE(series->count(), count);
387 QCOMPARE(series->count(), count);
388
388
389 // change values row mapping to invalid
389 // change values row mapping to invalid
390 m_hMapper->setFirstCandlestickSetRow(-1);
390 m_hMapper->setFirstSetRow(-1);
391 m_hMapper->setLastCandlestickSetRow(1);
391 m_hMapper->setLastSetRow(1);
392 QCOMPARE(series->count(), 0);
392 QCOMPARE(series->count(), 0);
393
393
394 m_chart->removeSeries(series);
394 m_chart->removeSeries(series);
@@ -400,7 +400,7 void tst_qcandlestickmodelmapper::seriesUpdated()
400 createVerticalMapper();
400 createVerticalMapper();
401 QVERIFY(m_vMapper->model() != nullptr);
401 QVERIFY(m_vMapper->model() != nullptr);
402
402
403 QCandlestickSet *set = m_series->candlestickSets().value(0, 0);
403 QCandlestickSet *set = m_series->sets().value(0, 0);
404 QVERIFY(set != nullptr);
404 QVERIFY(set != nullptr);
405
405
406 // update values
406 // update values
@@ -429,8 +429,8 void tst_qcandlestickmodelmapper::seriesUpdated()
429
429
430 // remove sets
430 // remove sets
431 newCandlestickSets.clear();
431 newCandlestickSets.clear();
432 newCandlestickSets << m_series->candlestickSets().at(m_series->count() - 1);
432 newCandlestickSets << m_series->sets().at(m_series->count() - 1);
433 newCandlestickSets << m_series->candlestickSets().at(m_series->count() - 2);
433 newCandlestickSets << m_series->sets().at(m_series->count() - 2);
434 m_series->remove(newCandlestickSets);
434 m_series->remove(newCandlestickSets);
435 QCOMPARE(m_model->columnCount(), m_modelColumnCount);
435 QCOMPARE(m_model->columnCount(), m_modelColumnCount);
436 }
436 }
@@ -438,7 +438,7 void tst_qcandlestickmodelmapper::seriesUpdated()
438 void tst_qcandlestickmodelmapper::verticalModelInsertRows()
438 void tst_qcandlestickmodelmapper::verticalModelInsertRows()
439 {
439 {
440 createVerticalMapper();
440 createVerticalMapper();
441 int count = m_vMapper->lastCandlestickSetColumn() - m_vMapper->firstCandlestickSetColumn() + 1;
441 int count = m_vMapper->lastSetColumn() - m_vMapper->firstSetColumn() + 1;
442 QVERIFY(m_vMapper->model() != 0);
442 QVERIFY(m_vMapper->model() != 0);
443 QCOMPARE(m_series->count(), count);
443 QCOMPARE(m_series->count(), count);
444
444
@@ -449,7 +449,7 void tst_qcandlestickmodelmapper::verticalModelInsertRows()
449 void tst_qcandlestickmodelmapper::verticalModelRemoveRows()
449 void tst_qcandlestickmodelmapper::verticalModelRemoveRows()
450 {
450 {
451 createVerticalMapper();
451 createVerticalMapper();
452 int count = m_vMapper->lastCandlestickSetColumn() - m_vMapper->firstCandlestickSetColumn() + 1;
452 int count = m_vMapper->lastSetColumn() - m_vMapper->firstSetColumn() + 1;
453 QVERIFY(m_vMapper->model() != 0);
453 QVERIFY(m_vMapper->model() != 0);
454 QCOMPARE(m_series->count(), count);
454 QCOMPARE(m_series->count(), count);
455
455
@@ -464,7 +464,7 void tst_qcandlestickmodelmapper::verticalModelRemoveRows()
464 void tst_qcandlestickmodelmapper::verticalModelInsertColumns()
464 void tst_qcandlestickmodelmapper::verticalModelInsertColumns()
465 {
465 {
466 createVerticalMapper();
466 createVerticalMapper();
467 int count = m_vMapper->lastCandlestickSetColumn() - m_vMapper->firstCandlestickSetColumn() + 1;
467 int count = m_vMapper->lastSetColumn() - m_vMapper->firstSetColumn() + 1;
468 QVERIFY(m_vMapper->model() != 0);
468 QVERIFY(m_vMapper->model() != 0);
469 QCOMPARE(m_series->count(), count);
469 QCOMPARE(m_series->count(), count);
470
470
@@ -475,7 +475,7 void tst_qcandlestickmodelmapper::verticalModelInsertColumns()
475 void tst_qcandlestickmodelmapper::verticalModelRemoveColumns()
475 void tst_qcandlestickmodelmapper::verticalModelRemoveColumns()
476 {
476 {
477 createVerticalMapper();
477 createVerticalMapper();
478 int count = m_vMapper->lastCandlestickSetColumn() - m_vMapper->firstCandlestickSetColumn() + 1;
478 int count = m_vMapper->lastSetColumn() - m_vMapper->firstSetColumn() + 1;
479 QVERIFY(m_vMapper->model() != 0);
479 QVERIFY(m_vMapper->model() != 0);
480 QCOMPARE(m_series->count(), count);
480 QCOMPARE(m_series->count(), count);
481
481
@@ -491,7 +491,7 void tst_qcandlestickmodelmapper::verticalModelRemoveColumns()
491 void tst_qcandlestickmodelmapper::horizontalModelInsertRows()
491 void tst_qcandlestickmodelmapper::horizontalModelInsertRows()
492 {
492 {
493 createHorizontalMapper();
493 createHorizontalMapper();
494 int count = m_hMapper->lastCandlestickSetRow() - m_hMapper->firstCandlestickSetRow() + 1;
494 int count = m_hMapper->lastSetRow() - m_hMapper->firstSetRow() + 1;
495 QVERIFY(m_hMapper->model() != 0);
495 QVERIFY(m_hMapper->model() != 0);
496 QCOMPARE(m_series->count(), count);
496 QCOMPARE(m_series->count(), count);
497
497
@@ -502,7 +502,7 void tst_qcandlestickmodelmapper::horizontalModelInsertRows()
502 void tst_qcandlestickmodelmapper::horizontalModelRemoveRows()
502 void tst_qcandlestickmodelmapper::horizontalModelRemoveRows()
503 {
503 {
504 createHorizontalMapper();
504 createHorizontalMapper();
505 int count = m_hMapper->lastCandlestickSetRow() - m_hMapper->firstCandlestickSetRow() + 1;
505 int count = m_hMapper->lastSetRow() - m_hMapper->firstSetRow() + 1;
506 QVERIFY(m_hMapper->model() != 0);
506 QVERIFY(m_hMapper->model() != 0);
507 QCOMPARE(m_series->count(), qMin(m_model->rowCount(), count));
507 QCOMPARE(m_series->count(), qMin(m_model->rowCount(), count));
508
508
@@ -518,7 +518,7 void tst_qcandlestickmodelmapper::horizontalModelRemoveRows()
518 void tst_qcandlestickmodelmapper::horizontalModelInsertColumns()
518 void tst_qcandlestickmodelmapper::horizontalModelInsertColumns()
519 {
519 {
520 createHorizontalMapper();
520 createHorizontalMapper();
521 int count = m_hMapper->lastCandlestickSetRow() - m_hMapper->firstCandlestickSetRow() + 1;
521 int count = m_hMapper->lastSetRow() - m_hMapper->firstSetRow() + 1;
522 QVERIFY(m_hMapper->model() != 0);
522 QVERIFY(m_hMapper->model() != 0);
523 QCOMPARE(m_series->count(), count);
523 QCOMPARE(m_series->count(), count);
524
524
@@ -529,7 +529,7 void tst_qcandlestickmodelmapper::horizontalModelInsertColumns()
529 void tst_qcandlestickmodelmapper::horizontalModelRemoveColumns()
529 void tst_qcandlestickmodelmapper::horizontalModelRemoveColumns()
530 {
530 {
531 createHorizontalMapper();
531 createHorizontalMapper();
532 int count = m_hMapper->lastCandlestickSetRow() - m_hMapper->firstCandlestickSetRow() + 1;
532 int count = m_hMapper->lastSetRow() - m_hMapper->firstSetRow() + 1;
533 QVERIFY(m_hMapper->model() != 0);
533 QVERIFY(m_hMapper->model() != 0);
534 QCOMPARE(m_series->count(), count);
534 QCOMPARE(m_series->count(), count);
535
535
@@ -550,7 +550,7 void tst_qcandlestickmodelmapper::modelUpdateCell()
550 qreal newValue = 44.0;
550 qreal newValue = 44.0;
551 QVERIFY(m_model->setData(index, newValue));
551 QVERIFY(m_model->setData(index, newValue));
552 QCOMPARE(m_model->data(index).toReal(), newValue);
552 QCOMPARE(m_model->data(index).toReal(), newValue);
553 QCOMPARE(m_series->candlestickSets().at(index.row())->timestamp(), newValue);
553 QCOMPARE(m_series->sets().at(index.row())->timestamp(), newValue);
554 }
554 }
555
555
556 void tst_qcandlestickmodelmapper::verticalMapperSignals()
556 void tst_qcandlestickmodelmapper::verticalMapperSignals()
@@ -564,8 +564,8 void tst_qcandlestickmodelmapper::verticalMapperSignals()
564 QSignalSpy spy4(mapper, SIGNAL(highRowChanged()));
564 QSignalSpy spy4(mapper, SIGNAL(highRowChanged()));
565 QSignalSpy spy5(mapper, SIGNAL(lowRowChanged()));
565 QSignalSpy spy5(mapper, SIGNAL(lowRowChanged()));
566 QSignalSpy spy6(mapper, SIGNAL(closeRowChanged()));
566 QSignalSpy spy6(mapper, SIGNAL(closeRowChanged()));
567 QSignalSpy spy7(mapper, SIGNAL(firstCandlestickSetColumnChanged()));
567 QSignalSpy spy7(mapper, SIGNAL(firstSetColumnChanged()));
568 QSignalSpy spy8(mapper, SIGNAL(lastCandlestickSetColumnChanged()));
568 QSignalSpy spy8(mapper, SIGNAL(lastSetColumnChanged()));
569
569
570 mapper->setModel(m_model);
570 mapper->setModel(m_model);
571 mapper->setSeries(m_series);
571 mapper->setSeries(m_series);
@@ -574,8 +574,8 void tst_qcandlestickmodelmapper::verticalMapperSignals()
574 mapper->setHighRow(3);
574 mapper->setHighRow(3);
575 mapper->setLowRow(4);
575 mapper->setLowRow(4);
576 mapper->setCloseRow(5);
576 mapper->setCloseRow(5);
577 mapper->setFirstCandlestickSetColumn(0);
577 mapper->setFirstSetColumn(0);
578 mapper->setLastCandlestickSetColumn(1);
578 mapper->setLastSetColumn(1);
579
579
580 QCOMPARE(spy0.count(), 1);
580 QCOMPARE(spy0.count(), 1);
581 QCOMPARE(spy1.count(), 1);
581 QCOMPARE(spy1.count(), 1);
@@ -601,8 +601,8 void tst_qcandlestickmodelmapper::horizontalMapperSignals()
601 QSignalSpy spy4(mapper, SIGNAL(highColumnChanged()));
601 QSignalSpy spy4(mapper, SIGNAL(highColumnChanged()));
602 QSignalSpy spy5(mapper, SIGNAL(lowColumnChanged()));
602 QSignalSpy spy5(mapper, SIGNAL(lowColumnChanged()));
603 QSignalSpy spy6(mapper, SIGNAL(closeColumnChanged()));
603 QSignalSpy spy6(mapper, SIGNAL(closeColumnChanged()));
604 QSignalSpy spy7(mapper, SIGNAL(firstCandlestickSetRowChanged()));
604 QSignalSpy spy7(mapper, SIGNAL(firstSetRowChanged()));
605 QSignalSpy spy8(mapper, SIGNAL(lastCandlestickSetRowChanged()));
605 QSignalSpy spy8(mapper, SIGNAL(lastSetRowChanged()));
606
606
607 mapper->setModel(m_model);
607 mapper->setModel(m_model);
608 mapper->setSeries(m_series);
608 mapper->setSeries(m_series);
@@ -611,8 +611,8 void tst_qcandlestickmodelmapper::horizontalMapperSignals()
611 mapper->setHighColumn(3);
611 mapper->setHighColumn(3);
612 mapper->setLowColumn(4);
612 mapper->setLowColumn(4);
613 mapper->setCloseColumn(5);
613 mapper->setCloseColumn(5);
614 mapper->setFirstCandlestickSetRow(0);
614 mapper->setFirstSetRow(0);
615 mapper->setLastCandlestickSetRow(1);
615 mapper->setLastSetRow(1);
616
616
617 QCOMPARE(spy0.count(), 1);
617 QCOMPARE(spy0.count(), 1);
618 QCOMPARE(spy1.count(), 1);
618 QCOMPARE(spy1.count(), 1);
@@ -57,7 +57,7 private Q_SLOTS:
57 void insert();
57 void insert();
58 void take();
58 void take();
59 void clear();
59 void clear();
60 void candlestickSets();
60 void sets();
61 void count();
61 void count();
62 void type();
62 void type();
63 void maximumColumnWidth_data();
63 void maximumColumnWidth_data();
@@ -182,7 +182,7 void tst_QCandlestickSeries::remove()
182 QCOMPARE(m_series->count(), m_sets.count() - removeCount);
182 QCOMPARE(m_series->count(), m_sets.count() - removeCount);
183
183
184 for (int i = removeCount; i < m_sets.count(); ++i)
184 for (int i = removeCount; i < m_sets.count(); ++i)
185 QCOMPARE(m_series->candlestickSets().at(i - removeCount), m_sets.at(i));
185 QCOMPARE(m_series->sets().at(i - removeCount), m_sets.at(i));
186
186
187 // Try removing all sets again (should be ok, even if some sets have already been removed)
187 // Try removing all sets again (should be ok, even if some sets have already been removed)
188 for (int i = 0; i < m_sets.count(); ++i)
188 for (int i = 0; i < m_sets.count(); ++i)
@@ -313,23 +313,23 void tst_QCandlestickSeries::clear()
313 QCOMPARE(m_series->count(), 0);
313 QCOMPARE(m_series->count(), 0);
314 }
314 }
315
315
316 void tst_QCandlestickSeries::candlestickSets()
316 void tst_QCandlestickSeries::sets()
317 {
317 {
318 m_series->append(m_sets);
318 m_series->append(m_sets);
319 QCOMPARE(m_series->candlestickSets(), m_sets);
319 QCOMPARE(m_series->sets(), m_sets);
320
320
321 for (int i = 0; i < m_sets.count(); ++i)
321 for (int i = 0; i < m_sets.count(); ++i)
322 QCOMPARE(m_series->candlestickSets().at(i), m_sets.at(i));
322 QCOMPARE(m_series->sets().at(i), m_sets.at(i));
323
323
324 m_series->clear();
324 m_series->clear();
325 QCOMPARE(m_series->candlestickSets(), QList<QCandlestickSet *>());
325 QCOMPARE(m_series->sets(), QList<QCandlestickSet *>());
326 }
326 }
327
327
328 void tst_QCandlestickSeries::count()
328 void tst_QCandlestickSeries::count()
329 {
329 {
330 m_series->append(m_sets);
330 m_series->append(m_sets);
331 QCOMPARE(m_series->count(), m_sets.count());
331 QCOMPARE(m_series->count(), m_sets.count());
332 QCOMPARE(m_series->count(), m_series->candlestickSets().count());
332 QCOMPARE(m_series->count(), m_series->sets().count());
333 }
333 }
334
334
335 void tst_QCandlestickSeries::type()
335 void tst_QCandlestickSeries::type()
@@ -586,8 +586,8 void tst_QCandlestickSeries::mouseClicked()
586 QVERIFY(m_series->append(m_sets));
586 QVERIFY(m_series->append(m_sets));
587 QCOMPARE(m_series->count(), m_sets.count());
587 QCOMPARE(m_series->count(), m_sets.count());
588
588
589 QCandlestickSet *set1 = m_series->candlestickSets().at(1);
589 QCandlestickSet *set1 = m_series->sets().at(1);
590 QCandlestickSet *set2 = m_series->candlestickSets().at(2);
590 QCandlestickSet *set2 = m_series->sets().at(2);
591
591
592 QSignalSpy seriesSpy(m_series, SIGNAL(clicked(QCandlestickSet *)));
592 QSignalSpy seriesSpy(m_series, SIGNAL(clicked(QCandlestickSet *)));
593 QSignalSpy setSpy1(set1, SIGNAL(clicked()));
593 QSignalSpy setSpy1(set1, SIGNAL(clicked()));
@@ -649,8 +649,8 void tst_QCandlestickSeries::mouseHovered()
649 QVERIFY(m_series->append(m_sets));
649 QVERIFY(m_series->append(m_sets));
650 QCOMPARE(m_series->count(), m_sets.count());
650 QCOMPARE(m_series->count(), m_sets.count());
651
651
652 QCandlestickSet *set1 = m_series->candlestickSets().at(1);
652 QCandlestickSet *set1 = m_series->sets().at(1);
653 QCandlestickSet *set2 = m_series->candlestickSets().at(2);
653 QCandlestickSet *set2 = m_series->sets().at(2);
654
654
655 QSignalSpy seriesSpy(m_series, SIGNAL(hovered(bool, QCandlestickSet *)));
655 QSignalSpy seriesSpy(m_series, SIGNAL(hovered(bool, QCandlestickSet *)));
656 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
656 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
@@ -764,8 +764,8 void tst_QCandlestickSeries::mousePressed()
764 QVERIFY(m_series->append(m_sets));
764 QVERIFY(m_series->append(m_sets));
765 QCOMPARE(m_series->count(), m_sets.count());
765 QCOMPARE(m_series->count(), m_sets.count());
766
766
767 QCandlestickSet *set1 = m_series->candlestickSets().at(1);
767 QCandlestickSet *set1 = m_series->sets().at(1);
768 QCandlestickSet *set2 = m_series->candlestickSets().at(2);
768 QCandlestickSet *set2 = m_series->sets().at(2);
769
769
770 QSignalSpy seriesSpy(m_series, SIGNAL(pressed(QCandlestickSet *)));
770 QSignalSpy seriesSpy(m_series, SIGNAL(pressed(QCandlestickSet *)));
771 QSignalSpy setSpy1(set1, SIGNAL(pressed()));
771 QSignalSpy setSpy1(set1, SIGNAL(pressed()));
@@ -827,8 +827,8 void tst_QCandlestickSeries::mouseReleased()
827 QVERIFY(m_series->append(m_sets));
827 QVERIFY(m_series->append(m_sets));
828 QCOMPARE(m_series->count(), m_sets.count());
828 QCOMPARE(m_series->count(), m_sets.count());
829
829
830 QCandlestickSet *set1 = m_series->candlestickSets().at(1);
830 QCandlestickSet *set1 = m_series->sets().at(1);
831 QCandlestickSet *set2 = m_series->candlestickSets().at(2);
831 QCandlestickSet *set2 = m_series->sets().at(2);
832
832
833 QSignalSpy seriesSpy(m_series, SIGNAL(released(QCandlestickSet *)));
833 QSignalSpy seriesSpy(m_series, SIGNAL(released(QCandlestickSet *)));
834 QSignalSpy setSpy1(set1, SIGNAL(released()));
834 QSignalSpy setSpy1(set1, SIGNAL(released()));
@@ -890,8 +890,8 void tst_QCandlestickSeries::mouseDoubleClicked()
890 QVERIFY(m_series->append(m_sets));
890 QVERIFY(m_series->append(m_sets));
891 QCOMPARE(m_series->count(), m_sets.count());
891 QCOMPARE(m_series->count(), m_sets.count());
892
892
893 QCandlestickSet *set1 = m_series->candlestickSets().at(1);
893 QCandlestickSet *set1 = m_series->sets().at(1);
894 QCandlestickSet *set2 = m_series->candlestickSets().at(2);
894 QCandlestickSet *set2 = m_series->sets().at(2);
895
895
896 QSignalSpy seriesSpy(m_series, SIGNAL(doubleClicked(QCandlestickSet *)));
896 QSignalSpy seriesSpy(m_series, SIGNAL(doubleClicked(QCandlestickSet *)));
897 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked()));
897 QSignalSpy setSpy1(set1, SIGNAL(doubleClicked()));
@@ -311,17 +311,17 void MainWidget::updateAxes()
311 series = nullptr;
311 series = nullptr;
312
312
313 m_axisX = m_chart->axes(Qt::Horizontal).first();
313 m_axisX = m_chart->axes(Qt::Horizontal).first();
314 if (series && !series->candlestickSets().isEmpty()) {
314 if (series && !series->sets().isEmpty()) {
315 if (m_axisX->type() == QAbstractAxis::AxisTypeBarCategory) {
315 if (m_axisX->type() == QAbstractAxis::AxisTypeBarCategory) {
316 QBarCategoryAxis *axisX = qobject_cast<QBarCategoryAxis *>(m_axisX);
316 QBarCategoryAxis *axisX = qobject_cast<QBarCategoryAxis *>(m_axisX);
317 QStringList categories;
317 QStringList categories;
318 for (int i = 0; i < series->candlestickSets().count(); ++i)
318 for (int i = 0; i < series->sets().count(); ++i)
319 categories.append(QString::number(i));
319 categories.append(QString::number(i));
320 axisX->setCategories(categories);
320 axisX->setCategories(categories);
321 } else { // QAbstractAxis::AxisTypeDateTime || QAbstractAxis::AxisTypeValue
321 } else { // QAbstractAxis::AxisTypeDateTime || QAbstractAxis::AxisTypeValue
322 qreal msInMonth = 31.0 * 24.0 * 60.0 * 60.0 * 1000.0;
322 qreal msInMonth = 31.0 * 24.0 * 60.0 * 60.0 * 1000.0;
323 qreal min = series->candlestickSets().first()->timestamp() - msInMonth;
323 qreal min = series->sets().first()->timestamp() - msInMonth;
324 qreal max = series->candlestickSets().last()->timestamp() + msInMonth;
324 qreal max = series->sets().last()->timestamp() + msInMonth;
325 QDateTime minDateTime = QDateTime::fromMSecsSinceEpoch(min);
325 QDateTime minDateTime = QDateTime::fromMSecsSinceEpoch(min);
326 QDateTime maxDateTime = QDateTime::fromMSecsSinceEpoch(max);
326 QDateTime maxDateTime = QDateTime::fromMSecsSinceEpoch(max);
327
327
@@ -369,8 +369,8 void MainWidget::addSeries()
369 }
369 }
370 } else {
370 } else {
371 QCandlestickSeries *s = qobject_cast<QCandlestickSeries *>(m_chart->series().at(0));
371 QCandlestickSeries *s = qobject_cast<QCandlestickSeries *>(m_chart->series().at(0));
372 for (int i = 0; i < s->candlestickSets().count(); ++i) {
372 for (int i = 0; i < s->sets().count(); ++i) {
373 QCandlestickSet *set = randomSet(s->candlestickSets().at(i)->timestamp());
373 QCandlestickSet *set = randomSet(s->sets().at(i)->timestamp());
374 series->append(set);
374 series->append(set);
375 }
375 }
376 }
376 }
@@ -424,7 +424,7 void MainWidget::addSet()
424
424
425 QDateTime dateTime;
425 QDateTime dateTime;
426 if (series->count()) {
426 if (series->count()) {
427 dateTime.setMSecsSinceEpoch(series->candlestickSets().last()->timestamp());
427 dateTime.setMSecsSinceEpoch(series->sets().last()->timestamp());
428 dateTime = dateTime.addMonths(1);
428 dateTime = dateTime.addMonths(1);
429 } else {
429 } else {
430 dateTime.setDate(QDate(QDateTime::currentDateTime().date().year(), 1, 1));
430 dateTime.setDate(QDate(QDateTime::currentDateTime().date().year(), 1, 1));
@@ -450,7 +450,7 void MainWidget::insertSet()
450
450
451 QDateTime dateTime;
451 QDateTime dateTime;
452 if (series->count()) {
452 if (series->count()) {
453 dateTime.setMSecsSinceEpoch(series->candlestickSets().first()->timestamp());
453 dateTime.setMSecsSinceEpoch(series->sets().first()->timestamp());
454 dateTime = dateTime.addMonths(-1);
454 dateTime = dateTime.addMonths(-1);
455 } else {
455 } else {
456 dateTime.setDate(QDate(QDateTime::currentDateTime().date().year(), 1, 1));
456 dateTime.setDate(QDate(QDateTime::currentDateTime().date().year(), 1, 1));
@@ -473,10 +473,10 void MainWidget::removeSet()
473
473
474 foreach (QAbstractSeries *s, m_chart->series()) {
474 foreach (QAbstractSeries *s, m_chart->series()) {
475 QCandlestickSeries *series = qobject_cast<QCandlestickSeries *>(s);
475 QCandlestickSeries *series = qobject_cast<QCandlestickSeries *>(s);
476 if (series->candlestickSets().isEmpty())
476 if (series->sets().isEmpty())
477 qDebug() << "Create a set first";
477 qDebug() << "Create a set first";
478 else
478 else
479 series->remove(series->candlestickSets().last());
479 series->remove(series->sets().last());
480 }
480 }
481
481
482 updateAxes();
482 updateAxes();
@@ -491,7 +491,7 void MainWidget::removeAllSets()
491
491
492 foreach (QAbstractSeries *s, m_chart->series()) {
492 foreach (QAbstractSeries *s, m_chart->series()) {
493 QCandlestickSeries *series = qobject_cast<QCandlestickSeries *>(s);
493 QCandlestickSeries *series = qobject_cast<QCandlestickSeries *>(s);
494 if (series->candlestickSets().isEmpty())
494 if (series->sets().isEmpty())
495 qDebug() << "Create a set first";
495 qDebug() << "Create a set first";
496 else
496 else
497 series->clear();
497 series->clear();
@@ -665,11 +665,11 void MainWidget::attachModelMapper()
665 series->setName(QStringLiteral("SWMM")); // Series With Model Mapper
665 series->setName(QStringLiteral("SWMM")); // Series With Model Mapper
666
666
667 CustomTableModel *model = qobject_cast<CustomTableModel *>(m_hModelMapper->model());
667 CustomTableModel *model = qobject_cast<CustomTableModel *>(m_hModelMapper->model());
668 foreach (QCandlestickSet *set, series->candlestickSets())
668 foreach (QCandlestickSet *set, series->sets())
669 model->addRow(set);
669 model->addRow(set);
670
670
671 m_hModelMapper->setFirstCandlestickSetRow(0);
671 m_hModelMapper->setFirstSetRow(0);
672 m_hModelMapper->setLastCandlestickSetRow(model->rowCount() - 1);
672 m_hModelMapper->setLastSetRow(model->rowCount() - 1);
673 m_hModelMapper->setSeries(series);
673 m_hModelMapper->setSeries(series);
674 }
674 }
675
675
@@ -683,8 +683,8 void MainWidget::detachModelMapper()
683 series->setName(QStringLiteral("S1"));
683 series->setName(QStringLiteral("S1"));
684
684
685 m_hModelMapper->setSeries(nullptr);
685 m_hModelMapper->setSeries(nullptr);
686 m_hModelMapper->setFirstCandlestickSetRow(-1);
686 m_hModelMapper->setFirstSetRow(-1);
687 m_hModelMapper->setLastCandlestickSetRow(-1);
687 m_hModelMapper->setLastSetRow(-1);
688
688
689 CustomTableModel *model = qobject_cast<CustomTableModel *>(m_hModelMapper->model());
689 CustomTableModel *model = qobject_cast<CustomTableModel *>(m_hModelMapper->model());
690 model->clearRows();
690 model->clearRows();
General Comments 0
You need to be logged in to leave comments. Login now