qwt_plot_spectrocurve.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 <qpainter.h>
15 
17 {
18 public:
20  colorRange( 0.0, 1000.0 ),
21  penWidth(0.0),
23  {
25  }
26 
28  {
29  delete colorMap;
30  }
31 
34  QVector<QRgb> colorTable;
35  double penWidth;
37 };
38 
44  QwtPlotSeriesItem( title )
45 {
46  init();
47 }
48 
54  QwtPlotSeriesItem( QwtText( title ) )
55 {
56  init();
57 }
58 
61 {
62  delete d_data;
63 }
64 
69 {
72 
73  d_data = new PrivateData;
75 
76  setZ( 20.0 );
77 }
78 
81 {
83 }
84 
93 {
94  if ( on )
95  d_data->paintAttributes |= attribute;
96  else
97  d_data->paintAttributes &= ~attribute;
98 }
99 
105 {
106  return ( d_data->paintAttributes & attribute );
107 }
108 
113 void QwtPlotSpectroCurve::setSamples( const QVector<QwtPoint3D> &samples )
114 {
115  setData( new QwtPoint3DSeriesData( samples ) );
116 }
117 
130 {
131  setData( data );
132 }
133 
146 {
147  if ( colorMap != d_data->colorMap )
148  {
149  delete d_data->colorMap;
151  }
152 
153  legendChanged();
154  itemChanged();
155 }
156 
162 {
163  return d_data->colorMap;
164 }
165 
175 {
176  if ( interval != d_data->colorRange )
177  {
178  d_data->colorRange = interval;
179 
180  legendChanged();
181  itemChanged();
182  }
183 }
184 
190 {
191  return d_data->colorRange;
192 }
193 
201 {
202  if ( penWidth < 0.0 )
203  penWidth = 0.0;
204 
205  if ( d_data->penWidth != penWidth )
206  {
208 
209  legendChanged();
210  itemChanged();
211  }
212 }
213 
219 {
220  return d_data->penWidth;
221 }
222 
236 void QwtPlotSpectroCurve::drawSeries( QPainter *painter,
237  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
238  const QRectF &canvasRect, int from, int to ) const
239 {
240  if ( !painter || dataSize() <= 0 )
241  return;
242 
243  if ( to < 0 )
244  to = dataSize() - 1;
245 
246  if ( from < 0 )
247  from = 0;
248 
249  if ( from > to )
250  return;
251 
252  drawDots( painter, xMap, yMap, canvasRect, from, to );
253 }
254 
268 void QwtPlotSpectroCurve::drawDots( QPainter *painter,
269  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
270  const QRectF &canvasRect, int from, int to ) const
271 {
272  if ( !d_data->colorRange.isValid() )
273  return;
274 
275  const bool doAlign = QwtPainter::roundingAlignment( painter );
276 
278  if ( format == QwtColorMap::Indexed )
280 
281  const QwtSeriesData<QwtPoint3D> *series = data();
282 
283  for ( int i = from; i <= to; i++ )
284  {
285  const QwtPoint3D sample = series->sample( i );
286 
287  double xi = xMap.transform( sample.x() );
288  double yi = yMap.transform( sample.y() );
289  if ( doAlign )
290  {
291  xi = qRound( xi );
292  yi = qRound( yi );
293  }
294 
296  {
297  if ( !canvasRect.contains( xi, yi ) )
298  continue;
299  }
300 
301  if ( format == QwtColorMap::RGB )
302  {
303  const QRgb rgb = d_data->colorMap->rgb(
304  d_data->colorRange, sample.z() );
305 
306  painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) );
307  }
308  else
309  {
310  const unsigned char index = d_data->colorMap->colorIndex(
311  256, d_data->colorRange, sample.z() );
312 
313  painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ),
314  d_data->penWidth ) );
315  }
316 
317  QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
318  }
319 
320  d_data->colorTable.clear();
321 }
virtual void legendChanged()
virtual size_t dataSize() const
QwtPlotSpectroCurve(const QString &title=QString())
QwtInterval & colorRange() const
virtual QVector< QRgb > colorTable256() const
virtual int rtti() const
A class representing an interval.
Definition: qwt_interval.h:26
For QwtPlotSpectroCurve.
Definition: qwt_plot_item.h:94
double y() const
Definition: qwt_point_3d.h:122
void setData(QwtSeriesData< QwtPoint3D > *series)
Interface for iterating over an array of 3D points.
Clip points outside the canvas rectangle.
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void setColorRange(const QwtInterval &)
QwtSeriesData< QwtPoint3D > * data()
PaintAttribute
Paint attributes.
void setSamples(const QVector< QwtPoint3D > &)
The item is represented on the legend.
QwtPlotSpectroCurve::PaintAttributes paintAttributes
void init()
Initialize data members.
double z() const
Definition: qwt_point_3d.h:128
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:24
bool isValid() const
Definition: qwt_interval.h:211
A class representing a text.
Definition: qwt_text.h:51
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
void setZ(double z)
Set the z value.
QwtColorMap is used to map values into colors.
Definition: qwt_color_map.h:33
bool testPaintAttribute(PaintAttribute) const
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
double x() const
Definition: qwt_point_3d.h:116
QwtLinearColorMap builds a color map from color stops.
Definition: qwt_color_map.h:95
A scale map.
Definition: qwt_scale_map.h:30
QwtPoint3D sample(int index) const
The map is intended to map into RGB values.
Definition: qwt_color_map.h:44
virtual void itemChanged()
void setColorMap(QwtColorMap *)
const QwtColorMap * colorMap() const
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
virtual T sample(size_t i) const =0
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Base class for plot items representing a series of samples.
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
Curve that displays 3D points as dots, where the z coordinate is mapped to a color.
virtual ~QwtPlotSpectroCurve()
Destructor.
int i
Format format() const
void setPaintAttribute(PaintAttribute, bool on=true)
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
static bool roundingAlignment()
Definition: qwt_painter.h:176
const QwtText & title() const
void setPenWidth(double width)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17