source: ntrip/trunk/BNC/qwt/qwt_plot.h@ 8294

Last change on this file since 8294 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 8.2 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#include <qlist.h>
20#include <qvariant.h>
21
22class QwtPlotLayout;
23class QwtAbstractLegend;
24class QwtScaleWidget;
25class QwtScaleEngine;
26class QwtScaleDiv;
27class QwtScaleDraw;
28class QwtTextLabel;
29
30/*!
31 \brief A 2-D plotting widget
32
33 QwtPlot is a widget for plotting two-dimensional graphs.
34 An unlimited number of plot items can be displayed on
35 its canvas. Plot items might be curves (QwtPlotCurve), markers
36 (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived
37 from QwtPlotItem.
38 A plot can have up to four axes, with each plot item attached to an x- and
39 a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or
40 are calculated from the plot items, using algorithms (QwtScaleEngine) which
41 can be configured separately for each axis.
42
43 The simpleplot example is a good starting point to see how to set up a
44 plot widget.
45
46 \image html plot.png
47
48 \par Example
49 The following example shows (schematically) the most simple
50 way to use QwtPlot. By default, only the left and bottom axes are
51 visible and their scales are computed automatically.
52 \verbatim
53#include <qwt_plot.h>
54#include <qwt_plot_curve.h>
55
56QwtPlot *myPlot = new QwtPlot("Two Curves", parent);
57
58// add curves
59QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
60QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
61
62// connect or copy the data to the curves
63curve1->setData(...);
64curve2->setData(...);
65
66curve1->attach(myPlot);
67curve2->attach(myPlot);
68
69// finally, refresh the plot
70myPlot->replot();
71\endverbatim
72*/
73
74class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
75{
76 Q_OBJECT
77
78 Q_PROPERTY( QBrush canvasBackground
79 READ canvasBackground WRITE setCanvasBackground )
80 Q_PROPERTY( bool autoReplot READ autoReplot WRITE setAutoReplot )
81
82#if 0
83 // This property is intended to configure the plot
84 // widget from a special dialog in the deigner plugin.
85 // Disabled until such a dialog has been implemented.
86
87 Q_PROPERTY( QString propertiesDocument
88 READ grabProperties WRITE applyProperties )
89#endif
90
91public:
92 //! \brief Axis index
93 enum Axis
94 {
95 //! Y axis left of the canvas
96 yLeft,
97
98 //! Y axis right of the canvas
99 yRight,
100
101 //! X axis below the canvas
102 xBottom,
103
104 //! X axis above the canvas
105 xTop,
106
107 //! Number of axes
108 axisCnt
109 };
110
111 /*!
112 Position of the legend, relative to the canvas.
113
114 \sa insertLegend()
115 */
116 enum LegendPosition
117 {
118 //! The legend will be left from the QwtPlot::yLeft axis.
119 LeftLegend,
120
121 //! The legend will be right from the QwtPlot::yRight axis.
122 RightLegend,
123
124 //! The legend will be below the footer
125 BottomLegend,
126
127 //! The legend will be above the title
128 TopLegend
129 };
130
131 explicit QwtPlot( QWidget * = NULL );
132 explicit QwtPlot( const QwtText &title, QWidget * = NULL );
133
134 virtual ~QwtPlot();
135
136 void applyProperties( const QString & );
137 QString grabProperties() const;
138
139 void setAutoReplot( bool = true );
140 bool autoReplot() const;
141
142 // Layout
143
144 void setPlotLayout( QwtPlotLayout * );
145
146 QwtPlotLayout *plotLayout();
147 const QwtPlotLayout *plotLayout() const;
148
149 // Title
150
151 void setTitle( const QString & );
152 void setTitle( const QwtText &t );
153 QwtText title() const;
154
155 QwtTextLabel *titleLabel();
156 const QwtTextLabel *titleLabel() const;
157
158 // Footer
159
160 void setFooter( const QString & );
161 void setFooter( const QwtText &t );
162 QwtText footer() const;
163
164 QwtTextLabel *footerLabel();
165 const QwtTextLabel *footerLabel() const;
166
167 // Canvas
168
169 void setCanvas( QWidget * );
170
171 QWidget *canvas();
172 const QWidget *canvas() const;
173
174 void setCanvasBackground( const QBrush & );
175 QBrush canvasBackground() const;
176
177 virtual QwtScaleMap canvasMap( int axisId ) const;
178
179 double invTransform( int axisId, int pos ) const;
180 double transform( int axisId, double value ) const;
181
182 // Axes
183
184 QwtScaleEngine *axisScaleEngine( int axisId );
185 const QwtScaleEngine *axisScaleEngine( int axisId ) const;
186 void setAxisScaleEngine( int axisId, QwtScaleEngine * );
187
188 void setAxisAutoScale( int axisId, bool on = true );
189 bool axisAutoScale( int axisId ) const;
190
191 void enableAxis( int axisId, bool tf = true );
192 bool axisEnabled( int axisId ) const;
193
194 void setAxisFont( int axisId, const QFont &f );
195 QFont axisFont( int axisId ) const;
196
197 void setAxisScale( int axisId, double min, double max, double step = 0 );
198 void setAxisScaleDiv( int axisId, const QwtScaleDiv & );
199 void setAxisScaleDraw( int axisId, QwtScaleDraw * );
200
201 double axisStepSize( int axisId ) const;
202 QwtInterval axisInterval( int axisId ) const;
203
204 const QwtScaleDiv &axisScaleDiv( int axisId ) const;
205
206 const QwtScaleDraw *axisScaleDraw( int axisId ) const;
207 QwtScaleDraw *axisScaleDraw( int axisId );
208
209 const QwtScaleWidget *axisWidget( int axisId ) const;
210 QwtScaleWidget *axisWidget( int axisId );
211
212 void setAxisLabelAlignment( int axisId, Qt::Alignment );
213 void setAxisLabelRotation( int axisId, double rotation );
214
215 void setAxisTitle( int axisId, const QString & );
216 void setAxisTitle( int axisId, const QwtText & );
217 QwtText axisTitle( int axisId ) const;
218
219 void setAxisMaxMinor( int axisId, int maxMinor );
220 int axisMaxMinor( int axisId ) const;
221
222 void setAxisMaxMajor( int axisId, int maxMajor );
223 int axisMaxMajor( int axisId ) const;
224
225 // Legend
226
227 void insertLegend( QwtAbstractLegend *,
228 LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 );
229
230 QwtAbstractLegend *legend();
231 const QwtAbstractLegend *legend() const;
232
233 void updateLegend();
234 void updateLegend( const QwtPlotItem * );
235
236 // Misc
237
238 virtual QSize sizeHint() const;
239 virtual QSize minimumSizeHint() const;
240
241 virtual void updateLayout();
242 virtual void drawCanvas( QPainter * );
243
244 void updateAxes();
245 void updateCanvasMargins();
246
247 virtual void getCanvasMarginsHint(
248 const QwtScaleMap maps[], const QRectF &canvasRect,
249 double &left, double &top, double &right, double &bottom) const;
250
251 virtual bool event( QEvent * );
252 virtual bool eventFilter( QObject *, QEvent * );
253
254 virtual void drawItems( QPainter *, const QRectF &,
255 const QwtScaleMap maps[axisCnt] ) const;
256
257 virtual QVariant itemToInfo( QwtPlotItem * ) const;
258 virtual QwtPlotItem *infoToItem( const QVariant & ) const;
259
260Q_SIGNALS:
261 /*!
262 A signal indicating, that an item has been attached/detached
263
264 \param plotItem Plot item
265 \param on Attached/Detached
266 */
267 void itemAttached( QwtPlotItem *plotItem, bool on );
268
269 /*!
270 A signal with the attributes how to update
271 the legend entries for a plot item.
272
273 \param itemInfo Info about a plot item, build from itemToInfo()
274 \param data Attributes of the entries ( usually <= 1 ) for
275 the plot item.
276
277 \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend()
278 */
279 void legendDataChanged( const QVariant &itemInfo,
280 const QList<QwtLegendData> &data );
281
282public Q_SLOTS:
283 virtual void replot();
284 void autoRefresh();
285
286protected:
287 static bool axisValid( int axisId );
288
289 virtual void resizeEvent( QResizeEvent *e );
290
291private Q_SLOTS:
292 void updateLegendItems( const QVariant &itemInfo,
293 const QList<QwtLegendData> &data );
294
295private:
296 friend class QwtPlotItem;
297 void attachItem( QwtPlotItem *, bool );
298
299 void initAxesData();
300 void deleteAxesData();
301 void updateScaleDiv();
302
303 void initPlot( const QwtText &title );
304
305 class AxisData;
306 AxisData *d_axisData[axisCnt];
307
308 class PrivateData;
309 PrivateData *d_data;
310};
311
312#endif
Note: See TracBrowser for help on using the repository browser.