From 1f7564788f9d2818200e3130c3847df734671bce 2016-07-07 13:06:37 From: jeandet Date: 2016-07-07 13:06:37 Subject: [PATCH] Some perfs improvments. Fixed bug on update outside of data range. Signed-off-by: jeandet --- diff --git a/src/charts/colormapchart/colormapchart.cpp b/src/charts/colormapchart/colormapchart.cpp index fea0845..73def87 100644 --- a/src/charts/colormapchart/colormapchart.cpp +++ b/src/charts/colormapchart/colormapchart.cpp @@ -85,7 +85,7 @@ void ColorMapChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt Q_UNUSED(option) painter->save(); - //m_series->setUseOpenGL(); + m_series->setUseOpenGL(); QRectF plotAreaRect = m_series->chart()->plotArea(); QRectF clipRect = mapColorMapToPlotArea(); @@ -94,8 +94,7 @@ void ColorMapChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt if(m_currentClipRect !=clipRect) { m_currentClipRect = clipRect; - m_grid.reserve(clipRect.width()*clipRect.height()); - m_grid.resize(clipRect.width()*clipRect.height()); + m_grid.resize(clipRect.width()*clipRect.height()); //faster than reserve m_series->getUniformGrid(qMax(m_series->minX(),domain()->minX()),qMin(m_series->maxX(),domain()->maxX()),qMax(m_series->minY(),domain()->minY()),qMin(m_series->maxY(),domain()->maxY()), clipRect.width(),clipRect.height(),m_grid, QColorMapSeries::LastPixel); addColorBar(plotAreaRect); @@ -141,11 +140,23 @@ QRectF ColorMapChart::mapColorMapToPlotArea() double widthToPaint = (qMin(seriesMaxX, domainMaxX)-qMax(seriesMinX, domainMinX))*plotAreaRect.width()/(domainMaxX-domainMinX); double heightTopaint= (qMin(seriesMaxY, domainMaxY)-qMax(seriesMinY, domainMinY))*plotAreaRect.height()/(domainMaxY-domainMinY); - QSizeF size = QSize(widthToPaint,heightTopaint); + double pointX = (qMax(seriesMinX,domainMinX)-domainMinX)*plotAreaRect.width()/(domainMaxX-domainMinX); double pointY = (domainMaxY-qMin(seriesMaxY,domainMaxY))*plotAreaRect.height()/(domainMaxY-domainMinY); + if(Q_UNLIKELY(widthToPaint < 0)) + widthToPaint = 0; + if(Q_UNLIKELY(heightTopaint < 0)) + heightTopaint = 0; + + QSizeF size = QSize(widthToPaint,heightTopaint); + + if(Q_UNLIKELY(pointX < 0)) + pointX = 0; + if(Q_UNLIKELY(pointY < 0)) + pointY = 0; + return QRectF(QPointF(pointX,pointY) ,size); } diff --git a/src/charts/colormapchart/colormapchart_p.h b/src/charts/colormapchart/colormapchart_p.h index 9426ee6..e5ce02b 100644 --- a/src/charts/colormapchart/colormapchart_p.h +++ b/src/charts/colormapchart/colormapchart_p.h @@ -79,6 +79,14 @@ Q_SIGNALS: void doubleClicked(const Point3D &point); void gradientTypeChanged(); +protected: +// void updateGeometry(); +// void mousePressEvent(QGraphicsSceneMouseEvent *event); +// void hoverEnterEvent(QGraphicsSceneHoverEvent *event); +// void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); +// void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); +// void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + private: inline bool isEmpty(); void addColorBar(QRectF plotAreaRect); @@ -88,7 +96,6 @@ private: QLinearGradient createColorMapGradient(GradientType gradientType); void changeGradient(GradientType gradientType); -protected: QColorMapSeries *m_series; QVector m_points; QRectF m_rect;