qwt_plot_item.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_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:
23  plot( NULL ),
24  isVisible( true ),
25  renderThreadCount( 1 ),
26  z( 0.0 ),
27  xAxis( QwtPlot::xBottom ),
28  yAxis( QwtPlot::yLeft ),
29  legendIconSize( 8, 8 )
30  {
31  }
32 
33  mutable QwtPlot *plot;
34 
35  bool isVisible;
36 
39 
42 
43  double z;
44 
45  int xAxis;
46  int yAxis;
47 
50 };
51 
56 {
57  d_data = new PrivateData;
58 }
59 
65 {
66  d_data = new PrivateData;
67  d_data->title = title;
68 }
69 
75 {
76  d_data = new PrivateData;
77  d_data->title = title;
78 }
79 
82 {
83  attach( NULL );
84  delete d_data;
85 }
86 
99 {
100  if ( plot == d_data->plot )
101  return;
102 
103  if ( d_data->plot )
104  d_data->plot->attachItem( this, false );
105 
106  d_data->plot = plot;
107 
108  if ( d_data->plot )
109  d_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 d_data->plot;
145 }
146 
152 double QwtPlotItem::z() const
153 {
154  return d_data->z;
155 }
156 
165 void QwtPlotItem::setZ( double z )
166 {
167  if ( d_data->z != z )
168  {
169  if ( d_data->plot ) // update the z order
170  d_data->plot->attachItem( this, false );
171 
172  d_data->z = z;
173 
174  if ( d_data->plot )
175  d_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 
199 {
200  if ( d_data->title != title )
201  {
202  d_data->title = title;
203 
204  legendChanged();
205 #if 0
206  itemChanged();
207 #endif
208  }
209 }
210 
216 {
217  return d_data->title;
218 }
219 
229 {
230  if ( d_data->attributes.testFlag( attribute ) != on )
231  {
232  if ( on )
233  d_data->attributes |= attribute;
234  else
235  d_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 ( d_data->plot )
251  d_data->plot->updateLegend( this );
252  }
253  }
254 
255  itemChanged();
256  }
257 }
258 
267 {
268  return d_data->attributes.testFlag( attribute );
269 }
270 
280 {
281  if ( d_data->interests.testFlag( interest ) != on )
282  {
283  if ( on )
284  d_data->interests |= interest;
285  else
286  d_data->interests &= ~interest;
287 
288  itemChanged();
289  }
290 }
291 
300 {
301  return d_data->interests.testFlag( interest );
302 }
303 
313 {
314  if ( d_data->renderHints.testFlag( hint ) != on )
315  {
316  if ( on )
317  d_data->renderHints |= hint;
318  else
319  d_data->renderHints &= ~hint;
320 
321  itemChanged();
322  }
323 }
324 
333 {
334  return d_data->renderHints.testFlag( hint );
335 }
336 
350 void QwtPlotItem::setRenderThreadCount( uint numThreads )
351 {
352  d_data->renderThreadCount = numThreads;
353 }
354 
361 {
362  return d_data->renderThreadCount;
363 }
364 
373 void QwtPlotItem::setLegendIconSize( const QSize &size )
374 {
375  if ( d_data->legendIconSize != size )
376  {
377  d_data->legendIconSize = size;
378  legendChanged();
379  }
380 }
381 
387 {
388  return d_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 != d_data->isVisible )
460  {
461  d_data->isVisible = on;
462  itemChanged();
463  }
464 }
465 
471 {
472  return d_data->isVisible;
473 }
474 
482 {
483  if ( d_data->plot )
484  d_data->plot->autoRefresh();
485 }
486 
492 {
494  d_data->plot->updateLegend( this );
495 }
496 
508 {
509  if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop )
510  d_data->xAxis = xAxis;
511 
512  if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight )
513  d_data->yAxis = yAxis;
514 
515  itemChanged();
516 }
517 
526 void QwtPlotItem::setXAxis( int axis )
527 {
528  if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
529  {
530  d_data->xAxis = axis;
531  itemChanged();
532  }
533 }
534 
543 void QwtPlotItem::setYAxis( int axis )
544 {
545  if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
546  {
547  d_data->yAxis = axis;
548  itemChanged();
549  }
550 }
551 
554 {
555  return d_data->xAxis;
556 }
557 
560 {
561  return d_data->yAxis;
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 
634  QVariant::fromValue( label ));
635 
636  const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
637  if ( !graphic.isNull() )
638  {
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 
691  const QList<QwtLegendData> &data )
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 }
virtual void legendChanged()
double p1() const
Definition: qwt_scale_map.h:99
virtual QList< QwtLegendData > legendData() const
Return all information, that is needed to represent the item on the legend.
ItemAttribute
Plot Item Attributes.
QFlags< RenderHint > RenderHints
Render hints.
X axis above the canvas.
Definition: qwt_plot.h:106
virtual int rtti() const
double s1() const
Definition: qwt_scale_map.h:83
void show()
Show the item.
lu_byte right
Definition: lparser.c:1229
int renderFlags() const
Definition: qwt_text.cpp:294
bool isVisible() const
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.
void setRenderFlags(int)
Change the render flags.
Definition: qwt_text.cpp:281
int xAxis() const
Return xAxis.
double sDist() const
lu_byte left
Definition: lparser.c:1228
void autoRefresh()
Replots the plot if autoReplot() is true.
Definition: qwt_plot.cpp:286
Y axis right of the canvas.
Definition: qwt_plot.h:100
QFlags< ItemAttribute > ItemAttributes
Plot Item Attributes.
A class representing a scale division.
Definition: qwt_scale_div.h:33
A 2-D plotting widget.
Definition: qwt_plot.h:75
QwtGraphic defaultIcon(const QBrush &, const QSizeF &) const
Return a default icon from a brush.
QwtPlot * plot() const
Return attached plot.
Y axis left of the canvas.
Definition: qwt_plot.h:97
QwtPlotItem::ItemInterests interests
QSize legendIconSize() const
QFlags< ItemInterest > ItemInterests
Plot Item Interests.
void setTitle(const QString &title)
void setDefaultSize(const QSizeF &)
Set a default size.
The item is represented on the legend.
void setYAxis(int axis)
bool testItemAttribute(ItemAttribute) const
bool testRenderHint(RenderHint) const
A class representing a text.
Definition: qwt_text.h:51
void setZ(double z)
Set the z value.
void attachItem(QwtPlotItem *, bool)
Attach/Detach a plot item.
Definition: qwt_plot.cpp:1072
A paint device for scalable graphics.
Definition: qwt_graphic.h:75
int yAxis() const
Return yAxis.
virtual QwtGraphic legendIcon(int index, const QSizeF &) const
void setXAxis(int axis)
virtual ~QwtPlotItem()
Destroy the QwtPlotItem.
RenderHint
Render hints.
QRectF paintRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding paint rectangle of 2 maps.
double z() const
A scale map.
Definition: qwt_scale_map.h:26
virtual void itemChanged()
void hide()
Hide the item.
double pDist() const
uint renderThreadCount() const
int top(lua_State *L)
Definition: sol.hpp:10543
virtual void setVisible(bool)
bool testItemInterest(ItemInterest) const
QwtPlotItem::RenderHints renderHints
void attach(QwtPlot *plot)
Attach the item to a plot.
void updateLegend()
Definition: qwt_plot.cpp:1007
QwtPlotItem::ItemAttributes attributes
void setValue(int role, const QVariant &)
virtual void updateScaleDiv(const QwtScaleDiv &, const QwtScaleDiv &)
Update the item to changes of the axes scale division.
void setRenderHint(RenderHint, bool on=true)
void setRenderThreadCount(uint numThreads)
virtual void updateLegend(const QwtPlotItem *, const QList< QwtLegendData > &)
Update the item to changes of the legend info.
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:65
void setItemAttribute(ItemAttribute, bool on=true)
void setLegendIconSize(const QSize &)
void setAxes(int xAxis, int yAxis)
bool isNull() const
void setItemInterest(ItemInterest, bool on=true)
dictionary data
Definition: mqtt_test.py:22
QRectF scaleRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding scale rectangle of 2 maps.
PrivateData * d_data
ItemInterest
Plot Item Interests.
Attributes of an entry on a legend.
Unspecific value, that can be used, when it doesn&#39;t matter.
Definition: qwt_plot_item.h:77
X axis below the canvas.
Definition: qwt_plot.h:103
const QwtText & title() const
void detach()
This method detaches a QwtPlotItem from any QwtPlot it has been associated with.
virtual QRectF boundingRect() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10