mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-02 00:02:12 -05:00
reset the fill/border color and border width when changing svg marker/svg fill SVG files This change makes the behaviour consistent between the svg marker symbol and the other marker symbols. Additionally, svg files which have customisable colors and NO default values set will be shaded in gray fill/black outline in the svg selector widget, to follow the same behaviour as the other marker symbol selectors. Note that this change has NO EFFECT unless the svg files are modified to remove the default param value, so there will be no change for users' custom symbols. A follow up commit will need to remove the default param values from the preinstalled SVG files though. If you want to test in the meantime, I've modified just the first two symbols in the accomodation group to make this change for testing. (refs #10908)
151 lines
7.3 KiB
Plaintext
151 lines
7.3 KiB
Plaintext
class QgsSvgCacheEntry
|
|
{
|
|
%TypeHeaderCode
|
|
#include <qgssvgcache.h>
|
|
%End
|
|
|
|
public:
|
|
QgsSvgCacheEntry();
|
|
/** 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
|
|
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
|
|
*/
|
|
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
|
|
~QgsSvgCacheEntry();
|
|
|
|
//! Absolute path to SVG file
|
|
QString file;
|
|
//! Lookup key used by QgsSvgCache's hashtable (relative or absolute path). Needed for removal from the hashtable
|
|
QString lookupKey;
|
|
double size; //size in pixels (cast to int for QImage)
|
|
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;
|
|
|
|
/** Don't consider image, picture, last used timestamp for comparison*/
|
|
bool operator==( const QgsSvgCacheEntry& other ) const;
|
|
/** Return memory usage in bytes*/
|
|
int dataSize() const;
|
|
};
|
|
|
|
/** A cache for images / pictures derived from svg files. This class supports parameter replacement in svg files
|
|
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)"*/
|
|
class QgsSvgCache : QObject
|
|
{
|
|
%TypeHeaderCode
|
|
#include <qgssvgcache.h>
|
|
%End
|
|
|
|
public:
|
|
|
|
static QgsSvgCache* instance();
|
|
~QgsSvgCache();
|
|
|
|
/** Get SVG as QImage.
|
|
* @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,
|
|
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
|
|
/** 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 );
|
|
|
|
/** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
|
|
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;
|
|
|
|
/** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
|
|
* 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
|
|
* @param defaultFillColor will be set to default fill color specified in SVG, if present
|
|
* @param hasOutlineParam will be true if outline param present in SVG
|
|
* @param hasDefaultOutlineColor will be true if outline param has a default value specified
|
|
* @param defaultOutlineColor will be set to default outline color specified in SVG, if present
|
|
* @param hasOutlineWidthParam will be true if outline width param present in SVG
|
|
* @param hasDefaultOutlineWidth will be true if outline width param has a default value specified
|
|
* @param defaultOutlineWidth will be set to default outline width specified in SVG, if present
|
|
* @note available in python bindings as containsParamsV2
|
|
* @note added in QGIS 2.12
|
|
*/
|
|
void containsParams( const QString& path, bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
|
|
bool& hasOutlineParam, bool& hasDefaultOutlineColor, QColor& defaultOutlineColor,
|
|
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const /PyName=containsParamsV2/;
|
|
|
|
/** Get image data*/
|
|
QByteArray getImageData( const QString &path ) const;
|
|
|
|
/** Get SVG content*/
|
|
const QByteArray& svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
|
|
double widthScaleFactor, double rasterScaleFactor );
|
|
|
|
signals:
|
|
/** Emit a signal to be caught by qgisapp and display a msg on status bar */
|
|
void statusChanged( const QString& theStatusQString );
|
|
|
|
protected:
|
|
//! protected constructor
|
|
QgsSvgCache( QObject * parent /TransferThis/ = 0 );
|
|
|
|
/** Creates new cache entry and returns pointer to it
|
|
* @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,
|
|
double widthScaleFactor, double rasterScaleFactor );
|
|
|
|
void replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry );
|
|
void cacheImage( QgsSvgCacheEntry* entry );
|
|
void cachePicture( QgsSvgCacheEntry* entry, bool forceVectorOutput = false );
|
|
/** Returns entry from cache or creates a new entry if it does not exist already*/
|
|
QgsSvgCacheEntry* cacheEntry( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
|
|
double widthScaleFactor, double rasterScaleFactor );
|
|
|
|
/** Removes the least used items until the maximum size is under the limit*/
|
|
void trimToMaximumSize();
|
|
|
|
//Removes entry from the ordered list (but does not delete the entry itself)
|
|
void takeEntryFromList( QgsSvgCacheEntry* entry );
|
|
};
|