[4272] | 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
| 2 | * QwtPolar Widget Library
|
---|
| 3 | * Copyright (C) 2008 Uwe Rathmann
|
---|
| 4 | *
|
---|
| 5 | * This library is free software; you can redistribute it and/or
|
---|
| 6 | * modify it under the terms of the Qwt License, Version 1.0
|
---|
| 7 | *****************************************************************************/
|
---|
| 8 |
|
---|
| 9 | #ifndef QWT_POLAR_PLOT_H
|
---|
| 10 | #define QWT_POLAR_PLOT_H 1
|
---|
| 11 |
|
---|
| 12 | #include "qwt_polar_global.h"
|
---|
| 13 | #include "qwt_polar.h"
|
---|
| 14 | #include "qwt_polar_itemdict.h"
|
---|
| 15 | #include <qwt_interval.h>
|
---|
| 16 | #include <qwt_scale_map.h>
|
---|
| 17 | #include <qwt_point_polar.h>
|
---|
| 18 | #include <qframe.h>
|
---|
| 19 |
|
---|
| 20 | class QwtRoundScaleDraw;
|
---|
| 21 | class QwtScaleEngine;
|
---|
| 22 | class QwtScaleDiv;
|
---|
| 23 | class QwtTextLabel;
|
---|
| 24 | class QwtPolarCanvas;
|
---|
| 25 | class QwtPolarLayout;
|
---|
[8127] | 26 | class QwtAbstractLegend;
|
---|
[4272] | 27 |
|
---|
| 28 | /*!
|
---|
| 29 | \brief A plotting widget, displaying a polar coordinate system
|
---|
| 30 |
|
---|
| 31 | An unlimited number of plot items can be displayed on
|
---|
| 32 | its canvas. Plot items might be curves (QwtPolarCurve), markers
|
---|
| 33 | (QwtPolarMarker), the grid (QwtPolarGrid), or anything else derived
|
---|
| 34 | from QwtPolarItem.
|
---|
| 35 |
|
---|
| 36 | The coordinate system is defined by a radial and a azimuth scale.
|
---|
| 37 | The scales at the axes can be explicitely set (QwtScaleDiv), or
|
---|
| 38 | are calculated from the plot items, using algorithms (QwtScaleEngine) which
|
---|
| 39 | can be configured separately for each axis. Autoscaling is supported
|
---|
| 40 | for the radial scale.
|
---|
| 41 |
|
---|
| 42 | In opposite to QwtPlot the scales might be different from the
|
---|
| 43 | view, that is displayed on the canvas. The view can be changed by
|
---|
| 44 | zooming - f.e. by using QwtPolarPanner or QwtPolarMaginfier.
|
---|
| 45 | */
|
---|
| 46 | class QWT_POLAR_EXPORT QwtPolarPlot: public QFrame, public QwtPolarItemDict
|
---|
| 47 | {
|
---|
| 48 | Q_OBJECT
|
---|
| 49 |
|
---|
| 50 | Q_PROPERTY( QBrush plotBackground READ plotBackground WRITE setPlotBackground )
|
---|
| 51 | Q_PROPERTY( double azimuthOrigin READ azimuthOrigin WRITE setAzimuthOrigin )
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | public:
|
---|
| 55 | /*!
|
---|
| 56 | Position of the legend, relative to the canvas.
|
---|
| 57 | \sa insertLegend()
|
---|
| 58 | */
|
---|
| 59 | enum LegendPosition
|
---|
| 60 | {
|
---|
| 61 | //! The legend will be left from the canvas.
|
---|
| 62 | LeftLegend,
|
---|
| 63 |
|
---|
| 64 | //! The legend will be right from the canvas.
|
---|
| 65 | RightLegend,
|
---|
| 66 |
|
---|
| 67 | //! The legend will be below the canvas.
|
---|
| 68 | BottomLegend,
|
---|
| 69 |
|
---|
| 70 | //! The legend will be between canvas and title.
|
---|
| 71 | TopLegend,
|
---|
| 72 |
|
---|
| 73 | /*!
|
---|
| 74 | External means that only the content of the legend
|
---|
| 75 | will be handled by QwtPlot, but not its geometry.
|
---|
| 76 | This might be interesting if an application wants to
|
---|
| 77 | have a legend in an external window ( or on the canvas ).
|
---|
| 78 |
|
---|
| 79 | \note The legend is not painted by QwtPolarRenderer
|
---|
| 80 | */
|
---|
| 81 | ExternalLegend
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | explicit QwtPolarPlot( QWidget *parent = NULL );
|
---|
| 85 | QwtPolarPlot( const QwtText &title, QWidget *parent = NULL );
|
---|
| 86 |
|
---|
| 87 | virtual ~QwtPolarPlot();
|
---|
| 88 |
|
---|
| 89 | void setTitle( const QString & );
|
---|
| 90 | void setTitle( const QwtText & );
|
---|
| 91 |
|
---|
| 92 | QwtText title() const;
|
---|
| 93 |
|
---|
| 94 | QwtTextLabel *titleLabel();
|
---|
| 95 | const QwtTextLabel *titleLabel() const;
|
---|
| 96 |
|
---|
| 97 | void setAutoReplot( bool tf = true );
|
---|
| 98 | bool autoReplot() const;
|
---|
| 99 |
|
---|
| 100 | void setAutoScale( int scaleId );
|
---|
| 101 | bool hasAutoScale( int scaleId ) const;
|
---|
| 102 |
|
---|
| 103 | void setScaleMaxMinor( int scaleId, int maxMinor );
|
---|
| 104 | int scaleMaxMinor( int scaleId ) const;
|
---|
| 105 |
|
---|
| 106 | int scaleMaxMajor( int scaleId ) const;
|
---|
| 107 | void setScaleMaxMajor( int scaleId, int maxMajor );
|
---|
| 108 |
|
---|
| 109 | QwtScaleEngine *scaleEngine( int scaleId );
|
---|
| 110 | const QwtScaleEngine *scaleEngine( int scaleId ) const;
|
---|
| 111 | void setScaleEngine( int scaleId, QwtScaleEngine * );
|
---|
| 112 |
|
---|
| 113 | void setScale( int scaleId, double min, double max, double step = 0 );
|
---|
| 114 |
|
---|
| 115 | void setScaleDiv( int scaleId, const QwtScaleDiv & );
|
---|
| 116 | const QwtScaleDiv *scaleDiv( int scaleId ) const;
|
---|
| 117 | QwtScaleDiv *scaleDiv( int scaleId );
|
---|
| 118 |
|
---|
| 119 | QwtScaleMap scaleMap( int scaleId, double radius ) const;
|
---|
| 120 | QwtScaleMap scaleMap( int scaleId ) const;
|
---|
| 121 |
|
---|
| 122 | void updateScale( int scaleId );
|
---|
| 123 |
|
---|
| 124 | double azimuthOrigin() const;
|
---|
| 125 |
|
---|
| 126 | void zoom( const QwtPointPolar&, double factor );
|
---|
| 127 | void unzoom();
|
---|
| 128 |
|
---|
| 129 | QwtPointPolar zoomPos() const;
|
---|
| 130 | double zoomFactor() const;
|
---|
| 131 |
|
---|
| 132 | // Canvas
|
---|
| 133 |
|
---|
| 134 | QwtPolarCanvas *canvas();
|
---|
| 135 | const QwtPolarCanvas *canvas() const;
|
---|
| 136 |
|
---|
| 137 | void setPlotBackground ( const QBrush &c );
|
---|
| 138 | const QBrush& plotBackground() const;
|
---|
| 139 |
|
---|
| 140 | virtual void drawCanvas( QPainter *, const QRectF & ) const;
|
---|
| 141 |
|
---|
| 142 | // Legend
|
---|
| 143 |
|
---|
[8127] | 144 | void insertLegend( QwtAbstractLegend *,
|
---|
[4272] | 145 | LegendPosition = RightLegend, double ratio = -1.0 );
|
---|
| 146 |
|
---|
[8127] | 147 | QwtAbstractLegend *legend();
|
---|
| 148 | const QwtAbstractLegend *legend() const;
|
---|
[4272] | 149 |
|
---|
[8127] | 150 | void updateLegend();
|
---|
| 151 | void updateLegend( const QwtPolarItem * );
|
---|
| 152 |
|
---|
[4272] | 153 | // Layout
|
---|
| 154 | QwtPolarLayout *plotLayout();
|
---|
| 155 | const QwtPolarLayout *plotLayout() const;
|
---|
| 156 |
|
---|
| 157 | QwtInterval visibleInterval() const;
|
---|
| 158 | QRectF plotRect() const;
|
---|
| 159 | QRectF plotRect( const QRectF & ) const;
|
---|
| 160 |
|
---|
| 161 | int plotMarginHint() const;
|
---|
| 162 |
|
---|
[8127] | 163 | virtual QVariant itemToInfo( QwtPolarItem * ) const;
|
---|
| 164 | virtual QwtPolarItem *infoToItem( const QVariant & ) const;
|
---|
| 165 |
|
---|
[4272] | 166 | Q_SIGNALS:
|
---|
| 167 | /*!
|
---|
[8127] | 168 | A signal indicating, that an item has been attached/detached
|
---|
[4272] | 169 |
|
---|
[8127] | 170 | \param plotItem Plot item
|
---|
| 171 | \param on Attached/Detached
|
---|
[4272] | 172 | */
|
---|
[8127] | 173 | void itemAttached( QwtPolarItem *plotItem, bool on );
|
---|
[4272] | 174 |
|
---|
[8127] | 175 | /*!
|
---|
| 176 | A signal with the attributes how to update
|
---|
| 177 | the legend entries for a plot item.
|
---|
| 178 |
|
---|
| 179 | \param itemInfo Info about a plot, build from itemToInfo()
|
---|
| 180 |
|
---|
| 181 | \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend()
|
---|
[4272] | 182 | */
|
---|
[8127] | 183 | void legendDataChanged( const QVariant &itemInfo,
|
---|
| 184 | const QList<QwtLegendData> &data );
|
---|
[4272] | 185 |
|
---|
| 186 | /*!
|
---|
| 187 | A signal that is emitted, whenever the layout of the plot
|
---|
| 188 | has been recalculated.
|
---|
| 189 | */
|
---|
| 190 | void layoutChanged();
|
---|
| 191 |
|
---|
| 192 | public Q_SLOTS:
|
---|
| 193 | virtual void replot();
|
---|
| 194 | void autoRefresh();
|
---|
| 195 | void setAzimuthOrigin( double );
|
---|
| 196 |
|
---|
| 197 | protected:
|
---|
| 198 | virtual bool event( QEvent * );
|
---|
| 199 | virtual void resizeEvent( QResizeEvent * );
|
---|
| 200 |
|
---|
| 201 | virtual void updateLayout();
|
---|
| 202 |
|
---|
| 203 | virtual void drawItems( QPainter *painter,
|
---|
| 204 | const QwtScaleMap &radialMap, const QwtScaleMap &azimuthMap,
|
---|
| 205 | const QPointF &pole, double radius,
|
---|
| 206 | const QRectF &canvasRect ) const;
|
---|
| 207 |
|
---|
| 208 | private:
|
---|
[8127] | 209 | friend class QwtPolarItem;
|
---|
| 210 | void attachItem( QwtPolarItem *, bool );
|
---|
| 211 |
|
---|
[4272] | 212 | void initPlot( const QwtText & );
|
---|
| 213 |
|
---|
| 214 | class ScaleData;
|
---|
| 215 | class PrivateData;
|
---|
| 216 | PrivateData *d_data;
|
---|
| 217 | };
|
---|
| 218 |
|
---|
| 219 | #endif
|
---|