123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
- * Qwt Widget Library
- * Copyright (C) 1997 Josef Wilgen
- * Copyright (C) 2002 Uwe Rathmann
- *
- * 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"
- #include "qwt_legend_data.h"
- #include "qwt_graphic.h"
- #include <qrect.h>
- #include <qlist.h>
- #include <qmetatype.h>
- class QPainter;
- class QwtScaleMap;
- class QwtScaleDiv;
- class QwtPlot;
- /*!
- \brief Base class for items on the plot canvas
- 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.
- */
- class QWT_EXPORT QwtPlotItem
- {
- public:
- /*!
- \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
- Rtti_PlotItem = 0,
- //! For QwtPlotGrid
- Rtti_PlotGrid,
- //! For QwtPlotScaleItem
- Rtti_PlotScale,
- //! For QwtPlotLegendItem
- Rtti_PlotLegend,
- //! For QwtPlotMarker
- Rtti_PlotMarker,
- //! For QwtPlotCurve
- Rtti_PlotCurve,
- //! For QwtPlotSpectroCurve
- Rtti_PlotSpectroCurve,
- //! For QwtPlotIntervalCurve
- Rtti_PlotIntervalCurve,
- //! For QwtPlotHistogram
- Rtti_PlotHistogram,
- //! For QwtPlotSpectrogram
- Rtti_PlotSpectrogram,
- //! For QwtPlotSvgItem
- Rtti_PlotSVG,
- //! 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.
- */
- Rtti_PlotUserItem = 1000
- };
- /*!
- \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
- };
- //! 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
- };
- //! Plot Item Interests
- typedef QFlags<ItemInterest> ItemInterests;
- //! Render hints
- enum RenderHint
- {
- //! Enable antialiasing
- RenderAntialiased = 0x1
- };
- //! Render hints
- typedef QFlags<RenderHint> RenderHints;
- explicit QwtPlotItem( const QwtText &title = QwtText() );
- virtual ~QwtPlotItem();
- void attach( QwtPlot *plot );
- void detach();
- QwtPlot *plot() const;
- void setTitle( const QString &title );
- void setTitle( const QwtText &title );
- const QwtText &title() const;
- virtual int rtti() const;
- void setItemAttribute( ItemAttribute, bool on = true );
- bool testItemAttribute( ItemAttribute ) const;
- 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;
- double z() const;
- void setZ( double z );
- void show();
- void hide();
- virtual void setVisible( bool );
- bool isVisible () const;
- void setAxes( int xAxis, int yAxis );
- void setXAxis( int axis );
- int xAxis() const;
- void setYAxis( int axis );
- int yAxis() const;
- virtual void itemChanged();
- virtual void legendChanged();
- /*!
- \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
- */
- virtual void draw( QPainter *painter,
- const QwtScaleMap &xMap, const QwtScaleMap &yMap,
- const QRectF &canvasRect ) const = 0;
- virtual QRectF boundingRect() const;
- virtual void getCanvasMarginHint(
- const QwtScaleMap &xMap, const QwtScaleMap &yMap,
- const QRectF &canvasRect,
- double &left, double &top, double &right, double &bottom) const;
- virtual void updateScaleDiv(
- const QwtScaleDiv&, const QwtScaleDiv& );
- virtual void updateLegend( const QwtPlotItem *,
- const QList<QwtLegendData> & );
- QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const;
- QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const;
- virtual QList<QwtLegendData> legendData() const;
- virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
- protected:
- QwtGraphic defaultIcon( const QBrush &, const QSizeF & ) const;
- private:
- // Disabled copy constructor and operator=
- QwtPlotItem( const QwtPlotItem & );
- QwtPlotItem &operator=( const QwtPlotItem & );
- class PrivateData;
- PrivateData *d_data;
- };
- 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 * )
- #endif
|