2012-09-24 02:28:15 +02:00
|
|
|
class QgsSvgCacheEntry
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgssvgcache.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
QgsSvgCacheEntry();
|
2017-04-27 14:26:21 +08:00
|
|
|
QgsSvgCacheEntry( const QString& path, double size, double strokeWidth, double widthScaleFactor, const QColor& fill, const QColor& stroke );
|
2012-09-24 02:28:15 +02:00
|
|
|
~QgsSvgCacheEntry();
|
|
|
|
|
2015-07-31 20:27:57 +02:00
|
|
|
//! Absolute path to SVG file
|
2017-04-27 14:26:21 +08:00
|
|
|
QString path;
|
2014-01-26 18:35:21 +01:00
|
|
|
double size; //size in pixels (cast to int for QImage)
|
2017-02-22 17:13:57 +10:00
|
|
|
double strokeWidth;
|
2012-09-24 02:28:15 +02:00
|
|
|
double widthScaleFactor;
|
2015-11-15 14:41:11 +11:00
|
|
|
|
|
|
|
/** SVG viewbox size.
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
QSizeF viewboxSize;
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
QColor fill;
|
2017-02-22 17:13:57 +10:00
|
|
|
QColor stroke;
|
2017-05-01 18:13:15 +02:00
|
|
|
QImage *image;
|
|
|
|
QPicture *picture;
|
2012-09-24 02:28:15 +02:00
|
|
|
//content (with params replaced)
|
|
|
|
QByteArray svgContent;
|
|
|
|
|
|
|
|
//keep entries on a least, sorted by last access
|
2017-05-01 18:13:15 +02:00
|
|
|
QgsSvgCacheEntry *nextEntry;
|
|
|
|
QgsSvgCacheEntry *previousEntry;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Don't consider image, picture, last used timestamp for comparison*/
|
2017-05-01 18:13: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;
|
2016-01-22 18:45:45 +11:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
QgsSvgCacheEntry( const QgsSvgCacheEntry &rh );
|
2012-09-24 02:28:15 +02:00
|
|
|
};
|
|
|
|
|
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:
|
|
|
|
|
2017-05-03 07:45:22 +02:00
|
|
|
QgsSvgCache( QObject *parent /TransferThis/ = 0 );
|
2016-12-28 16:09:05 +10:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
~QgsSvgCache();
|
|
|
|
|
2017-04-27 14:26:21 +08:00
|
|
|
QImage svgAsImage( const QString& path, double size, const QColor& fill, const QColor& stroke, double strokeWidth,
|
|
|
|
double widthScaleFactor, bool& fitsInCache );
|
|
|
|
|
|
|
|
QPicture svgAsPicture( const QString& path, double size, const QColor& fill, const QColor& stroke, double strokeWidth,
|
2017-01-16 16:01:52 +10:00
|
|
|
double widthScaleFactor, bool forceVectorOutput = false );
|
2015-11-15 14:41:11 +11:00
|
|
|
|
2017-04-27 14:26:21 +08:00
|
|
|
QSizeF svgViewboxSize( const QString& path, double size, const QColor& fill, const QColor& stroke, double strokeWidth,
|
2017-01-16 16:01:52 +10:00
|
|
|
double widthScaleFactor );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-02-22 17:13:57 +10:00
|
|
|
/** Tests if an svg file contains parameters for fill, stroke color, stroke 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*/
|
2017-02-22 17:13:57 +10:00
|
|
|
void containsParams( const QString& path, bool& hasFillParam, QColor& defaultFillColor, bool& hasStrokeParam, QColor& defaultStrokeColor, bool& hasStrokeWidthParam,
|
2017-05-01 18:13:15 +02:00
|
|
|
double &defaultStrokeWidth ) const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-02-22 17:13:57 +10:00
|
|
|
/** Tests if an svg file contains parameters for fill, stroke color, stroke width. If yes, possible default values are returned. If there are several
|
2015-10-11 22:54:13 +11:00
|
|
|
* default values in the svg file, only the first one is considered.
|
|
|
|
* @param path path to SVG file
|
|
|
|
* @param hasFillParam will be true if fill param present in SVG
|
|
|
|
* @param hasDefaultFillParam will be true if fill param has a default value specified
|
2015-12-08 22:45:51 +11:00
|
|
|
* @param defaultFillColor will be set to default fill color specified in SVG, if present
|
|
|
|
* @param hasFillOpacityParam will be true if fill opacity param present in SVG
|
|
|
|
* @param hasDefaultFillOpacity will be true if fill opacity param has a default value specified
|
|
|
|
* @param defaultFillOpacity will be set to default fill opacity specified in SVG, if present
|
2017-02-22 17:13:57 +10:00
|
|
|
* @param hasStrokeParam will be true if stroke param present in SVG
|
|
|
|
* @param hasDefaultStrokeColor will be true if stroke param has a default value specified
|
|
|
|
* @param defaultStrokeColor will be set to default stroke color specified in SVG, if present
|
|
|
|
* @param hasStrokeWidthParam will be true if stroke width param present in SVG
|
|
|
|
* @param hasDefaultStrokeWidth will be true if stroke width param has a default value specified
|
|
|
|
* @param defaultStrokeWidth will be set to default stroke width specified in SVG, if present
|
|
|
|
* @param hasStrokeOpacityParam will be true if stroke opacity param present in SVG
|
|
|
|
* @param hasDefaultStrokeOpacity will be true if stroke opacity param has a default value specified
|
|
|
|
* @param defaultStrokeOpacity will be set to default stroke opacity specified in SVG, if present
|
2015-12-08 22:45:51 +11:00
|
|
|
* @note available in python bindings as containsParamsV3
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
void containsParams( const QString& path, bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
|
|
|
|
bool& hasFillOpacityParam, bool& hasDefaultFillOpacity, double& defaultFillOpacity,
|
2017-02-22 17:13:57 +10:00
|
|
|
bool& hasStrokeParam, bool& hasDefaultStrokeColor, QColor& defaultStrokeColor,
|
|
|
|
bool& hasStrokeWidthParam, bool& hasDefaultStrokeWidth, double& defaultStrokeWidth,
|
2017-05-01 18:13:15 +02:00
|
|
|
bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity ) const /PyName=containsParamsV3/;
|
2015-10-11 22:54:13 +11:00
|
|
|
|
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*/
|
2017-04-27 14:26:21 +08:00
|
|
|
QByteArray svgContent( const QString& path, double size, const QColor& fill, const QColor& stroke, double strokeWidth,
|
2017-01-16 16:01:52 +10:00
|
|
|
double widthScaleFactor );
|
2015-06-19 22:22:16 +02:00
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
signals:
|
|
|
|
/** Emit a signal to be caught by qgisapp and display a msg on status bar */
|
2017-02-21 18:14:58 +01:00
|
|
|
void statusChanged( const QString& statusQString );
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
protected:
|
|
|
|
|
2017-04-27 14:26:21 +08:00
|
|
|
QgsSvgCacheEntry* insertSvg( const QString& path, double size, const QColor& fill, const QColor& stroke, double strokeWidth,
|
2017-01-16 16:01:52 +10:00
|
|
|
double widthScaleFactor );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-05-01 18:13:15 +02:00
|
|
|
void replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry );
|
|
|
|
void cacheImage( QgsSvgCacheEntry *entry );
|
|
|
|
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*/
|
2017-04-27 14:26:21 +08:00
|
|
|
QgsSvgCacheEntry* cacheEntry( const QString& path, double size, const QColor& fill, const QColor& stroke, double strokeWidth,
|
2017-01-16 16:01:52 +10:00
|
|
|
double widthScaleFactor );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
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)
|
2017-05-01 18:13:15 +02:00
|
|
|
void takeEntryFromList( QgsSvgCacheEntry *entry );
|
2016-01-22 18:45:45 +11:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
};
|