Skip to content

Commit

Permalink
Restore svg marker selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 27, 2011
1 parent bc61e9f commit 718093f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
34 changes: 11 additions & 23 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -489,30 +489,8 @@ QString QgsSvgMarkerSymbolLayerV2::layerType() const

void QgsSvgMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
double pictureSize = 0;
QgsRenderContext& rc = context.renderContext();

if ( rc.painter() && rc.painter()->device() )
{
//correct QPictures DPI correction
pictureSize = context.outputLineWidth( mSize ) / rc.painter()->device()->logicalDpiX() * mPicture.logicalDpiX();
}
else
{
pictureSize = context.outputLineWidth( mSize );
}
QRectF rect( QPointF( -pictureSize / 2.0, -pictureSize / 2.0 ), QSizeF( pictureSize, pictureSize ) );
QSvgRenderer renderer( mPath );
QPainter painter( &mPicture );
renderer.render( &painter, rect );
QPainter selPainter( &mSelPicture );
selPainter.setRenderHint( QPainter::Antialiasing );
selPainter.setBrush( QBrush( context.selectionColor() ) );
selPainter.setPen( Qt::NoPen );
selPainter.drawEllipse( QPointF( 0, 0 ), pictureSize*0.6, pictureSize*0.6 );
renderer.render( &selPainter, rect );

mOrigSize = mSize; // save in case the size would be data defined
Q_UNUSED( context );
}

void QgsSvgMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
Expand Down Expand Up @@ -556,6 +534,16 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
p->drawPicture( 0, 0, pct );
}

if( context.selected() )
{
QPen pen( context.selectionColor() );
pen.setWidth( 2 );
p->setPen( pen );
p->setBrush( Qt::NoBrush );
double sizePixel = context.outputLineWidth( mSize );
p->drawRect( QRectF( -sizePixel / 2.0, -sizePixel / 2.0, sizePixel, sizePixel ) );
}

p->restore();
}

Expand Down
4 changes: 0 additions & 4 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -134,10 +134,6 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;


QPicture mPicture;
QPicture mSelPicture;
double mOrigSize;
};

Expand Down
27 changes: 20 additions & 7 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -576,6 +576,20 @@ void QgsSvgMarkerSymbolLayerV2Widget::populateList()
viewImages->setModel( m );
}

void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QString& svgPath )
{
//activate gui for svg parameters only if supported by the svg file
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QgsSvgCache::instance()->containsParams( svgPath, hasFillParam, hasOutlineParam, hasOutlineWidthParam );
mChangeColorButton->setEnabled( hasFillParam );
mChangeBorderColorButton->setEnabled( hasOutlineParam );
mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );

mFileLineEdit->blockSignals( true );
mFileLineEdit->setText( svgPath );
mFileLineEdit->blockSignals( false );
}


void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
Expand Down Expand Up @@ -613,6 +627,8 @@ void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
spinOffsetY->blockSignals( true );
spinOffsetY->setValue( mLayer->offset().y() );
spinOffsetY->blockSignals( false );

setGuiForSvg( mLayer->path() );
}

QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2Widget::symbolLayer()
Expand All @@ -626,13 +642,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::setName( const QModelIndex& idx )
mLayer->setPath( name );
mFileLineEdit->setText( name );

//activate gui for svg parameters only if supported by the svg file
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QgsSvgCache::instance()->containsParams( name, hasFillParam, hasOutlineParam, hasOutlineWidthParam );
mChangeColorButton->setEnabled( hasFillParam );
mChangeBorderColorButton->setEnabled( hasOutlineParam );
mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );

setGuiForSvg( name );
emit changed();
}

Expand Down Expand Up @@ -689,6 +699,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mChangeColorButton_clicked()
if ( c.isValid() )
{
mLayer->setFillColor( c );
emit changed();
}
}

Expand All @@ -702,6 +713,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mChangeBorderColorButton_clicked()
if ( c.isValid() )
{
mLayer->setOutlineColor( c );
emit changed();
}
}

Expand All @@ -710,6 +722,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthSpinBox_valueChanged( doubl
if ( mLayer )
{
mLayer->setOutlineWidth( d );
emit changed();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -188,6 +188,8 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget
protected:

void populateList();
//update gui for svg file (insert new path, update activation of gui elements for svg params)
void setGuiForSvg( const QString& svgPath );

QgsSvgMarkerSymbolLayerV2* mLayer;
};
Expand Down

0 comments on commit 718093f

Please sign in to comment.