qwt_plot_rasteritem.h 4.68 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12
/* -*- 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_RASTERITEM_H
#define QWT_PLOT_RASTERITEM_H

Bryant's avatar
Bryant committed
13 14 15
#include "qwt_global.h"
#include "qwt_plot_item.h"
#include "qwt_interval.h"
pixhawk's avatar
pixhawk committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <qglobal.h>
#include <qstring.h>
#include <qimage.h>

/*!
  \brief A class, which displays raster data

  Raster data is a grid of pixel values, that can be represented
  as a QImage. It is used for many types of information like
  spectrograms, cartograms, geographical maps ...

  Often a plot has several types of raster data organized in layers.
  ( f.e a geographical map, with weather statistics ).
  Using setAlpha() raster items can be stacked easily.

  QwtPlotRasterItem is only implemented for images of the following formats:
  QImage::Format_Indexed8, QImage::Format_ARGB32.

  \sa QwtPlotSpectrogram
*/

class QWT_EXPORT QwtPlotRasterItem: public QwtPlotItem
{
public:
    /*!
Bryant's avatar
Bryant committed
41
      \brief Cache policy
pixhawk's avatar
pixhawk committed
42 43
      The default policy is NoCache
     */
Bryant's avatar
Bryant committed
44 45 46 47 48
    enum CachePolicy
    {
        /*!
          renderImage() is called each time the item has to be repainted
         */
pixhawk's avatar
pixhawk committed
49
        NoCache,
Bryant's avatar
Bryant committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

        /*!
          renderImage() is called, whenever the image cache is not valid,
          or the scales, or the size of the canvas has changed. 

          This type of cache is useful for improving the performance 
          of hide/show operations or manipulations of the alpha value. 
          All other situations are handled by the canvas backing store.
         */
        PaintCache
    };

    /*!
        Attributes to modify the drawing algorithm.
        \sa setPaintAttribute(), testPaintAttribute()
    */
    enum PaintAttribute
    {
        /*!
          When the image is rendered according to the data pixels
          ( QwtRasterData::pixelHint() ) it can be expanded to paint
          device resolution before it is passed to QPainter. 
          The expansion algorithm rounds the pixel borders in the same 
          way as the axis ticks, what is usually better than the
          scaling algorithm implemented in Qt.
          Disabling this flag might make sense, to reduce the size of a 
          document/file. If this is possible for a document format
          depends on the implementation of the specific QPaintEngine.
         */

        PaintInDeviceResolution = 1
pixhawk's avatar
pixhawk committed
81 82
    };

Bryant's avatar
Bryant committed
83 84 85 86 87
    //! Paint attributes
    typedef QFlags<PaintAttribute> PaintAttributes;

    explicit QwtPlotRasterItem( const QString& title = QString::null );
    explicit QwtPlotRasterItem( const QwtText& title );
pixhawk's avatar
pixhawk committed
88 89
    virtual ~QwtPlotRasterItem();

Bryant's avatar
Bryant committed
90 91 92 93
    void setPaintAttribute( PaintAttribute, bool on = true );
    bool testPaintAttribute( PaintAttribute ) const;

    void setAlpha( int alpha );
pixhawk's avatar
pixhawk committed
94 95
    int alpha() const;

Bryant's avatar
Bryant committed
96
    void setCachePolicy( CachePolicy );
pixhawk's avatar
pixhawk committed
97 98 99 100
    CachePolicy cachePolicy() const;

    void invalidateCache();

Bryant's avatar
Bryant committed
101 102 103
    virtual void draw( QPainter *p,
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
        const QRectF &rect ) const;
pixhawk's avatar
pixhawk committed
104

Bryant's avatar
Bryant committed
105
    virtual QRectF pixelHint( const QRectF & ) const;
pixhawk's avatar
pixhawk committed
106

Bryant's avatar
Bryant committed
107 108
    virtual QwtInterval interval(Qt::Axis) const;
    virtual QRectF boundingRect() const;
pixhawk's avatar
pixhawk committed
109

Bryant's avatar
Bryant committed
110
protected:
111
    /*!
Bryant's avatar
Bryant committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
      \brief Render an image 

      An implementation of render() might iterate over all
      pixels of imageRect. Each pixel has to be translated into 
      the corresponding position in scale coordinates using the maps.
      This position can be used to look up a value in a implementation
      specific way and to map it into a color.

      \param xMap X-Scale Map
      \param yMap Y-Scale Map
      \param area Requested area for the image in scale coordinates
      \param imageSize Requested size of the image
   
      \return Rendered image
     */
    virtual QImage renderImage( const QwtScaleMap &xMap,
        const QwtScaleMap &yMap, const QRectF &area,
        const QSize &imageSize ) const = 0;
130

Bryant's avatar
Bryant committed
131 132 133
    virtual QwtScaleMap imageMap( Qt::Orientation,
        const QwtScaleMap &map, const QRectF &area,
        const QSize &imageSize, double pixelSize) const;
pixhawk's avatar
pixhawk committed
134 135 136 137 138 139 140

private:
    QwtPlotRasterItem( const QwtPlotRasterItem & );
    QwtPlotRasterItem &operator=( const QwtPlotRasterItem & );

    void init();

Bryant's avatar
Bryant committed
141 142 143 144 145
    QImage compose( const QwtScaleMap &, const QwtScaleMap &,
        const QRectF &imageArea, const QRectF &paintRect,
        const QSize &imageSize, bool doCache) const;


pixhawk's avatar
pixhawk committed
146 147 148 149
    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
150 151
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotRasterItem::PaintAttributes )

pixhawk's avatar
pixhawk committed
152
#endif