If svg files with params do not have a default value set, then don't

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)
This commit is contained in:
Nyall Dawson 2015-10-11 22:54:13 +11:00
parent 1bd2a69f9b
commit a784d6bc3d
9 changed files with 152 additions and 47 deletions

View File

@ -26,7 +26,7 @@
<rect id="rect4134" x="1" y="1" display="inline" fill="none" stroke="#757575" stroke-width="0.1" width="10" height="10"/>
<rect id="rect4136" x="2" y="2" display="inline" fill="none" stroke="#757575" stroke-width="0.1" width="8" height="8"/>
</g>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M385.039,331.465l-26.564-14.867l-38.115-46.031
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M385.039,331.465l-26.564-14.867l-38.115-46.031
c-5.268-6.194-12.706-10.067-22.313-11.618c-16.729-2.478-29.279,3.409-37.648,17.661l-42.301,72.983
c-2.79,4.653-4.029,10.384-3.716,17.192l1.39,92.503l-32.073,68.799c-1.239,2.789-2.009,5.111-2.312,6.965
c-0.937,5.892,0.3,11.083,3.709,15.575s8.06,7.206,13.951,8.143c9.911,1.541,16.88-1.868,20.909-10.228l35.335-75.31
@ -35,14 +35,14 @@
l-31.733-44.25l30.683-53.45l15.334,19.519c1.239,1.863,3.102,3.259,5.589,4.186l30.583,14.853v179.932
c0,3.553,2.881,6.434,6.434,6.434s6.434-2.881,6.434-6.434V362.743c2.345-0.813,4.464-2.246,6.351-4.319
c3.102-3.409,4.652-7.284,4.652-11.625C396.203,339.054,392.481,333.942,385.039,331.465z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M196.252,343.082c5.268,3.102,9.296,2.02,12.086-3.248
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M196.252,343.082c5.268,3.102,9.296,2.02,12.086-3.248
l46.485-79.949c3.102-5.267,2.019-9.296-3.248-12.086l-14.88-8.837c-5.268-3.092-9.296-2.004-12.086,3.263l-46.485,79.948
c-3.092,5.268-2.005,9.296,3.263,12.086L196.252,343.082z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M317.11,254.765c8.369,0,15.651-3.021,21.846-9.064
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M317.11,254.765c8.369,0,15.651-3.021,21.846-9.064
s9.291-13.4,9.291-22.072c0-8.369-3.097-15.653-9.291-21.853c-6.194-6.199-13.477-9.298-21.846-9.299
c-8.682,0-16.044,3.1-22.087,9.299c-6.042,6.199-9.064,13.483-9.064,21.853c0,8.672,3.021,16.029,9.064,22.072
C301.066,251.743,308.429,254.765,317.11,254.765z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M556.268,171.503c-0.549-3.575-2.75-6.681-5.941-8.383
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M556.268,171.503c-0.549-3.575-2.75-6.681-5.941-8.383
L293.698,26.253c-3.373-1.8-7.423-1.8-10.797,0L26.273,163.121c-3.207,1.71-5.413,4.838-5.948,8.432s0.663,7.229,3.231,9.799
l17.098,17.113c3.255,3.258,8.143,4.253,12.414,2.528l19.15-7.739v287.454c0,6.949,5.633,12.583,12.583,12.583h31.996
c6.949,0,12.583-5.634,12.583-12.583v-308.13c0-0.798-0.083-1.575-0.225-2.332l7.835-3.167l151.207-17.894l150.871,18.158

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -56,22 +56,22 @@
<rect id="rect4134" x="1" y="1" display="inline" fill="none" stroke="#757575" stroke-width="0.1" width="10" height="10"/>
<rect id="rect4136" x="2" y="2" display="inline" fill="none" stroke="#757575" stroke-width="0.1" width="8" height="8"/>
</g>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M269.939,305.951c3.069,2.776,7.104,4.185,11.991,4.185
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M269.939,305.951c3.069,2.776,7.104,4.185,11.991,4.185
c5.216,0,11.134-2.046,17.59-6.08l0.836-0.522l-0.781-0.602c-6.047-4.651-13.907-11.544-23.361-20.486l-0.407-0.384l-0.458,0.321
c-4.047,2.842-6.67,5.226-8.019,7.287c-1.357,2.073-2.046,4.305-2.046,6.633C265.284,299.91,266.85,303.156,269.939,305.951z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M285.799,258.768l0.466-0.254c3.76-2.046,6.711-4.312,8.772-6.732
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M285.799,258.768l0.466-0.254c3.76-2.046,6.711-4.312,8.772-6.732
c2.114-2.483,3.187-4.892,3.187-7.159c0-2.395-0.928-4.446-2.757-6.098c-1.81-1.633-4.306-2.462-7.42-2.462
c-3.07,0-5.616,0.913-7.566,2.713c-1.966,1.815-2.963,3.995-2.963,6.48c0,3.115,2.59,7.408,7.918,13.123L285.799,258.768z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M182.433,261.415c2.091-1.838,3.151-4.507,3.151-7.932
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M182.433,261.415c2.091-1.838,3.151-4.507,3.151-7.932
c0-3.193-1.062-5.733-3.154-7.548c-2.093-1.816-5.563-2.699-10.609-2.699h-14.748v20.917h14.537
C176.798,264.152,180.339,263.256,182.433,261.415z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M425.98,285.335c-2.375-1.976-6.348-2.936-12.145-2.936h-16.856
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M425.98,285.335c-2.375-1.976-6.348-2.936-12.145-2.936h-16.856
v22.252h16.927c5.707,0,9.648-1.009,12.05-3.085c2.396-2.071,3.611-4.884,3.611-8.357
C429.567,289.963,428.361,287.314,425.98,285.335z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M422.339,261.415c2.091-1.838,3.15-4.507,3.15-7.932
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M422.339,261.415c2.091-1.838,3.15-4.507,3.15-7.932
c0-3.193-1.061-5.733-3.153-7.548c-2.094-1.816-5.564-2.699-10.609-2.699h-14.747v20.917h14.536
C416.705,264.152,420.245,263.256,422.339,261.415z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M289.488,28.744L29.521,258.427h52.756V553.03h156.264V379.165
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M289.488,28.744L29.521,258.427h52.756V553.03h156.264V379.165
h105.434l0.001,173.865h152.723V258.427h52.756L289.488,28.744z M244.156,282.195c3.843-5.101,10.251-9.485,19.045-13.031
l0.867-0.35l-0.595-0.721c-3.69-4.474-6.257-8.403-7.631-11.677c-1.364-3.251-2.056-6.604-2.056-9.965
c0-7.068,2.733-12.972,8.125-17.548c5.425-4.604,13.816-6.939,24.94-6.939c11.36,0,19.801,2.218,25.087,6.593
@ -89,7 +89,7 @@
c3.375,4.191,5.087,9.546,5.087,15.918c0,5.196-1.223,9.93-3.634,14.069c-2.412,4.142-5.758,7.464-9.946,9.877
c-2.581,1.494-6.564,2.601-11.84,3.289c-7.108,0.929-11.881,1.4-14.185,1.4h-54.3V223.722h58.94c9.713,0,17.257,2.423,22.422,7.201
c5.149,4.764,7.761,10.746,7.761,17.778C455.339,254.596,453.479,259.72,449.812,263.931z"/>
<path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d="M186.075,285.335c-2.375-1.976-6.348-2.936-12.145-2.936h-16.857
<path fill="param(fill)" stroke="param(outline)" stroke-width="param(outline-width)" d="M186.075,285.335c-2.375-1.976-6.348-2.936-12.145-2.936h-16.857
v22.252H174c5.707,0,9.648-1.009,12.049-3.085c2.397-2.071,3.612-4.884,3.612-8.357
C189.662,289.963,188.455,287.314,186.075,285.335z"/>
</svg>

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -88,6 +88,25 @@ class QgsSvgCache : QObject
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;

View File

@ -1712,6 +1712,9 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double
setSvgFilePath( svgFilePath );
mOutlineWidth = 0.3;
mAngle = angle;
mSvgFillColor = QColor( 0, 0, 0 );
mSvgOutlineColor = QColor( 0, 0, 0 );
mSvgOutlineWidth = 0.3;
setDefaultSvgParams();
mSvgPattern = 0;
}
@ -1725,6 +1728,9 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double
storeViewBox();
mOutlineWidth = 0.3;
mAngle = angle;
mSvgFillColor = QColor( 0, 0, 0 );
mSvgOutlineColor = QColor( 0, 0, 0 );
mSvgOutlineWidth = 0.3;
setSubSymbol( new QgsLineSymbolV2() );
setDefaultSvgParams();
mSvgPattern = 0;
@ -2224,31 +2230,28 @@ void QgsSVGFillSymbolLayer::storeViewBox()
void QgsSVGFillSymbolLayer::setDefaultSvgParams()
{
//default values
mSvgFillColor = QColor( 0, 0, 0 );
mSvgOutlineColor = QColor( 0, 0, 0 );
mSvgOutlineWidth = 0.3;
if ( mSvgFilePath.isEmpty() )
{
return;
}
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
bool hasDefaultFillColor, hasDefaultOutlineColor, hasDefaultOutlineWidth;
QColor defaultFillColor, defaultOutlineColor;
double defaultOutlineWidth;
QgsSvgCache::instance()->containsParams( mSvgFilePath, hasFillParam, defaultFillColor, hasOutlineParam, defaultOutlineColor, hasOutlineWidthParam,
defaultOutlineWidth );
QgsSvgCache::instance()->containsParams( mSvgFilePath, hasFillParam, hasDefaultFillColor, defaultFillColor,
hasOutlineParam, hasDefaultOutlineColor, defaultOutlineColor,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
if ( hasFillParam )
if ( hasDefaultFillColor )
{
mSvgFillColor = defaultFillColor;
}
if ( hasOutlineParam )
if ( hasDefaultOutlineColor )
{
mSvgOutlineColor = defaultOutlineColor;
}
if ( hasOutlineWidthParam )
if ( hasDefaultOutlineWidth )
{
mSvgOutlineWidth = defaultOutlineWidth;
}

View File

@ -1070,17 +1070,20 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
{
QColor fillColor, outlineColor;
double outlineWidth;
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QgsSvgCache::instance()->containsParams( name, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
if ( hasFillParam )
bool hasFillParam = false, hasOutlineParam = false, hasOutlineWidthParam = false;
bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
QgsSvgCache::instance()->containsParams( name, hasFillParam, hasDefaultFillColor, fillColor,
hasOutlineParam, hasDefaultOutlineColor, outlineColor,
hasOutlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
if ( hasDefaultFillColor )
{
m->setFillColor( fillColor );
}
if ( hasOutlineParam )
if ( hasDefaultOutlineColor )
{
m->setOutlineColor( outlineColor );
}
if ( hasOutlineWidthParam )
if ( hasDefaultOutlineWidth )
{
m->setOutlineWidth( outlineWidth );
}
@ -1163,17 +1166,20 @@ void QgsSvgMarkerSymbolLayerV2::setPath( const QString& path )
mPath = path;
QColor fillColor, outlineColor;
double outlineWidth;
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QgsSvgCache::instance()->containsParams( path, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
if ( hasFillParam )
bool hasFillParam = false, hasOutlineParam = false, hasOutlineWidthParam = false;
bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
QgsSvgCache::instance()->containsParams( path, hasFillParam, hasDefaultFillColor, fillColor,
hasOutlineParam, hasDefaultOutlineColor, outlineColor,
hasOutlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
if ( hasDefaultFillColor )
{
setFillColor( fillColor );
}
if ( hasOutlineParam )
if ( hasDefaultOutlineColor )
{
setOutlineColor( outlineColor );
}
if ( hasOutlineWidthParam )
if ( hasDefaultOutlineWidth )
{
setOutlineWidth( outlineWidth );
}

View File

@ -226,14 +226,32 @@ QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, cons
void QgsSvgCache::containsParams( const QString& path, bool& hasFillParam, QColor& defaultFillColor, bool& hasOutlineParam, QColor& defaultOutlineColor,
bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const
{
bool hasDefaultFillColor = false;
bool hasDefaultOutlineColor = false;
bool hasDefaultOutlineWidth = false;
containsParams( path, hasFillParam, hasDefaultFillColor, defaultFillColor,
hasOutlineParam, hasDefaultOutlineColor, defaultOutlineColor,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
}
void QgsSvgCache::containsParams( const QString& path,
bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
bool& hasOutlineParam, bool& hasDefaultOutlineColor, QColor& defaultOutlineColor,
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const
{
hasFillParam = false;
hasOutlineParam = false;
hasOutlineWidthParam = false;
defaultFillColor = QColor( Qt::black );
defaultFillColor = QColor( Qt::white );
defaultOutlineColor = QColor( Qt::black );
defaultOutlineWidth = 0.2;
hasDefaultFillParam = false;
hasDefaultOutlineColor = false;
hasDefaultOutlineWidth = false;
QDomDocument svgDoc;
if ( !svgDoc.setContent( getImageData( path ) ) )
{
@ -241,7 +259,9 @@ void QgsSvgCache::containsParams( const QString& path, bool& hasFillParam, QColo
}
QDomElement docElem = svgDoc.documentElement();
containsElemParams( docElem, hasFillParam, defaultFillColor, hasOutlineParam, defaultOutlineColor, hasOutlineWidthParam, defaultOutlineWidth );
containsElemParams( docElem, hasFillParam, hasDefaultFillParam, defaultFillColor,
hasOutlineParam, hasDefaultOutlineColor, defaultOutlineColor,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
}
void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry )
@ -632,8 +652,8 @@ void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, cons
}
}
void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillParam, QColor& defaultFill, bool& hasOutlineParam, QColor& defaultOutline,
bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const
void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillParam, bool& hasDefaultFill, QColor& defaultFill, bool& hasOutlineParam, bool& hasDefaultOutline, QColor& defaultOutline,
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const
{
if ( elem.isNull() )
{
@ -675,6 +695,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
if ( valueSplit.size() > 1 )
{
defaultFill = QColor( valueSplit.at( 1 ) );
hasDefaultFill = true;
}
}
else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
@ -683,6 +704,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
if ( valueSplit.size() > 1 )
{
defaultOutline = QColor( valueSplit.at( 1 ) );
hasDefaultOutline = true;
}
}
else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
@ -691,6 +713,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
if ( valueSplit.size() > 1 )
{
defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
hasDefaultOutlineWidth = true;
}
}
}
@ -705,6 +728,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
if ( valueSplit.size() > 1 )
{
defaultFill = QColor( valueSplit.at( 1 ) );
hasDefaultFill = true;
}
}
else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
@ -713,6 +737,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
if ( valueSplit.size() > 1 )
{
defaultOutline = QColor( valueSplit.at( 1 ) );
hasDefaultOutline = true;
}
}
else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
@ -721,6 +746,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
if ( valueSplit.size() > 1 )
{
defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
hasDefaultOutlineWidth = true;
}
}
}
@ -732,7 +758,9 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
for ( int i = 0; i < nChildren; ++i )
{
QDomElement childElem = childList.at( i ).toElement();
containsElemParams( childElem, hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
containsElemParams( childElem, hasFillParam, hasDefaultFill, defaultFill,
hasOutlineParam, hasDefaultOutline, defaultOutline,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
}
}

View File

@ -114,6 +114,25 @@ class CORE_EXPORT QgsSvgCache : public QObject
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;
/** Get image data*/
QByteArray getImageData( const QString &path ) const;
@ -175,8 +194,10 @@ class CORE_EXPORT QgsSvgCache : public QObject
/** Replaces parameters in elements of a dom node and calls method for all child nodes*/
void replaceElemParams( QDomElement& elem, const QColor& fill, const QColor& outline, double outlineWidth );
void containsElemParams( const QDomElement& elem, bool& hasFillParam, QColor& defaultFill, bool& hasOutlineParam, QColor& defaultOutline,
bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const;
void containsElemParams( const QDomElement& elem,
bool& hasFillParam, bool& hasDefaultFill, QColor& defaultFill,
bool& hasOutlineParam, bool& hasDefaultOutline, QColor& defaultOutline,
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const;
/** Calculates scaling for rendered image sizes to SVG logical sizes*/
double calcSizeScaleFactor( QgsSvgCacheEntry* entry, const QDomElement& docElem ) const;

View File

@ -67,7 +67,18 @@ QVariant QgsSvgSelectorListModel::data( const QModelIndex & index, int role ) co
QColor fill, outline;
double outlineWidth;
bool fillParam, outlineParam, outlineWidthParam;
QgsSvgCache::instance()->containsParams( entry, fillParam, fill, outlineParam, outline, outlineWidthParam, outlineWidth );
bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
QgsSvgCache::instance()->containsParams( entry, fillParam, hasDefaultFillColor, fill,
outlineParam, hasDefaultOutlineColor, outline,
outlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
//if defaults not set in symbol, use these values
if ( !hasDefaultFillColor )
fill = QColor( 200, 200, 200 );
if ( !hasDefaultOutlineColor )
outline = Qt::black;
if ( !hasDefaultOutlineWidth )
outlineWidth = 0.2;
bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
const QImage& img = QgsSvgCache::instance()->svgAsImage( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );

View File

@ -1603,7 +1603,18 @@ class QgsSvgListModel : public QAbstractListModel
QColor fill, outline;
double outlineWidth;
bool fillParam, outlineParam, outlineWidthParam;
QgsSvgCache::instance()->containsParams( entry, fillParam, fill, outlineParam, outline, outlineWidthParam, outlineWidth );
bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
QgsSvgCache::instance()->containsParams( entry, fillParam, hasDefaultFillColor, fill,
outlineParam, hasDefaultOutlineColor, outline,
outlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
//if defaults not set in symbol, use these values
if ( !hasDefaultFillColor )
fill = QColor( 200, 200, 200 );
if ( !hasDefaultOutlineColor )
outline = Qt::black;
if ( !hasDefaultOutlineWidth )
outlineWidth = 0.6;
bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
const QImage& img = QgsSvgCache::instance()->svgAsImage( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
@ -1716,7 +1727,10 @@ void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLaye
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QColor defaultFill, defaultOutline;
double defaultOutlineWidth;
QgsSvgCache::instance()->containsParams( layer->path(), hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
bool hasDefaultFillColor, hasDefaultOutlineColor, hasDefaultOutlineWidth;
QgsSvgCache::instance()->containsParams( layer->path(), hasFillParam, hasDefaultFillColor, defaultFill,
hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
mChangeColorButton->setEnabled( hasFillParam );
mChangeBorderColorButton->setEnabled( hasOutlineParam );
mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
@ -1727,7 +1741,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLaye
{
mChangeColorButton->setColor( layer->fillColor() );
}
else
else if ( hasDefaultFillColor )
{
mChangeColorButton->setColor( defaultFill );
}
@ -1738,7 +1752,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLaye
{
mChangeBorderColorButton->setColor( layer->outlineColor() );
}
else
else if ( hasDefaultOutlineColor )
{
mChangeBorderColorButton->setColor( defaultOutline );
}
@ -2195,18 +2209,21 @@ void QgsSVGFillSymbolLayerWidget::updateParamGui( bool resetValues )
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QColor defaultFill, defaultOutline;
double defaultOutlineWidth;
QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
if ( hasFillParam && resetValues )
bool hasDefaultFillColor, hasDefaultOutlineColor, hasDefaultOutlineWidth;
QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, hasDefaultFillColor, defaultFill,
hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
if ( hasDefaultFillColor && resetValues )
{
mChangeColorButton->setColor( defaultFill );
}
mChangeColorButton->setEnabled( hasFillParam );
if ( hasOutlineParam && resetValues )
if ( hasDefaultOutlineColor && resetValues )
{
mChangeBorderColorButton->setColor( defaultOutline );
}
mChangeBorderColorButton->setEnabled( hasOutlineParam );
if ( hasOutlineWidthParam && resetValues )
if ( hasDefaultOutlineWidth && resetValues )
{
mBorderWidthSpinBox->setValue( defaultOutlineWidth );
}