Qwt User's Guide  6.2.0
qwt_plot.h
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 #ifndef QWT_PLOT_H
11 #define QWT_PLOT_H
12 
13 #include "qwt_global.h"
14 #include "qwt_axis_id.h"
15 #include "qwt_plot_dict.h"
16 
17 #include <qframe.h>
18 
19 class QwtPlotLayout;
20 class QwtAbstractLegend;
21 class QwtScaleWidget;
22 class QwtScaleEngine;
23 class QwtScaleDiv;
24 class QwtScaleMap;
25 class QwtScaleDraw;
26 class QwtTextLabel;
27 class QwtInterval;
28 class QwtText;
29 template< typename T > class QList;
30 
31 // 6.1 compatibility definitions
32 #define QWT_AXIS_COMPAT 1
33 
78 class QWT_EXPORT QwtPlot : public QFrame, public QwtPlotDict
79 {
80  Q_OBJECT
81 
82  Q_PROPERTY( QBrush canvasBackground
83  READ canvasBackground WRITE setCanvasBackground )
84 
85  Q_PROPERTY( bool autoReplot READ autoReplot WRITE setAutoReplot )
86 
87  public:
94  {
97 
100 
103 
105  TopLegend
106  };
107 
108  explicit QwtPlot( QWidget* = NULL );
109  explicit QwtPlot( const QwtText& title, QWidget* = NULL );
110 
111  virtual ~QwtPlot();
112 
113  void setAutoReplot( bool = true );
114  bool autoReplot() const;
115 
116  // Layout
117 
118  void setPlotLayout( QwtPlotLayout* );
119 
120  QwtPlotLayout* plotLayout();
121  const QwtPlotLayout* plotLayout() const;
122 
123  // Title
124 
125  void setTitle( const QString& );
126  void setTitle( const QwtText& );
127  QwtText title() const;
128 
129  QwtTextLabel* titleLabel();
130  const QwtTextLabel* titleLabel() const;
131 
132  // Footer
133 
134  void setFooter( const QString& );
135  void setFooter( const QwtText& );
136  QwtText footer() const;
137 
138  QwtTextLabel* footerLabel();
139  const QwtTextLabel* footerLabel() const;
140 
141  // Canvas
142 
143  void setCanvas( QWidget* );
144 
145  QWidget* canvas();
146  const QWidget* canvas() const;
147 
148  void setCanvasBackground( const QBrush& );
149  QBrush canvasBackground() const;
150 
151  virtual QwtScaleMap canvasMap( QwtAxisId ) const;
152 
153  double invTransform( QwtAxisId, double pos ) const;
154  double transform( QwtAxisId, double value ) const;
155 
156  // Axes
157 
158  bool isAxisValid( QwtAxisId ) const;
159 
160  void setAxisVisible( QwtAxisId, bool on = true );
161  bool isAxisVisible( QwtAxisId ) const;
162 
163  // Axes data
164 
165  QwtScaleEngine* axisScaleEngine( QwtAxisId );
166  const QwtScaleEngine* axisScaleEngine( QwtAxisId ) const;
167  void setAxisScaleEngine( QwtAxisId, QwtScaleEngine* );
168 
169  void setAxisAutoScale( QwtAxisId, bool on = true );
170  bool axisAutoScale( QwtAxisId ) const;
171 
172  void setAxisFont( QwtAxisId, const QFont& );
173  QFont axisFont( QwtAxisId ) const;
174 
175  void setAxisScale( QwtAxisId, double min, double max, double stepSize = 0 );
176  void setAxisScaleDiv( QwtAxisId, const QwtScaleDiv& );
177  void setAxisScaleDraw( QwtAxisId, QwtScaleDraw* );
178 
179  double axisStepSize( QwtAxisId ) const;
180  QwtInterval axisInterval( QwtAxisId ) const;
181  const QwtScaleDiv& axisScaleDiv( QwtAxisId ) const;
182 
183  const QwtScaleDraw* axisScaleDraw( QwtAxisId ) const;
184  QwtScaleDraw* axisScaleDraw( QwtAxisId );
185 
186  const QwtScaleWidget* axisWidget( QwtAxisId ) const;
187  QwtScaleWidget* axisWidget( QwtAxisId );
188 
189  void setAxisLabelAlignment( QwtAxisId, Qt::Alignment );
190  void setAxisLabelRotation( QwtAxisId, double rotation );
191 
192  void setAxisTitle( QwtAxisId, const QString& );
193  void setAxisTitle( QwtAxisId, const QwtText& );
194  QwtText axisTitle( QwtAxisId ) const;
195 
196  void setAxisMaxMinor( QwtAxisId, int maxMinor );
197  int axisMaxMinor( QwtAxisId ) const;
198 
199  void setAxisMaxMajor( QwtAxisId, int maxMajor );
200  int axisMaxMajor( QwtAxisId ) const;
201 
202  // Legend
203 
204  void insertLegend( QwtAbstractLegend*,
205  LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 );
206 
207  QwtAbstractLegend* legend();
208  const QwtAbstractLegend* legend() const;
209 
210  void updateLegend();
211  void updateLegend( const QwtPlotItem* );
212 
213  // Misc
214 
215  virtual QSize sizeHint() const QWT_OVERRIDE;
216  virtual QSize minimumSizeHint() const QWT_OVERRIDE;
217 
218  virtual void updateLayout();
219  virtual void drawCanvas( QPainter* );
220 
221  void updateAxes();
222  void updateCanvasMargins();
223 
224  virtual void getCanvasMarginsHint(
225  const QwtScaleMap maps[], const QRectF& canvasRect,
226  double& left, double& top, double& right, double& bottom) const;
227 
228  virtual bool event( QEvent* ) QWT_OVERRIDE;
229  virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
230 
231  virtual void drawItems( QPainter*, const QRectF&,
232  const QwtScaleMap maps[ QwtAxis::AxisPositions ] ) const;
233 
234  virtual QVariant itemToInfo( QwtPlotItem* ) const;
235  virtual QwtPlotItem* infoToItem( const QVariant& ) const;
236 
237 #if QWT_AXIS_COMPAT
238  enum Axis
239  {
240  yLeft = QwtAxis::YLeft,
241  yRight = QwtAxis::YRight,
242  xBottom = QwtAxis::XBottom,
243  xTop = QwtAxis::XTop,
244 
245  axisCnt = QwtAxis::AxisPositions
246  };
247 
248  void enableAxis( int axisId, bool on = true )
249  {
250  setAxisVisible( axisId, on );
251  }
252 
253  bool axisEnabled( int axisId ) const
254  {
255  return isAxisVisible( axisId );
256  }
257 #endif
258 
259  Q_SIGNALS:
266  void itemAttached( QwtPlotItem* plotItem, bool on );
267 
278  void legendDataChanged( const QVariant& itemInfo,
279  const QList< QwtLegendData >& data );
280 
281  public Q_SLOTS:
282  virtual void replot();
283  void autoRefresh();
284 
285  protected:
286 
287  virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
288 
289  private Q_SLOTS:
290  void updateLegendItems( const QVariant& itemInfo,
291  const QList< QwtLegendData >& legendData );
292 
293  private:
294  friend class QwtPlotItem;
295  void attachItem( QwtPlotItem*, bool );
296 
297  void initAxesData();
298  void deleteAxesData();
299  void updateScaleDiv();
300 
301  void initPlot( const QwtText& title );
302 
303  class ScaleData;
304  ScaleData* m_scaleData;
305 
306  class PrivateData;
307  PrivateData* m_data;
308 };
309 
310 #endif
Abstract base class for legend widgets.
A class representing an interval.
Definition: qwt_interval.h:23
A dictionary for plot items.
Definition: qwt_plot_dict.h:33
A 2-D plotting widget.
Definition: qwt_plot.h:79
void itemAttached(QwtPlotItem *plotItem, bool on)
LegendPosition
Definition: qwt_plot.h:94
@ LeftLegend
The legend will be left from the QwtAxis::YLeft axis.
Definition: qwt_plot.h:96
@ RightLegend
The legend will be right from the QwtAxis::YRight axis.
Definition: qwt_plot.h:99
@ BottomLegend
The legend will be below the footer.
Definition: qwt_plot.h:102
void legendDataChanged(const QVariant &itemInfo, const QList< QwtLegendData > &data)
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:67
const QwtText & title() const
virtual void updateScaleDiv(const QwtScaleDiv &, const QwtScaleDiv &)
Update the item to changes of the axes scale division.
Layout engine for QwtPlot.
A class representing a scale division.
Definition: qwt_scale_div.h:34
A class for drawing scales.
Base class for scale engines.
A scale map.
Definition: qwt_scale_map.h:27
A Widget which contains a scale.
A class representing a text.
Definition: qwt_text.h:52
A Widget which displays a QwtText.
@ YRight
Y axis right of the canvas.
Definition: qwt_axis.h:27
@ XTop
X axis above the canvas.
Definition: qwt_axis.h:33
@ XBottom
X axis below the canvas.
Definition: qwt_axis.h:30
@ YLeft
Y axis left of the canvas.
Definition: qwt_axis.h:24