##// END OF EJS Templates
fixed crash in barseries with empty sets
sauimone -
r1339:495016ed1794
parent child
Show More
@@ -38,9 +38,10 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
38 {
38 {
39 setFlag(ItemClipsChildrenToShape);
39 setFlag(ItemClipsChildrenToShape);
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool)));
41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
42 setZValue(ChartPresenter::BarSeriesZValue);
43 setZValue(ChartPresenter::BarSeriesZValue);
43 dataChanged();
44 handleDataStructureChanged();
44 }
45 }
45
46
46 BarChartItem::~BarChartItem()
47 BarChartItem::~BarChartItem()
@@ -59,7 +60,7 QRectF BarChartItem::boundingRect() const
59 return m_rect;
60 return m_rect;
60 }
61 }
61
62
62 void BarChartItem::dataChanged()
63 void BarChartItem::handleDataStructureChanged()
63 {
64 {
64 foreach(QGraphicsItem *item, childItems()) {
65 foreach(QGraphicsItem *item, childItems()) {
65 delete item;
66 delete item;
@@ -92,6 +93,7 void BarChartItem::dataChanged()
92
93
93 // TODO: Is this the right place to call it?
94 // TODO: Is this the right place to call it?
94 // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
95 // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
96 handleLayoutChanged();
95 }
97 }
96
98
97 QVector<QRectF> BarChartItem::calculateLayout()
99 QVector<QRectF> BarChartItem::calculateLayout()
@@ -150,18 +152,20 QVector<QRectF> BarChartItem::calculateLayout()
150
152
151 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
153 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
152 {
154 {
153 if (animator())
155 if (animator()) {
154 animator()->updateLayout(this, m_layout, layout);
156 animator()->updateLayout(this, m_layout, layout);
155 else
157 } else {
156 setLayout(layout);
158 setLayout(layout);
159 }
157 }
160 }
158
161
159 void BarChartItem::setLayout(const QVector<QRectF> &layout)
162 void BarChartItem::setLayout(const QVector<QRectF> &layout)
160 {
163 {
161 m_layout = layout;
164 m_layout = layout;
162
165
163 for (int i=0; i < m_bars.count(); i++)
166 for (int i=0; i < m_bars.count(); i++) {
164 m_bars.at(i)->setRect(layout.at(i));
167 m_bars.at(i)->setRect(layout.at(i));
168 }
165
169
166 update();
170 update();
167 }
171 }
@@ -194,7 +198,7 void BarChartItem::handleLayoutChanged()
194 update();
198 update();
195 }
199 }
196
200
197 void BarChartItem::labelsVisibleChanged(bool visible)
201 void BarChartItem::handleLabelsVisibleChanged(bool visible)
198 {
202 {
199 foreach (QGraphicsSimpleTextItem* label, m_labels) {
203 foreach (QGraphicsSimpleTextItem* label, m_labels) {
200 label->setVisible(visible);
204 label->setVisible(visible);
@@ -53,8 +53,6 public:
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54 QRectF boundingRect() const;
54 QRectF boundingRect() const;
55
55
56 virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes
57
58 virtual QVector<QRectF> calculateLayout();
56 virtual QVector<QRectF> calculateLayout();
59 void applyLayout(const QVector<QRectF> &layout);
57 void applyLayout(const QVector<QRectF> &layout);
60 void setLayout(const QVector<QRectF> &layout);
58 void setLayout(const QVector<QRectF> &layout);
@@ -66,7 +64,8 public Q_SLOTS:
66 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
64 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
67 void handleGeometryChanged(const QRectF &size);
65 void handleGeometryChanged(const QRectF &size);
68 void handleLayoutChanged();
66 void handleLayoutChanged();
69 void labelsVisibleChanged(bool visible);
67 void handleLabelsVisibleChanged(bool visible);
68 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
70
69
71 protected:
70 protected:
72
71
@@ -428,11 +428,6 qreal QBarSeriesPrivate::maxCategorySum()
428 return max;
428 return max;
429 }
429 }
430
430
431 void QBarSeriesPrivate::barsetChanged()
432 {
433 emit updatedBars();
434 }
435
436 void QBarSeriesPrivate::scaleDomain(Domain& domain)
431 void QBarSeriesPrivate::scaleDomain(Domain& domain)
437 {
432 {
438 qreal minX(domain.minX());
433 qreal minX(domain.minX());
@@ -486,7 +481,8 bool QBarSeriesPrivate::append(QBarSet *set)
486 return false;
481 return false;
487 }
482 }
488 m_barSets.append(set);
483 m_barSets.append(set);
489 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
484 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
485 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
490 if (m_dataset) {
486 if (m_dataset) {
491 m_dataset->updateSeries(q); // this notifies legend
487 m_dataset->updateSeries(q); // this notifies legend
492 }
488 }
@@ -502,7 +498,8 bool QBarSeriesPrivate::remove(QBarSet *set)
502 return false;
498 return false;
503 }
499 }
504 m_barSets.removeOne(set);
500 m_barSets.removeOne(set);
505 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
501 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
502 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
506 if (m_dataset) {
503 if (m_dataset) {
507 m_dataset->updateSeries(q); // this notifies legend
504 m_dataset->updateSeries(q); // this notifies legend
508 }
505 }
@@ -526,7 +523,8 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
526
523
527 foreach (QBarSet* set, sets) {
524 foreach (QBarSet* set, sets) {
528 m_barSets.append(set);
525 m_barSets.append(set);
529 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
526 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
527 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
530 }
528 }
531 if (m_dataset) {
529 if (m_dataset) {
532 m_dataset->updateSeries(q); // this notifies legend
530 m_dataset->updateSeries(q); // this notifies legend
@@ -542,7 +540,8 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
542 foreach (QBarSet* set, sets) {
540 foreach (QBarSet* set, sets) {
543 if (m_barSets.contains(set)) {
541 if (m_barSets.contains(set)) {
544 m_barSets.removeOne(set);
542 m_barSets.removeOne(set);
545 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
543 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
544 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
546 setsRemoved = true;
545 setsRemoved = true;
547 }
546 }
548 }
547 }
@@ -83,9 +83,6 Q_SIGNALS:
83 void categoriesUpdated();
83 void categoriesUpdated();
84 void labelsVisibleChanged(bool visible);
84 void labelsVisibleChanged(bool visible);
85
85
86 private Q_SLOTS:
87 void barsetChanged();
88
89 protected:
86 protected:
90 QList<QBarSet *> m_barSets;
87 QList<QBarSet *> m_barSets;
91 QStringList m_categories;
88 QStringList m_categories;
@@ -349,7 +349,8 void tst_QBarSet::customize()
349
349
350 // Append set1 to series
350 // Append set1 to series
351 QGroupedBarSeries *series = new QGroupedBarSeries();
351 QGroupedBarSeries *series = new QGroupedBarSeries();
352 series->append(set1);
352 bool success = series->append(set1);
353 QVERIFY(success);
353
354
354 // Add series to the chart
355 // Add series to the chart
355 QChartView view(new QChart());
356 QChartView view(new QChart());
General Comments 0
You need to be logged in to leave comments. Login now