From 4c0668542a5484deb7ac597608eb3c04a9bbe4d7 2012-04-23 11:02:46 From: Michal Klocek Date: 2012-04-23 11:02:46 Subject: [PATCH] Bugfixes for spline vector allocation issues --- diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 0ff7144..d32505f 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -236,6 +236,7 @@ void ChartPresenter::zoomIn(const QRectF& rect) { QRectF r = rect.normalized(); r.translate(-m_chartMargins.topLeft()); + if(!r.isValid()) return; if(m_animator) { QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); @@ -257,6 +258,7 @@ void ChartPresenter::zoomOut() QSizeF size = chartGeometry().size(); QRectF rect = chartGeometry(); rect.translate(-m_chartMargins.topLeft()); + if(!rect.isValid()) return; m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); diff --git a/src/splinechart/qsplineseries.cpp b/src/splinechart/qsplineseries.cpp index 4f85d08..c369a01 100644 --- a/src/splinechart/qsplineseries.cpp +++ b/src/splinechart/qsplineseries.cpp @@ -67,6 +67,14 @@ QSplineSeries::QSplineSeries(QObject *parent) : { } +QSplineSeries::~QSplineSeries() +{ + Q_D(QSplineSeries); + if(d->m_dataset){ + d->m_dataset->removeSeries(this); + } +} + QAbstractSeries::QSeriesType QSplineSeries::type() const { return QAbstractSeries::SeriesTypeSpline; diff --git a/src/splinechart/qsplineseries.h b/src/splinechart/qsplineseries.h index 099233d..f23ad84 100644 --- a/src/splinechart/qsplineseries.h +++ b/src/splinechart/qsplineseries.h @@ -37,6 +37,7 @@ class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries public: explicit QSplineSeries(QObject *parent = 0); + ~QSplineSeries(); QAbstractSeries::QSeriesType type() const; QPointF controlPoint(int index) const; diff --git a/src/splinechart/splinechartitem.cpp b/src/splinechart/splinechartitem.cpp index 7fab2db..22eeb8d 100644 --- a/src/splinechart/splinechartitem.cpp +++ b/src/splinechart/splinechartitem.cpp @@ -23,6 +23,7 @@ #include "chartpresenter_p.h" #include "chartanimator_p.h" #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -47,10 +48,12 @@ QPainterPath SplineChartItem::shape() const } void SplineChartItem::updateLayout(QVector &oldPoints, QVector &newPoints,int index) -{ +{ QVector controlPoints; - controlPoints.resize(newPoints.count()*2-2); + if(newPoints.count()>=2){ + controlPoints.resize(newPoints.count()*2-2); + } for (int i = 0; i < newPoints.size() - 1; i++) { controlPoints[2*i] = calculateGeometryControlPoint(2 * i); @@ -102,6 +105,7 @@ void SplineChartItem::setLayout(QVector &points, QVector &cont m_rect = splinePath.boundingRect(); XYChartItem::setLayout(points); m_controlPoints=controlPoints; + } //handlers @@ -121,7 +125,7 @@ void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o { Q_UNUSED(widget) Q_UNUSED(option) - + qDebug()<<__FUNCTION__; painter->save(); painter->setClipRect(clipRect()); painter->setPen(m_linePen); diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index 3b4abba..6fd5031 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -416,7 +416,6 @@ void QXYSeriesPrivate::scaleDomain(Domain& domain) maxY=1.0; } - for (int i = 0; i < points.count(); i++) { qreal x = points[i].x(); diff --git a/src/xychart/xychartitem.cpp b/src/xychart/xychartitem.cpp index 4405a83..2eef246 100644 --- a/src/xychart/xychartitem.cpp +++ b/src/xychart/xychartitem.cpp @@ -239,7 +239,7 @@ void XYChartItem::handleGeometryChanged(const QRectF &rect) bool XYChartItem::isEmpty() { - return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY); + return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty(); } void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/test/auto/qchart/tst_qchart.cpp b/test/auto/qchart/tst_qchart.cpp index 8c36c8d..fe5ca33 100644 --- a/test/auto/qchart/tst_qchart.cpp +++ b/test/auto/qchart/tst_qchart.cpp @@ -319,7 +319,6 @@ void tst_QChart::isBackgroundVisible() QFETCH(bool, isBackgroundVisible); m_chart->setBackgroundVisible(isBackgroundVisible); QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); - } void tst_QChart::legend_data() @@ -338,15 +337,12 @@ void tst_QChart::margins_data() } void tst_QChart::margins() -{QTest::addColumn("seriesCount"); -QTest::newRow("0") << 0; -QTest::newRow("-1") << -1; +{ createTestData(); QRectF rect = m_chart->geometry(); QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); - } void tst_QChart::removeAllSeries_data()