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

Last change on this file since 10573 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

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