Skip to content
Permalink
Browse files

Restore svg marker selection

  • Loading branch information
mhugent committed Jun 27, 2011
1 parent bc61e9f commit 718093fa6c0b348c954c7a8feaa12d70c710aacb
@@ -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 )
@@ -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();
}

@@ -134,10 +134,6 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;


QPicture mPicture;
QPicture mSelPicture;
double mOrigSize;
};

@@ -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 )
{
@@ -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()
@@ -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();
}

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

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

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

@@ -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;
};

0 comments on commit 718093f

Please sign in to comment.
You can’t perform that action at this time.