diff --git a/images/svg/accommodation/accommodation_alpinehut.svg b/images/svg/accommodation/accommodation_alpinehut.svg index 356cd02e722..33c55d92c23 100644 --- a/images/svg/accommodation/accommodation_alpinehut.svg +++ b/images/svg/accommodation/accommodation_alpinehut.svg @@ -26,7 +26,7 @@ - - - - - - - - - - - diff --git a/python/core/symbology-ng/qgssvgcache.sip b/python/core/symbology-ng/qgssvgcache.sip index 4ecc8f8fc62..ae9d6c532ec 100644 --- a/python/core/symbology-ng/qgssvgcache.sip +++ b/python/core/symbology-ng/qgssvgcache.sip @@ -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; diff --git a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp index 2cbb85210c6..cc9b7045cc6 100644 --- a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp @@ -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; } diff --git a/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp b/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp index a746ec9df81..9a920446b60 100644 --- a/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp @@ -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 ); } diff --git a/src/core/symbology-ng/qgssvgcache.cpp b/src/core/symbology-ng/qgssvgcache.cpp index a5e16122b9b..449d28594cc 100644 --- a/src/core/symbology-ng/qgssvgcache.cpp +++ b/src/core/symbology-ng/qgssvgcache.cpp @@ -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 ); } } diff --git a/src/core/symbology-ng/qgssvgcache.h b/src/core/symbology-ng/qgssvgcache.h index d1e7811d408..fb7ea46a446 100644 --- a/src/core/symbology-ng/qgssvgcache.h +++ b/src/core/symbology-ng/qgssvgcache.h @@ -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; diff --git a/src/gui/symbology-ng/qgssvgselectorwidget.cpp b/src/gui/symbology-ng/qgssvgselectorwidget.cpp index 0705bad4ab0..7b8460bb04a 100644 --- a/src/gui/symbology-ng/qgssvgselectorwidget.cpp +++ b/src/gui/symbology-ng/qgssvgselectorwidget.cpp @@ -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 ); diff --git a/src/gui/symbology-ng/qgssymbollayerv2widget.cpp b/src/gui/symbology-ng/qgssymbollayerv2widget.cpp index 0ff563ab996..ea27d0bf84b 100644 --- a/src/gui/symbology-ng/qgssymbollayerv2widget.cpp +++ b/src/gui/symbology-ng/qgssymbollayerv2widget.cpp @@ -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 ); }