Classes | Public Types | Public Member Functions | Protected Member Functions

QwtPlotRasterItem Class Reference

A class, which displays raster data. More...

#include <qwt_plot_rasteritem.h>

Inheritance diagram for QwtPlotRasterItem:
Inheritance graph
[legend]
Collaboration diagram for QwtPlotRasterItem:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

Public Types

enum  CachePolicy { NoCache, PaintCache, ScreenCache }

Public Member Functions

 QwtPlotRasterItem (const QString &title=QString::null)
 Constructor.
 QwtPlotRasterItem (const QwtText &title)
 Constructor.
virtual ~QwtPlotRasterItem ()
 Destructor.
void setAlpha (int alpha)
 Set an alpha value for the raster data.
int alpha () const
void setCachePolicy (CachePolicy)
CachePolicy cachePolicy () const
void invalidateCache ()
virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &rect) const
 Draw the raster data.
virtual QSize rasterHint (const QwtDoubleRect &) const
 Returns the recommended raster for a given rect.

Protected Member Functions

virtual QImage renderImage (const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtDoubleRect &area) const =0

Detailed Description

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.

See also:
QwtPlotSpectrogram

Definition at line 36 of file qwt_plot_rasteritem.h.


Member Enumeration Documentation

  • NoCache
    renderImage() is called, whenever the item has to be repainted
  • PaintCache
    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 only useful for improving the performance of hide/show operations. All other situations are already handled by the plot canvas cache.
  • ScreenCache
    The screen cache is an image in size of the screen. As long as the scales don't change the target image is scaled from the cache. This might improve the performance when resizing the plot widget, but suffers from scaling effects.

The default policy is NoCache

Enumerator:
NoCache 
PaintCache 
ScreenCache 

Definition at line 56 of file qwt_plot_rasteritem.h.


Constructor & Destructor Documentation

QwtPlotRasterItem::QwtPlotRasterItem ( const QString &  title = QString::null ) [explicit]

Constructor.

Definition at line 91 of file qwt_plot_rasteritem.cpp.

                                                        :
    QwtPlotItem(QwtText(title))
{
    init();
}
QwtPlotRasterItem::QwtPlotRasterItem ( const QwtText title ) [explicit]

Constructor.

Definition at line 98 of file qwt_plot_rasteritem.cpp.

                                                        :
    QwtPlotItem(title)
{
    init();
}
QwtPlotRasterItem::~QwtPlotRasterItem (  ) [virtual]

Destructor.

Definition at line 105 of file qwt_plot_rasteritem.cpp.

{
    delete d_data;
}

Member Function Documentation

int QwtPlotRasterItem::alpha (  ) const
Returns:
Alpha value of the raster item
See also:
setAlpha()

Definition at line 163 of file qwt_plot_rasteritem.cpp.

References QwtPlotRasterItem::PrivateData::alpha.

Referenced by setAlpha().

{
    return d_data->alpha;
}
QwtPlotRasterItem::CachePolicy QwtPlotRasterItem::cachePolicy (  ) const
Returns:
Cache policy
See also:
CachePolicy, setCachePolicy()

Definition at line 192 of file qwt_plot_rasteritem.cpp.

References QwtPlotRasterItem::PrivateData::cache, and QwtPlotRasterItem::PrivateData::ImageCache::policy.

{
    return d_data->cache.policy;
}
void QwtPlotRasterItem::draw ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRect &  canvasRect 
) const [virtual]

Draw the raster data.

Parameters:
painterPainter
xMapX-Scale Map
yMapY-Scale Map
canvasRectContents rect of the plot canvas

Implements QwtPlotItem.

Reimplemented in QwtPlotSpectrogram.

Definition at line 229 of file qwt_plot_rasteritem.cpp.

References QwtPlotRasterItem::PrivateData::alpha, QwtPlotItem::boundingRect(), QwtPlotRasterItem::PrivateData::cache, QwtPlotRasterItem::PrivateData::ImageCache::image, QwtPlotItem::invTransform(), NoCache, PaintCache, QwtPlotItem::paintRect(), QwtPlotRasterItem::PrivateData::ImageCache::policy, QwtPlotRasterItem::PrivateData::ImageCache::rect, renderImage(), ScreenCache, QwtScaleMap::setPaintInterval(), QwtPlotRasterItem::PrivateData::ImageCache::size, toRgba(), and QwtPlotItem::transform().

{
    if ( canvasRect.isEmpty() || d_data->alpha == 0 )
        return;

    QwtDoubleRect area = invTransform(xMap, yMap, canvasRect);
    if ( boundingRect().isValid() )
        area &= boundingRect();

    const QRect paintRect = transform(xMap, yMap, area);
    if ( !paintRect.isValid() )
        return;

    QImage image;

    bool doCache = true;
    if ( painter->device()->devType() == QInternal::Printer 
            || painter->device()->devType() == QInternal::Picture )
    {
        doCache = false;
    }

    if ( !doCache || d_data->cache.policy == NoCache )
    {
        image = renderImage(xMap, yMap, area);
        if ( d_data->alpha >= 0 && d_data->alpha < 255 )
            image = toRgba(image, d_data->alpha);

    }
    else if ( d_data->cache.policy == PaintCache )
    {
        if ( d_data->cache.image.isNull() || d_data->cache.rect != area
            || d_data->cache.size != paintRect.size() )
        {
            d_data->cache.image = renderImage(xMap, yMap, area);
            d_data->cache.rect = area;
            d_data->cache.size = paintRect.size();
        }

        image = d_data->cache.image;
        if ( d_data->alpha >= 0 && d_data->alpha < 255 )
            image = toRgba(image, d_data->alpha);
    }
    else if ( d_data->cache.policy == ScreenCache )
    {
        const QSize screenSize =
            QApplication::desktop()->screenGeometry().size();

        if ( paintRect.width() > screenSize.width() ||
            paintRect.height() > screenSize.height() )
        {
            image = renderImage(xMap, yMap, area);
        }
        else
        {
            if ( d_data->cache.image.isNull() || d_data->cache.rect != area )
            {
                QwtScaleMap cacheXMap = xMap;
                cacheXMap.setPaintInterval( 0, screenSize.width());

                QwtScaleMap cacheYMap = yMap;
                cacheYMap.setPaintInterval(screenSize.height(), 0);

                d_data->cache.image = renderImage(
                    cacheXMap, cacheYMap, area);
                d_data->cache.rect = area;
                d_data->cache.size = paintRect.size();
            }

            image = d_data->cache.image;
        }
        image = toRgba(image, d_data->alpha);
    }

    painter->drawImage(paintRect, image);
}
void QwtPlotRasterItem::invalidateCache (  )
QSize QwtPlotRasterItem::rasterHint ( const QwtDoubleRect  ) const [virtual]

Returns the recommended raster for a given rect.

F.e the raster hint can be used to limit the resolution of the image that is rendered.

The default implementation returns an invalid size (QSize()), what means: no hint.

Reimplemented in QwtPlotSpectrogram.

Definition at line 217 of file qwt_plot_rasteritem.cpp.

{
    return QSize();
}
virtual QImage QwtPlotRasterItem::renderImage ( const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QwtDoubleRect area 
) const [protected, pure virtual]

Renders an image for an area

The format of the image must be QImage::Format_Indexed8, QImage::Format_RGB32 or QImage::Format_ARGB32

Parameters:
xMapMaps x-values into pixel coordinates.
yMapMaps y-values into pixel coordinates.
areaRequested area for the image in scale coordinates

Implemented in QwtPlotSpectrogram.

Referenced by draw().

void QwtPlotRasterItem::setAlpha ( int  alpha )

Set an alpha value for the raster data.

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.

The alpha value is a value [0, 255] to control the transparency of the image. 0 represents a fully transparent color, while 255 represents a fully opaque color.

Parameters:
alphaAlpha value
  • alpha >= 0
    All alpha values of the pixels returned by renderImage() will be set to alpha, beside those with an alpha value of 0 (invalid pixels).
  • alpha < 0 The alpha values returned by renderImage() are not changed.

The default alpha value is -1.

See also:
alpha()

Definition at line 143 of file qwt_plot_rasteritem.cpp.

References alpha(), QwtPlotRasterItem::PrivateData::alpha, and QwtPlotItem::itemChanged().

{
    if ( alpha < 0 )
        alpha = -1;

    if ( alpha > 255 )
        alpha = 255;

    if ( alpha != d_data->alpha )
    {
        d_data->alpha = alpha;

        itemChanged();
    }
}
void QwtPlotRasterItem::setCachePolicy ( QwtPlotRasterItem::CachePolicy  policy )

Change the cache policy

The default policy is NoCache

Parameters:
policyCache policy
See also:
CachePolicy, cachePolicy()

Definition at line 176 of file qwt_plot_rasteritem.cpp.

References QwtPlotRasterItem::PrivateData::cache, invalidateCache(), QwtPlotItem::itemChanged(), and QwtPlotRasterItem::PrivateData::ImageCache::policy.

{
    if ( d_data->cache.policy != policy )
    {
        d_data->cache.policy = policy;

        invalidateCache();
        itemChanged();
    }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines