[89] | 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_ITEM_H
|
---|
| 11 | #define QWT_PLOT_ITEM_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include "qwt_legend_itemmanager.h"
|
---|
| 15 | #include "qwt_text.h"
|
---|
| 16 | #include "qwt_double_rect.h"
|
---|
| 17 |
|
---|
| 18 | class QString;
|
---|
| 19 | class QRect;
|
---|
| 20 | class QPainter;
|
---|
| 21 | class QWidget;
|
---|
| 22 | class QwtPlot;
|
---|
| 23 | class QwtLegend;
|
---|
| 24 | class QwtScaleMap;
|
---|
| 25 | class QwtScaleDiv;
|
---|
| 26 |
|
---|
| 27 | /*!
|
---|
| 28 | \brief Base class for items on the plot canvas
|
---|
| 29 |
|
---|
| 30 | A plot item is "something", that can be painted on the plot canvas,
|
---|
| 31 | or only affects the scales of the plot widget. They can be categorized as:
|
---|
| 32 |
|
---|
| 33 | - Representator\n
|
---|
| 34 | A "Representator" is an item that represents some sort of data
|
---|
| 35 | on the plot canvas. The different representator classes are organized
|
---|
| 36 | according to the characteristics of the data:
|
---|
| 37 | - QwtPlotMarker
|
---|
| 38 | Represents a point or a horizontal/vertical coordinate
|
---|
| 39 | - QwtPlotCurve
|
---|
| 40 | Represents a series of points
|
---|
| 41 | - QwtPlotSpectrogram ( QwtPlotRasterItem )
|
---|
| 42 | Represents raster data
|
---|
| 43 | - ...
|
---|
| 44 |
|
---|
| 45 | - Decorators\n
|
---|
| 46 | A "Decorator" is an item, that displays additional information, that
|
---|
| 47 | is not related to any data:
|
---|
| 48 | - QwtPlotGrid
|
---|
| 49 | - QwtPlotScaleItem
|
---|
| 50 | - QwtPlotSvgItem
|
---|
| 51 | - ...
|
---|
| 52 |
|
---|
| 53 | Depending on the QwtPlotItem::ItemAttribute flags, an item is included
|
---|
| 54 | into autoscaling or has an entry on the legnd.
|
---|
| 55 |
|
---|
| 56 | Before misusing the existing item classes it might be better to
|
---|
| 57 | implement a new type of plot item
|
---|
| 58 | ( don't implement a watermark as spectrogram ).
|
---|
| 59 | Deriving a new type of QwtPlotItem primarily means to implement
|
---|
| 60 | the YourPlotItem::draw() method.
|
---|
| 61 |
|
---|
| 62 | \sa The cpuplot example shows the implementation of additional plot items.
|
---|
| 63 | */
|
---|
| 64 |
|
---|
| 65 | class QWT_EXPORT QwtPlotItem: public QwtLegendItemManager
|
---|
| 66 | {
|
---|
| 67 | public:
|
---|
| 68 | /*!
|
---|
| 69 | \brief Runtime type information
|
---|
| 70 |
|
---|
| 71 | RttiValues is used to cast plot items, without
|
---|
| 72 | having to enable runtime type information of the compiler.
|
---|
| 73 | */
|
---|
| 74 | enum RttiValues
|
---|
| 75 | {
|
---|
| 76 | Rtti_PlotItem = 0,
|
---|
| 77 |
|
---|
| 78 | Rtti_PlotGrid,
|
---|
| 79 | Rtti_PlotScale,
|
---|
| 80 | Rtti_PlotMarker,
|
---|
| 81 | Rtti_PlotCurve,
|
---|
| 82 | Rtti_PlotHistogram,
|
---|
| 83 | Rtti_PlotSpectrogram,
|
---|
| 84 | Rtti_PlotSVG,
|
---|
| 85 |
|
---|
| 86 | Rtti_PlotUserItem = 1000
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 | /*!
|
---|
| 90 | Plot Item Attributes
|
---|
| 91 |
|
---|
| 92 | - Legend\n
|
---|
| 93 | The item is represented on the legend.
|
---|
| 94 | - AutoScale \n
|
---|
| 95 | The boundingRect() of the item is included in the
|
---|
| 96 | autoscaling calculation.
|
---|
| 97 |
|
---|
| 98 | \sa setItemAttribute(), testItemAttribute()
|
---|
| 99 | */
|
---|
| 100 | enum ItemAttribute
|
---|
| 101 | {
|
---|
| 102 | Legend = 1,
|
---|
| 103 | AutoScale = 2
|
---|
| 104 | };
|
---|
| 105 |
|
---|
| 106 | #if QT_VERSION >= 0x040000
|
---|
| 107 | //! Render hints
|
---|
| 108 | enum RenderHint
|
---|
| 109 | {
|
---|
| 110 | RenderAntialiased = 1
|
---|
| 111 | };
|
---|
| 112 | #endif
|
---|
| 113 |
|
---|
| 114 | explicit QwtPlotItem(const QwtText &title = QwtText());
|
---|
| 115 | virtual ~QwtPlotItem();
|
---|
| 116 |
|
---|
| 117 | void attach(QwtPlot *plot);
|
---|
| 118 |
|
---|
| 119 | /*!
|
---|
| 120 | \brief This method detaches a QwtPlotItem from any QwtPlot it has been
|
---|
| 121 | associated with.
|
---|
| 122 |
|
---|
| 123 | detach() is equivalent to calling attach( NULL )
|
---|
| 124 | \sa attach( QwtPlot* plot )
|
---|
| 125 | */
|
---|
| 126 | void detach() { attach(NULL); }
|
---|
| 127 |
|
---|
| 128 | QwtPlot *plot() const;
|
---|
| 129 |
|
---|
| 130 | void setTitle(const QString &title);
|
---|
| 131 | void setTitle(const QwtText &title);
|
---|
| 132 | const QwtText &title() const;
|
---|
| 133 |
|
---|
| 134 | virtual int rtti() const;
|
---|
| 135 |
|
---|
| 136 | void setItemAttribute(ItemAttribute, bool on = true);
|
---|
| 137 | bool testItemAttribute(ItemAttribute) const;
|
---|
| 138 |
|
---|
| 139 | #if QT_VERSION >= 0x040000
|
---|
| 140 | void setRenderHint(RenderHint, bool on = true);
|
---|
| 141 | bool testRenderHint(RenderHint) const;
|
---|
| 142 | #endif
|
---|
| 143 |
|
---|
| 144 | double z() const;
|
---|
| 145 | void setZ(double z);
|
---|
| 146 |
|
---|
| 147 | void show();
|
---|
| 148 | void hide();
|
---|
| 149 | virtual void setVisible(bool);
|
---|
| 150 | bool isVisible () const;
|
---|
| 151 |
|
---|
| 152 | void setAxis(int xAxis, int yAxis);
|
---|
| 153 |
|
---|
| 154 | void setXAxis(int axis);
|
---|
| 155 | int xAxis() const;
|
---|
| 156 |
|
---|
| 157 | void setYAxis(int axis);
|
---|
| 158 | int yAxis() const;
|
---|
| 159 |
|
---|
| 160 | virtual void itemChanged();
|
---|
| 161 |
|
---|
| 162 | /*!
|
---|
| 163 | \brief Draw the item
|
---|
| 164 |
|
---|
| 165 | \param painter Painter
|
---|
| 166 | \param xMap Maps x-values into pixel coordinates.
|
---|
| 167 | \param yMap Maps y-values into pixel coordinates.
|
---|
| 168 | \param canvasRect Contents rect of the canvas in painter coordinates
|
---|
| 169 | */
|
---|
| 170 | virtual void draw(QPainter *painter,
|
---|
| 171 | const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
---|
| 172 | const QRect &canvasRect) const = 0;
|
---|
| 173 |
|
---|
| 174 | virtual QwtDoubleRect boundingRect() const;
|
---|
| 175 |
|
---|
| 176 | virtual void updateLegend(QwtLegend *) const;
|
---|
| 177 | virtual void updateScaleDiv(const QwtScaleDiv&,
|
---|
| 178 | const QwtScaleDiv&);
|
---|
| 179 |
|
---|
| 180 | virtual QWidget *legendItem() const;
|
---|
| 181 |
|
---|
| 182 | QwtDoubleRect scaleRect(const QwtScaleMap &, const QwtScaleMap &) const;
|
---|
| 183 | QRect paintRect(const QwtScaleMap &, const QwtScaleMap &) const;
|
---|
| 184 |
|
---|
| 185 | QRect transform(const QwtScaleMap &, const QwtScaleMap &,
|
---|
| 186 | const QwtDoubleRect&) const;
|
---|
| 187 | QwtDoubleRect invTransform(const QwtScaleMap &, const QwtScaleMap &,
|
---|
| 188 | const QRect&) const;
|
---|
| 189 |
|
---|
| 190 | private:
|
---|
| 191 | // Disabled copy constructor and operator=
|
---|
| 192 | QwtPlotItem( const QwtPlotItem & );
|
---|
| 193 | QwtPlotItem &operator=( const QwtPlotItem & );
|
---|
| 194 |
|
---|
| 195 | class PrivateData;
|
---|
| 196 | PrivateData *d_data;
|
---|
| 197 | };
|
---|
| 198 |
|
---|
| 199 | #endif
|
---|