Skip to content
Permalink
Browse files

Support also style-syntax for svg params

  • Loading branch information
mhugent committed Jun 27, 2011
1 parent 718093f commit 166b3d2589428f72bb642157bc1409abea38a12b
Showing with 53 additions and 17 deletions.
  1. +1 −1 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
  2. +52 −16 src/core/symbology-ng/qgssvgcache.cpp
@@ -537,7 +537,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
if( context.selected() )
{
QPen pen( context.selectionColor() );
pen.setWidth( 2 );
pen.setWidth( context.outputLineWidth( 1.0 ) );
p->setPen( pen );
p->setBrush( Qt::NoBrush );
double sizePixel = context.outputLineWidth( mSize );
@@ -74,7 +74,7 @@ QgsSvgCache::QgsSvgCache(): mTotalSize( 0 )
QgsSvgCache::~QgsSvgCache()
{
QMultiHash< QString, QgsSvgCacheEntry* >::iterator it = mEntryLookup.begin();
for( ; it != mEntryLookup.end(); ++it )
for ( ; it != mEntryLookup.end(); ++it )
{
delete it.value();
}
@@ -94,7 +94,7 @@ const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const Q
}

//debug: display current cache usage
QgsDebugMsg("cache size: " + QString::number( mTotalSize ) );
QgsDebugMsg( "cache size: " + QString::number( mTotalSize ) );

//set entry timestamp to current time
currentEntry->lastUsed = QDateTime::currentDateTime();
@@ -115,7 +115,7 @@ const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, con
}

//debug: display current cache usage
QgsDebugMsg("cache size: " + QString::number( mTotalSize ) );
QgsDebugMsg( "cache size: " + QString::number( mTotalSize ) );

//set entry timestamp to current time
currentEntry->lastUsed = QDateTime::currentDateTime();
@@ -155,15 +155,15 @@ void QgsSvgCache::containsParams( const QString& path, bool& hasFillParam, bool&

//there are surely faster ways to get this information
QString content = svgDoc.toString();
if( content.contains("param(fill") )
if ( content.contains( "param(fill" ) )
{
hasFillParam = true;
}
if( content.contains("param(outline") )
if ( content.contains( "param(outline" ) )
{
hasOutlineParam = true;
}
if( content.contains("param(outline-width)" ) )
if ( content.contains( "param(outline-width)" ) )
{
hasOutlineWidthParam = true;
}
@@ -215,7 +215,7 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry* entry )
r.render( &p );

entry->image = image;
mTotalSize += (image->width() * image->height() * 32);
mTotalSize += ( image->width() * image->height() * 32 );
}

void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry )
@@ -284,18 +284,54 @@ void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, cons
for ( int i = 0; i < nAttributes; ++i )
{
QDomAttr attribute = attributes.item( i ).toAttr();
QString value = attribute.value();
if ( value.startsWith( "param(fill)" ) )
//e.g. style="fill:param(fill);param(stroke)"
if ( attribute.name().compare( "style", Qt::CaseInsensitive ) == 0 )
{
elem.setAttribute( attribute.name(), fill.name() );
//entries separated by ';'
QString newAttributeString;

QStringList entryList = attribute.value().split( ';' );
QStringList::const_iterator entryIt = entryList.constBegin();
for ( ; entryIt != entryList.constEnd(); ++entryIt )
{
QStringList keyValueSplit = entryIt->split( ':' );
if ( keyValueSplit.size() < 2 )
{
continue;
}
QString key = keyValueSplit.at( 0 );
QString value = keyValueSplit.at( 1 );
if ( value.startsWith( "param(fill" ) )
{
value = fill.name();
}
else if ( value.startsWith( "param(outline)" ) )
{
value = outline.name();
}
else if ( value.startsWith( "param(outline-width)" ) )
{
value = QString::number( outlineWidth );
}
newAttributeString.append( key + ":" + value + ";" );
}
elem.setAttribute( attribute.name(), newAttributeString );
}
else if ( value.startsWith( "param(outline)" ) )
else
{
elem.setAttribute( attribute.name(), outline.name() );
}
else if ( value.startsWith( "param(outline-width)" ) )
{
elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
QString value = attribute.value();
if ( value.startsWith( "param(fill)" ) )
{
elem.setAttribute( attribute.name(), fill.name() );
}
else if ( value.startsWith( "param(outline)" ) )
{
elem.setAttribute( attribute.name(), outline.name() );
}
else if ( value.startsWith( "param(outline-width)" ) )
{
elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
}
}
}

0 comments on commit 166b3d2

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