From 3dd93906f007479864adfd7e4962b92a9d85a12d 2013-06-10 07:38:27 From: Miikka Heikkinen Date: 2013-06-10 07:38:27 Subject: [PATCH] Further crash fixes to boxplot Change-Id: Ic14119490bb39a7040d4bed65af4f19548846a89 Reviewed-by: Mika Salmela --- diff --git a/src/animations/boxplotanimation.cpp b/src/animations/boxplotanimation.cpp index a73aa7d..c5880a8 100644 --- a/src/animations/boxplotanimation.cpp +++ b/src/animations/boxplotanimation.cpp @@ -39,7 +39,7 @@ void BoxPlotAnimation::addBox(BoxWhiskers *box) { BoxWhiskersAnimation *animation = m_animations.value(box); if (!animation) { - animation = new BoxWhiskersAnimation(box); + animation = new BoxWhiskersAnimation(box, this); m_animations.insert(box, animation); BoxWhiskersData start; start.m_median = box->m_data.m_median; @@ -76,10 +76,16 @@ void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box) void BoxPlotAnimation::stopAll() { - foreach (BoxWhiskersAnimation *animation, m_animations.values()) + foreach (BoxWhiskers *box, m_animations.keys()) { + BoxWhiskersAnimation *animation = m_animations.value(box); animation->stopAndDestroyLater(); + m_animations.remove(box); + } } -//#include "moc_boxplotanimation_p.cpp" +void BoxPlotAnimation::removeBoxAnimation(BoxWhiskers *box) +{ + m_animations.remove(box); +} QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/boxplotanimation_p.h b/src/animations/boxplotanimation_p.h index 9a64490..2f99b81 100644 --- a/src/animations/boxplotanimation_p.h +++ b/src/animations/boxplotanimation_p.h @@ -52,6 +52,7 @@ public: void setAnimationStart(BoxWhiskers *box); void stopAll(); + void removeBoxAnimation(BoxWhiskers *box); protected: BoxPlotChartItem *m_item; diff --git a/src/animations/boxwhiskersanimation.cpp b/src/animations/boxwhiskersanimation.cpp index a46aa76..2ce9352 100644 --- a/src/animations/boxwhiskersanimation.cpp +++ b/src/animations/boxwhiskersanimation.cpp @@ -29,9 +29,10 @@ Q_DECLARE_METATYPE(qreal) QTCOMMERCIALCHART_BEGIN_NAMESPACE -BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) +BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation) : ChartAnimation(box), - m_box(box) + m_box(box), + m_boxPlotAnimation(boxPlotAnimation) { setDuration(ChartAnimationDuration); setEasingCurve(QEasingCurve::OutQuart); @@ -39,6 +40,8 @@ BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) BoxWhiskersAnimation::~BoxWhiskersAnimation() { + if (m_boxPlotAnimation) + m_boxPlotAnimation->removeBoxAnimation(m_box); } QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const diff --git a/src/animations/boxwhiskersanimation_p.h b/src/animations/boxwhiskersanimation_p.h index 975ced3..dcad2e9 100644 --- a/src/animations/boxwhiskersanimation_p.h +++ b/src/animations/boxwhiskersanimation_p.h @@ -43,7 +43,7 @@ class BoxWhiskersAnimation : public ChartAnimation Q_OBJECT public: - BoxWhiskersAnimation(BoxWhiskers *box); + BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation); ~BoxWhiskersAnimation(); public: // from QVariantAnimation @@ -60,6 +60,7 @@ protected: friend class BoxPlotAnimation; BoxWhiskers *m_box; bool m_moveMedianLine; + BoxPlotAnimation *m_boxPlotAnimation; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/boxplotchart/qboxplotseries.cpp b/src/boxplotchart/qboxplotseries.cpp index 7635071..547d086 100644 --- a/src/boxplotchart/qboxplotseries.cpp +++ b/src/boxplotchart/qboxplotseries.cpp @@ -559,13 +559,14 @@ void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) bool QBoxPlotSeriesPrivate::append(QBoxSet *set) { - if ((m_boxSets.contains(set)) || (set == 0)) + if (m_boxSets.contains(set) || (set == 0) || set->d_ptr->m_series) return false; // Fail if set is already in list or set is null. m_boxSets.append(set); QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + set->d_ptr->m_series = this; emit restructuredBoxes(); // this notifies boxplotchartitem return true; @@ -576,6 +577,7 @@ bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) if (!m_boxSets.contains(set)) return false; // Fail if set is not in list + set->d_ptr->m_series = 0; m_boxSets.removeOne(set); QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); @@ -588,7 +590,7 @@ bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) bool QBoxPlotSeriesPrivate::append(QList sets) { foreach (QBoxSet *set, sets) { - if ((set == 0) || (m_boxSets.contains(set))) + if ((set == 0) || m_boxSets.contains(set) || set->d_ptr->m_series) return false; // Fail if any of the sets is null or is already appended. if (sets.count(set) != 1) return false; // Also fail if same set is more than once in given list. @@ -599,6 +601,7 @@ bool QBoxPlotSeriesPrivate::append(QList sets) QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + set->d_ptr->m_series = this; } emit restructuredBoxes(); // this notifies boxplotchartitem @@ -618,6 +621,7 @@ bool QBoxPlotSeriesPrivate::remove(QList sets) } foreach (QBoxSet *set, sets) { + set->d_ptr->m_series = 0; m_boxSets.removeOne(set); QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); @@ -631,10 +635,11 @@ bool QBoxPlotSeriesPrivate::remove(QList sets) bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) { - if ((m_boxSets.contains(set)) || (set == 0)) + if ((m_boxSets.contains(set)) || (set == 0) || set->d_ptr->m_series) return false; // Fail if set is already in list or set is null. m_boxSets.insert(index, set); + set->d_ptr->m_series = this; QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); diff --git a/src/boxplotchart/qboxset.cpp b/src/boxplotchart/qboxset.cpp index 36b9ee4..fc47b5b 100644 --- a/src/boxplotchart/qboxset.cpp +++ b/src/boxplotchart/qboxset.cpp @@ -325,7 +325,8 @@ QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(p m_valuesCount(5), m_appendCount(0), m_pen(QPen(Qt::NoPen)), - m_brush(QBrush(Qt::NoBrush)) + m_brush(QBrush(Qt::NoBrush)), + m_series(0) { m_values = new qreal[m_valuesCount]; } diff --git a/src/boxplotchart/qboxset_p.h b/src/boxplotchart/qboxset_p.h index 4891dca..697c192 100644 --- a/src/boxplotchart/qboxset_p.h +++ b/src/boxplotchart/qboxset_p.h @@ -38,6 +38,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QBoxPlotSeriesPrivate; + class QBoxSetPrivate : public QObject { Q_OBJECT @@ -71,6 +73,7 @@ private: QBrush m_brush; QBrush m_labelBrush; QFont m_labelFont; + QBoxPlotSeriesPrivate *m_series; friend class QBoxSet; friend class QBoxPlotSeriesPrivate;