qwt_plot_item.h 8.15 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
2
3
4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6
7
8
9
10
11
12
13
14
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_PLOT_ITEM_H
#define QWT_PLOT_ITEM_H

#include "qwt_global.h"
#include "qwt_text.h"
Bryant's avatar
Bryant committed
15
16
17
18
19
#include "qwt_legend_data.h"
#include "qwt_graphic.h"
#include <qrect.h>
#include <qlist.h>
#include <qmetatype.h>
pixhawk's avatar
pixhawk committed
20
21
22
23

class QPainter;
class QwtScaleMap;
class QwtScaleDiv;
Bryant's avatar
Bryant committed
24
class QwtPlot;
pixhawk's avatar
pixhawk committed
25
26
27

/*!
  \brief Base class for items on the plot canvas
Bryant's avatar
Bryant committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

  A plot item is "something", that can be painted on the plot canvas,
  or only affects the scales of the plot widget. They can be categorized as:

  - Representator\n
    A "Representator" is an item that represents some sort of data
    on the plot canvas. The different representator classes are organized
    according to the characteristics of the data:
    - QwtPlotMarker
      Represents a point or a horizontal/vertical coordinate
    - QwtPlotCurve
      Represents a series of points
    - QwtPlotSpectrogram ( QwtPlotRasterItem )
      Represents raster data
    - ...

  - Decorators\n
    A "Decorator" is an item, that displays additional information, that
    is not related to any data:
    - QwtPlotGrid
    - QwtPlotScaleItem
    - QwtPlotSvgItem
    - ...

  Depending on the QwtPlotItem::ItemAttribute flags, an item is included
  into autoscaling or has an entry on the legend.

  Before misusing the existing item classes it might be better to
  implement a new type of plot item
  ( don't implement a watermark as spectrogram ).
  Deriving a new type of QwtPlotItem primarily means to implement
  the YourPlotItem::draw() method.

  \sa The cpuplot example shows the implementation of additional plot items.
pixhawk's avatar
pixhawk committed
62
63
*/

Bryant's avatar
Bryant committed
64
class QWT_EXPORT QwtPlotItem
pixhawk's avatar
pixhawk committed
65
66
{
public:
Bryant's avatar
Bryant committed
67
68
69
70
71
72
73
74
75
    /*!
        \brief Runtime type information

        RttiValues is used to cast plot items, without
        having to enable runtime type information of the compiler.
     */
    enum RttiValues
    {
        //! Unspecific value, that can be used, when it doesn't matter
pixhawk's avatar
pixhawk committed
76
77
        Rtti_PlotItem = 0,

Bryant's avatar
Bryant committed
78
        //! For QwtPlotGrid
pixhawk's avatar
pixhawk committed
79
        Rtti_PlotGrid,
Bryant's avatar
Bryant committed
80
81

        //! For QwtPlotScaleItem
pixhawk's avatar
pixhawk committed
82
        Rtti_PlotScale,
Bryant's avatar
Bryant committed
83
84
85
86
87

        //! For QwtPlotLegendItem
        Rtti_PlotLegend,

        //! For QwtPlotMarker
pixhawk's avatar
pixhawk committed
88
        Rtti_PlotMarker,
Bryant's avatar
Bryant committed
89
90

        //! For QwtPlotCurve
pixhawk's avatar
pixhawk committed
91
        Rtti_PlotCurve,
Bryant's avatar
Bryant committed
92
93
94
95
96
97
98
99

        //! For QwtPlotSpectroCurve
        Rtti_PlotSpectroCurve,

        //! For QwtPlotIntervalCurve
        Rtti_PlotIntervalCurve,

        //! For QwtPlotHistogram
pixhawk's avatar
pixhawk committed
100
        Rtti_PlotHistogram,
Bryant's avatar
Bryant committed
101
102

        //! For QwtPlotSpectrogram
pixhawk's avatar
pixhawk committed
103
        Rtti_PlotSpectrogram,
Bryant's avatar
Bryant committed
104
105

        //! For QwtPlotSvgItem
pixhawk's avatar
pixhawk committed
106
107
        Rtti_PlotSVG,

Bryant's avatar
Bryant committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
        //! For QwtPlotTradingCurve
        Rtti_PlotTradingCurve,

        //! For QwtPlotBarChart
        Rtti_PlotBarChart,

        //! For QwtPlotMultiBarChart
        Rtti_PlotMultiBarChart,

        //! For QwtPlotShapeItem
        Rtti_PlotShape,

        //! For QwtPlotTextLabel
        Rtti_PlotTextLabel,

        //! For QwtPlotZoneItem
        Rtti_PlotZone,

        /*! 
           Values >= Rtti_PlotUserItem are reserved for plot items
           not implemented in the Qwt library.
         */
pixhawk's avatar
pixhawk committed
130
131
132
        Rtti_PlotUserItem = 1000
    };

Bryant's avatar
Bryant committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    /*!
       \brief Plot Item Attributes

       Various aspects of a plot widget depend on the attributes of
       the attached plot items. If and how a single plot item 
       participates in these updates depends on its attributes.
       
       \sa setItemAttribute(), testItemAttribute(), ItemInterest
     */
    enum ItemAttribute
    {
        //! The item is represented on the legend.
        Legend = 0x01,

        /*!
           The boundingRect() of the item is included in the
           autoscaling calculation as long as its width or height
           is >= 0.0.
         */
        AutoScale = 0x02,

        /*!
           The item needs extra space to display something outside
           its bounding rectangle. 
           \sa getCanvasMarginHint()
         */
        Margins = 0x04
pixhawk's avatar
pixhawk committed
160
161
    };

Bryant's avatar
Bryant committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    //! Plot Item Attributes
    typedef QFlags<ItemAttribute> ItemAttributes;

    /*!
       \brief Plot Item Interests

       Plot items might depend on the situation of the corresponding
       plot widget. By enabling an interest the plot item will be
       notified, when the corresponding attribute of the plot widgets
       has changed.

       \sa setItemAttribute(), testItemAttribute(), ItemInterest
     */
    enum ItemInterest
    {
        /*! 
           The item is interested in updates of the scales
           \sa updateScaleDiv()
         */
        ScaleInterest = 0x01,

        /*! 
           The item is interested in updates of the legend ( of other items )
           This flag is intended for items, that want to implement a legend
           for displaying entries of other plot item.

           \note If the plot item wants to be represented on a legend
                 enable QwtPlotItem::Legend instead.

           \sa updateLegend()
         */
        LegendInterest = 0x02
pixhawk's avatar
pixhawk committed
194
195
    };

Bryant's avatar
Bryant committed
196
197
    //! Plot Item Interests
    typedef QFlags<ItemInterest> ItemInterests;
pixhawk's avatar
pixhawk committed
198

Bryant's avatar
Bryant committed
199
200
201
202
203
204
    //! Render hints
    enum RenderHint
    {
        //! Enable antialiasing
        RenderAntialiased = 0x1
    };
pixhawk's avatar
pixhawk committed
205

Bryant's avatar
Bryant committed
206
207
    //! Render hints
    typedef QFlags<RenderHint> RenderHints;
pixhawk's avatar
pixhawk committed
208

Bryant's avatar
Bryant committed
209
210
211
212
213
    explicit QwtPlotItem( const QwtText &title = QwtText() );
    virtual ~QwtPlotItem();

    void attach( QwtPlot *plot );
    void detach();
pixhawk's avatar
pixhawk committed
214
215

    QwtPlot *plot() const;
216

Bryant's avatar
Bryant committed
217
218
    void setTitle( const QString &title );
    void setTitle( const QwtText &title );
pixhawk's avatar
pixhawk committed
219
220
221
222
    const QwtText &title() const;

    virtual int rtti() const;

Bryant's avatar
Bryant committed
223
224
    void setItemAttribute( ItemAttribute, bool on = true );
    bool testItemAttribute( ItemAttribute ) const;
pixhawk's avatar
pixhawk committed
225

Bryant's avatar
Bryant committed
226
227
228
229
230
231
232
233
234
235
236
    void setItemInterest( ItemInterest, bool on = true );
    bool testItemInterest( ItemInterest ) const;

    void setRenderHint( RenderHint, bool on = true );
    bool testRenderHint( RenderHint ) const;

    void setRenderThreadCount( uint numThreads );
    uint renderThreadCount() const;

    void setLegendIconSize( const QSize & );
    QSize legendIconSize() const;
pixhawk's avatar
pixhawk committed
237

238
    double z() const;
Bryant's avatar
Bryant committed
239
    void setZ( double z );
pixhawk's avatar
pixhawk committed
240
241
242

    void show();
    void hide();
Bryant's avatar
Bryant committed
243
    virtual void setVisible( bool );
pixhawk's avatar
pixhawk committed
244
245
    bool isVisible () const;

Bryant's avatar
Bryant committed
246
    void setAxes( int xAxis, int yAxis );
pixhawk's avatar
pixhawk committed
247

Bryant's avatar
Bryant committed
248
    void setXAxis( int axis );
pixhawk's avatar
pixhawk committed
249
250
    int xAxis() const;

Bryant's avatar
Bryant committed
251
    void setYAxis( int axis );
pixhawk's avatar
pixhawk committed
252
253
254
    int yAxis() const;

    virtual void itemChanged();
Bryant's avatar
Bryant committed
255
    virtual void legendChanged();
pixhawk's avatar
pixhawk committed
256
257
258
259
260
261
262
263
264

    /*!
      \brief Draw the item

      \param painter Painter
      \param xMap Maps x-values into pixel coordinates.
      \param yMap Maps y-values into pixel coordinates.
      \param canvasRect Contents rect of the canvas in painter coordinates
    */
Bryant's avatar
Bryant committed
265
266
267
268
269
    virtual void draw( QPainter *painter,
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
        const QRectF &canvasRect ) const = 0;

    virtual QRectF boundingRect() const;
pixhawk's avatar
pixhawk committed
270

Bryant's avatar
Bryant committed
271
272
273
274
    virtual void getCanvasMarginHint( 
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
        const QRectF &canvasSize,
        double &left, double &top, double &right, double &bottom) const;
pixhawk's avatar
pixhawk committed
275

Bryant's avatar
Bryant committed
276
277
    virtual void updateScaleDiv( 
        const QwtScaleDiv&, const QwtScaleDiv& );
pixhawk's avatar
pixhawk committed
278

Bryant's avatar
Bryant committed
279
280
    virtual void updateLegend( const QwtPlotItem *,
        const QList<QwtLegendData> & );
pixhawk's avatar
pixhawk committed
281

Bryant's avatar
Bryant committed
282
283
    QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const;
    QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const;
284

Bryant's avatar
Bryant committed
285
286
287
288
289
290
    virtual QList<QwtLegendData> legendData() const;

    virtual QwtGraphic legendIcon( int index, const QSizeF  & ) const;

protected:
    QwtGraphic defaultIcon( const QBrush &, const QSizeF & ) const;
pixhawk's avatar
pixhawk committed
291
292
293
294
295
296
297
298
299

private:
    // Disabled copy constructor and operator=
    QwtPlotItem( const QwtPlotItem & );
    QwtPlotItem &operator=( const QwtPlotItem & );

    class PrivateData;
    PrivateData *d_data;
};
300

Bryant's avatar
Bryant committed
301
302
303
304
305
306
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemAttributes )
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemInterests )
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::RenderHints )

Q_DECLARE_METATYPE( QwtPlotItem * )

pixhawk's avatar
pixhawk committed
307
#endif