Skip to content

Commit a784d6b

Browse files
committed
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)
1 parent 1bd2a69 commit a784d6b

File tree

9 files changed

+152
-47
lines changed

9 files changed

+152
-47
lines changed

images/svg/accommodation/accommodation_alpinehut.svg

Lines changed: 4 additions & 4 deletions
Loading

images/svg/accommodation/accommodation_bed_and_breakfast.svg

Lines changed: 7 additions & 7 deletions
Loading

python/core/symbology-ng/qgssvgcache.sip

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ class QgsSvgCache : QObject
8888
void containsParams( const QString& path, bool& hasFillParam, QColor& defaultFillColor, bool& hasOutlineParam, QColor& defaultOutlineColor, bool& hasOutlineWidthParam,
8989
double& defaultOutlineWidth ) const;
9090

91+
/** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
92+
* default values in the svg file, only the first one is considered.
93+
* @param path path to SVG file
94+
* @param hasFillParam will be true if fill param present in SVG
95+
* @param hasDefaultFillParam will be true if fill param has a default value specified
96+
* @param defaultFillColor will be set to default fill color specified in SVG, if present
97+
* @param hasOutlineParam will be true if outline param present in SVG
98+
* @param hasDefaultOutlineColor will be true if outline param has a default value specified
99+
* @param defaultOutlineColor will be set to default outline color specified in SVG, if present
100+
* @param hasOutlineWidthParam will be true if outline width param present in SVG
101+
* @param hasDefaultOutlineWidth will be true if outline width param has a default value specified
102+
* @param defaultOutlineWidth will be set to default outline width specified in SVG, if present
103+
* @note available in python bindings as containsParamsV2
104+
* @note added in QGIS 2.12
105+
*/
106+
void containsParams( const QString& path, bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
107+
bool& hasOutlineParam, bool& hasDefaultOutlineColor, QColor& defaultOutlineColor,
108+
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const /PyName=containsParamsV2/;
109+
91110
/** Get image data*/
92111
QByteArray getImageData( const QString &path ) const;
93112

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,9 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double
17121712
setSvgFilePath( svgFilePath );
17131713
mOutlineWidth = 0.3;
17141714
mAngle = angle;
1715+
mSvgFillColor = QColor( 0, 0, 0 );
1716+
mSvgOutlineColor = QColor( 0, 0, 0 );
1717+
mSvgOutlineWidth = 0.3;
17151718
setDefaultSvgParams();
17161719
mSvgPattern = 0;
17171720
}
@@ -1725,6 +1728,9 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double
17251728
storeViewBox();
17261729
mOutlineWidth = 0.3;
17271730
mAngle = angle;
1731+
mSvgFillColor = QColor( 0, 0, 0 );
1732+
mSvgOutlineColor = QColor( 0, 0, 0 );
1733+
mSvgOutlineWidth = 0.3;
17281734
setSubSymbol( new QgsLineSymbolV2() );
17291735
setDefaultSvgParams();
17301736
mSvgPattern = 0;
@@ -2224,31 +2230,28 @@ void QgsSVGFillSymbolLayer::storeViewBox()
22242230

22252231
void QgsSVGFillSymbolLayer::setDefaultSvgParams()
22262232
{
2227-
//default values
2228-
mSvgFillColor = QColor( 0, 0, 0 );
2229-
mSvgOutlineColor = QColor( 0, 0, 0 );
2230-
mSvgOutlineWidth = 0.3;
2231-
22322233
if ( mSvgFilePath.isEmpty() )
22332234
{
22342235
return;
22352236
}
22362237

22372238
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
2239+
bool hasDefaultFillColor, hasDefaultOutlineColor, hasDefaultOutlineWidth;
22382240
QColor defaultFillColor, defaultOutlineColor;
22392241
double defaultOutlineWidth;
2240-
QgsSvgCache::instance()->containsParams( mSvgFilePath, hasFillParam, defaultFillColor, hasOutlineParam, defaultOutlineColor, hasOutlineWidthParam,
2241-
defaultOutlineWidth );
2242+
QgsSvgCache::instance()->containsParams( mSvgFilePath, hasFillParam, hasDefaultFillColor, defaultFillColor,
2243+
hasOutlineParam, hasDefaultOutlineColor, defaultOutlineColor,
2244+
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
22422245

2243-
if ( hasFillParam )
2246+
if ( hasDefaultFillColor )
22442247
{
22452248
mSvgFillColor = defaultFillColor;
22462249
}
2247-
if ( hasOutlineParam )
2250+
if ( hasDefaultOutlineColor )
22482251
{
22492252
mSvgOutlineColor = defaultOutlineColor;
22502253
}
2251-
if ( hasOutlineWidthParam )
2254+
if ( hasDefaultOutlineWidth )
22522255
{
22532256
mSvgOutlineWidth = defaultOutlineWidth;
22542257
}

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,17 +1070,20 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
10701070
{
10711071
QColor fillColor, outlineColor;
10721072
double outlineWidth;
1073-
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
1074-
QgsSvgCache::instance()->containsParams( name, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
1075-
if ( hasFillParam )
1073+
bool hasFillParam = false, hasOutlineParam = false, hasOutlineWidthParam = false;
1074+
bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
1075+
QgsSvgCache::instance()->containsParams( name, hasFillParam, hasDefaultFillColor, fillColor,
1076+
hasOutlineParam, hasDefaultOutlineColor, outlineColor,
1077+
hasOutlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
1078+
if ( hasDefaultFillColor )
10761079
{
10771080
m->setFillColor( fillColor );
10781081
}
1079-
if ( hasOutlineParam )
1082+
if ( hasDefaultOutlineColor )
10801083
{
10811084
m->setOutlineColor( outlineColor );
10821085
}
1083-
if ( hasOutlineWidthParam )
1086+
if ( hasDefaultOutlineWidth )
10841087
{
10851088
m->setOutlineWidth( outlineWidth );
10861089
}
@@ -1163,17 +1166,20 @@ void QgsSvgMarkerSymbolLayerV2::setPath( const QString& path )
11631166
mPath = path;
11641167
QColor fillColor, outlineColor;
11651168
double outlineWidth;
1166-
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
1167-
QgsSvgCache::instance()->containsParams( path, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
1168-
if ( hasFillParam )
1169+
bool hasFillParam = false, hasOutlineParam = false, hasOutlineWidthParam = false;
1170+
bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
1171+
QgsSvgCache::instance()->containsParams( path, hasFillParam, hasDefaultFillColor, fillColor,
1172+
hasOutlineParam, hasDefaultOutlineColor, outlineColor,
1173+
hasOutlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
1174+
if ( hasDefaultFillColor )
11691175
{
11701176
setFillColor( fillColor );
11711177
}
1172-
if ( hasOutlineParam )
1178+
if ( hasDefaultOutlineColor )
11731179
{
11741180
setOutlineColor( outlineColor );
11751181
}
1176-
if ( hasOutlineWidthParam )
1182+
if ( hasDefaultOutlineWidth )
11771183
{
11781184
setOutlineWidth( outlineWidth );
11791185
}

src/core/symbology-ng/qgssvgcache.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,42 @@ QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, cons
226226

227227
void QgsSvgCache::containsParams( const QString& path, bool& hasFillParam, QColor& defaultFillColor, bool& hasOutlineParam, QColor& defaultOutlineColor,
228228
bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const
229+
{
230+
bool hasDefaultFillColor = false;
231+
bool hasDefaultOutlineColor = false;
232+
bool hasDefaultOutlineWidth = false;
233+
234+
containsParams( path, hasFillParam, hasDefaultFillColor, defaultFillColor,
235+
hasOutlineParam, hasDefaultOutlineColor, defaultOutlineColor,
236+
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
237+
}
238+
239+
void QgsSvgCache::containsParams( const QString& path,
240+
bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
241+
bool& hasOutlineParam, bool& hasDefaultOutlineColor, QColor& defaultOutlineColor,
242+
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const
229243
{
230244
hasFillParam = false;
231245
hasOutlineParam = false;
232246
hasOutlineWidthParam = false;
233-
defaultFillColor = QColor( Qt::black );
247+
defaultFillColor = QColor( Qt::white );
234248
defaultOutlineColor = QColor( Qt::black );
235249
defaultOutlineWidth = 0.2;
236250

251+
hasDefaultFillParam = false;
252+
hasDefaultOutlineColor = false;
253+
hasDefaultOutlineWidth = false;
254+
237255
QDomDocument svgDoc;
238256
if ( !svgDoc.setContent( getImageData( path ) ) )
239257
{
240258
return;
241259
}
242260

243261
QDomElement docElem = svgDoc.documentElement();
244-
containsElemParams( docElem, hasFillParam, defaultFillColor, hasOutlineParam, defaultOutlineColor, hasOutlineWidthParam, defaultOutlineWidth );
262+
containsElemParams( docElem, hasFillParam, hasDefaultFillParam, defaultFillColor,
263+
hasOutlineParam, hasDefaultOutlineColor, defaultOutlineColor,
264+
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
245265
}
246266

247267
void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry )
@@ -632,8 +652,8 @@ void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, cons
632652
}
633653
}
634654

635-
void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillParam, QColor& defaultFill, bool& hasOutlineParam, QColor& defaultOutline,
636-
bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const
655+
void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillParam, bool& hasDefaultFill, QColor& defaultFill, bool& hasOutlineParam, bool& hasDefaultOutline, QColor& defaultOutline,
656+
bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const
637657
{
638658
if ( elem.isNull() )
639659
{
@@ -675,6 +695,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
675695
if ( valueSplit.size() > 1 )
676696
{
677697
defaultFill = QColor( valueSplit.at( 1 ) );
698+
hasDefaultFill = true;
678699
}
679700
}
680701
else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
@@ -683,6 +704,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
683704
if ( valueSplit.size() > 1 )
684705
{
685706
defaultOutline = QColor( valueSplit.at( 1 ) );
707+
hasDefaultOutline = true;
686708
}
687709
}
688710
else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
@@ -691,6 +713,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
691713
if ( valueSplit.size() > 1 )
692714
{
693715
defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
716+
hasDefaultOutlineWidth = true;
694717
}
695718
}
696719
}
@@ -705,6 +728,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
705728
if ( valueSplit.size() > 1 )
706729
{
707730
defaultFill = QColor( valueSplit.at( 1 ) );
731+
hasDefaultFill = true;
708732
}
709733
}
710734
else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
@@ -713,6 +737,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
713737
if ( valueSplit.size() > 1 )
714738
{
715739
defaultOutline = QColor( valueSplit.at( 1 ) );
740+
hasDefaultOutline = true;
716741
}
717742
}
718743
else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
@@ -721,6 +746,7 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
721746
if ( valueSplit.size() > 1 )
722747
{
723748
defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
749+
hasDefaultOutlineWidth = true;
724750
}
725751
}
726752
}
@@ -732,7 +758,9 @@ void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillPara
732758
for ( int i = 0; i < nChildren; ++i )
733759
{
734760
QDomElement childElem = childList.at( i ).toElement();
735-
containsElemParams( childElem, hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
761+
containsElemParams( childElem, hasFillParam, hasDefaultFill, defaultFill,
762+
hasOutlineParam, hasDefaultOutline, defaultOutline,
763+
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
736764
}
737765
}
738766

0 commit comments

Comments
 (0)