##// END OF EJS Templates
Some perfs improvments....
jeandet -
r2902:1f7564788f9d 5.7
parent child
Show More
@@ -1,299 +1,310
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22
22
23 #include <private/colormapchart_p.h>
23 #include <private/colormapchart_p.h>
24 #include <QtCharts/QColorMapSeries>
24 #include <QtCharts/QColorMapSeries>
25 #include <private/qcolormapseries_p.h>
25 #include <private/qcolormapseries_p.h>
26 #include <private/chartpresenter_p.h>
26 #include <private/chartpresenter_p.h>
27 #include <private/abstractdomain_p.h>
27 #include <private/abstractdomain_p.h>
28 #include <private/chartdataset_p.h>
28 #include <private/chartdataset_p.h>
29 #include <private/qabstractaxis_p.h>
29 #include <private/qabstractaxis_p.h>
30 #include <QtGui/QPainter>
30 #include <QtGui/QPainter>
31 #include <QColorBarAxis>
31 #include <QColorBarAxis>
32
32
33 #include <QRgb>
33 #include <QRgb>
34
34
35 #define nbOfColors 65000
35 #define nbOfColors 65000
36
36
37 QT_CHARTS_BEGIN_NAMESPACE
37 QT_CHARTS_BEGIN_NAMESPACE
38
38
39 ColorMapChart::ColorMapChart(QColorMapSeries *series, QGraphicsItem *item)
39 ColorMapChart::ColorMapChart(QColorMapSeries *series, QGraphicsItem *item)
40 : ChartItem(series->d_func(), item),
40 : ChartItem(series->d_func(), item),
41 m_series(series),
41 m_series(series),
42 m_dirty(true),
42 m_dirty(true),
43 m_gradientType(Rainbow),
43 m_gradientType(Rainbow),
44 m_colorbar(Q_NULLPTR),
44 m_colorbar(Q_NULLPTR),
45 m_isColorBarDrawn(false),
45 m_isColorBarDrawn(false),
46 m_currentClipRect(QRectF())
46 m_currentClipRect(QRectF())
47 {
47 {
48 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
48 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
49 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
49 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
50 // QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
50 // QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
51 // QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
51 // QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
52 // QObject::connect(series, SIGNAL(pointsRemoved(int, int)), this, SLOT(handlePointsRemoved(int, int)));
52 // QObject::connect(series, SIGNAL(pointsRemoved(int, int)), this, SLOT(handlePointsRemoved(int, int)));
53 // QObject::connect(this, SIGNAL(clicked(Point3D)), series, SIGNAL(clicked(Point3D)));
53 // QObject::connect(this, SIGNAL(clicked(Point3D)), series, SIGNAL(clicked(Point3D)));
54 // QObject::connect(this, SIGNAL(hovered(Point3D,bool)), series, SIGNAL(hovered(Point3D,bool)));
54 // QObject::connect(this, SIGNAL(hovered(Point3D,bool)), series, SIGNAL(hovered(Point3D,bool)));
55 // QObject::connect(this, SIGNAL(pressed(Point3D)), series, SIGNAL(pressed(Point3D)));
55 // QObject::connect(this, SIGNAL(pressed(Point3D)), series, SIGNAL(pressed(Point3D)));
56 // QObject::connect(this, SIGNAL(released(Point3D)), series, SIGNAL(released(Point3D)));
56 // QObject::connect(this, SIGNAL(released(Point3D)), series, SIGNAL(released(Point3D)));
57 // QObject::connect(this, SIGNAL(doubleClicked(Point3D)), series, SIGNAL(doubleClicked(Point3D)));
57 // QObject::connect(this, SIGNAL(doubleClicked(Point3D)), series, SIGNAL(doubleClicked(Point3D)));
58
58
59 connect(this,SIGNAL(gradientTypeChanged()), this, SLOT(populateColorTable()));
59 connect(this,SIGNAL(gradientTypeChanged()), this, SLOT(populateColorTable()));
60
60
61 m_colorTable = new QVector<QRgb>();
61 m_colorTable = new QVector<QRgb>();
62 m_colorTable->reserve(nbOfColors);
62 m_colorTable->reserve(nbOfColors);
63 populateColorTable();
63 populateColorTable();
64 }
64 }
65
65
66 ColorMapChart::~ColorMapChart()
66 ColorMapChart::~ColorMapChart()
67 {
67 {
68 delete m_colorTable;
68 delete m_colorTable;
69 delete m_colorbar;
69 delete m_colorbar;
70 }
70 }
71
71
72 void ColorMapChart::setDirty(bool dirty)
72 void ColorMapChart::setDirty(bool dirty)
73 {
73 {
74 m_dirty = dirty;
74 m_dirty = dirty;
75 }
75 }
76
76
77 QRectF ColorMapChart::boundingRect() const
77 QRectF ColorMapChart::boundingRect() const
78 {
78 {
79 return m_rect;
79 return m_rect;
80 }
80 }
81
81
82 void ColorMapChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
82 void ColorMapChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
83 {
83 {
84 Q_UNUSED(widget)
84 Q_UNUSED(widget)
85 Q_UNUSED(option)
85 Q_UNUSED(option)
86
86
87 painter->save();
87 painter->save();
88 //m_series->setUseOpenGL();
88 m_series->setUseOpenGL();
89
89
90 QRectF plotAreaRect = m_series->chart()->plotArea();
90 QRectF plotAreaRect = m_series->chart()->plotArea();
91 QRectF clipRect = mapColorMapToPlotArea();
91 QRectF clipRect = mapColorMapToPlotArea();
92 painter->setClipRect(clipRect);
92 painter->setClipRect(clipRect);
93
93
94 if(m_currentClipRect !=clipRect)
94 if(m_currentClipRect !=clipRect)
95 {
95 {
96 m_currentClipRect = clipRect;
96 m_currentClipRect = clipRect;
97 m_grid.reserve(clipRect.width()*clipRect.height());
97 m_grid.resize(clipRect.width()*clipRect.height()); //faster than reserve
98 m_grid.resize(clipRect.width()*clipRect.height());
99
98
100 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);
99 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);
101 addColorBar(plotAreaRect);
100 addColorBar(plotAreaRect);
102 }
101 }
103
102
104 QImage colorMapImage(clipRect.width(),clipRect.height(),QImage::Format_RGB32);
103 QImage colorMapImage(clipRect.width(),clipRect.height(),QImage::Format_RGB32);
105 //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.
104 //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.
106 colorMapImage.fill(QColor(Qt::white).rgb());
105 colorMapImage.fill(QColor(Qt::white).rgb());
107
106
108 fillColorMapImage(colorMapImage);
107 fillColorMapImage(colorMapImage);
109
108
110 painter->drawImage(clipRect,colorMapImage);
109 painter->drawImage(clipRect,colorMapImage);
111 painter->restore();
110 painter->restore();
112 }
111 }
113
112
114 void ColorMapChart::addColorBar(QRectF plotAreaRect)
113 void ColorMapChart::addColorBar(QRectF plotAreaRect)
115 {
114 {
116 double maxZ = m_series->maxZ();
115 double maxZ = m_series->maxZ();
117 double minZ = m_series->minZ();
116 double minZ = m_series->minZ();
118
117
119 if(m_isColorBarDrawn)
118 if(m_isColorBarDrawn)
120 m_series->chart()->removeAxis(m_colorbar);
119 m_series->chart()->removeAxis(m_colorbar);
121
120
122 m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this);
121 m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this);
123 m_series->chart()->addAxis(m_colorbar, Qt::AlignRight);
122 m_series->chart()->addAxis(m_colorbar, Qt::AlignRight);
124 m_isColorBarDrawn = true;
123 m_isColorBarDrawn = true;
125 }
124 }
126
125
127 QRectF ColorMapChart::mapColorMapToPlotArea()
126 QRectF ColorMapChart::mapColorMapToPlotArea()
128 {
127 {
129 QRectF plotAreaRect = m_series->chart()->plotArea();
128 QRectF plotAreaRect = m_series->chart()->plotArea();
130
129
131 double seriesMinX = m_series->minX();
130 double seriesMinX = m_series->minX();
132 double seriesMaxX = m_series->maxX();
131 double seriesMaxX = m_series->maxX();
133 double seriesMinY = m_series->minY();
132 double seriesMinY = m_series->minY();
134 double seriesMaxY = m_series->maxY();
133 double seriesMaxY = m_series->maxY();
135
134
136 double domainMinX = domain()->minX();
135 double domainMinX = domain()->minX();
137 double domainMaxX = domain()->maxX();
136 double domainMaxX = domain()->maxX();
138 double domainMinY = domain()->minY();
137 double domainMinY = domain()->minY();
139 double domainMaxY = domain()->maxY();
138 double domainMaxY = domain()->maxY();
140
139
141 double widthToPaint = (qMin(seriesMaxX, domainMaxX)-qMax(seriesMinX, domainMinX))*plotAreaRect.width()/(domainMaxX-domainMinX);
140 double widthToPaint = (qMin(seriesMaxX, domainMaxX)-qMax(seriesMinX, domainMinX))*plotAreaRect.width()/(domainMaxX-domainMinX);
142 double heightTopaint= (qMin(seriesMaxY, domainMaxY)-qMax(seriesMinY, domainMinY))*plotAreaRect.height()/(domainMaxY-domainMinY);
141 double heightTopaint= (qMin(seriesMaxY, domainMaxY)-qMax(seriesMinY, domainMinY))*plotAreaRect.height()/(domainMaxY-domainMinY);
143
142
144 QSizeF size = QSize(widthToPaint,heightTopaint);
143
145
144
146 double pointX = (qMax(seriesMinX,domainMinX)-domainMinX)*plotAreaRect.width()/(domainMaxX-domainMinX);
145 double pointX = (qMax(seriesMinX,domainMinX)-domainMinX)*plotAreaRect.width()/(domainMaxX-domainMinX);
147 double pointY = (domainMaxY-qMin(seriesMaxY,domainMaxY))*plotAreaRect.height()/(domainMaxY-domainMinY);
146 double pointY = (domainMaxY-qMin(seriesMaxY,domainMaxY))*plotAreaRect.height()/(domainMaxY-domainMinY);
148
147
148 if(Q_UNLIKELY(widthToPaint < 0))
149 widthToPaint = 0;
150 if(Q_UNLIKELY(heightTopaint < 0))
151 heightTopaint = 0;
152
153 QSizeF size = QSize(widthToPaint,heightTopaint);
154
155 if(Q_UNLIKELY(pointX < 0))
156 pointX = 0;
157 if(Q_UNLIKELY(pointY < 0))
158 pointY = 0;
159
149 return QRectF(QPointF(pointX,pointY) ,size);
160 return QRectF(QPointF(pointX,pointY) ,size);
150 }
161 }
151
162
152 void ColorMapChart::fillColorMapImage(QImage &colorMapImage)
163 void ColorMapChart::fillColorMapImage(QImage &colorMapImage)
153 {
164 {
154 double maxZ = m_series->maxZ();
165 double maxZ = m_series->maxZ();
155 double minZ = m_series->minZ();
166 double minZ = m_series->minZ();
156 double rangeZ = maxZ - minZ;
167 double rangeZ = maxZ - minZ;
157
168
158 int imageWidth = colorMapImage.width();
169 int imageWidth = colorMapImage.width();
159 int imageHeight = colorMapImage.height();
170 int imageHeight = colorMapImage.height();
160
171
161 for(int i=0;i<imageWidth;i++)
172 for(int i=0;i<imageWidth;i++)
162 {
173 {
163 for(int j=0;j<imageHeight;j++)
174 for(int j=0;j<imageHeight;j++)
164 {
175 {
165 double value = m_grid.at(i+j*(imageWidth));
176 double value = m_grid.at(i+j*(imageWidth));
166 double pix=((value-minZ)/rangeZ);
177 double pix=((value-minZ)/rangeZ);
167 int indexInColorTable = pix*(nbOfColors-1);
178 int indexInColorTable = pix*(nbOfColors-1);
168 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
179 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
169 }
180 }
170 }
181 }
171 }
182 }
172
183
173 /*!
184 /*!
174 Returns the predefined QLinearGradient corresponding to the \a gradientType passed as argument.
185 Returns the predefined QLinearGradient corresponding to the \a gradientType passed as argument.
175 */
186 */
176 QLinearGradient ColorMapChart::createColorMapGradient(GradientType gradientType)
187 QLinearGradient ColorMapChart::createColorMapGradient(GradientType gradientType)
177 {
188 {
178 QLinearGradient gradient(0,0,1,100);
189 QLinearGradient gradient(0,0,1,100);
179 switch(gradientType)
190 switch(gradientType)
180 {
191 {
181 case Rainbow :
192 case Rainbow :
182 gradient.setColorAt(1.0,Qt::darkRed);
193 gradient.setColorAt(1.0,Qt::darkRed);
183 gradient.setColorAt(0.8,Qt::red);
194 gradient.setColorAt(0.8,Qt::red);
184 gradient.setColorAt(0.6,Qt::yellow);
195 gradient.setColorAt(0.6,Qt::yellow);
185 gradient.setColorAt(0.4,Qt::green);
196 gradient.setColorAt(0.4,Qt::green);
186 gradient.setColorAt(0.2,Qt::cyan);
197 gradient.setColorAt(0.2,Qt::cyan);
187 gradient.setColorAt(0.0,Qt::blue);
198 gradient.setColorAt(0.0,Qt::blue);
188 break;
199 break;
189 case CyclingRainbow :
200 case CyclingRainbow :
190 gradient.setColorAt(1.0,Qt::red);
201 gradient.setColorAt(1.0,Qt::red);
191 gradient.setColorAt(0.8,Qt::yellow);
202 gradient.setColorAt(0.8,Qt::yellow);
192 gradient.setColorAt(0.6,Qt::green);
203 gradient.setColorAt(0.6,Qt::green);
193 gradient.setColorAt(0.4,Qt::cyan);
204 gradient.setColorAt(0.4,Qt::cyan);
194 gradient.setColorAt(0.2,Qt::blue);
205 gradient.setColorAt(0.2,Qt::blue);
195 gradient.setColorAt(0.0,Qt::magenta);
206 gradient.setColorAt(0.0,Qt::magenta);
196 break;
207 break;
197 case BlackAndWhite :
208 case BlackAndWhite :
198 gradient.setColorAt(1.0, Qt::black);
209 gradient.setColorAt(1.0, Qt::black);
199 gradient.setColorAt(0.0, Qt::white);
210 gradient.setColorAt(0.0, Qt::white);
200 break;
211 break;
201 case ReverseBlackAndWhite :
212 case ReverseBlackAndWhite :
202 gradient.setColorAt(1.0, Qt::white);
213 gradient.setColorAt(1.0, Qt::white);
203 gradient.setColorAt(0.0, Qt::black);
214 gradient.setColorAt(0.0, Qt::black);
204 break;
215 break;
205 default:
216 default:
206 break;
217 break;
207 }
218 }
208 return gradient;
219 return gradient;
209 }
220 }
210
221
211 /*!
222 /*!
212 Changes the type of gradient used to paint the ColorMap.
223 Changes the type of gradient used to paint the ColorMap.
213 */
224 */
214 void ColorMapChart::changeGradient(GradientType gradientType)
225 void ColorMapChart::changeGradient(GradientType gradientType)
215 {
226 {
216 if(m_gradientType == gradientType)
227 if(m_gradientType == gradientType)
217 return;
228 return;
218 else
229 else
219 m_gradientType = gradientType;
230 m_gradientType = gradientType;
220 emit gradientTypeChanged();
231 emit gradientTypeChanged();
221 }
232 }
222
233
223 /*!
234 /*!
224 Creates a color table corresponding to the gradient type currently selected.
235 Creates a color table corresponding to the gradient type currently selected.
225 */
236 */
226 void ColorMapChart::populateColorTable()
237 void ColorMapChart::populateColorTable()
227 {
238 {
228 QLinearGradient gradient = createColorMapGradient(m_gradientType);
239 QLinearGradient gradient = createColorMapGradient(m_gradientType);
229 QGradientStops colorStops = gradient.stops();
240 QGradientStops colorStops = gradient.stops();
230
241
231 for(int i=0;i<nbOfColors;i++)
242 for(int i=0;i<nbOfColors;i++)
232 {
243 {
233 double colorIndex = (double)i/nbOfColors;
244 double colorIndex = (double)i/nbOfColors;
234 for(int k =0;k<colorStops.size()-1;k++)
245 for(int k =0;k<colorStops.size()-1;k++)
235 {
246 {
236 QGradientStop lowerBound = colorStops.at(k);
247 QGradientStop lowerBound = colorStops.at(k);
237 QGradientStop upperBound = colorStops.at(k+1);
248 QGradientStop upperBound = colorStops.at(k+1);
238 if(colorIndex >= lowerBound.first && colorIndex < upperBound.first)
249 if(colorIndex >= lowerBound.first && colorIndex < upperBound.first)
239 {
250 {
240 double ratio = (colorIndex-lowerBound.first)/(upperBound.first - lowerBound.first);
251 double ratio = (colorIndex-lowerBound.first)/(upperBound.first - lowerBound.first);
241 int red = (int)((1-ratio)*lowerBound.second.red() + ratio*upperBound.second.red());
252 int red = (int)((1-ratio)*lowerBound.second.red() + ratio*upperBound.second.red());
242 int green = (int)((1-ratio)*lowerBound.second.green() + ratio*upperBound.second.green());
253 int green = (int)((1-ratio)*lowerBound.second.green() + ratio*upperBound.second.green());
243 int blue = (int)((1-ratio)*lowerBound.second.blue() + ratio*upperBound.second.blue());
254 int blue = (int)((1-ratio)*lowerBound.second.blue() + ratio*upperBound.second.blue());
244 m_colorTable->append(qRgb(red, green, blue));
255 m_colorTable->append(qRgb(red, green, blue));
245 break;
256 break;
246 }
257 }
247 else
258 else
248 {
259 {
249 if(k==colorStops.size()-2)
260 if(k==colorStops.size()-2)
250 {
261 {
251 m_colorTable->append(qRgb(colorStops.at(colorStops.size()-1).second.red(), colorStops.at(colorStops.size()-1).second.green(), colorStops.at(colorStops.size()-1).second.blue()));
262 m_colorTable->append(qRgb(colorStops.at(colorStops.size()-1).second.red(), colorStops.at(colorStops.size()-1).second.green(), colorStops.at(colorStops.size()-1).second.blue()));
252 }
263 }
253 }
264 }
254 }
265 }
255 }
266 }
256 }
267 }
257
268
258
269
259 //handlers
270 //handlers
260
271
261 void ColorMapChart::handlePointAdded(int index)
272 void ColorMapChart::handlePointAdded(int index)
262 {
273 {
263
274
264 }
275 }
265
276
266 void ColorMapChart::handlePointRemoved(int index)
277 void ColorMapChart::handlePointRemoved(int index)
267 {
278 {
268
279
269 }
280 }
270
281
271 void ColorMapChart::handlePointsRemoved(int index, int count)
282 void ColorMapChart::handlePointsRemoved(int index, int count)
272 {
283 {
273
284
274 }
285 }
275
286
276 void ColorMapChart::handlePointReplaced(int index)
287 void ColorMapChart::handlePointReplaced(int index)
277 {
288 {
278
289
279 }
290 }
280
291
281 void ColorMapChart::handlePointsReplaced()
292 void ColorMapChart::handlePointsReplaced()
282 {
293 {
283
294
284 }
295 }
285
296
286 void ColorMapChart::handleDomainUpdated()
297 void ColorMapChart::handleDomainUpdated()
287 {
298 {
288
299
289 }
300 }
290
301
291 bool ColorMapChart::isEmpty()
302 bool ColorMapChart::isEmpty()
292 {
303 {
293
304
294 }
305 }
295
306
296
307
297 #include "moc_colormapchart_p.cpp"
308 #include "moc_colormapchart_p.cpp"
298
309
299 QT_CHARTS_END_NAMESPACE
310 QT_CHARTS_END_NAMESPACE
@@ -1,154 +1,161
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22
22
23 #ifndef COLORMAPCHART_H
23 #ifndef COLORMAPCHART_H
24 #define COLORMAPCHART_H
24 #define COLORMAPCHART_H
25
25
26 #include "point3d.h"
26 #include "point3d.h"
27 #include <QtCharts/QChartGlobal>
27 #include <QtCharts/QChartGlobal>
28 #include <private/chartitem_p.h>
28 #include <private/chartitem_p.h>
29 #include <QtCharts/QValueAxis>
29 #include <QtCharts/QValueAxis>
30 #include <QtGui/QPen>
30 #include <QtGui/QPen>
31
31
32 //#include <QtCharts/QColorBarAxis> TODO : fix this
32 //#include <QtCharts/QColorBarAxis> TODO : fix this
33 #include "qcolorbaraxis.h"
33 #include "qcolorbaraxis.h"
34
34
35 QT_CHARTS_BEGIN_NAMESPACE
35 QT_CHARTS_BEGIN_NAMESPACE
36
36
37 class ChartPresenter;
37 class ChartPresenter;
38 class QColorMapSeries;
38 class QColorMapSeries;
39
39
40 class ColorMapChart : public ChartItem
40 class ColorMapChart : public ChartItem
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44
44
45 enum GradientType
45 enum GradientType
46 {
46 {
47 Rainbow,
47 Rainbow,
48 CyclingRainbow,
48 CyclingRainbow,
49 BlackAndWhite,
49 BlackAndWhite,
50 ReverseBlackAndWhite
50 ReverseBlackAndWhite
51 };
51 };
52
52
53 explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0);
53 explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0);
54 ~ColorMapChart();
54 ~ColorMapChart();
55
55
56 bool isDirty() const { return m_dirty; }
56 bool isDirty() const { return m_dirty; }
57 void setDirty(bool dirty);
57 void setDirty(bool dirty);
58
58
59 // from QGraphicsItem
59 // from QGraphicsItem
60 QRectF boundingRect() const;
60 QRectF boundingRect() const;
61 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
61 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
62
62
63 public Q_SLOTS:
63 public Q_SLOTS:
64 void handlePointAdded(int index);
64 void handlePointAdded(int index);
65 void handlePointRemoved(int index);
65 void handlePointRemoved(int index);
66 void handlePointsRemoved(int index, int count);
66 void handlePointsRemoved(int index, int count);
67 void handlePointReplaced(int index);
67 void handlePointReplaced(int index);
68 void handlePointsReplaced();
68 void handlePointsReplaced();
69 void handleDomainUpdated();
69 void handleDomainUpdated();
70
70
71 private slots :
71 private slots :
72 void populateColorTable();
72 void populateColorTable();
73
73
74 Q_SIGNALS:
74 Q_SIGNALS:
75 void clicked(const Point3D &point);
75 void clicked(const Point3D &point);
76 void hovered(const Point3D &point, bool state);
76 void hovered(const Point3D &point, bool state);
77 void pressed(const Point3D &point);
77 void pressed(const Point3D &point);
78 void released(const Point3D &point);
78 void released(const Point3D &point);
79 void doubleClicked(const Point3D &point);
79 void doubleClicked(const Point3D &point);
80 void gradientTypeChanged();
80 void gradientTypeChanged();
81
81
82 protected:
83 // void updateGeometry();
84 // void mousePressEvent(QGraphicsSceneMouseEvent *event);
85 // void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
86 // void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
87 // void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
88 // void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
89
82 private:
90 private:
83 inline bool isEmpty();
91 inline bool isEmpty();
84 void addColorBar(QRectF plotAreaRect);
92 void addColorBar(QRectF plotAreaRect);
85
93
86 QRectF mapColorMapToPlotArea();
94 QRectF mapColorMapToPlotArea();
87 void fillColorMapImage(QImage &colorMapImage);
95 void fillColorMapImage(QImage &colorMapImage);
88 QLinearGradient createColorMapGradient(GradientType gradientType);
96 QLinearGradient createColorMapGradient(GradientType gradientType);
89 void changeGradient(GradientType gradientType);
97 void changeGradient(GradientType gradientType);
90
98
91 protected:
92 QColorMapSeries *m_series;
99 QColorMapSeries *m_series;
93 QVector<Point3D> m_points;
100 QVector<Point3D> m_points;
94 QRectF m_rect;
101 QRectF m_rect;
95 bool m_dirty;
102 bool m_dirty;
96 QVector<QRgb> *m_colorTable;
103 QVector<QRgb> *m_colorTable;
97 GradientType m_gradientType;
104 GradientType m_gradientType;
98 bool m_isColorBarDrawn;
105 bool m_isColorBarDrawn;
99 QColorBarAxis *m_colorbar;
106 QColorBarAxis *m_colorbar;
100 QRectF m_currentClipRect;
107 QRectF m_currentClipRect;
101 QVector<double> m_grid;
108 QVector<double> m_grid;
102 };
109 };
103
110
104 //class PixmapMarker: public QGraphicsRectItem
111 //class PixmapMarker: public QGraphicsRectItem
105 //{
112 //{
106
113
107 //public:
114 //public:
108 // PixmapMarker(qreal x, qreal y, qreal w, qreal h, ColorMapChart *parent)
115 // PixmapMarker(qreal x, qreal y, qreal w, qreal h, ColorMapChart *parent)
109 // : QGraphicsRectItem(x, y, w, h, parent),
116 // : QGraphicsRectItem(x, y, w, h, parent),
110 // m_parent(parent)
117 // m_parent(parent)
111 // {
118 // {
112 // setAcceptHoverEvents(true);
119 // setAcceptHoverEvents(true);
113 // setFlag(QGraphicsItem::ItemIsSelectable);
120 // setFlag(QGraphicsItem::ItemIsSelectable);
114 // }
121 // }
115
122
116 //protected:
123 //protected:
117 // void mousePressEvent(QGraphicsSceneMouseEvent *event)
124 // void mousePressEvent(QGraphicsSceneMouseEvent *event)
118 // {
125 // {
119 // QGraphicsRectItem::mousePressEvent(event);
126 // QGraphicsRectItem::mousePressEvent(event);
120 // m_parent->markerPressed(this);
127 // m_parent->markerPressed(this);
121 // m_parent->setMousePressed();
128 // m_parent->setMousePressed();
122 // }
129 // }
123 // void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
130 // void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
124 // {
131 // {
125 // QGraphicsRectItem::hoverEnterEvent(event);
132 // QGraphicsRectItem::hoverEnterEvent(event);
126 // m_parent->markerHovered(this, true);
133 // m_parent->markerHovered(this, true);
127 // }
134 // }
128 // void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
135 // void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
129 // {
136 // {
130 // QGraphicsRectItem::hoverLeaveEvent(event);
137 // QGraphicsRectItem::hoverLeaveEvent(event);
131 // m_parent->markerHovered(this, false);
138 // m_parent->markerHovered(this, false);
132 // }
139 // }
133 // void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
140 // void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
134 // {
141 // {
135 // QGraphicsRectItem::mouseReleaseEvent(event);
142 // QGraphicsRectItem::mouseReleaseEvent(event);
136 // m_parent->markerReleased(this);
143 // m_parent->markerReleased(this);
137 // if (m_parent->mousePressed())
144 // if (m_parent->mousePressed())
138 // m_parent->markerSelected(this);
145 // m_parent->markerSelected(this);
139 // m_parent->setMousePressed(false);
146 // m_parent->setMousePressed(false);
140 // }
147 // }
141 // void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
148 // void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
142 // {
149 // {
143 // QGraphicsRectItem::mouseDoubleClickEvent(event);
150 // QGraphicsRectItem::mouseDoubleClickEvent(event);
144 // m_parent->markerDoubleClicked(this);
151 // m_parent->markerDoubleClicked(this);
145 // }
152 // }
146
153
147 //private:
154 //private:
148 // ColorMapChart *m_parent;
155 // ColorMapChart *m_parent;
149 //};
156 //};
150
157
151
158
152 QT_CHARTS_END_NAMESPACE
159 QT_CHARTS_END_NAMESPACE
153
160
154 #endif // COLORMAPCHART_H
161 #endif // COLORMAPCHART_H
General Comments 0
You need to be logged in to leave comments. Login now