##// END OF EJS Templates
Bugfixes for spline vector allocation issues
Michal Klocek -
r1082:4c0668542a54
parent child
Show More
@@ -236,6 +236,7 void ChartPresenter::zoomIn(const QRectF& rect)
236 {
236 {
237 QRectF r = rect.normalized();
237 QRectF r = rect.normalized();
238 r.translate(-m_chartMargins.topLeft());
238 r.translate(-m_chartMargins.topLeft());
239 if(!r.isValid()) return;
239 if(m_animator) {
240 if(m_animator) {
240
241
241 QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
242 QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
@@ -257,6 +258,7 void ChartPresenter::zoomOut()
257 QSizeF size = chartGeometry().size();
258 QSizeF size = chartGeometry().size();
258 QRectF rect = chartGeometry();
259 QRectF rect = chartGeometry();
259 rect.translate(-m_chartMargins.topLeft());
260 rect.translate(-m_chartMargins.topLeft());
261 if(!rect.isValid()) return;
260 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
262 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
261 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
263 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
262
264
@@ -67,6 +67,14 QSplineSeries::QSplineSeries(QObject *parent) :
67 {
67 {
68 }
68 }
69
69
70 QSplineSeries::~QSplineSeries()
71 {
72 Q_D(QSplineSeries);
73 if(d->m_dataset){
74 d->m_dataset->removeSeries(this);
75 }
76 }
77
70 QAbstractSeries::QSeriesType QSplineSeries::type() const
78 QAbstractSeries::QSeriesType QSplineSeries::type() const
71 {
79 {
72 return QAbstractSeries::SeriesTypeSpline;
80 return QAbstractSeries::SeriesTypeSpline;
@@ -37,6 +37,7 class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries
37 public:
37 public:
38
38
39 explicit QSplineSeries(QObject *parent = 0);
39 explicit QSplineSeries(QObject *parent = 0);
40 ~QSplineSeries();
40 QAbstractSeries::QSeriesType type() const;
41 QAbstractSeries::QSeriesType type() const;
41
42
42 QPointF controlPoint(int index) const;
43 QPointF controlPoint(int index) const;
@@ -23,6 +23,7
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QPainter>
25 #include <QPainter>
26 #include <QDebug>
26
27
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29
@@ -47,10 +48,12 QPainterPath SplineChartItem::shape() const
47 }
48 }
48
49
49 void SplineChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
50 void SplineChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
50 {
51 {
51 QVector<QPointF> controlPoints;
52 QVector<QPointF> controlPoints;
52
53
53 controlPoints.resize(newPoints.count()*2-2);
54 if(newPoints.count()>=2){
55 controlPoints.resize(newPoints.count()*2-2);
56 }
54
57
55 for (int i = 0; i < newPoints.size() - 1; i++) {
58 for (int i = 0; i < newPoints.size() - 1; i++) {
56 controlPoints[2*i] = calculateGeometryControlPoint(2 * i);
59 controlPoints[2*i] = calculateGeometryControlPoint(2 * i);
@@ -102,6 +105,7 void SplineChartItem::setLayout(QVector<QPointF> &points, QVector<QPointF> &cont
102 m_rect = splinePath.boundingRect();
105 m_rect = splinePath.boundingRect();
103 XYChartItem::setLayout(points);
106 XYChartItem::setLayout(points);
104 m_controlPoints=controlPoints;
107 m_controlPoints=controlPoints;
108
105 }
109 }
106
110
107 //handlers
111 //handlers
@@ -121,7 +125,7 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
121 {
125 {
122 Q_UNUSED(widget)
126 Q_UNUSED(widget)
123 Q_UNUSED(option)
127 Q_UNUSED(option)
124
128 qDebug()<<__FUNCTION__;
125 painter->save();
129 painter->save();
126 painter->setClipRect(clipRect());
130 painter->setClipRect(clipRect());
127 painter->setPen(m_linePen);
131 painter->setPen(m_linePen);
@@ -416,7 +416,6 void QXYSeriesPrivate::scaleDomain(Domain& domain)
416 maxY=1.0;
416 maxY=1.0;
417 }
417 }
418
418
419
420 for (int i = 0; i < points.count(); i++)
419 for (int i = 0; i < points.count(); i++)
421 {
420 {
422 qreal x = points[i].x();
421 qreal x = points[i].x();
@@ -239,7 +239,7 void XYChartItem::handleGeometryChanged(const QRectF &rect)
239
239
240 bool XYChartItem::isEmpty()
240 bool XYChartItem::isEmpty()
241 {
241 {
242 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY);
242 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty();
243 }
243 }
244
244
245 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
245 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -319,7 +319,6 void tst_QChart::isBackgroundVisible()
319 QFETCH(bool, isBackgroundVisible);
319 QFETCH(bool, isBackgroundVisible);
320 m_chart->setBackgroundVisible(isBackgroundVisible);
320 m_chart->setBackgroundVisible(isBackgroundVisible);
321 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
321 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
322
323 }
322 }
324
323
325 void tst_QChart::legend_data()
324 void tst_QChart::legend_data()
@@ -338,15 +337,12 void tst_QChart::margins_data()
338 }
337 }
339
338
340 void tst_QChart::margins()
339 void tst_QChart::margins()
341 {QTest::addColumn<int>("seriesCount");
340 {
342 QTest::newRow("0") << 0;
343 QTest::newRow("-1") << -1;
344 createTestData();
341 createTestData();
345 QRectF rect = m_chart->geometry();
342 QRectF rect = m_chart->geometry();
346
343
347 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
344 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
348 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
345 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
349
350 }
346 }
351
347
352 void tst_QChart::removeAllSeries_data()
348 void tst_QChart::removeAllSeries_data()
General Comments 0
You need to be logged in to leave comments. Login now