diff --git a/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp b/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp --- a/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp +++ b/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp @@ -136,18 +136,19 @@ void ChartColorBarAxisY::createColorBar( } //colorbar - QRectF rect(m_position.x()+10,m_position.y(),m_height/20,m_height); //remove 10 if needed + QRectF rect(m_position.x()+10,m_position.y(),m_height/20,m_height); //remove +10 if needed QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this); colorbar->setZValue(ChartPresenter::AxisZValue); colorbar->setBrush(gradient); + //colorbar labels for(int i=0;itickCount();i++) { qreal value = m_axis->max() - (i * (m_axis->max() - m_axis->min()) / (m_axis->tickCount() - 1)); QGraphicsTextItem *label = new QGraphicsTextItem(this); label->setPlainText(QString::number(value)); - label->setPos((m_position.x()+10+m_height/20+1),(m_position.y()*0.85+i*(m_height/(m_axis->tickCount()-1)))); //remove 10 if needed + label->setPos((m_position.x()+10+m_height/20+1),(m_position.y()*0.85+i*(m_height/(m_axis->tickCount()-1)))); //remove +10 if needed } } diff --git a/src/charts/colormapchart/colormapchart.cpp b/src/charts/colormapchart/colormapchart.cpp --- a/src/charts/colormapchart/colormapchart.cpp +++ b/src/charts/colormapchart/colormapchart.cpp @@ -20,8 +20,7 @@ ColorMapChart::ColorMapChart(QColorMapSe m_gradientType(Rainbow), m_colorbar(Q_NULLPTR), m_isColorBarDrawn(false), - m_currentplotArea(QRectF()), - m_grid(Q_NULLPTR) + m_currentplotArea(QRectF()) { // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); @@ -74,7 +73,10 @@ void ColorMapChart::paint(QPainter *pain { m_currentplotArea = plotAreaRect; - m_grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel); + m_grid.reserve(plotAreaRect.width()*plotAreaRect.height()); + m_grid.resize(plotAreaRect.width()*plotAreaRect.height()); + + m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),m_grid, QColorMapSeries::LastPixel); addColorBar(plotAreaRect); } @@ -94,7 +96,7 @@ void ColorMapChart::paint(QPainter *pain { for(int j=0;jat(i+j*(imageWidth)); + double value = m_grid.at(i+j*(imageWidth)); double pix=((value-minZ)/rangeZ); int indexInColorTable = pix*(nbOfColors-1); colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable)); diff --git a/src/charts/colormapchart/colormapchart_p.h b/src/charts/colormapchart/colormapchart_p.h --- a/src/charts/colormapchart/colormapchart_p.h +++ b/src/charts/colormapchart/colormapchart_p.h @@ -73,7 +73,7 @@ protected: bool m_isColorBarDrawn; QColorBarAxis *m_colorbar; QRectF m_currentplotArea; - QVector * m_grid; + QVector m_grid; }; //class PixmapMarker: public QGraphicsRectItem diff --git a/src/charts/colormapchart/qcolormapseries.cpp b/src/charts/colormapchart/qcolormapseries.cpp --- a/src/charts/colormapchart/qcolormapseries.cpp +++ b/src/charts/colormapchart/qcolormapseries.cpp @@ -120,10 +120,10 @@ QColorMapSeries &QColorMapSeries::operat from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n When there are more points than pixels, \a strategy is applied to determine which to choose. */ -QVector *QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy) +void QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QVector &grid, QColorMapSeries::Strategy strategy) { Q_D(QColorMapSeries); - return d->getUniformGrid(xpos, ypos,width,height, strategy); + d->getUniformGrid(xpos, ypos,width,height, grid, strategy); } //void QColorMapSeries::attachAxis(QAbstractAxis *axis) @@ -433,10 +433,8 @@ QAbstractAxis* QColorMapSeriesPrivate::c } -QVector *QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QColorMapSeries::Strategy strategy) +void QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QVector &grid, QColorMapSeries::Strategy strategy) { - QVector *grid = new QVector(width*height); - double dx = (m_maxX - m_minX)/(double)width; double dy = (m_maxY - m_minY)/(double)height; @@ -446,7 +444,7 @@ QVector *QColorMapSeriesPrivate: QVector cluster; cluster.reserve(height*width/1000); - for (auto cell= grid->begin();cellend();++cell) + for (auto cell= grid.begin();cellbuildCluster(x,y,dx,dy,cluster); @@ -466,8 +464,6 @@ cluster.reserve(height*width/1000); y++; } } - - return grid; } /*! diff --git a/src/charts/colormapchart/qcolormapseries.h b/src/charts/colormapchart/qcolormapseries.h --- a/src/charts/colormapchart/qcolormapseries.h +++ b/src/charts/colormapchart/qcolormapseries.h @@ -48,8 +48,8 @@ public : QColorMapSeries &operator << (const ColorMapDataPart &dataPart); QColorMapSeries &operator << (const QList &dataParts); - QVector *getUniformGrid(int xpos, int ypos,int width, int height, Strategy strategy); - // QVector *getUniformGrid(int width, int height, Strategy lambda); + void getUniformGrid(int xpos, int ypos,int width, int height, QVector &grid, Strategy strategy); + // QVector *getUniformGrid(int width, int height, QVector &grid, Strategy lambda); // virtual void attachAxis(QAbstractAxis *axis); diff --git a/src/charts/colormapchart/qcolormapseries_p.h b/src/charts/colormapchart/qcolormapseries_p.h --- a/src/charts/colormapchart/qcolormapseries_p.h +++ b/src/charts/colormapchart/qcolormapseries_p.h @@ -31,7 +31,7 @@ public : QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; QAbstractAxis* createDefaultAxis(Qt::Orientation) const; - QVector *getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy); + void getUniformGrid(int xpos, int ypos,int width, int height,QVector &grid, QColorMapSeries::Strategy strategy); Q_SIGNALS: void updated();