1
/***************************************************************************
2
qgssvgcache.h - SVG rendering and pixmap caching
4
begin : Sat Jul 17 2004
5
copyright : (C) 2004 by Lars Luthman
6
email : larsl at users dot sourceforge dot org
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
/* $Id: qgssvgcache.h,v 1.3 2005/04/02 09:44:11 rabla Exp $ */
29
/** This class is a singleton that does all the SVG rendering in QGIS.
30
When another part of the program needs to render an SVG file, it
31
calls the getPixmap() function to get a pixmap rendering of that
32
SVG file in the wanted scale. This class also does some extra
33
tricks to make Qt's SVG renderings look a little bit better, and
34
it caches the pixmaps to speed things up.
41
/** This function returns a pixmap containing a rendering of the SVG file
42
@c filename scaled by the factor @c scaleFactor. The pixmaps background
43
will be transparent, and if the file for some reason can't be rendered
44
the pixmap will be completely transparent. */
45
QPixmap getPixmap(QString filename, double scaleFactor);
47
/** Returns SVG picture in original size */
48
QPicture getPicture(QString filename);
50
/** This function clears the pixmap cache and forces all newly requested
51
pixmaps to be rendered again. Can be useful if the oversampling factor
52
has changed and you want to get rid of cached lower-quality pixmaps. */
55
/** When a pixmap is requested and it is not in the cache, it will be
56
loaded using a QPicture and rendered to a QPixmap. Since Qt does not do
57
any kind of anti-aliasing or smoothing, the QPicture is first rendered
58
to a pixmap that is larger than the requested size, and then it's scaled
59
down using QImage::smoothScale() to smooth out sharp edges and lines.
60
The oversampling factor determins how much larger the first pixmap is -
61
the larger this factor is the smoother the final pixmap will look, but
62
it will also take longer time to render and scale the image. This
63
function sets the oversampling factor. It should be larger than or equal
66
void setOversampling(int oversamplingFactor);
68
/** This function returns the oversampling factor.
69
@see setOversampling()
71
int getOversampling() const;
73
/** This function returns a reference to the singleton object. */
74
static inline QgsSVGCache& instance();
78
typedef std::map<QString, QPicture> PictureMap;
79
PictureMap pictureMap;
81
typedef std::map<std::pair<QString, double>, QPixmap> PixmapMap;
84
std::queue<PixmapMap::key_type> fifo;
91
QgsSVGCache& QgsSVGCache::instance() {
92
static QgsSVGCache obj;