Skip to content

Commit

Permalink
Fix svg fills losing fill and border color and border width settings …
Browse files Browse the repository at this point in the history
…when loading symbol dialog (fix #9945)
  • Loading branch information
nyalldawson committed May 4, 2014
1 parent 639d4c4 commit c1d3958
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
8 changes: 7 additions & 1 deletion python/gui/symbology-ng/qgssymbollayerv2widget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ class QgsSVGFillSymbolLayerWidget : QgsSymbolLayerV2Widget

protected:
void insertIcons();
void updateParamGui();

/**Enables or disables svg fill color, border color and border width based on whether the
* svg file supports custom parameters.
* @param resetValues set to true to overwrite existing layer fill color, border color and border width
* with default values from svg file
*/
void updateParamGui( bool resetValues = true );
};

//////////
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,11 +1559,11 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
//svg parameters
if ( properties.contains( "svgFillColor" ) )
{
symbolLayer->setSvgFillColor( QColor( properties["svgFillColor"] ) );
symbolLayer->setSvgFillColor( QgsSymbolLayerV2Utils::decodeColor( properties["svgFillColor"] ) );
}
if ( properties.contains( "svgOutlineColor" ) )
{
symbolLayer->setSvgOutlineColor( QColor( properties["svgOutlineColor"] ) );
symbolLayer->setSvgOutlineColor( QgsSymbolLayerV2Utils::decodeColor( properties["svgOutlineColor"] ) );
}
if ( properties.contains( "svgOutlineWidth" ) )
{
Expand Down Expand Up @@ -1698,8 +1698,8 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
map.insert( "angle", QString::number( mAngle ) );

//svg parameters
map.insert( "svgFillColor", mSvgFillColor.name() );
map.insert( "svgOutlineColor", mSvgOutlineColor.name() );
map.insert( "svgFillColor", QgsSymbolLayerV2Utils::encodeColor( mSvgFillColor ) );
map.insert( "svgOutlineColor", QgsSymbolLayerV2Utils::encodeColor( mSvgOutlineColor ) );
map.insert( "svgOutlineWidth", QString::number( mSvgOutlineWidth ) );

//units
Expand Down
25 changes: 21 additions & 4 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1999,8 +1999,17 @@ void QgsSVGFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
mSvgOutlineWidthUnitComboBox->blockSignals( true );
mSvgOutlineWidthUnitComboBox->setCurrentIndex( mLayer->svgOutlineWidthUnit() );
mSvgOutlineWidthUnitComboBox->blockSignals( false );
mChangeColorButton->blockSignals( true );
mChangeColorButton->setColor( mLayer->svgFillColor() );
mChangeColorButton->blockSignals( false );
mChangeBorderColorButton->blockSignals( true );
mChangeBorderColorButton->setColor( mLayer->svgOutlineColor() );
mChangeBorderColorButton->blockSignals( false );
mBorderWidthSpinBox->blockSignals( true );
mBorderWidthSpinBox->setValue( mLayer->svgOutlineWidth() );
mBorderWidthSpinBox->blockSignals( false );
}
updateParamGui();
updateParamGui( false );
}

QgsSymbolLayerV2* QgsSVGFillSymbolLayerWidget::symbolLayer()
Expand Down Expand Up @@ -2115,19 +2124,27 @@ void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
}
}

void QgsSVGFillSymbolLayerWidget::updateParamGui()
void QgsSVGFillSymbolLayerWidget::updateParamGui( bool resetValues )
{
//activate gui for svg parameters only if supported by the svg file
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QColor defaultFill, defaultOutline;
double defaultOutlineWidth;
QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
if ( hasFillParam )
if ( hasFillParam && resetValues )
{
mChangeColorButton->setColor( defaultFill );
}
mChangeColorButton->setEnabled( hasFillParam );
if ( hasOutlineParam )
if ( hasOutlineParam && resetValues )
{
mChangeBorderColorButton->setColor( defaultOutline );
}
mChangeBorderColorButton->setEnabled( hasOutlineParam );
if ( hasOutlineWidthParam && resetValues )
{
mBorderWidthSpinBox->setValue( defaultOutlineWidth );
}
mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
}

Expand Down
7 changes: 6 additions & 1 deletion src/gui/symbology-ng/qgssymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,12 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr
protected:
QgsSVGFillSymbolLayer* mLayer;
void insertIcons();
void updateParamGui();
/**Enables or disables svg fill color, border color and border width based on whether the
* svg file supports custom parameters.
* @param resetValues set to true to overwrite existing layer fill color, border color and border width
* with default values from svg file
*/
void updateParamGui( bool resetValues = true );

private slots:
void on_mBrowseToolButton_clicked();
Expand Down

0 comments on commit c1d3958

Please sign in to comment.