Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_plot_spectrocurve.cpp
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#include "qwt_plot_spectrocurve.h"
11#include "qwt_color_map.h"
12#include "qwt_scale_map.h"
13#include "qwt_painter.h"
14#include "qwt_text.h"
15
16#include <qpainter.h>
17
18class QwtPlotSpectroCurve::PrivateData
19{
20 public:
21 PrivateData()
22 : colorRange( 0.0, 1000.0 )
23 , penWidth( 0.0 )
24 , paintAttributes( QwtPlotSpectroCurve::ClipPoints )
25 {
26 colorMap = new QwtLinearColorMap();
27 }
28
29 ~PrivateData()
30 {
31 delete colorMap;
32 }
33
34 QwtColorMap* colorMap;
35 QwtInterval colorRange;
36 QVector< QRgb > colorTable;
37 double penWidth;
39};
40
46 : QwtPlotSeriesItem( title )
47{
48 init();
49}
50
56 : QwtPlotSeriesItem( QwtText( title ) )
57{
58 init();
59}
60
66
70void QwtPlotSpectroCurve::init()
71{
74
75 m_data = new PrivateData;
77
78 setZ( 20.0 );
79}
80
86
95{
96 if ( on )
97 m_data->paintAttributes |= attribute;
98 else
99 m_data->paintAttributes &= ~attribute;
100}
101
107{
108 return ( m_data->paintAttributes & attribute );
109}
110
116{
117 setData( new QwtPoint3DSeriesData( samples ) );
118}
119
135
148{
149 if ( colorMap != m_data->colorMap )
150 {
151 delete m_data->colorMap;
152 m_data->colorMap = colorMap;
153 }
154
156 itemChanged();
157}
158
164{
165 return m_data->colorMap;
166}
167
177{
178 if ( interval != m_data->colorRange )
179 {
180 m_data->colorRange = interval;
181
183 itemChanged();
184 }
185}
186
192{
193 return m_data->colorRange;
194}
195
203{
204 if ( penWidth < 0.0 )
205 penWidth = 0.0;
206
207 if ( m_data->penWidth != penWidth )
208 {
209 m_data->penWidth = penWidth;
210
212 itemChanged();
213 }
214}
215
221{
222 return m_data->penWidth;
223}
224
238void QwtPlotSpectroCurve::drawSeries( QPainter* painter,
239 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
240 const QRectF& canvasRect, int from, int to ) const
241{
242 if ( !painter || dataSize() <= 0 )
243 return;
244
245 if ( to < 0 )
246 to = dataSize() - 1;
247
248 if ( from < 0 )
249 from = 0;
250
251 if ( from > to )
252 return;
253
254 drawDots( painter, xMap, yMap, canvasRect, from, to );
255}
256
270void QwtPlotSpectroCurve::drawDots( QPainter* painter,
271 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
272 const QRectF& canvasRect, int from, int to ) const
273{
274 if ( !m_data->colorRange.isValid() )
275 return;
276
277 const bool doAlign = QwtPainter::roundingAlignment( painter );
278
279 const QwtColorMap::Format format = m_data->colorMap->format();
280 if ( format == QwtColorMap::Indexed )
281 m_data->colorTable = m_data->colorMap->colorTable256();
282
283 const QwtSeriesData< QwtPoint3D >* series = data();
284
285 for ( int i = from; i <= to; i++ )
286 {
287 const QwtPoint3D sample = series->sample( i );
288
289 double xi = xMap.transform( sample.x() );
290 double yi = yMap.transform( sample.y() );
291 if ( doAlign )
292 {
293 xi = qRound( xi );
294 yi = qRound( yi );
295 }
296
297 if ( m_data->paintAttributes & QwtPlotSpectroCurve::ClipPoints )
298 {
299 if ( !canvasRect.contains( xi, yi ) )
300 continue;
301 }
302
303 if ( format == QwtColorMap::RGB )
304 {
305 const QRgb rgb = m_data->colorMap->rgb(
306 m_data->colorRange, sample.z() );
307
308 painter->setPen( QPen( QColor::fromRgba( rgb ), m_data->penWidth ) );
309 }
310 else
311 {
312 const unsigned char index = m_data->colorMap->colorIndex(
313 256, m_data->colorRange, sample.z() );
314
315 painter->setPen( QPen( QColor::fromRgba( m_data->colorTable[index] ),
316 m_data->penWidth ) );
317 }
318
319 QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
320 }
321
322 m_data->colorTable.clear();
323}
Template class for data, that is organized as QVector.
QwtColorMap is used to map values into colors.
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
@ RGB
The map is intended to map into RGB values.
virtual QVector< QRgb > colorTable256() const
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
A class representing an interval.
bool isValid() const
QwtLinearColorMap builds a color map from color stops.
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
static bool roundingAlignment()
virtual void legendChanged()
void setZ(double z)
Set the z value.
void setItemAttribute(ItemAttribute, bool on=true)
@ Rtti_PlotSpectroCurve
For QwtPlotSpectroCurve.
virtual void itemChanged()
@ Legend
The item is represented on the legend.
Base class for plot items representing a series of samples.
Curve that displays 3D points as dots, where the z coordinate is mapped to a color.
void setColorRange(const QwtInterval &)
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const override
const QwtColorMap * colorMap() const
void setPaintAttribute(PaintAttribute, bool on=true)
void setSamples(const QVector< QwtPoint3D > &)
void setColorMap(QwtColorMap *)
virtual ~QwtPlotSpectroCurve()
Destructor.
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
QwtInterval & colorRange() const
QwtPlotSpectroCurve(const QString &title=QString())
virtual int rtti() const override
bool testPaintAttribute(PaintAttribute) const
PaintAttribute
Paint attributes.
@ ClipPoints
Clip points outside the canvas rectangle.
QFlags< PaintAttribute > PaintAttributes
QwtPoint3D class defines a 3D point in double coordinates.
double z() const
double y() const
double x() const
A scale map.
double transform(double s) const
virtual T sample(size_t i) const =0
QwtPoint3D sample(int index) const
virtual size_t dataSize() const override
QwtSeriesData< QwtPoint3D > * data()
void setData(QwtSeriesData< QwtPoint3D > *series)
A class representing a text.
Definition qwt_text.h:52