Skip to content

Commit 718093f

Browse files
committed
Restore svg marker selection
1 parent bc61e9f commit 718093f

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -489,30 +489,8 @@ QString QgsSvgMarkerSymbolLayerV2::layerType() const
489489

490490
void QgsSvgMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
491491
{
492-
double pictureSize = 0;
493-
QgsRenderContext& rc = context.renderContext();
494-
495-
if ( rc.painter() && rc.painter()->device() )
496-
{
497-
//correct QPictures DPI correction
498-
pictureSize = context.outputLineWidth( mSize ) / rc.painter()->device()->logicalDpiX() * mPicture.logicalDpiX();
499-
}
500-
else
501-
{
502-
pictureSize = context.outputLineWidth( mSize );
503-
}
504-
QRectF rect( QPointF( -pictureSize / 2.0, -pictureSize / 2.0 ), QSizeF( pictureSize, pictureSize ) );
505-
QSvgRenderer renderer( mPath );
506-
QPainter painter( &mPicture );
507-
renderer.render( &painter, rect );
508-
QPainter selPainter( &mSelPicture );
509-
selPainter.setRenderHint( QPainter::Antialiasing );
510-
selPainter.setBrush( QBrush( context.selectionColor() ) );
511-
selPainter.setPen( Qt::NoPen );
512-
selPainter.drawEllipse( QPointF( 0, 0 ), pictureSize*0.6, pictureSize*0.6 );
513-
renderer.render( &selPainter, rect );
514-
515492
mOrigSize = mSize; // save in case the size would be data defined
493+
Q_UNUSED( context );
516494
}
517495

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

537+
if( context.selected() )
538+
{
539+
QPen pen( context.selectionColor() );
540+
pen.setWidth( 2 );
541+
p->setPen( pen );
542+
p->setBrush( Qt::NoBrush );
543+
double sizePixel = context.outputLineWidth( mSize );
544+
p->drawRect( QRectF( -sizePixel / 2.0, -sizePixel / 2.0, sizePixel, sizePixel ) );
545+
}
546+
559547
p->restore();
560548
}
561549

src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
134134
QColor mFillColor;
135135
QColor mOutlineColor;
136136
double mOutlineWidth;
137-
138-
139-
QPicture mPicture;
140-
QPicture mSelPicture;
141137
double mOrigSize;
142138
};
143139

src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,20 @@ void QgsSvgMarkerSymbolLayerV2Widget::populateList()
576576
viewImages->setModel( m );
577577
}
578578

579+
void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QString& svgPath )
580+
{
581+
//activate gui for svg parameters only if supported by the svg file
582+
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
583+
QgsSvgCache::instance()->containsParams( svgPath, hasFillParam, hasOutlineParam, hasOutlineWidthParam );
584+
mChangeColorButton->setEnabled( hasFillParam );
585+
mChangeBorderColorButton->setEnabled( hasOutlineParam );
586+
mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
587+
588+
mFileLineEdit->blockSignals( true );
589+
mFileLineEdit->setText( svgPath );
590+
mFileLineEdit->blockSignals( false );
591+
}
592+
579593

580594
void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
581595
{
@@ -613,6 +627,8 @@ void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
613627
spinOffsetY->blockSignals( true );
614628
spinOffsetY->setValue( mLayer->offset().y() );
615629
spinOffsetY->blockSignals( false );
630+
631+
setGuiForSvg( mLayer->path() );
616632
}
617633

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

629-
//activate gui for svg parameters only if supported by the svg file
630-
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
631-
QgsSvgCache::instance()->containsParams( name, hasFillParam, hasOutlineParam, hasOutlineWidthParam );
632-
mChangeColorButton->setEnabled( hasFillParam );
633-
mChangeBorderColorButton->setEnabled( hasOutlineParam );
634-
mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
635-
645+
setGuiForSvg( name );
636646
emit changed();
637647
}
638648

@@ -689,6 +699,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mChangeColorButton_clicked()
689699
if ( c.isValid() )
690700
{
691701
mLayer->setFillColor( c );
702+
emit changed();
692703
}
693704
}
694705

@@ -702,6 +713,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mChangeBorderColorButton_clicked()
702713
if ( c.isValid() )
703714
{
704715
mLayer->setOutlineColor( c );
716+
emit changed();
705717
}
706718
}
707719

@@ -710,6 +722,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthSpinBox_valueChanged( doubl
710722
if ( mLayer )
711723
{
712724
mLayer->setOutlineWidth( d );
725+
emit changed();
713726
}
714727
}
715728

src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget
188188
protected:
189189

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

192194
QgsSvgMarkerSymbolLayerV2* mLayer;
193195
};

0 commit comments

Comments
 (0)