A class, which displays raster data. More...
#include <qwt_plot_rasteritem.h>


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 |
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.
Definition at line 36 of file qwt_plot_rasteritem.h.
The default policy is NoCache
Definition at line 56 of file qwt_plot_rasteritem.h.
{
NoCache,
PaintCache,
ScreenCache
};
| 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] |
| int QwtPlotRasterItem::alpha | ( | ) | const |
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 |
Definition at line 192 of file qwt_plot_rasteritem.cpp.
References QwtPlotRasterItem::PrivateData::cache, and QwtPlotRasterItem::PrivateData::ImageCache::policy.
| void QwtPlotRasterItem::draw | ( | QPainter * | painter, |
| const QwtScaleMap & | xMap, | ||
| const QwtScaleMap & | yMap, | ||
| const QRect & | canvasRect | ||
| ) | const [virtual] |
Draw the raster data.
| painter | Painter |
| xMap | X-Scale Map |
| yMap | Y-Scale Map |
| canvasRect | Contents 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 | ( | ) |
Invalidate the paint cache
Definition at line 201 of file qwt_plot_rasteritem.cpp.
References QwtPlotRasterItem::PrivateData::cache, QwtPlotRasterItem::PrivateData::ImageCache::image, QwtPlotRasterItem::PrivateData::ImageCache::rect, and QwtPlotRasterItem::PrivateData::ImageCache::size.
Referenced by setCachePolicy(), QwtPlotSpectrogram::setColorMap(), and QwtPlotSpectrogram::setData().
| 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
| xMap | Maps x-values into pixel coordinates. |
| yMap | Maps y-values into pixel coordinates. |
| area | Requested 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.
| alpha | Alpha value |
The default alpha value is -1.
Definition at line 143 of file qwt_plot_rasteritem.cpp.
References alpha(), QwtPlotRasterItem::PrivateData::alpha, and QwtPlotItem::itemChanged().
| void QwtPlotRasterItem::setCachePolicy | ( | QwtPlotRasterItem::CachePolicy | policy ) |
Change the cache policy
The default policy is NoCache
| policy | Cache policy |
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();
}
}
1.7.2