##// END OF EJS Templates
Improve theme initialization performance for bar series...
Titta Heikkala -
r2598:764a09c2b2a5
parent child
Show More
@@ -196,25 +196,27 void AbstractBarChartItem::handleOpacityChanged()
196 196
197 197 void AbstractBarChartItem::handleUpdatedBars()
198 198 {
199 // Handle changes in pen, brush, labels etc.
200 int categoryCount = m_series->d_func()->categoryCount();
201 int setCount = m_series->count();
202 int itemIndex(0);
203
204 for (int category = 0; category < categoryCount; category++) {
205 for (int set = 0; set < setCount; set++) {
206 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
207 Bar *bar = m_bars.at(itemIndex);
208 bar->setPen(barSet->m_pen);
209 bar->setBrush(barSet->m_brush);
210 bar->update();
211
212 QGraphicsTextItem *label = m_labels.at(itemIndex);
213 label->setHtml(QString("%1").arg(barSet->value(category)));
214 label->setFont(barSet->m_labelFont);
215 label->setDefaultTextColor(barSet->m_labelBrush.color());
216 label->update();
217 itemIndex++;
199 if (!m_series->d_func()->blockBarUpdate()) {
200 // Handle changes in pen, brush, labels etc.
201 int categoryCount = m_series->d_func()->categoryCount();
202 int setCount = m_series->count();
203 int itemIndex(0);
204
205 for (int category = 0; category < categoryCount; category++) {
206 for (int set = 0; set < setCount; set++) {
207 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
208 Bar *bar = m_bars.at(itemIndex);
209 bar->setPen(barSet->m_pen);
210 bar->setBrush(barSet->m_brush);
211 bar->update();
212
213 QGraphicsTextItem *label = m_labels.at(itemIndex);
214 label->setHtml(QString("%1").arg(barSet->value(category)));
215 label->setFont(barSet->m_labelFont);
216 label->setDefaultTextColor(barSet->m_labelBrush.color());
217 label->update();
218 itemIndex++;
219 }
218 220 }
219 221 }
220 222 }
@@ -413,7 +413,8 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
413 413 QAbstractSeriesPrivate(q),
414 414 m_barWidth(0.5), // Default value is 50% of category width
415 415 m_labelsVisible(false),
416 m_visible(true)
416 m_visible(true),
417 m_blockBarUpdate(false)
417 418 {
418 419 }
419 420
@@ -652,6 +653,10 qreal QAbstractBarSeriesPrivate::bottom()
652 653 return bottom;
653 654 }
654 655
656 bool QAbstractBarSeriesPrivate::blockBarUpdate()
657 {
658 return m_blockBarUpdate;
659 }
655 660
656 661 void QAbstractBarSeriesPrivate::initializeDomain()
657 662 {
@@ -843,6 +848,8 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orie
843 848
844 849 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
845 850 {
851 m_blockBarUpdate = true; // Ensures that the bars are not updated before the theme is ready
852
846 853 const QList<QGradient> gradients = theme->seriesGradients();
847 854
848 855 qreal takeAtPos = 0.5;
@@ -875,12 +882,13 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bo
875 882 else
876 883 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
877 884 }
878
879 885 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) {
880 886 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
881 887 m_barSets.at(i)->setPen(c);
882 888 }
883 889 }
890 m_blockBarUpdate = false;
891 emit updatedBars();
884 892 }
885 893
886 894 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
@@ -85,6 +85,8 public:
85 85 qreal top();
86 86 qreal bottom();
87 87
88 bool blockBarUpdate();
89
88 90 Q_SIGNALS:
89 91 void clicked(int index, QBarSet *barset);
90 92 void updatedBars();
@@ -101,6 +103,7 protected:
101 103 qreal m_barWidth;
102 104 bool m_labelsVisible;
103 105 bool m_visible;
106 bool m_blockBarUpdate;
104 107
105 108 private:
106 109 Q_DECLARE_PUBLIC(QAbstractBarSeries)
General Comments 0
You need to be logged in to leave comments. Login now