2012-09-24 02:28:15 +02:00
class QgsSvgCacheEntry
{
%TypeHeaderCode
#include <qgssvgcache.h>
%End
public:
QgsSvgCacheEntry();
2014-01-26 18:35:21 +01:00
/** Constructor.
* @param file Absolute path to SVG file (relative paths are not resolved).
* @param size
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @param fill color of fill
* @param outline color of outline
2015-07-31 20:27:57 +02:00
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
2014-01-26 18:35:21 +01:00
*/
2015-07-31 20:27:57 +02:00
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
2012-09-24 02:28:15 +02:00
~QgsSvgCacheEntry();
2015-07-31 20:27:57 +02:00
//! Absolute path to SVG file
2012-09-24 02:28:15 +02:00
QString file;
2015-07-31 20:27:57 +02:00
//! Lookup key used by QgsSvgCache's hashtable (relative or absolute path). Needed for removal from the hashtable
QString lookupKey;
2014-01-26 18:35:21 +01:00
double size; //size in pixels (cast to int for QImage)
2012-09-24 02:28:15 +02:00
double outlineWidth;
double widthScaleFactor;
double rasterScaleFactor;
QColor fill;
QColor outline;
QImage* image;
QPicture* picture;
//content (with params replaced)
QByteArray svgContent;
//keep entries on a least, sorted by last access
QgsSvgCacheEntry* nextEntry;
QgsSvgCacheEntry* previousEntry;
2015-07-29 11:52:14 +02:00
/** Don't consider image, picture, last used timestamp for comparison*/
2012-09-24 02:28:15 +02:00
bool operator==( const QgsSvgCacheEntry& other ) const;
2015-07-29 11:52:14 +02:00
/** Return memory usage in bytes*/
2012-09-24 02:28:15 +02:00
int dataSize() const;
};
2015-07-29 11:52:14 +02:00
/** A cache for images / pictures derived from svg files. This class supports parameter replacement in svg files
2012-09-24 02:28:15 +02:00
according to the svg params specification (http://www.w3.org/TR/2009/WD-SVGParamPrimer-20090616/). Supported are
the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g. <circle fill="param(fill-color red)" stroke="param(pen-color black)" stroke-width="param(outline-width 1)"*/
2012-11-27 00:49:38 +01:00
class QgsSvgCache : QObject
2012-09-24 02:28:15 +02:00
{
%TypeHeaderCode
#include <qgssvgcache.h>
%End
public:
static QgsSvgCache* instance();
~QgsSvgCache();
2014-01-27 09:22:24 +01:00
/** Get SVG as QImage.
2014-01-26 18:35:21 +01:00
* @param file Absolute or relative path to SVG file.
* @param size size of cached image
* @param fill color of fill
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @param fitsInCache
*/
const QImage& svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
2012-12-09 14:09:22 -07:00
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
2014-01-26 18:35:21 +01:00
/** Get SVG as QPicture&.
* @param file Absolute or relative path to SVG file.
* @param size size of cached image
* @param fill color of fill
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
* @param forceVectorOutput
*/
const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );
2012-09-24 02:28:15 +02:00
2015-07-29 11:52:14 +02:00
/** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
2012-09-24 02:28:15 +02:00
default values in the svg file, only the first one is considered*/
void containsParams( const QString& path, bool& hasFillParam, QColor& defaultFillColor, bool& hasOutlineParam, QColor& defaultOutlineColor, bool& hasOutlineWidthParam,
double& defaultOutlineWidth ) const;
2015-07-29 11:52:14 +02:00
/** Get image data*/
2014-01-26 18:35:21 +01:00
QByteArray getImageData( const QString &path ) const;
2015-07-29 11:52:14 +02:00
/** Get SVG content*/
2015-06-19 22:22:16 +02:00
const QByteArray& svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );
2014-01-26 18:35:21 +01:00
signals:
/** Emit a signal to be caught by qgisapp and display a msg on status bar */
void statusChanged( const QString& theStatusQString );
2012-09-24 02:28:15 +02:00
protected:
2012-11-27 00:49:38 +01:00
//! protected constructor
2015-02-18 17:00:36 +11:00
QgsSvgCache( QObject * parent /TransferThis/ = 0 );
2012-09-24 02:28:15 +02:00
2015-07-29 11:52:14 +02:00
/** Creates new cache entry and returns pointer to it
2014-01-26 18:35:21 +01:00
* @param file Absolute or relative path to SVG file. If the path is relative the file is searched by QgsSymbolLayerV2Utils::symbolNameToPath() in SVG paths.
in settings svg/searchPathsForSVG
* @param size size of cached image
* @param fill color of fill
* @param outline color of outline
* @param outlineWidth width of outline
* @param widthScaleFactor width scale factor
* @param rasterScaleFactor raster scale factor
*/
QgsSvgCacheEntry* insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
2012-09-24 02:28:15 +02:00
double widthScaleFactor, double rasterScaleFactor );
void replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry );
void cacheImage( QgsSvgCacheEntry* entry );
2014-01-26 18:35:21 +01:00
void cachePicture( QgsSvgCacheEntry* entry, bool forceVectorOutput = false );
2015-07-29 11:52:14 +02:00
/** Returns entry from cache or creates a new entry if it does not exist already*/
2014-01-26 18:35:21 +01:00
QgsSvgCacheEntry* cacheEntry( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
2012-09-24 02:28:15 +02:00
double widthScaleFactor, double rasterScaleFactor );
2015-07-29 11:52:14 +02:00
/** Removes the least used items until the maximum size is under the limit*/
2012-09-24 02:28:15 +02:00
void trimToMaximumSize();
//Removes entry from the ordered list (but does not delete the entry itself)
void takeEntryFromList( QgsSvgCacheEntry* entry );
};