Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Jun 30, 2011
2 parents 4888f51 + b6fa94f commit 127f7c0
Show file tree
Hide file tree
Showing 14 changed files with 938 additions and 61 deletions.
4 changes: 2 additions & 2 deletions images/svg/geometric/Square1.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions images/svg/geometric/Square2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions images/svg/geometric/Triangle1.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/svg/transport/amenity=airport.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions images/svg/transport/amenity=ferry_terminal.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions images/svg/transport/amenity=taxi.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SET(QGIS_CORE_SRCS
symbology-ng/qgsvectorcolorrampv2.cpp
symbology-ng/qgsstylev2.cpp
symbology-ng/qgssymbologyv2conversion.cpp
symbology-ng/qgssvgcache.cpp

qgis.cpp
qgsapplication.cpp
Expand Down
107 changes: 82 additions & 25 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgssvgcache.h"

#include <QPainter>
#include <QSvgRenderer>
Expand Down Expand Up @@ -449,6 +450,9 @@ QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2( QString name, double size,
mSize = size;
mAngle = angle;
mOffset = QPointF( 0, 0 );
mOutlineWidth = 1.0;
mFillColor = QColor( Qt::black );
mOutlineColor = QColor( Qt::black );
}


Expand All @@ -466,11 +470,60 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
angle = props["angle"].toDouble();

QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( name, size, angle );

//we only check the svg default parameters if necessary, since it could be expensive
if( !props.contains("fill") && !props.contains("outline") && !props.contains("outline-width") )
{
QColor fillColor, outlineColor;
double outlineWidth;
bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
QgsSvgCache::instance()->containsParams( name, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
if( hasFillParam )
{
m->setFillColor( fillColor );
}
if( hasOutlineParam )
{
m->setOutlineColor( outlineColor );
}
if( hasOutlineWidthParam )
{
m->setOutlineWidth( outlineWidth );
}
}

if ( props.contains( "offset" ) )
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
if ( props.contains( "fill" ) )
m->setFillColor( QColor( props["fill"] ) );
if ( props.contains( "outline" ) )
m->setOutlineColor( QColor( props["outline"] ) );
if ( props.contains( "outline-width" ) )
m->setOutlineWidth( props["outline-width"].toDouble() );
return m;
}

void QgsSvgMarkerSymbolLayerV2::setPath( 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 )
{
setFillColor( fillColor );
}
if( hasOutlineParam )
{
setOutlineColor( outlineColor );
}
if( hasOutlineWidthParam )
{
setOutlineWidth( outlineWidth );
}
}


QString QgsSvgMarkerSymbolLayerV2::layerType() const
{
Expand All @@ -479,30 +532,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 @@ -533,8 +564,28 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
if ( mAngle != 0 )
p->rotate( mAngle );

QPicture &pct = context.selected() ? mSelPicture : mPicture;
p->drawPicture( 0, 0, pct );
if ( doubleNear( context.renderContext().rasterScaleFactor(), 1.0, 0.1 ) )
{
const QImage& img = QgsSvgCache::instance()->svgAsImage( mPath, mSize, mFillColor, mOutlineColor, mOutlineWidth,
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawImage( -img.width() / 2.0, -img.width() / 2.0, img );
}
else
{
const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( mPath, mSize, mFillColor, mOutlineColor, mOutlineWidth,
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawPicture( 0, 0, pct );
}

if( context.selected() )
{
QPen pen( context.selectionColor() );
pen.setWidth( context.outputLineWidth( 1.0 ) );
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 All @@ -547,12 +598,18 @@ QgsStringMap QgsSvgMarkerSymbolLayerV2::properties() const
map["size"] = QString::number( mSize );
map["angle"] = QString::number( mAngle );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["fill"] = mFillColor.name();
map["outline"] = mOutlineColor.name();
map["outline-width"] = QString::number( mOutlineWidth );
return map;
}

QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
{
QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( mPath, mSize, mAngle );
m->setFillColor( mFillColor );
m->setOutlineColor( mOutlineColor );
m->setOutlineWidth( mOutlineWidth );
m->setOffset( mOffset );
return m;
}
Expand Down
19 changes: 16 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,28 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QgsSymbolLayerV2* clone() const;

QString path() const { return mPath; }
void setPath( QString path ) { mPath = path; }
void setPath( QString path );

QColor fillColor() const { return mFillColor; }
void setFillColor( const QColor& c ) { mFillColor = c; }

QColor outlineColor() const { return mOutlineColor; }
void setOutlineColor( const QColor& c ) { mOutlineColor = c; }

double outlineWidth() const { return mOutlineWidth; }
void setOutlineWidth( double w ) { mOutlineWidth = w; }

protected:

void loadSvg();

QString mPath;
QPicture mPicture;
QPicture mSelPicture;

//param(fill), param(outline), param(outline-width) are going
//to be replaced in memory
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;
double mOrigSize;
};

Expand Down

0 comments on commit 127f7c0

Please sign in to comment.