Skip to content

Commit 7f922b5

Browse files
author
wonder
committed
Refactored output unit encoding/decoding to their own functions
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12762 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7689baa commit 7f922b5

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/core/symbology-ng/qgssymbollayerv2utils.cpp

+31-15
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ QPointF QgsSymbolLayerV2Utils::decodePoint( QString str )
148148
return QPointF( lst[0].toDouble(), lst[1].toDouble() );
149149
}
150150

151+
QString QgsSymbolLayerV2Utils::encodeOutputUnit( QgsSymbolV2::OutputUnit unit )
152+
{
153+
switch ( unit )
154+
{
155+
case QgsSymbolV2::MM:
156+
return "MM";
157+
case QgsSymbolV2::MapUnit:
158+
return "MapUnit";
159+
default:
160+
return "MM";
161+
}
162+
}
163+
164+
QgsSymbolV2::OutputUnit QgsSymbolLayerV2Utils::decodeOutputUnit( QString str )
165+
{
166+
if ( str == "MM" )
167+
{
168+
return QgsSymbolV2::MM;
169+
}
170+
else if ( str == "MapUnit" )
171+
{
172+
return QgsSymbolV2::MapUnit;
173+
}
174+
175+
// milimeters are default
176+
return QgsSymbolV2::MM;
177+
}
178+
151179
QIcon QgsSymbolLayerV2Utils::symbolPreviewIcon( QgsSymbolV2* symbol, QSize size )
152180
{
153181
return QIcon( symbolPreviewPixmap( symbol, size ) );
@@ -343,7 +371,6 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
343371
}
344372

345373
QString symbolType = element.attribute( "type" );
346-
QString unitString = element.attribute( "outputUnit", "MM" );
347374

348375
QgsSymbolV2* symbol = 0;
349376
if ( symbolType == "line" )
@@ -358,14 +385,8 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
358385
return NULL;
359386
}
360387

361-
if ( unitString == "MM" )
362-
{
363-
symbol->setOutputUnit( QgsSymbolV2::MM );
364-
}
365-
else
366-
{
367-
symbol->setOutputUnit( QgsSymbolV2::MapUnit );
368-
}
388+
symbol->setOutputUnit( decodeOutputUnit( element.attribute( "outputUnit" ) ) );
389+
369390
return symbol;
370391
}
371392

@@ -409,12 +430,7 @@ QDomElement QgsSymbolLayerV2Utils::saveSymbol( QString name, QgsSymbolV2* symbol
409430
QDomElement symEl = doc.createElement( "symbol" );
410431
symEl.setAttribute( "type", _nameForSymbolType( symbol->type() ) );
411432
symEl.setAttribute( "name", name );
412-
QString unitString = "MM";
413-
if ( symbol->outputUnit() == QgsSymbolV2::MapUnit )
414-
{
415-
unitString = "MapUnit";
416-
}
417-
symEl.setAttribute( "outputUnit", unitString );
433+
symEl.setAttribute( "outputUnit", encodeOutputUnit( symbol->outputUnit() ) );
418434
QgsDebugMsg( "num layers " + QString::number( symbol->symbolLayerCount() ) );
419435
for ( int i = 0; i < symbol->symbolLayerCount(); i++ )
420436
{

src/core/symbology-ng/qgssymbollayerv2utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
4444
static QString encodePoint( QPointF point );
4545
static QPointF decodePoint( QString str );
4646

47+
static QString encodeOutputUnit( QgsSymbolV2::OutputUnit unit );
48+
static QgsSymbolV2::OutputUnit decodeOutputUnit( QString str );
49+
4750
static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
4851
static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
4952
static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );

0 commit comments

Comments
 (0)