##// END OF EJS Templates
Refactored model related methods in PieSeries
Marek Rosa -
r1063:f5b66b3a494a
parent child
Show More
@@ -94,7 +94,10 void BarChartItem::dataChanged()
94 m_labels.append(value);
94 m_labels.append(value);
95 connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
95 connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
96 }
96 }
97 }
97 }
98
99 // TODO: Is this the right place to call it?
100 // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
98 }
101 }
99
102
100 QVector<QRectF> BarChartItem::calculateLayout()
103 QVector<QRectF> BarChartItem::calculateLayout()
@@ -168,7 +171,8 void BarChartItem::setLayout(const QVector<QRectF> &layout)
168
171
169 void BarChartItem::handleModelChanged()
172 void BarChartItem::handleModelChanged()
170 {
173 {
171 dataChanged();
174 // dataChanged();
175 presenter()->resetAllElements();
172 }
176 }
173
177
174 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
178 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
@@ -559,7 +559,7 void QBarSeriesPrivate::initializeDataFromModel()
559 // create the initial bars
559 // create the initial bars
560 m_categories.clear();
560 m_categories.clear();
561 m_barSets.clear();
561 m_barSets.clear();
562 emit restructuredBars();
562 // emit restructuredBars();
563 if (m_mapOrientation == Qt::Vertical) {
563 if (m_mapOrientation == Qt::Vertical) {
564 int rowCount = 0;
564 int rowCount = 0;
565 if(m_mapCount == -1)
565 if(m_mapCount == -1)
@@ -594,7 +594,7 void QBarSeriesPrivate::initializeDataFromModel()
594 }
594 }
595 }
595 }
596 emit restructuredBars();
596 emit restructuredBars();
597 emit updatedBars();
597 // emit updatedBars();
598 }
598 }
599
599
600 void QBarSeriesPrivate::insertCategory(int index, const QString category)
600 void QBarSeriesPrivate::insertCategory(int index, const QString category)
@@ -218,6 +218,8 void ChartPresenter::resetAllElements()
218 foreach(QAbstractSeries *series, seriesList) {
218 foreach(QAbstractSeries *series, seriesList) {
219 handleSeriesRemoved(series);
219 handleSeriesRemoved(series);
220 handleSeriesAdded(series,m_dataset->domain(series));
220 handleSeriesAdded(series,m_dataset->domain(series));
221 // m_dataset->removeSeries(series);
222 // m_dataset->addSeries(series);
221 }
223 }
222 }
224 }
223
225
@@ -615,60 +615,6 void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
615 for (int i = m_slices.size() - 1; i >= m_mapCount; i--)
615 for (int i = m_slices.size() - 1; i >= m_mapCount; i--)
616 q->remove(q->slices().at(i));
616 q->remove(q->slices().at(i));
617 }
617 }
618
619 // // adding items to unlimited map
620 // else if (m_mapCount == -1 && start >= m_mapFirst) {
621 // for (int i = start; i <= end; i++) {
622 // QPieSlice *slice = new QPieSlice;
623 // slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble());
624 // slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
625 // slice->setLabelVisible(true);
626 // q->insert(i - m_mapFirst, slice);
627 // // handlePointAdded(i - first);
628 // }
629 // } else if (m_mapCount == - 1 && start < m_mapFirst) {
630 // // not all newly added items
631 // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) {
632 // QPieSlice *slice = new QPieSlice;
633 // slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble());
634 // slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
635 // slice->setLabelVisible(true);
636 // q->insert(i - m_mapFirst, slice);
637 // // handlePointAdded(i - first);
638 // }
639 // }
640
641 // // adding items to limited map
642 // else if (start >= m_mapFirst) {
643 // // remove the items that will no longer fit into the map
644 // // int toRemove = addedCount - (count - points().size());
645 // for (int i = start; i <= end; i++) {
646 // QPieSlice *slice = new QPieSlice;
647 // slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble());
648 // slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
649 // slice->setLabelVisible(true);
650 // q->insert(i - m_mapFirst, slice);
651 // }
652 // if (m_slices.size() > m_mapCount)
653 // for (int i = m_slices.size() - 1; i >= m_mapCount; i--)
654 // q->remove(q->slices().at(i));
655 // // handlePointRemoved(i);
656 // // update();
657 // } else {
658 // //
659 // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) {
660 // QPieSlice *slice = new QPieSlice;
661 // slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble());
662 // slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
663 // slice->setLabelVisible(true);
664 // q->insert(i - m_mapFirst, slice);
665 // // handlePointAdded(i - first);
666 // }
667 // if (m_slices.size() > m_mapCount)
668 // for (int i = m_slices.size() - 1; i >= m_mapCount; i--)
669 // q->remove(q->slices().at(i));
670 // // handlePointRemoved(i);
671 // }
672 }
618 }
673
619
674 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
620 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
@@ -678,98 +624,36 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
678 int removedCount = end - start + 1;
624 int removedCount = end - start + 1;
679 if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) {
625 if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) {
680 return;
626 return;
681 }
627 } else {
682
628 int toRemove = qMin(m_slices.size(), removedCount); // first find how many items can actually be removed
683 // else if (m_mapCount == -1) {
629 int first = qMax(start, m_mapFirst); // get the index of the first item that will be removed.
684 // // first find how many items can actually be removed
630 int last = qMin(first + toRemove - 1, m_slices.size() + m_mapFirst - 1); // get the index of the last item that will be removed.
685 // int toRemove = qMin(m_slices.size(), removedCount);
631 for (int i = last; i >= first; i--)
686 // // get the index of the first item that will be removed.
687 // int first = qMax(start, m_mapFirst);
688 // // get the index of the last item that will be removed.
689 // int last = first + toRemove;
690 // for (int i = last - 1; i >= first; i--)
691 // q->remove(q->slices().at(i - m_mapFirst));
692 // }
693 // else {
694 // int toRemove = qMin(m_slices.size() - 1, removedCount);
695 // int first = qMax(start, m_mapFirst);
696 // int last = qMax(end, m_mapFirst + toRemove - 1);
697
698 // }
699
700 // removing items from unlimited map
701 else if (m_mapCount == -1 && start >= m_mapFirst) {
702 for (int i = end; i >= start; i--)
703 q->remove(q->slices().at(i - m_mapFirst));
704 // handlePointRemoved(i - m_mapFirst);
705 } else if (m_mapCount == - 1 && start < m_mapFirst) {
706 // not all removed items
707 int lastExisting = qMin(m_mapFirst + m_slices.size() - 1, m_mapFirst + removedCount - 1);
708 for (int i = lastExisting; i >= m_mapFirst; i--)
709 q->remove(q->slices().at(i - m_mapFirst));
632 q->remove(q->slices().at(i - m_mapFirst));
710 // handlePointRemoved(i - m_mapFirst);
711 }
712
633
713 // removing items from limited map
634 if (m_mapCount != -1) {
714 else if (start >= m_mapFirst) {
635 int itemsAvailable; // check how many are available to be added
715 //
636 if (m_mapOrientation == Qt::Vertical)
716 // int sizeAfter = m_slices.size();
637 itemsAvailable = m_model->rowCount() - m_mapFirst - m_slices.size();
717 int lastExisting = qMin(m_mapFirst + m_slices.size() - 1, end);
638 else
718 for (int i = lastExisting; i >= start; i--) {
639 itemsAvailable = m_model->columnCount() - m_mapFirst - m_slices.size();
719 q->remove(q->slices().at(i - m_mapFirst));
640 int toBeAdded = qMin(itemsAvailable, m_mapCount - m_slices.size()); // add not more items than there is space left to be filled.
720 // sizeAfter--;
641 int currentSize = m_slices.size();
721 // handlePointRemoved(i - m_mapFirst);
642 if (toBeAdded > 0)
643 for (int i = m_slices.size(); i < currentSize + toBeAdded; i++) {
644 QPieSlice *slice = new QPieSlice;
645 if (m_mapOrientation == Qt::Vertical) {
646 slice->setValue(m_model->data(m_model->index(i + m_mapFirst, m_mapValues), Qt::DisplayRole).toDouble());
647 slice->setLabel(m_model->data(m_model->index(i + m_mapFirst, m_mapLabels), Qt::DisplayRole).toString());
648 } else {
649 slice->setValue(m_model->data(m_model->index(m_mapValues, i + m_mapFirst), Qt::DisplayRole).toDouble());
650 slice->setLabel(m_model->data(m_model->index(m_mapLabels, i + m_mapFirst), Qt::DisplayRole).toString());
651 }
652 slice->setLabelVisible();
653 q->insert(i, slice);
654 }
722 }
655 }
723
724 // the map is limited, so after removing the items some new items may have fall within the mapped area
725 int itemsAvailable;
726 if (m_mapOrientation == Qt::Vertical)
727 itemsAvailable = m_model->rowCount() - m_mapFirst - m_slices.size();
728 else
729 itemsAvailable = m_model->columnCount() - m_mapFirst - m_slices.size();
730 int toBeAdded = qMin(itemsAvailable, m_mapCount - m_slices.size());
731 int currentSize = m_slices.size();
732 if (itemsAvailable > 0)
733 for (int i = m_slices.size() + m_mapFirst; i < currentSize + toBeAdded + m_mapFirst; i++) {
734 // handlePointAdded(i);
735 QPieSlice *slice = new QPieSlice;
736 slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble());
737 slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
738 slice->setLabelVisible(true);
739 q->insert(i - m_mapFirst, slice);
740 }
741
742 // for (int i = lastExisting; i >= start; i--) {
743 // q->remove(q->slices().at(i - m_mapFirst));
744 //// sizeAfter--;
745 //// handlePointRemoved(i - m_mapFirst);
746 // }
747 } else {
748 // first remove item lays before the mapped area
749 int toRemove = qMin(m_slices.size(), removedCount);
750 for (int i = m_mapFirst; i < m_mapFirst + toRemove; i++)
751 q->remove(q->slices().at(0));
752 // handlePointRemoved(0);
753
754 // the map is limited, so after removing the items some new items may have fall into the map
755 int itemsAvailable;
756 if (m_mapOrientation == Qt::Vertical)
757 itemsAvailable = m_model->rowCount() - m_mapFirst - m_slices.size();
758 else
759 itemsAvailable = m_model->columnCount() - m_mapFirst - m_slices.size();
760 int toBeAdded = qMin(itemsAvailable, m_mapCount - m_slices.size());
761 int currentSize = m_slices.size();
762 if (itemsAvailable > 0)
763 for (int i = m_slices.size(); i < currentSize + toBeAdded; i++) {
764 QPieSlice *slice = new QPieSlice;
765 slice->setValue(m_model->data(m_model->index(i + m_mapFirst, m_mapValues), Qt::DisplayRole).toDouble());
766 slice->setLabel(m_model->data(m_model->index(i + m_mapFirst, m_mapLabels), Qt::DisplayRole).toString());
767 slice->setLabelVisible(true);
768 q->insert(i, slice);
769 // handlePointAdded(i);
770 }
771 }
656 }
772
773 }
657 }
774
658
775 void QPieSeriesPrivate::initializePieFromModel()
659 void QPieSeriesPrivate::initializePieFromModel()
@@ -39,7 +39,8
39 #include <QTime>
39 #include <QTime>
40
40
41 TableWidget::TableWidget(QWidget *parent)
41 TableWidget::TableWidget(QWidget *parent)
42 : QWidget(parent),specialPie(0)
42 : QWidget(parent)
43 // specialPie(0)
43 {
44 {
44 setGeometry(1900, 100, 1000, 600);
45 setGeometry(1900, 100, 1000, 600);
45 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
46 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
@@ -53,7 +54,7 TableWidget::TableWidget(QWidget *parent)
53 // tableView->setItemDelegate(new QStyledItemDelegate);
54 // tableView->setItemDelegate(new QStyledItemDelegate);
54 m_chart = new QChart;
55 m_chart = new QChart;
55 m_chart->legend()->setVisible(true);
56 m_chart->legend()->setVisible(true);
56 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
57 m_chart->setAnimationOptions(QChart::SeriesAnimations);
57 m_chartView = new QChartView(m_chart);
58 m_chartView = new QChartView(m_chart);
58 m_chartView->setRenderHint(QPainter::Antialiasing);
59 m_chartView->setRenderHint(QPainter::Antialiasing);
59 m_chartView->setMinimumSize(640, 480);
60 m_chartView->setMinimumSize(640, 480);
@@ -147,7 +148,7 void TableWidget::updateChartType(bool toggle)
147 // this if is needed, so that the function is only called once.
148 // this if is needed, so that the function is only called once.
148 // For the radioButton that was enabled.
149 // For the radioButton that was enabled.
149 if (toggle) {
150 if (toggle) {
150 specialPie = 0;
151 // specialPie = 0;
151 m_chart->removeAllSeries();
152 m_chart->removeAllSeries();
152 m_chart->axisX()->setNiceNumbersEnabled(false);
153 m_chart->axisX()->setNiceNumbersEnabled(false);
153 m_chart->axisY()->setNiceNumbersEnabled(false);
154 m_chart->axisY()->setNiceNumbersEnabled(false);
@@ -299,25 +300,25 void TableWidget::updateChartType(bool toggle)
299 pieSeries->setModelMapping(2,2, Qt::Vertical);
300 pieSeries->setModelMapping(2,2, Qt::Vertical);
300 pieSeries->setLabelsVisible(true);
301 pieSeries->setLabelsVisible(true);
301 pieSeries->setPieSize(0.35);
302 pieSeries->setPieSize(0.35);
302 pieSeries->setHorizontalPosition(0.2);
303 pieSeries->setHorizontalPosition(0.5);
303 pieSeries->setVerticalPosition(0.75);
304 pieSeries->setVerticalPosition(0.75);
304 m_chart->addSeries(pieSeries);
305 m_chart->addSeries(pieSeries);
305 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
306 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
306 m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
307 m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
307
308
308 // special pie
309 // // special pie
309 specialPie = new QPieSeries;
310 // specialPie = new QPieSeries;
310 specialPie->append(17, "1");
311 // specialPie->append(17, "1");
311 specialPie->append(45, "2");
312 // specialPie->append(45, "2");
312 specialPie->append(77, "3");
313 // specialPie->append(77, "3");
313 specialPie->append(37, "4");
314 // specialPie->append(37, "4");
314 specialPie->append(27, "5");
315 // specialPie->append(27, "5");
315 specialPie->append(47, "6");
316 // specialPie->append(47, "6");
316 specialPie->setPieSize(0.35);
317 // specialPie->setPieSize(0.35);
317 specialPie->setHorizontalPosition(0.8);
318 // specialPie->setHorizontalPosition(0.8);
318 specialPie->setVerticalPosition(0.75);
319 // specialPie->setVerticalPosition(0.75);
319 specialPie->setLabelsVisible(true);
320 // specialPie->setLabelsVisible(true);
320 m_chart->addSeries(specialPie);
321 // m_chart->addSeries(specialPie);
321 }
322 }
322 else if (m_areaRadioButton->isChecked())
323 else if (m_areaRadioButton->isChecked())
323 {
324 {
@@ -362,11 +363,11 void TableWidget::updateChartType(bool toggle)
362
363
363 void TableWidget::testPie()
364 void TableWidget::testPie()
364 {
365 {
365 if (specialPie) {
366 // if (specialPie) {
366 specialPie->remove(specialPie->slices().at(2));
367 // specialPie->remove(specialPie->slices().at(2));
367 // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
368 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
368 specialPie->append(4, "heloo");
369 // specialPie->append(4, "heloo");
369 }
370 // }
370 }
371 }
371
372
372 TableWidget::~TableWidget()
373 TableWidget::~TableWidget()
@@ -63,7 +63,7 public:
63 QRadioButton* m_areaRadioButton;
63 QRadioButton* m_areaRadioButton;
64 QRadioButton* m_barRadioButton;
64 QRadioButton* m_barRadioButton;
65 QSpinBox* m_linesCountSpinBox;
65 QSpinBox* m_linesCountSpinBox;
66 QPieSeries* specialPie;
66 // QPieSeries* specialPie;
67 };
67 };
68
68
69 #endif // TABLEWIDGET_H
69 #endif // TABLEWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now