##// END OF EJS Templates
functionnal colorbar
winter -
r4:6986421aea60 default draft
parent child
Show More
@@ -23,6 +23,7 ChartColorBarAxisY::ChartColorBarAxisY(Q
23 QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
23 QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
24
24
25 createColorBar();
25 createColorBar();
26
26 }
27 }
27
28
28 ChartColorBarAxisY::~ChartColorBarAxisY()
29 ChartColorBarAxisY::~ChartColorBarAxisY()
@@ -124,25 +125,32 QSizeF ChartColorBarAxisY::sizeHint(Qt::
124
125
125 void ChartColorBarAxisY::createColorBar()
126 void ChartColorBarAxisY::createColorBar()
126 {
127 {
127 //m_position.setX(80+m_position.x());// TODO : remove this when you know how to move labels
128 m_axis->setLabelsColor(QColor(0,0,255,0)); //make automatic labels disappear without changing layout (as it would be the case with setlabelVisible(false))
128
129
129 //gradient
130 //gradient
130 QGradientStops stops = m_gradient.stops();
131 QGradientStops stops = m_gradient.stops();
131 QLinearGradient gradient(0,0,1,m_height);
132 QLinearGradient gradient(0,m_position.y(),1,m_height);
132 foreach(QGradientStop stop, stops)
133 foreach(QGradientStop stop, stops)
133 {
134 {
134 gradient.setColorAt(1-stop.first,stop.second);
135 gradient.setColorAt(1-stop.first,stop.second);
135 }
136 }
136
137
137 //colorbar
138 //colorbar
138 QRectF rect(m_position.x(),m_position.y(),m_height/20,m_height);
139 QRectF rect(m_position.x()+10,m_position.y(),m_height/20,m_height); //remove 10 if needed
139
140
140 QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this);
141 QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this);
141 colorbar->setZValue(ChartPresenter::AxisZValue);
142 colorbar->setZValue(ChartPresenter::AxisZValue);
142 colorbar->setBrush(gradient);
143 colorbar->setBrush(gradient);
143 setGraphicsItem(colorbar);
144
145 for(int i=0;i<m_axis->tickCount();i++)
146 {
147 qreal value = m_axis->max() - (i * (m_axis->max() - m_axis->min()) / (m_axis->tickCount() - 1));
148 QGraphicsTextItem *label = new QGraphicsTextItem(this);
149 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 }
144 }
152 }
145
153
146 #include "moc_chartcolorbaraxisy_p.cpp"
154 #include "moc_chartcolorbaraxisy_p.cpp"
147
155
148 QT_CHARTS_END_NAMESPACE
156 QT_CHARTS_END_NAMESPACE
@@ -18,7 +18,10 ColorMapChart::ColorMapChart(QColorMapSe
18 m_series(series),
18 m_series(series),
19 m_dirty(true),
19 m_dirty(true),
20 m_gradientType(Rainbow),
20 m_gradientType(Rainbow),
21 m_colorbar(false)
21 m_colorbar(Q_NULLPTR),
22 m_isColorBarDrawn(false),
23 m_currentplotArea(QRectF()),
24 m_grid(Q_NULLPTR)
22 {
25 {
23 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
26 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
24 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
27 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
@@ -38,6 +41,12 ColorMapChart::ColorMapChart(QColorMapSe
38 populateColorTable();
41 populateColorTable();
39 }
42 }
40
43
44 ColorMapChart::~ColorMapChart()
45 {
46 delete m_colorTable;
47 delete m_colorbar;
48 }
49
41 void ColorMapChart::setDirty(bool dirty)
50 void ColorMapChart::setDirty(bool dirty)
42 {
51 {
43 m_dirty = dirty;
52 m_dirty = dirty;
@@ -61,18 +70,19 void ColorMapChart::paint(QPainter *pain
61 painter->setClipRect(clipRect);
70 painter->setClipRect(clipRect);
62
71
63 QRectF plotAreaRect = m_series->chart()->plotArea();
72 QRectF plotAreaRect = m_series->chart()->plotArea();
73 if(m_currentplotArea !=plotAreaRect)
74 {
75 m_currentplotArea = plotAreaRect;
76
77 m_grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel);
78
79 addColorBar(plotAreaRect);
80 }
81
64 QImage colorMapImage(plotAreaRect.width(),plotAreaRect.height(),QImage::Format_RGB32);
82 QImage colorMapImage(plotAreaRect.width(),plotAreaRect.height(),QImage::Format_RGB32);
65 //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.
83 //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.
66 colorMapImage.fill(QColor(Qt::white).rgb());
84 colorMapImage.fill(QColor(Qt::white).rgb());
67
85
68 QElapsedTimer timer;
69 timer.start();
70
71 QVector<double> * grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel);
72
73 int msec = timer.elapsed();
74 int msec2 = 0+msec;
75
76 double maxZ = m_series->maxZ();
86 double maxZ = m_series->maxZ();
77 double minZ = m_series->minZ();
87 double minZ = m_series->minZ();
78 double rangeZ = maxZ - minZ;
88 double rangeZ = maxZ - minZ;
@@ -84,22 +94,18 void ColorMapChart::paint(QPainter *pain
84 {
94 {
85 for(int j=0;j<imageHeight;j++)
95 for(int j=0;j<imageHeight;j++)
86 {
96 {
87 double value = grid->at(i+j*(imageWidth));
97 double value = m_grid->at(i+j*(imageWidth));
88 double pix=((value-minZ)/rangeZ);
98 double pix=((value-minZ)/rangeZ);
89 int indexInColorTable = pix*(nbOfColors-1);
99 int indexInColorTable = pix*(nbOfColors-1);
90 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
100 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
91 }
101 }
92 }
102 }
93
103
94 addColorBar(plotAreaRect);
95
96
97 painter->drawImage(clipRect,colorMapImage);
104 painter->drawImage(clipRect,colorMapImage);
98 update();//Qt docs: Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion
105 //This line was causing re-painting loop
106 //update();//Qt docs: Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion
99
107
100 painter->restore();
108 painter->restore();
101
102
103 }
109 }
104
110
105 void ColorMapChart::addColorBar(QRectF plotAreaRect)
111 void ColorMapChart::addColorBar(QRectF plotAreaRect)
@@ -29,7 +29,7 public:
29 };
29 };
30
30
31 explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0);
31 explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0);
32 ~ColorMapChart() {}
32 ~ColorMapChart();
33
33
34 bool isDirty() const { return m_dirty; }
34 bool isDirty() const { return m_dirty; }
35 void setDirty(bool dirty);
35 void setDirty(bool dirty);
@@ -72,6 +72,8 protected:
72 GradientType m_gradientType;
72 GradientType m_gradientType;
73 bool m_isColorBarDrawn;
73 bool m_isColorBarDrawn;
74 QColorBarAxis *m_colorbar;
74 QColorBarAxis *m_colorbar;
75 QRectF m_currentplotArea;
76 QVector<double> * m_grid;
75 };
77 };
76
78
77 //class PixmapMarker: public QGraphicsRectItem
79 //class PixmapMarker: public QGraphicsRectItem
General Comments 0
You need to be logged in to leave comments. Login now