qwt_plot_spectrocurve.cpp
Go to the documentation of this file.
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 
19 {
20  public:
21  PrivateData()
22  : colorRange( 0.0, 1000.0 )
23  , penWidth( 0.0 )
25  {
27  }
28 
29  ~PrivateData()
30  {
31  delete colorMap;
32  }
33 
37  double penWidth;
38  QwtPlotSpectroCurve::PaintAttributes paintAttributes;
39 };
40 
46  : QwtPlotSeriesItem( title )
47 {
48  init();
49 }
50 
56  : QwtPlotSeriesItem( QwtText( title ) )
57 {
58  init();
59 }
60 
63 {
64  delete m_data;
65 }
66 
71 {
74 
75  m_data = new PrivateData;
77 
78  setZ( 20.0 );
79 }
80 
83 {
85 }
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 
132 {
133  setData( data );
134 }
135 
148 {
149  if ( colorMap != m_data->colorMap )
150  {
151  delete m_data->colorMap;
153  }
154 
155  legendChanged();
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 
182  legendChanged();
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  {
210 
211  legendChanged();
212  itemChanged();
213  }
214 }
215 
221 {
222  return m_data->penWidth;
223 }
224 
238 void 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 
270 void 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 
280  if ( format == QwtColorMap::Indexed )
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 
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 }
QwtPlotSpectroCurve::setPenWidth
void setPenWidth(double)
Definition: qwt_plot_spectrocurve.cpp:202
QwtInterval::isValid
bool isValid() const
Definition: qwt_interval.h:210
QwtPlotSpectroCurve::PrivateData::colorMap
QwtColorMap * colorMap
Definition: qwt_plot_spectrocurve.cpp:41
QwtColorMap::Format
Format
Definition: qwt_color_map.h:45
QwtSeriesStore< QwtPoint3D >::sample
QwtPoint3D sample(int index) const
Definition: qwt_series_store.h:158
QwtLinearColorMap
QwtLinearColorMap builds a color map from color stops.
Definition: qwt_color_map.h:98
QwtPlotItem::legendChanged
virtual void legendChanged()
Definition: qwt_plot_item.cpp:491
QwtPlotSeriesItem
Base class for plot items representing a series of samples.
Definition: qwt_plot_seriesitem.h:24
QwtColorMap::colorTable256
virtual QVector< QRgb > colorTable256() const
Definition: qwt_color_map.cpp:304
QwtPlotSpectroCurve::setSamples
void setSamples(const QVector< QwtPoint3D > &)
Definition: qwt_plot_spectrocurve.cpp:115
QVector< QRgb >
rgb
Definition: color.h:192
QwtPlotSpectroCurve::setPaintAttribute
void setPaintAttribute(PaintAttribute, bool on=true)
Definition: qwt_plot_spectrocurve.cpp:94
QwtPlotSpectroCurve::PrivateData::PrivateData
PrivateData()
Definition: qwt_plot_spectrocurve.cpp:28
QwtColorMap::Indexed
@ Indexed
Definition: qwt_color_map.h:60
QwtSeriesStore< QwtPoint3D >::setData
void setData(QwtSeriesData< QwtPoint3D > *series)
Definition: qwt_series_store.h:164
QwtPlotSpectroCurve::~QwtPlotSpectroCurve
virtual ~QwtPlotSpectroCurve()
Destructor.
Definition: qwt_plot_spectrocurve.cpp:62
QwtPlotItem::Legend
@ Legend
The item is represented on the legend.
Definition: qwt_plot_item.h:150
QwtPainter::roundingAlignment
static bool roundingAlignment()
Definition: qwt_painter.h:183
QwtPlotSpectroCurve::QwtPlotSpectroCurve
QwtPlotSpectroCurve(const QString &title=QString())
Definition: qwt_plot_spectrocurve.cpp:55
QwtPlotSpectroCurve::PrivateData::~PrivateData
~PrivateData()
Definition: qwt_plot_spectrocurve.cpp:36
QwtScaleRendererReal::penWidth
qreal penWidth(const QPainter *painter, const QwtScaleDraw *scaleDraw)
Definition: qwt_scale_draw.cpp:28
QwtPoint3D::y
double y() const
Definition: qwt_point_3d.h:109
QwtColorMap::colorIndex
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
Definition: qwt_color_map.cpp:278
QwtPlotSpectroCurve::init
void init()
Initialize data members.
Definition: qwt_plot_spectrocurve.cpp:70
QwtColorMap::RGB
@ RGB
The map is intended to map into RGB values.
Definition: qwt_color_map.h:48
QwtPainter::drawPoint
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
Definition: qwt_painter.cpp:691
QwtPlotItem::AutoScale
@ AutoScale
Definition: qwt_plot_item.h:157
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:22
QwtPlotSpectroCurve::PaintAttribute
PaintAttribute
Paint attributes.
Definition: qwt_plot_spectrocurve.h:28
QwtPlotSpectroCurve::drawDots
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Definition: qwt_plot_spectrocurve.cpp:270
qwt_scale_map.h
QwtText
A class representing a text.
Definition: qwt_text.h:51
QwtPlotSpectroCurve::colorRange
QwtInterval & colorRange() const
Definition: qwt_plot_spectrocurve.cpp:191
QwtPlotItem::setZ
void setZ(double z)
Set the z value.
Definition: qwt_plot_item.cpp:165
QwtPlotSpectroCurve::ClipPoints
@ ClipPoints
Clip points outside the canvas rectangle.
Definition: qwt_plot_spectrocurve.h:31
QwtSeriesData< QwtPoint3D >
QwtPlotSpectroCurve::PrivateData::penWidth
double penWidth
Definition: qwt_plot_spectrocurve.cpp:44
qwt_color_map.h
QwtPlotSpectroCurve::setColorMap
void setColorMap(QwtColorMap *)
Definition: qwt_plot_spectrocurve.cpp:147
QwtPlotItem::Rtti_PlotSpectroCurve
@ Rtti_PlotSpectroCurve
For QwtPlotSpectroCurve.
Definition: qwt_plot_item.h:96
QwtPoint3D::x
double x() const
Definition: qwt_point_3d.h:103
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtPoint3D::z
double z() const
Definition: qwt_point_3d.h:115
QwtSeriesStore< QwtPoint3D >::data
QwtSeriesData< QwtPoint3D > * data()
Definition: qwt_series_store.h:146
QwtScaleMap::transform
double transform(double s) const
Definition: qwt_scale_map.h:137
QwtPlotItem::itemChanged
virtual void itemChanged()
Definition: qwt_plot_item.cpp:481
QwtPlotSpectroCurve::setColorRange
void setColorRange(const QwtInterval &)
Definition: qwt_plot_spectrocurve.cpp:176
QwtColorMap::format
Format format() const
Definition: qwt_color_map.h:257
QwtSeriesStore< QwtPoint3D >::dataSize
virtual size_t dataSize() const QWT_OVERRIDE
Definition: qwt_series_store.h:175
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
QwtPlotSpectroCurve::rtti
virtual int rtti() const QWT_OVERRIDE
Definition: qwt_plot_spectrocurve.cpp:82
qwt_painter.h
QwtColorMap::rgb
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
QwtPlotItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition: qwt_plot_item.cpp:228
QwtPlotSpectroCurve::m_data
PrivateData * m_data
Definition: qwt_plot_spectrocurve.h:71
QwtPlotSpectroCurve::colorMap
const QwtColorMap * colorMap() const
Definition: qwt_plot_spectrocurve.cpp:163
QwtPlotSpectroCurve::PrivateData::paintAttributes
QwtPlotSpectroCurve::PaintAttributes paintAttributes
Definition: qwt_plot_spectrocurve.cpp:45
QwtPlotSpectroCurve::PrivateData::colorTable
QVector< QRgb > colorTable
Definition: qwt_plot_spectrocurve.cpp:43
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
QwtPoint3DSeriesData
QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:217
qwt_plot_spectrocurve.h
QwtPlotSpectroCurve::penWidth
double penWidth() const
Definition: qwt_plot_spectrocurve.cpp:220
QwtColorMap
QwtColorMap is used to map values into colors.
Definition: qwt_color_map.h:37
QwtPlotSpectroCurve::PrivateData::colorRange
QwtInterval colorRange
Definition: qwt_plot_spectrocurve.cpp:42
QwtPlotSpectroCurve::drawSeries
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const QWT_OVERRIDE
Definition: qwt_plot_spectrocurve.cpp:238
qwt_text.h
QwtPoint3D
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:22
QwtPlotSpectroCurve::PrivateData
Definition: qwt_plot_spectrocurve.cpp:18
QwtPlotSpectroCurve::testPaintAttribute
bool testPaintAttribute(PaintAttribute) const
Definition: qwt_plot_spectrocurve.cpp:106


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46