qwt_plot_item.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_item.h"
11 #include "qwt_text.h"
12 #include "qwt_plot.h"
13 #include "qwt_legend_data.h"
14 #include "qwt_scale_map.h"
15 #include "qwt_graphic.h"
16 
17 #include <qpainter.h>
18 
20 {
21  public:
22  PrivateData()
23  : plot( NULL )
24  , isVisible( true )
25  , renderThreadCount( 1 )
26  , z( 0.0 )
29  , legendIconSize( 8, 8 )
30  {
31  }
32 
33  mutable QwtPlot* plot;
34 
35  bool isVisible;
36 
37  QwtPlotItem::ItemAttributes attributes;
38  QwtPlotItem::ItemInterests interests;
39 
40  QwtPlotItem::RenderHints renderHints;
41  uint renderThreadCount;
42 
43  double z;
44 
47 
49  QSize legendIconSize;
50 };
51 
56 {
57  m_data = new PrivateData;
58 }
59 
64 QwtPlotItem::QwtPlotItem( const QString& title )
65 {
66  m_data = new PrivateData;
67  m_data->title = title;
68 }
69 
75 {
76  m_data = new PrivateData;
77  m_data->title = title;
78 }
79 
82 {
83  attach( NULL );
84  delete m_data;
85 }
86 
99 {
100  if ( plot == m_data->plot )
101  return;
102 
103  if ( m_data->plot )
104  m_data->plot->attachItem( this, false );
105 
106  m_data->plot = plot;
107 
108  if ( m_data->plot )
109  m_data->plot->attachItem( this, true );
110 }
111 
120 {
121  attach( NULL );
122 }
123 
136 int QwtPlotItem::rtti() const
137 {
138  return Rtti_PlotItem;
139 }
140 
143 {
144  return m_data->plot;
145 }
146 
152 double QwtPlotItem::z() const
153 {
154  return m_data->z;
155 }
156 
165 void QwtPlotItem::setZ( double z )
166 {
167  if ( m_data->z != z )
168  {
169  if ( m_data->plot ) // update the z order
170  m_data->plot->attachItem( this, false );
171 
172  m_data->z = z;
173 
174  if ( m_data->plot )
175  m_data->plot->attachItem( this, true );
176 
177  itemChanged();
178  }
179 }
180 
187 void QwtPlotItem::setTitle( const QString& title )
188 {
189  setTitle( QwtText( title ) );
190 }
191 
198 void QwtPlotItem::setTitle( const QwtText& title )
199 {
200  if ( m_data->title != title )
201  {
202  m_data->title = title;
203 
204  legendChanged();
205 #if 0
206  itemChanged();
207 #endif
208  }
209 }
210 
216 {
217  return m_data->title;
218 }
219 
229 {
230  if ( m_data->attributes.testFlag( attribute ) != on )
231  {
232  if ( on )
233  m_data->attributes |= attribute;
234  else
235  m_data->attributes &= ~attribute;
236 
237  if ( attribute == QwtPlotItem::Legend )
238  {
239  if ( on )
240  {
241  legendChanged();
242  }
243  else
244  {
245  /*
246  In the special case of taking an item from
247  the legend we can't use legendChanged() as
248  it depends on QwtPlotItem::Legend being enabled
249  */
250  if ( m_data->plot )
251  m_data->plot->updateLegend( this );
252  }
253  }
254 
255  itemChanged();
256  }
257 }
258 
267 {
268  return m_data->attributes.testFlag( attribute );
269 }
270 
280 {
281  if ( m_data->interests.testFlag( interest ) != on )
282  {
283  if ( on )
284  m_data->interests |= interest;
285  else
286  m_data->interests &= ~interest;
287 
288  itemChanged();
289  }
290 }
291 
300 {
301  return m_data->interests.testFlag( interest );
302 }
303 
313 {
314  if ( m_data->renderHints.testFlag( hint ) != on )
315  {
316  if ( on )
317  m_data->renderHints |= hint;
318  else
319  m_data->renderHints &= ~hint;
320 
321  itemChanged();
322  }
323 }
324 
333 {
334  return m_data->renderHints.testFlag( hint );
335 }
336 
350 void QwtPlotItem::setRenderThreadCount( uint numThreads )
351 {
352  m_data->renderThreadCount = numThreads;
353 }
354 
361 {
362  return m_data->renderThreadCount;
363 }
364 
374 {
375  if ( m_data->legendIconSize != size )
376  {
378  legendChanged();
379  }
380 }
381 
387 {
388  return m_data->legendIconSize;
389 }
390 
403  int index, const QSizeF& size ) const
404 {
405  Q_UNUSED( index )
406  Q_UNUSED( size )
407 
408  return QwtGraphic();
409 }
410 
423  const QBrush& brush, const QSizeF& size ) const
424 {
425  QwtGraphic icon;
426  if ( !size.isEmpty() )
427  {
428  icon.setDefaultSize( size );
429 
430  QRectF r( 0, 0, size.width(), size.height() );
431 
432  QPainter painter( &icon );
433  painter.fillRect( r, brush );
434  }
435 
436  return icon;
437 }
438 
441 {
442  setVisible( true );
443 }
444 
447 {
448  setVisible( false );
449 }
450 
457 void QwtPlotItem::setVisible( bool on )
458 {
459  if ( on != m_data->isVisible )
460  {
461  m_data->isVisible = on;
462  itemChanged();
463  }
464 }
465 
471 {
472  return m_data->isVisible;
473 }
474 
482 {
483  if ( m_data->plot )
484  m_data->plot->autoRefresh();
485 }
486 
492 {
494  m_data->plot->updateLegend( this );
495 }
496 
507 void QwtPlotItem::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId )
508 {
509  if ( QwtAxis::isXAxis( xAxisId ) )
510  m_data->xAxisId = xAxisId;
511 
512  if ( QwtAxis::isYAxis( yAxisId ) )
513  m_data->yAxisId = yAxisId;
514 
515  itemChanged();
516 }
517 
527 {
528  if ( QwtAxis::isXAxis( axisId ) )
529  {
530  m_data->xAxisId = axisId;
531  itemChanged();
532  }
533 }
534 
544 {
545  if ( QwtAxis::isYAxis( axisId ) )
546  {
547  m_data->yAxisId = axisId;
548  itemChanged();
549  }
550 }
551 
554 {
555  return m_data->xAxisId;
556 }
557 
560 {
561  return m_data->yAxisId;
562 }
563 
569 {
570  return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
571 }
572 
596  const QwtScaleMap& yMap, const QRectF& canvasRect,
597  double& left, double& top, double& right, double& bottom ) const
598 {
599  Q_UNUSED( xMap );
600  Q_UNUSED( yMap );
601  Q_UNUSED( canvasRect );
602 
603  // use QMargins, when we don't need to support Qt < 4.6 anymore
604  left = top = right = bottom = 0.0;
605 }
606 
627 {
629 
630  QwtText label = title();
631  label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
632 
633  data.setValue( QwtLegendData::TitleRole,
634  QVariant::fromValue( label ) );
635 
636  const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
637  if ( !graphic.isNull() )
638  {
639  data.setValue( QwtLegendData::IconRole,
640  QVariant::fromValue( graphic ) );
641  }
642 
644  list += data;
645 
646  return list;
647 }
648 
666  const QwtScaleDiv& yScaleDiv )
667 {
668  Q_UNUSED( xScaleDiv );
669  Q_UNUSED( yScaleDiv );
670 }
671 
692 {
693  Q_UNUSED( item );
694  Q_UNUSED( data );
695 }
696 
706  const QwtScaleMap& yMap ) const
707 {
708  return QRectF( xMap.s1(), yMap.s1(),
709  xMap.sDist(), yMap.sDist() );
710 }
711 
721  const QwtScaleMap& yMap ) const
722 {
723  const QRectF rect( xMap.p1(), yMap.p1(),
724  xMap.pDist(), yMap.pDist() );
725 
726  return rect;
727 }
qwt_graphic.h
left
lu_byte left
Definition: lparser.c:1226
QwtLegendData
Attributes of an entry on a legend.
Definition: qwt_legend_data.h:36
QwtPlotItem::ItemInterest
ItemInterest
Plot Item Interests.
Definition: qwt_plot_item.h:179
QwtPlotItem::ItemAttribute
ItemAttribute
Plot Item Attributes.
Definition: qwt_plot_item.h:147
QwtPlotItem::getCanvasMarginHint
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
Calculate a hint for the canvas margin.
Definition: qwt_plot_item.cpp:595
sol::stack::top
int top(lua_State *L)
Definition: sol.hpp:11684
QwtAxis::isYAxis
bool isYAxis(int axisPos)
Definition: qwt_axis.h:57
QwtPlotItem::setItemInterest
void setItemInterest(ItemInterest, bool on=true)
Definition: qwt_plot_item.cpp:279
QwtPlotItem::PrivateData::interests
QwtPlotItem::ItemInterests interests
Definition: qwt_plot_item.cpp:45
QwtPlotItem::PrivateData::xAxisId
QwtAxisId xAxisId
Definition: qwt_plot_item.cpp:52
QwtPlotItem::legendChanged
virtual void legendChanged()
Definition: qwt_plot_item.cpp:491
QwtGraphic
A paint device for scalable graphics.
Definition: qwt_graphic.h:75
QwtPlotItem::PrivateData
Definition: qwt_plot_item.cpp:19
QwtPlotItem::show
void show()
Show the item.
Definition: qwt_plot_item.cpp:440
right
lu_byte right
Definition: lparser.c:1227
QwtPlot
A 2-D plotting widget.
Definition: qwt_plot.h:78
QwtPlotItem::PrivateData::plot
QwtPlot * plot
Definition: qwt_plot_item.cpp:40
QwtPlotItem::defaultIcon
QwtGraphic defaultIcon(const QBrush &, const QSizeF &) const
Return a default icon from a brush.
Definition: qwt_plot_item.cpp:422
QwtLegendData::TitleRole
@ TitleRole
Definition: qwt_legend_data.h:59
QwtScaleMap::s1
double s1() const
Definition: qwt_scale_map.h:83
QwtText::setRenderFlags
void setRenderFlags(int)
Change the render flags.
Definition: qwt_text.cpp:304
QList
Definition: qwt_abstract_legend.h:17
QwtPlotItem::setAxes
void setAxes(QwtAxisId xAxis, QwtAxisId yAxis)
Definition: qwt_plot_item.cpp:507
qwt_legend_data.h
QwtPlotItem::Legend
@ Legend
The item is represented on the legend.
Definition: qwt_plot_item.h:150
QwtAxis::YLeft
@ YLeft
Y axis left of the canvas.
Definition: qwt_axis.h:38
QwtPlotItem::setTitle
void setTitle(const QString &title)
Definition: qwt_plot_item.cpp:187
QwtPlotItem::xAxis
QwtAxisId xAxis() const
Return xAxis.
Definition: qwt_plot_item.cpp:553
mqtt_test_proto.z
z
Definition: mqtt_test_proto.py:36
QwtPlotItem::m_data
PrivateData * m_data
Definition: qwt_plot_item.h:300
QwtPlotItem::boundingRect
virtual QRectF boundingRect() const
Definition: qwt_plot_item.cpp:568
QwtPlotItem::PrivateData::z
double z
Definition: qwt_plot_item.cpp:50
QwtPlotItem::plot
QwtPlot * plot() const
Return attached plot.
Definition: qwt_plot_item.cpp:142
QwtPlot::updateLegend
void updateLegend()
Definition: qwt_plot.cpp:1016
QwtPlot::autoRefresh
void autoRefresh()
Replots the plot if autoReplot() is true.
Definition: qwt_plot.cpp:289
QwtPlotItem::PrivateData::attributes
QwtPlotItem::ItemAttributes attributes
Definition: qwt_plot_item.cpp:44
QwtScaleMap::p1
double p1() const
Definition: qwt_scale_map.h:99
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
QwtPlotItem::isVisible
bool isVisible() const
Definition: qwt_plot_item.cpp:470
QwtPlotItem::~QwtPlotItem
virtual ~QwtPlotItem()
Destroy the QwtPlotItem.
Definition: qwt_plot_item.cpp:81
qwt_scale_map.h
QwtText
A class representing a text.
Definition: qwt_text.h:51
QwtPlotItem::legendIcon
virtual QwtGraphic legendIcon(int index, const QSizeF &) const
Definition: qwt_plot_item.cpp:402
QwtPlotItem::paintRect
QRectF paintRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding paint rectangle of 2 maps.
Definition: qwt_plot_item.cpp:720
QwtPlotItem::Rtti_PlotItem
@ Rtti_PlotItem
Unspecific value, that can be used, when it doesn't matter.
Definition: qwt_plot_item.h:78
QwtPlotItem::setZ
void setZ(double z)
Set the z value.
Definition: qwt_plot_item.cpp:165
QwtPlotItem::hide
void hide()
Hide the item.
Definition: qwt_plot_item.cpp:446
QwtPlotItem
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:66
QwtPlotItem::legendData
virtual QList< QwtLegendData > legendData() const
Return all information, that is needed to represent the item on the legend.
Definition: qwt_plot_item.cpp:626
QwtPlotItem::setYAxis
void setYAxis(QwtAxisId)
Definition: qwt_plot_item.cpp:543
QwtText::renderFlags
int renderFlags() const
Definition: qwt_text.cpp:317
QwtAxis::isXAxis
bool isXAxis(int axisPos)
Definition: qwt_axis.h:51
QwtPlotItem::itemChanged
virtual void itemChanged()
Definition: qwt_plot_item.cpp:481
QwtPlotItem::scaleRect
QRectF scaleRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding scale rectangle of 2 maps.
Definition: qwt_plot_item.cpp:705
QwtAxisId
int QwtAxisId
Axis identifier.
Definition: qwt_axis_id.h:26
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
QwtPlot::attachItem
void attachItem(QwtPlotItem *, bool)
Attach/Detach a plot item.
Definition: qwt_plot.cpp:1081
QwtPlotItem::PrivateData::title
QwtText title
Definition: qwt_plot_item.cpp:55
QwtPlotItem::testItemInterest
bool testItemInterest(ItemInterest) const
Definition: qwt_plot_item.cpp:299
QwtPlotItem::PrivateData::yAxisId
QwtAxisId yAxisId
Definition: qwt_plot_item.cpp:53
QwtGraphic::isNull
bool isNull() const
Definition: qwt_graphic.cpp:413
QwtPlotItem::RenderHint
RenderHint
Render hints.
Definition: qwt_plot_item.h:203
QwtPlotItem::setRenderThreadCount
void setRenderThreadCount(uint numThreads)
Definition: qwt_plot_item.cpp:350
QwtPlotItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition: qwt_plot_item.cpp:228
QwtPlotItem::PrivateData::renderHints
QwtPlotItem::RenderHints renderHints
Definition: qwt_plot_item.cpp:47
QwtScaleMap::pDist
double pDist() const
Definition: qwt_scale_map.h:115
QwtScaleMap::sDist
double sDist() const
Definition: qwt_scale_map.h:123
QwtPlotItem::PrivateData::legendIconSize
QSize legendIconSize
Definition: qwt_plot_item.cpp:56
QwtPlotItem::updateScaleDiv
virtual void updateScaleDiv(const QwtScaleDiv &, const QwtScaleDiv &)
Update the item to changes of the axes scale division.
Definition: qwt_plot_item.cpp:665
QwtPlotItem::PrivateData::PrivateData
PrivateData()
Definition: qwt_plot_item.cpp:29
QwtPlotItem::updateLegend
virtual void updateLegend(const QwtPlotItem *, const QList< QwtLegendData > &)
Update the item to changes of the legend info.
Definition: qwt_plot_item.cpp:690
qwt_plot_item.h
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
QwtPlotItem::PrivateData::renderThreadCount
uint renderThreadCount
Definition: qwt_plot_item.cpp:48
QwtPlotItem::setXAxis
void setXAxis(QwtAxisId)
Definition: qwt_plot_item.cpp:526
QwtScaleDiv
A class representing a scale division.
Definition: qwt_scale_div.h:33
QwtPlotItem::setVisible
virtual void setVisible(bool)
Definition: qwt_plot_item.cpp:457
QwtPlotItem::setRenderHint
void setRenderHint(RenderHint, bool on=true)
Definition: qwt_plot_item.cpp:312
QwtPlotItem::attach
void attach(QwtPlot *plot)
Attach the item to a plot.
Definition: qwt_plot_item.cpp:98
QwtPlotItem::testRenderHint
bool testRenderHint(RenderHint) const
Definition: qwt_plot_item.cpp:332
qwt_text.h
QwtPlotItem::QwtPlotItem
QwtPlotItem()
Definition: qwt_plot_item.cpp:55
QwtPlotItem::PrivateData::isVisible
bool isVisible
Definition: qwt_plot_item.cpp:42
QwtPlotItem::rtti
virtual int rtti() const
Definition: qwt_plot_item.cpp:136
QwtPlotItem::setLegendIconSize
void setLegendIconSize(const QSize &)
Definition: qwt_plot_item.cpp:373
QwtPlotItem::detach
void detach()
This method detaches a QwtPlotItem from any QwtPlot it has been associated with.
Definition: qwt_plot_item.cpp:119
QwtGraphic::setDefaultSize
void setDefaultSize(const QSizeF &)
Set a default size.
Definition: qwt_graphic.cpp:553
QwtPlotItem::testItemAttribute
bool testItemAttribute(ItemAttribute) const
Definition: qwt_plot_item.cpp:266
QwtPlotItem::yAxis
QwtAxisId yAxis() const
Return yAxis.
Definition: qwt_plot_item.cpp:559
QwtLegendData::IconRole
@ IconRole
Definition: qwt_legend_data.h:62
QwtPlotItem::title
const QwtText & title() const
Definition: qwt_plot_item.cpp:215
qwt_plot.h
QwtPlotItem::legendIconSize
QSize legendIconSize() const
Definition: qwt_plot_item.cpp:386
QwtPlotItem::z
double z() const
Definition: qwt_plot_item.cpp:152
QwtPlotItem::renderThreadCount
uint renderThreadCount() const
Definition: qwt_plot_item.cpp:360
QwtAxis::XBottom
@ XBottom
X axis below the canvas.
Definition: qwt_axis.h:44


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