##// END OF EJS Templates
fix: changing barset colors no more triggers layout calculations
sauimone -
r1917:2390e49cbc51
parent child
Show More
@@ -38,8 +38,10 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPres
38 m_animation(0),
38 m_animation(0),
39 m_series(series)
39 m_series(series)
40 {
40 {
41
41 setFlag(ItemClipsChildrenToShape);
42 setFlag(ItemClipsChildrenToShape);
42 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
43 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
44 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
43 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
45 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
44 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
46 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
45 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
47 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
@@ -173,6 +175,30 void AbstractBarChartItem::handleVisibleChanged()
173 }
175 }
174 }
176 }
175
177
178 void AbstractBarChartItem::handleUpdatedBars()
179 {
180 // Handle changes in pen, brush, labels etc.
181 int categoryCount = m_series->d_func()->categoryCount();
182 int setCount = m_series->count();
183 int itemIndex(0);
184
185 for (int category = 0; category < categoryCount; category++) {
186 for (int set = 0; set < setCount; set++) {
187 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
188 Bar* bar = m_bars.at(itemIndex);
189 bar->setPen(barSet->m_pen);
190 bar->setBrush(barSet->m_brush);
191 bar->update();
192
193 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
194 label->setFont(barSet->m_labelFont);
195 label->setBrush(barSet->m_labelBrush);
196 label->update();
197 itemIndex++;
198 }
199 }
200 }
201
176 #include "moc_abstractbarchartitem_p.cpp"
202 #include "moc_abstractbarchartitem_p.cpp"
177
203
178 QTCOMMERCIALCHART_END_NAMESPACE
204 QTCOMMERCIALCHART_END_NAMESPACE
@@ -68,6 +68,7 public Q_SLOTS:
68 void handleLabelsVisibleChanged(bool visible);
68 void handleLabelsVisibleChanged(bool visible);
69 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
69 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
70 void handleVisibleChanged();
70 void handleVisibleChanged();
71 void handleUpdatedBars();
71
72
72 protected:
73 protected:
73
74
@@ -405,7 +405,7 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
405 width = 0.0;
405 width = 0.0;
406 }
406 }
407 m_barWidth = width;
407 m_barWidth = width;
408 emit updatedBars();
408 emit updatedLayout();
409 }
409 }
410
410
411 qreal QAbstractBarSeriesPrivate::barWidth() const
411 qreal QAbstractBarSeriesPrivate::barWidth() const
@@ -421,7 +421,7 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
421 void QAbstractBarSeriesPrivate::setVisible(bool visible)
421 void QAbstractBarSeriesPrivate::setVisible(bool visible)
422 {
422 {
423 m_visible = visible;
423 m_visible = visible;
424 emit updatedBars();
424 emit visibleChanged();
425 }
425 }
426
426
427 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
427 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
@@ -678,6 +678,7 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
678 return false;
678 return false;
679 }
679 }
680 m_barSets.append(set);
680 m_barSets.append(set);
681 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
681 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
682 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
682 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
683 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
683 emit restructuredBars(); // this notifies barchartitem
684 emit restructuredBars(); // this notifies barchartitem
@@ -695,6 +696,7 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
695 return false;
696 return false;
696 }
697 }
697 m_barSets.removeOne(set);
698 m_barSets.removeOne(set);
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
698 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
700 emit restructuredBars(); // this notifies barchartitem
702 emit restructuredBars(); // this notifies barchartitem
@@ -720,6 +722,7 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
720
722
721 foreach (QBarSet* set, sets) {
723 foreach (QBarSet* set, sets) {
722 m_barSets.append(set);
724 m_barSets.append(set);
725 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
723 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
724 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
725 }
728 }
@@ -749,6 +752,7 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
749
752
750 foreach (QBarSet* set, sets) {
753 foreach (QBarSet* set, sets) {
751 m_barSets.removeOne(set);
754 m_barSets.removeOne(set);
755 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
752 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
756 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
753 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
757 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
754 }
758 }
@@ -768,6 +772,7 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
768 return false;
772 return false;
769 }
773 }
770 m_barSets.insert(index, set);
774 m_barSets.insert(index, set);
775 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
771 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
776 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
772 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
777 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
773 emit restructuredBars(); // this notifies barchartitem
778 emit restructuredBars(); // this notifies barchartitem
@@ -84,8 +84,10 public:
84 Q_SIGNALS:
84 Q_SIGNALS:
85 void clicked(int index, QBarSet *barset);
85 void clicked(int index, QBarSet *barset);
86 void updatedBars();
86 void updatedBars();
87 void updatedLayout();
87 void restructuredBars();
88 void restructuredBars();
88 void labelsVisibleChanged(bool visible);
89 void labelsVisibleChanged(bool visible);
90 void visibleChanged();
89
91
90 private:
92 private:
91 void populateCategories(QBarCategoryAxis* axis);
93 void populateCategories(QBarCategoryAxis* axis);
@@ -617,13 +617,13 int QBarSetPrivate::remove(const int index, const int count)
617 void QBarSetPrivate::replace(const int index, const qreal value)
617 void QBarSetPrivate::replace(const int index, const qreal value)
618 {
618 {
619 m_values.replace(index,QPointF(index,value));
619 m_values.replace(index,QPointF(index,value));
620 emit updatedBars();
620 emit updatedLayout();
621 }
621 }
622
622
623 void QBarSetPrivate::replace(const int index, const QPointF value)
623 void QBarSetPrivate::replace(const int index, const QPointF value)
624 {
624 {
625 m_values.replace(index,value);
625 m_values.replace(index,value);
626 emit updatedBars();
626 emit updatedLayout();
627 }
627 }
628
628
629 qreal QBarSetPrivate::pos(const int index)
629 qreal QBarSetPrivate::pos(const int index)
@@ -63,6 +63,7 public:
63 Q_SIGNALS:
63 Q_SIGNALS:
64 void restructuredBars();
64 void restructuredBars();
65 void updatedBars();
65 void updatedBars();
66 void updatedLayout();
66
67
67 public:
68 public:
68 QBarSet * const q_ptr;
69 QBarSet * const q_ptr;
General Comments 0
You need to be logged in to leave comments. Login now