##// 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 //colorbar
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 QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this);
141 QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this);
142 colorbar->setZValue(ChartPresenter::AxisZValue);
142 colorbar->setZValue(ChartPresenter::AxisZValue);
143 colorbar->setBrush(gradient);
143 colorbar->setBrush(gradient);
144
144
145 //colorbar labels
145 for(int i=0;i<m_axis->tickCount();i++)
146 for(int i=0;i<m_axis->tickCount();i++)
146 {
147 {
147 qreal value = m_axis->max() - (i * (m_axis->max() - m_axis->min()) / (m_axis->tickCount() - 1));
148 qreal value = m_axis->max() - (i * (m_axis->max() - m_axis->min()) / (m_axis->tickCount() - 1));
148 QGraphicsTextItem *label = new QGraphicsTextItem(this);
149 QGraphicsTextItem *label = new QGraphicsTextItem(this);
149 label->setPlainText(QString::number(value));
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 m_gradientType(Rainbow),
20 m_gradientType(Rainbow),
21 m_colorbar(Q_NULLPTR),
21 m_colorbar(Q_NULLPTR),
22 m_isColorBarDrawn(false),
22 m_isColorBarDrawn(false),
23 m_currentplotArea(QRectF()),
23 m_currentplotArea(QRectF())
24 m_grid(Q_NULLPTR)
25 {
24 {
26 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
25 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
27 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
26 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
@@ -74,7 +73,10 void ColorMapChart::paint(QPainter *pain
74 {
73 {
75 m_currentplotArea = plotAreaRect;
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 addColorBar(plotAreaRect);
81 addColorBar(plotAreaRect);
80 }
82 }
@@ -94,7 +96,7 void ColorMapChart::paint(QPainter *pain
94 {
96 {
95 for(int j=0;j<imageHeight;j++)
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 double pix=((value-minZ)/rangeZ);
100 double pix=((value-minZ)/rangeZ);
99 int indexInColorTable = pix*(nbOfColors-1);
101 int indexInColorTable = pix*(nbOfColors-1);
100 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
102 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
@@ -73,7 +73,7 protected:
73 bool m_isColorBarDrawn;
73 bool m_isColorBarDrawn;
74 QColorBarAxis *m_colorbar;
74 QColorBarAxis *m_colorbar;
75 QRectF m_currentplotArea;
75 QRectF m_currentplotArea;
76 QVector<double> * m_grid;
76 QVector<double> m_grid;
77 };
77 };
78
78
79 //class PixmapMarker: public QGraphicsRectItem
79 //class PixmapMarker: public QGraphicsRectItem
@@ -120,10 +120,10 QColorMapSeries &QColorMapSeries::operat
120 from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n
120 from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n
121 When there are more points than pixels, \a strategy is applied to determine which to choose.
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 Q_D(QColorMapSeries);
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 //void QColorMapSeries::attachAxis(QAbstractAxis *axis)
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 double dx = (m_maxX - m_minX)/(double)width;
438 double dx = (m_maxX - m_minX)/(double)width;
441 double dy = (m_maxY - m_minY)/(double)height;
439 double dy = (m_maxY - m_minY)/(double)height;
442
440
@@ -446,7 +444,7 QVector<double> *QColorMapSeriesPrivate:
446 QVector<Point3D> cluster;
444 QVector<Point3D> cluster;
447 cluster.reserve(height*width/1000);
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 cluster.resize(0);
449 cluster.resize(0);
452 this->buildCluster(x,y,dx,dy,cluster);
450 this->buildCluster(x,y,dx,dy,cluster);
@@ -466,8 +464,6 cluster.reserve(height*width/1000);
466 y++;
464 y++;
467 }
465 }
468 }
466 }
469
470 return grid;
471 }
467 }
472
468
473 /*!
469 /*!
@@ -48,8 +48,8 public :
48 QColorMapSeries &operator << (const ColorMapDataPart &dataPart);
48 QColorMapSeries &operator << (const ColorMapDataPart &dataPart);
49 QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts);
49 QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts);
50
50
51 QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, Strategy strategy);
51 void getUniformGrid(int xpos, int ypos,int width, int height, QVector<double> &grid, Strategy strategy);
52 // QVector<double> *getUniformGrid(int width, int height, Strategy lambda);
52 // QVector<double> *getUniformGrid(int width, int height, QVector<double> &grid, Strategy lambda);
53
53
54 // virtual void attachAxis(QAbstractAxis *axis);
54 // virtual void attachAxis(QAbstractAxis *axis);
55
55
@@ -31,7 +31,7 public :
31 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
31 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
32 QAbstractAxis* createDefaultAxis(Qt::Orientation) const;
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 Q_SIGNALS:
36 Q_SIGNALS:
37 void updated();
37 void updated();
General Comments 0
You need to be logged in to leave comments. Login now