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_div.h"
15 #include "qwt_graphic.h"
16 #include <qpainter.h>
17 
19 {
20 public:
22  plot( NULL ),
23  isVisible( true ),
24  attributes( 0 ),
25  interests( 0 ),
26  renderHints( 0 ),
27  renderThreadCount( 1 ),
28  z( 0.0 ),
29  xAxis( QwtPlot::xBottom ),
30  yAxis( QwtPlot::yLeft ),
31  legendIconSize( 8, 8 )
32  {
33  }
34 
35  mutable QwtPlot *plot;
36 
37  bool isVisible;
38 
41 
44 
45  double z;
46 
47  int xAxis;
48  int yAxis;
49 
52 };
53 
59 {
60  d_data = new PrivateData;
61  d_data->title = title;
62 }
63 
66 {
67  attach( NULL );
68  delete d_data;
69 }
70 
83 {
84  if ( plot == d_data->plot )
85  return;
86 
87  if ( d_data->plot )
88  d_data->plot->attachItem( this, false );
89 
90  d_data->plot = plot;
91 
92  if ( d_data->plot )
93  d_data->plot->attachItem( this, true );
94 }
95 
104 {
105  attach( NULL );
106 }
107 
120 int QwtPlotItem::rtti() const
121 {
122  return Rtti_PlotItem;
123 }
124 
127 {
128  return d_data->plot;
129 }
130 
136 double QwtPlotItem::z() const
137 {
138  return d_data->z;
139 }
140 
149 void QwtPlotItem::setZ( double z )
150 {
151  if ( d_data->z != z )
152  {
153  if ( d_data->plot ) // update the z order
154  d_data->plot->attachItem( this, false );
155 
156  d_data->z = z;
157 
158  if ( d_data->plot )
159  d_data->plot->attachItem( this, true );
160 
161  itemChanged();
162  }
163 }
164 
171 void QwtPlotItem::setTitle( const QString &title )
172 {
173  setTitle( QwtText( title ) );
174 }
175 
183 {
184  if ( d_data->title != title )
185  {
186  d_data->title = title;
187 
188  legendChanged();
189 #if 0
190  itemChanged();
191 #endif
192  }
193 }
194 
200 {
201  return d_data->title;
202 }
203 
213 {
214  if ( d_data->attributes.testFlag( attribute ) != on )
215  {
216  if ( on )
217  d_data->attributes |= attribute;
218  else
219  d_data->attributes &= ~attribute;
220 
221  if ( attribute == QwtPlotItem::Legend )
222  legendChanged();
223 
224  itemChanged();
225  }
226 }
227 
236 {
237  return d_data->attributes.testFlag( attribute );
238 }
239 
249 {
250  if ( d_data->interests.testFlag( interest ) != on )
251  {
252  if ( on )
253  d_data->interests |= interest;
254  else
255  d_data->interests &= ~interest;
256 
257  itemChanged();
258  }
259 }
260 
269 {
270  return d_data->interests.testFlag( interest );
271 }
272 
282 {
283  if ( d_data->renderHints.testFlag( hint ) != on )
284  {
285  if ( on )
286  d_data->renderHints |= hint;
287  else
288  d_data->renderHints &= ~hint;
289 
290  itemChanged();
291  }
292 }
293 
302 {
303  return d_data->renderHints.testFlag( hint );
304 }
305 
319 void QwtPlotItem::setRenderThreadCount( uint numThreads )
320 {
321  d_data->renderThreadCount = numThreads;
322 }
323 
330 {
331  return d_data->renderThreadCount;
332 }
333 
342 void QwtPlotItem::setLegendIconSize( const QSize &size )
343 {
344  if ( d_data->legendIconSize != size )
345  {
346  d_data->legendIconSize = size;
347  legendChanged();
348  }
349 }
350 
356 {
357  return d_data->legendIconSize;
358 }
359 
372  int index, const QSizeF &size ) const
373 {
374  Q_UNUSED( index )
375  Q_UNUSED( size )
376 
377  return QwtGraphic();
378 }
379 
392  const QBrush &brush, const QSizeF &size ) const
393 {
394  QwtGraphic icon;
395  if ( !size.isEmpty() )
396  {
397  icon.setDefaultSize( size );
398 
399  QRectF r( 0, 0, size.width(), size.height() );
400 
401  QPainter painter( &icon );
402  painter.fillRect( r, brush );
403  }
404 
405  return icon;
406 }
407 
410 {
411  setVisible( true );
412 }
413 
416 {
417  setVisible( false );
418 }
419 
426 void QwtPlotItem::setVisible( bool on )
427 {
428  if ( on != d_data->isVisible )
429  {
430  d_data->isVisible = on;
431  itemChanged();
432  }
433 }
434 
440 {
441  return d_data->isVisible;
442 }
443 
451 {
452  if ( d_data->plot )
453  d_data->plot->autoRefresh();
454 }
455 
461 {
463  d_data->plot->updateLegend( this );
464 }
465 
477 {
478  if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop )
479  d_data->xAxis = xAxis;
480 
481  if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight )
482  d_data->yAxis = yAxis;
483 
484  itemChanged();
485 }
486 
495 void QwtPlotItem::setXAxis( int axis )
496 {
497  if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
498  {
499  d_data->xAxis = axis;
500  itemChanged();
501  }
502 }
503 
512 void QwtPlotItem::setYAxis( int axis )
513 {
514  if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
515  {
516  d_data->yAxis = axis;
517  itemChanged();
518  }
519 }
520 
523 {
524  return d_data->xAxis;
525 }
526 
529 {
530  return d_data->yAxis;
531 }
532 
538 {
539  return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
540 }
541 
565  const QwtScaleMap &yMap, const QRectF &canvasRect,
566  double &left, double &top, double &right, double &bottom ) const
567 {
568  Q_UNUSED( xMap );
569  Q_UNUSED( yMap );
570  Q_UNUSED( canvasRect );
571 
572  // use QMargins, when we don't need to support Qt < 4.6 anymore
573  left = top = right = bottom = 0.0;
574 }
575 
595 QList<QwtLegendData> QwtPlotItem::legendData() const
596 {
598 
599  QwtText label = title();
600  label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
601 
602  QVariant titleValue;
603  qVariantSetValue( titleValue, label );
604  data.setValue( QwtLegendData::TitleRole, titleValue );
605 
606  const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
607  if ( !graphic.isNull() )
608  {
609  QVariant iconValue;
610  qVariantSetValue( iconValue, graphic );
611  data.setValue( QwtLegendData::IconRole, iconValue );
612  }
613 
614  QList<QwtLegendData> list;
615  list += data;
616 
617  return list;
618 }
619 
637  const QwtScaleDiv &yScaleDiv )
638 {
639  Q_UNUSED( xScaleDiv );
640  Q_UNUSED( yScaleDiv );
641 }
642 
662  const QList<QwtLegendData> &data )
663 {
664  Q_UNUSED( item );
665  Q_UNUSED( data );
666 }
667 
677  const QwtScaleMap &yMap ) const
678 {
679  return QRectF( xMap.s1(), yMap.s1(),
680  xMap.sDist(), yMap.sDist() );
681 }
682 
692  const QwtScaleMap &yMap ) const
693 {
694  const QRectF rect( xMap.p1(), yMap.p1(),
695  xMap.pDist(), yMap.pDist() );
696 
697  return rect;
698 }
virtual void legendChanged()
double p1() const
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:105
virtual int rtti() const
double s1() const
Definition: qwt_scale_map.h:85
void show()
Show the item.
int renderFlags() const
Definition: qwt_text.cpp:284
bool isVisible() const
int xAxis() const
Return xAxis.
double sDist() const
void autoRefresh()
Replots the plot if autoReplot() is true.
Definition: qwt_plot.cpp:293
Y axis right of the canvas.
Definition: qwt_plot.h:99
QFlags< ItemAttribute > ItemAttributes
Plot Item Attributes.
A class representing a scale division.
Definition: qwt_scale_div.h:36
A 2-D plotting widget.
Definition: qwt_plot.h:74
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:96
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
void setRenderFlags(int flags)
Change the render flags.
Definition: qwt_text.cpp:271
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:1079
A paint device for scalable graphics.
Definition: qwt_graphic.h:74
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:30
virtual void itemChanged()
void hide()
Hide the item.
double pDist() const
uint renderThreadCount() const
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:1014
QwtPlotItem::ItemAttributes attributes
void setValue(int role, const QVariant &)
QwtPlotItem(const QwtText &title=QwtText())
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:64
void setItemAttribute(ItemAttribute, bool on=true)
void setLegendIconSize(const QSize &)
void setAxes(int xAxis, int yAxis)
empty_struct data[sizeof(T)/sizeof(empty_struct)]
bool isNull() const
void setItemInterest(ItemInterest, bool on=true)
QRectF scaleRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding scale rectangle of 2 maps.
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasSize, double &left, double &top, double &right, double &bottom) const
Calculate a hint for the canvas margin.
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:76
X axis below the canvas.
Definition: qwt_plot.h:102
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 Sat Jul 6 2019 03:44:17