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

Last change on this file since 9471 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
RevLine 
[4271]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>
[8127]19#include <qlist.h>
20#include <qvariant.h>
[4271]21
22class QwtPlotLayout;
[8127]23class QwtAbstractLegend;
[4271]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
[8127]39 a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or
[4271]40 are calculated from the plot items, using algorithms (QwtScaleEngine) which
41 can be configured separately for each axis.
42
[9383]43 The simpleplot example is a good starting point to see how to set up a
[8127]44 plot widget.
45
[4271]46 \image html plot.png
47
48 \par Example
[9383]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>
[4271]55
[9383]56 QwtPlot *myPlot = new QwtPlot( "Two Curves", parent );
[4271]57
[9383]58 // add curves
59 QwtPlotCurve *curve1 = new QwtPlotCurve( "Curve 1" );
60 QwtPlotCurve *curve2 = new QwtPlotCurve( "Curve 2" );
[4271]61
[9383]62 // connect or copy the data to the curves
63 curve1->setData( ... );
64 curve2->setData( ... );
[4271]65
[9383]66 curve1->attach( myPlot );
67 curve2->attach( myPlot );
[4271]68
[9383]69 // finally, refresh the plot
70 myPlot->replot();
71 \endcode
72 \endpar
[4271]73*/
74
75class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
76{
77 Q_OBJECT
[8127]78
[9383]79 Q_PROPERTY( QBrush canvasBackground
[8127]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
[4271]88 Q_PROPERTY( QString propertiesDocument
89 READ grabProperties WRITE applyProperties )
[8127]90#endif
[4271]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
[9383]125 //! The legend will be below the footer
[4271]126 BottomLegend,
127
[8127]128 //! The legend will be above the title
129 TopLegend
[4271]130 };
131
132 explicit QwtPlot( QWidget * = NULL );
[8127]133 explicit QwtPlot( const QwtText &title, QWidget * = NULL );
[4271]134
135 virtual ~QwtPlot();
136
137 void applyProperties( const QString & );
138 QString grabProperties() const;
139
[8127]140 void setAutoReplot( bool = true );
[4271]141 bool autoReplot() const;
142
143 // Layout
144
[8127]145 void setPlotLayout( QwtPlotLayout * );
146
[4271]147 QwtPlotLayout *plotLayout();
148 const QwtPlotLayout *plotLayout() const;
149
150 // Title
151
152 void setTitle( const QString & );
[9383]153 void setTitle( const QwtText & );
[4271]154 QwtText title() const;
155
156 QwtTextLabel *titleLabel();
157 const QwtTextLabel *titleLabel() const;
158
[8127]159 // Footer
160
161 void setFooter( const QString & );
[9383]162 void setFooter( const QwtText & );
[8127]163 QwtText footer() const;
164
165 QwtTextLabel *footerLabel();
166 const QwtTextLabel *footerLabel() const;
167
[4271]168 // Canvas
169
[8127]170 void setCanvas( QWidget * );
[4271]171
[8127]172 QWidget *canvas();
173 const QWidget *canvas() const;
174
[4271]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
[9383]195 void setAxisFont( int axisId, const QFont & );
[4271]196 QFont axisFont( int axisId ) const;
197
[9383]198 void setAxisScale( int axisId, double min, double max, double stepSize = 0 );
[4271]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
[8127]205 const QwtScaleDiv &axisScaleDiv( int axisId ) const;
[4271]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
[9383]228 void insertLegend( QwtAbstractLegend *,
[8127]229 LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 );
[4271]230
[8127]231 QwtAbstractLegend *legend();
232 const QwtAbstractLegend *legend() const;
[4271]233
[8127]234 void updateLegend();
235 void updateLegend( const QwtPlotItem * );
236
[4271]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();
[8127]246 void updateCanvasMargins();
[4271]247
[9383]248 virtual void getCanvasMarginsHint(
[8127]249 const QwtScaleMap maps[], const QRectF &canvasRect,
250 double &left, double &top, double &right, double &bottom) const;
251
[4271]252 virtual bool event( QEvent * );
[8127]253 virtual bool eventFilter( QObject *, QEvent * );
[4271]254
255 virtual void drawItems( QPainter *, const QRectF &,
256 const QwtScaleMap maps[axisCnt] ) const;
257
[8127]258 virtual QVariant itemToInfo( QwtPlotItem * ) const;
259 virtual QwtPlotItem *infoToItem( const QVariant & ) const;
260
[4271]261Q_SIGNALS:
262 /*!
[8127]263 A signal indicating, that an item has been attached/detached
[4271]264
[8127]265 \param plotItem Plot item
266 \param on Attached/Detached
[4271]267 */
[8127]268 void itemAttached( QwtPlotItem *plotItem, bool on );
[4271]269
270 /*!
[9383]271 A signal with the attributes how to update
[8127]272 the legend entries for a plot item.
[4271]273
[8127]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.
[4271]277
[8127]278 \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend()
[4271]279 */
[9383]280 void legendDataChanged( const QVariant &itemInfo,
[8127]281 const QList<QwtLegendData> &data );
[4271]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
[8127]292private Q_SLOTS:
293 void updateLegendItems( const QVariant &itemInfo,
[9383]294 const QList<QwtLegendData> &legendData );
[8127]295
[4271]296private:
[8127]297 friend class QwtPlotItem;
298 void attachItem( QwtPlotItem *, bool );
299
[4271]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.