##// END OF EJS Templates
memory leak fixed
winter -
r5:d44370b2cb06 default draft
parent child
Show More
@@ -136,18 +136,19 void ChartColorBarAxisY::createColorBar(
136 136 }
137 137
138 138 //colorbar
139 QRectF rect(m_position.x()+10,m_position.y(),m_height/20,m_height); //remove 10 if needed
139 QRectF rect(m_position.x()+10,m_position.y(),m_height/20,m_height); //remove +10 if needed
140 140
141 141 QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this);
142 142 colorbar->setZValue(ChartPresenter::AxisZValue);
143 143 colorbar->setBrush(gradient);
144 144
145 //colorbar labels
145 146 for(int i=0;i<m_axis->tickCount();i++)
146 147 {
147 148 qreal value = m_axis->max() - (i * (m_axis->max() - m_axis->min()) / (m_axis->tickCount() - 1));
148 149 QGraphicsTextItem *label = new QGraphicsTextItem(this);
149 150 label->setPlainText(QString::number(value));
150 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
151 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
151 152 }
152 153 }
153 154
@@ -20,8 +20,7 ColorMapChart::ColorMapChart(QColorMapSe
20 20 m_gradientType(Rainbow),
21 21 m_colorbar(Q_NULLPTR),
22 22 m_isColorBarDrawn(false),
23 m_currentplotArea(QRectF()),
24 m_grid(Q_NULLPTR)
23 m_currentplotArea(QRectF())
25 24 {
26 25 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
27 26 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
@@ -74,7 +73,10 void ColorMapChart::paint(QPainter *pain
74 73 {
75 74 m_currentplotArea = plotAreaRect;
76 75
77 m_grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel);
76 m_grid.reserve(plotAreaRect.width()*plotAreaRect.height());
77 m_grid.resize(plotAreaRect.width()*plotAreaRect.height());
78
79 m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),m_grid, QColorMapSeries::LastPixel);
78 80
79 81 addColorBar(plotAreaRect);
80 82 }
@@ -94,7 +96,7 void ColorMapChart::paint(QPainter *pain
94 96 {
95 97 for(int j=0;j<imageHeight;j++)
96 98 {
97 double value = m_grid->at(i+j*(imageWidth));
99 double value = m_grid.at(i+j*(imageWidth));
98 100 double pix=((value-minZ)/rangeZ);
99 101 int indexInColorTable = pix*(nbOfColors-1);
100 102 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
@@ -73,7 +73,7 protected:
73 73 bool m_isColorBarDrawn;
74 74 QColorBarAxis *m_colorbar;
75 75 QRectF m_currentplotArea;
76 QVector<double> * m_grid;
76 QVector<double> m_grid;
77 77 };
78 78
79 79 //class PixmapMarker: public QGraphicsRectItem
@@ -120,10 +120,10 QColorMapSeries &QColorMapSeries::operat
120 120 from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n
121 121 When there are more points than pixels, \a strategy is applied to determine which to choose.
122 122 */
123 QVector<double> *QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy)
123 void QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy)
124 124 {
125 125 Q_D(QColorMapSeries);
126 return d->getUniformGrid(xpos, ypos,width,height, strategy);
126 d->getUniformGrid(xpos, ypos,width,height, grid, strategy);
127 127 }
128 128
129 129 //void QColorMapSeries::attachAxis(QAbstractAxis *axis)
@@ -433,10 +433,8 QAbstractAxis* QColorMapSeriesPrivate::c
433 433 }
434 434
435 435
436 QVector<double> *QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QColorMapSeries::Strategy strategy)
436 void QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy)
437 437 {
438 QVector<double> *grid = new QVector<double>(width*height);
439
440 438 double dx = (m_maxX - m_minX)/(double)width;
441 439 double dy = (m_maxY - m_minY)/(double)height;
442 440
@@ -446,7 +444,7 QVector<double> *QColorMapSeriesPrivate:
446 444 QVector<Point3D> cluster;
447 445 cluster.reserve(height*width/1000);
448 446
449 for (auto cell= grid->begin();cell<grid->end();++cell)
447 for (auto cell= grid.begin();cell<grid.end();++cell)
450 448 {
451 449 cluster.resize(0);
452 450 this->buildCluster(x,y,dx,dy,cluster);
@@ -466,8 +464,6 cluster.reserve(height*width/1000);
466 464 y++;
467 465 }
468 466 }
469
470 return grid;
471 467 }
472 468
473 469 /*!
@@ -48,8 +48,8 public :
48 48 QColorMapSeries &operator << (const ColorMapDataPart &dataPart);
49 49 QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts);
50 50
51 QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, Strategy strategy);
52 // QVector<double> *getUniformGrid(int width, int height, Strategy lambda);
51 void getUniformGrid(int xpos, int ypos,int width, int height, QVector<double> &grid, Strategy strategy);
52 // QVector<double> *getUniformGrid(int width, int height, QVector<double> &grid, Strategy lambda);
53 53
54 54 // virtual void attachAxis(QAbstractAxis *axis);
55 55
@@ -31,7 +31,7 public :
31 31 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
32 32 QAbstractAxis* createDefaultAxis(Qt::Orientation) const;
33 33
34 QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy);
34 void getUniformGrid(int xpos, int ypos,int width, int height,QVector<double> &grid, QColorMapSeries::Strategy strategy);
35 35
36 36 Q_SIGNALS:
37 37 void updated();
General Comments 0
You need to be logged in to leave comments. Login now