Skip to content

Commit 166b3d2

Browse files
committedJun 27, 2011
Support also style-syntax for svg params
1 parent 718093f commit 166b3d2

File tree

2 files changed

+53
-17
lines changed

2 files changed

+53
-17
lines changed
 

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
537537
if( context.selected() )
538538
{
539539
QPen pen( context.selectionColor() );
540-
pen.setWidth( 2 );
540+
pen.setWidth( context.outputLineWidth( 1.0 ) );
541541
p->setPen( pen );
542542
p->setBrush( Qt::NoBrush );
543543
double sizePixel = context.outputLineWidth( mSize );

‎src/core/symbology-ng/qgssvgcache.cpp

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ QgsSvgCache::QgsSvgCache(): mTotalSize( 0 )
7474
QgsSvgCache::~QgsSvgCache()
7575
{
7676
QMultiHash< QString, QgsSvgCacheEntry* >::iterator it = mEntryLookup.begin();
77-
for( ; it != mEntryLookup.end(); ++it )
77+
for ( ; it != mEntryLookup.end(); ++it )
7878
{
7979
delete it.value();
8080
}
@@ -94,7 +94,7 @@ const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const Q
9494
}
9595

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

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

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

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

156156
//there are surely faster ways to get this information
157157
QString content = svgDoc.toString();
158-
if( content.contains("param(fill") )
158+
if ( content.contains( "param(fill" ) )
159159
{
160160
hasFillParam = true;
161161
}
162-
if( content.contains("param(outline") )
162+
if ( content.contains( "param(outline" ) )
163163
{
164164
hasOutlineParam = true;
165165
}
166-
if( content.contains("param(outline-width)" ) )
166+
if ( content.contains( "param(outline-width)" ) )
167167
{
168168
hasOutlineWidthParam = true;
169169
}
@@ -215,7 +215,7 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry* entry )
215215
r.render( &p );
216216

217217
entry->image = image;
218-
mTotalSize += (image->width() * image->height() * 32);
218+
mTotalSize += ( image->width() * image->height() * 32 );
219219
}
220220

221221
void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry )
@@ -284,18 +284,54 @@ void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, cons
284284
for ( int i = 0; i < nAttributes; ++i )
285285
{
286286
QDomAttr attribute = attributes.item( i ).toAttr();
287-
QString value = attribute.value();
288-
if ( value.startsWith( "param(fill)" ) )
287+
//e.g. style="fill:param(fill);param(stroke)"
288+
if ( attribute.name().compare( "style", Qt::CaseInsensitive ) == 0 )
289289
{
290-
elem.setAttribute( attribute.name(), fill.name() );
290+
//entries separated by ';'
291+
QString newAttributeString;
292+
293+
QStringList entryList = attribute.value().split( ';' );
294+
QStringList::const_iterator entryIt = entryList.constBegin();
295+
for ( ; entryIt != entryList.constEnd(); ++entryIt )
296+
{
297+
QStringList keyValueSplit = entryIt->split( ':' );
298+
if ( keyValueSplit.size() < 2 )
299+
{
300+
continue;
301+
}
302+
QString key = keyValueSplit.at( 0 );
303+
QString value = keyValueSplit.at( 1 );
304+
if ( value.startsWith( "param(fill" ) )
305+
{
306+
value = fill.name();
307+
}
308+
else if ( value.startsWith( "param(outline)" ) )
309+
{
310+
value = outline.name();
311+
}
312+
else if ( value.startsWith( "param(outline-width)" ) )
313+
{
314+
value = QString::number( outlineWidth );
315+
}
316+
newAttributeString.append( key + ":" + value + ";" );
317+
}
318+
elem.setAttribute( attribute.name(), newAttributeString );
291319
}
292-
else if ( value.startsWith( "param(outline)" ) )
320+
else
293321
{
294-
elem.setAttribute( attribute.name(), outline.name() );
295-
}
296-
else if ( value.startsWith( "param(outline-width)" ) )
297-
{
298-
elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
322+
QString value = attribute.value();
323+
if ( value.startsWith( "param(fill)" ) )
324+
{
325+
elem.setAttribute( attribute.name(), fill.name() );
326+
}
327+
else if ( value.startsWith( "param(outline)" ) )
328+
{
329+
elem.setAttribute( attribute.name(), outline.name() );
330+
}
331+
else if ( value.startsWith( "param(outline-width)" ) )
332+
{
333+
elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
334+
}
299335
}
300336
}
301337

0 commit comments

Comments
 (0)
Please sign in to comment.