source: ntrip/branches/BNC_2.11.0/qwt/qwt_plot.h@ 9484

Last change on this file since 9484 was 4271, checked in by mervart, 13 years ago
File size: 7.6 KB
Line 
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#ifndef QWT_PLOT_H
11#define QWT_PLOT_H
12
13#include "qwt_global.h"
14#include "qwt_text.h"
15#include "qwt_plot_dict.h"
16#include "qwt_scale_map.h"
17#include "qwt_interval.h"
18#include <qframe.h>
19
20class QwtPlotLayout;
21class QwtLegend;
22class QwtScaleWidget;
23class QwtScaleEngine;
24class QwtScaleDiv;
25class QwtScaleDraw;
26class QwtTextLabel;
27class QwtPlotCanvas;
28
29/*!
30 \brief A 2-D plotting widget
31
32 QwtPlot is a widget for plotting two-dimensional graphs.
33 An unlimited number of plot items can be displayed on
34 its canvas. Plot items might be curves (QwtPlotCurve), markers
35 (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived
36 from QwtPlotItem.
37 A plot can have up to four axes, with each plot item attached to an x- and
38 a y axis. The scales at the axes can be explicitely set (QwtScaleDiv), or
39 are calculated from the plot items, using algorithms (QwtScaleEngine) which
40 can be configured separately for each axis.
41
42 \image html plot.png
43
44 \par Example
45 The following example shows (schematically) the most simple
46 way to use QwtPlot. By default, only the left and bottom axes are
47 visible and their scales are computed automatically.
48 \verbatim
49#include <qwt_plot.h>
50#include <qwt_plot_curve.h>
51
52QwtPlot *myPlot = new QwtPlot("Two Curves", parent);
53
54// add curves
55QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
56QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
57
58// copy the data into the curves
59curve1->setData(...);
60curve2->setData(...);
61
62curve1->attach(myPlot);
63curve2->attach(myPlot);
64
65// finally, refresh the plot
66myPlot->replot();
67\endverbatim
68*/
69
70class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
71{
72 Q_OBJECT
73 Q_PROPERTY( QString propertiesDocument
74 READ grabProperties WRITE applyProperties )
75
76public:
77 //! \brief Axis index
78 enum Axis
79 {
80 //! Y axis left of the canvas
81 yLeft,
82
83 //! Y axis right of the canvas
84 yRight,
85
86 //! X axis below the canvas
87 xBottom,
88
89 //! X axis above the canvas
90 xTop,
91
92 //! Number of axes
93 axisCnt
94 };
95
96 /*!
97 Position of the legend, relative to the canvas.
98
99 \sa insertLegend()
100 \note In case of ExternalLegend, the legend is not
101 handled by QwtPlotRenderer
102 */
103 enum LegendPosition
104 {
105 //! The legend will be left from the QwtPlot::yLeft axis.
106 LeftLegend,
107
108 //! The legend will be right from the QwtPlot::yRight axis.
109 RightLegend,
110
111 //! The legend will be below QwtPlot::xBottom axis.
112 BottomLegend,
113
114 //! The legend will be between QwtPlot::xTop axis and the title.
115 TopLegend,
116
117 /*!
118 External means that only the content of the legend
119 will be handled by QwtPlot, but not its geometry.
120 This type can be used to have a legend in an
121 external window ( or on the canvas ).
122 */
123 ExternalLegend
124 };
125
126 explicit QwtPlot( QWidget * = NULL );
127 explicit QwtPlot( const QwtText &title, QWidget *p = NULL );
128
129 virtual ~QwtPlot();
130
131 void applyProperties( const QString & );
132 QString grabProperties() const;
133
134 void setAutoReplot( bool tf = true );
135 bool autoReplot() const;
136
137 // Layout
138
139 QwtPlotLayout *plotLayout();
140 const QwtPlotLayout *plotLayout() const;
141
142 // Title
143
144 void setTitle( const QString & );
145 void setTitle( const QwtText &t );
146 QwtText title() const;
147
148 QwtTextLabel *titleLabel();
149 const QwtTextLabel *titleLabel() const;
150
151 // Canvas
152
153 QwtPlotCanvas *canvas();
154 const QwtPlotCanvas *canvas() const;
155
156 void setCanvasBackground( const QBrush & );
157 QBrush canvasBackground() const;
158
159 void setCanvasLineWidth( int w );
160 int canvasLineWidth() const;
161
162 virtual QwtScaleMap canvasMap( int axisId ) const;
163
164 double invTransform( int axisId, int pos ) const;
165 double transform( int axisId, double value ) const;
166
167 // Axes
168
169 QwtScaleEngine *axisScaleEngine( int axisId );
170 const QwtScaleEngine *axisScaleEngine( int axisId ) const;
171 void setAxisScaleEngine( int axisId, QwtScaleEngine * );
172
173 void setAxisAutoScale( int axisId, bool on = true );
174 bool axisAutoScale( int axisId ) const;
175
176 void enableAxis( int axisId, bool tf = true );
177 bool axisEnabled( int axisId ) const;
178
179 void setAxisFont( int axisId, const QFont &f );
180 QFont axisFont( int axisId ) const;
181
182 void setAxisScale( int axisId, double min, double max, double step = 0 );
183 void setAxisScaleDiv( int axisId, const QwtScaleDiv & );
184 void setAxisScaleDraw( int axisId, QwtScaleDraw * );
185
186 double axisStepSize( int axisId ) const;
187 QwtInterval axisInterval( int axisId ) const;
188
189 const QwtScaleDiv *axisScaleDiv( int axisId ) const;
190 QwtScaleDiv *axisScaleDiv( int axisId );
191
192 const QwtScaleDraw *axisScaleDraw( int axisId ) const;
193 QwtScaleDraw *axisScaleDraw( int axisId );
194
195 const QwtScaleWidget *axisWidget( int axisId ) const;
196 QwtScaleWidget *axisWidget( int axisId );
197
198 void setAxisLabelAlignment( int axisId, Qt::Alignment );
199 void setAxisLabelRotation( int axisId, double rotation );
200
201 void setAxisTitle( int axisId, const QString & );
202 void setAxisTitle( int axisId, const QwtText & );
203 QwtText axisTitle( int axisId ) const;
204
205 void setAxisMaxMinor( int axisId, int maxMinor );
206 int axisMaxMinor( int axisId ) const;
207
208 void setAxisMaxMajor( int axisId, int maxMajor );
209 int axisMaxMajor( int axisId ) const;
210
211 // Legend
212
213 void insertLegend( QwtLegend *, LegendPosition = QwtPlot::RightLegend,
214 double ratio = -1.0 );
215
216 QwtLegend *legend();
217 const QwtLegend *legend() const;
218
219 // Misc
220
221 virtual QSize sizeHint() const;
222 virtual QSize minimumSizeHint() const;
223
224 virtual void updateLayout();
225 virtual void drawCanvas( QPainter * );
226
227 void updateAxes();
228
229 virtual bool event( QEvent * );
230
231 virtual void drawItems( QPainter *, const QRectF &,
232 const QwtScaleMap maps[axisCnt] ) const;
233
234Q_SIGNALS:
235 /*!
236 A signal which is emitted when the user has clicked on
237 a legend item, which is in QwtLegend::ClickableItem mode.
238
239 \param plotItem Corresponding plot item of the
240 selected legend item
241
242 \note clicks are disabled as default
243 \sa QwtLegend::setItemMode(), QwtLegend::itemMode()
244 */
245 void legendClicked( QwtPlotItem *plotItem );
246
247 /*!
248 A signal which is emitted when the user has clicked on
249 a legend item, which is in QwtLegend::CheckableItem mode
250
251 \param plotItem Corresponding plot item of the
252 selected legend item
253 \param on True when the legen item is checked
254
255 \note clicks are disabled as default
256 \sa QwtLegend::setItemMode(), QwtLegend::itemMode()
257 */
258
259 void legendChecked( QwtPlotItem *plotItem, bool on );
260
261public Q_SLOTS:
262 virtual void replot();
263 void autoRefresh();
264
265protected Q_SLOTS:
266 virtual void legendItemClicked();
267 virtual void legendItemChecked( bool );
268
269protected:
270 static bool axisValid( int axisId );
271
272 virtual void updateTabOrder();
273
274 virtual void resizeEvent( QResizeEvent *e );
275
276private:
277 void initAxesData();
278 void deleteAxesData();
279 void updateScaleDiv();
280
281 void initPlot( const QwtText &title );
282
283 class AxisData;
284 AxisData *d_axisData[axisCnt];
285
286 class PrivateData;
287 PrivateData *d_data;
288};
289
290#endif
Note: See TracBrowser for help on using the repository browser.