Skip to content

Commit

Permalink
Refactored output unit encoding/decoding to their own functions
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12762 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 14, 2010
1 parent 95c2fdd commit 7505309
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -148,6 +148,34 @@ QPointF QgsSymbolLayerV2Utils::decodePoint( QString str )
return QPointF( lst[0].toDouble(), lst[1].toDouble() );
}

QString QgsSymbolLayerV2Utils::encodeOutputUnit( QgsSymbolV2::OutputUnit unit )
{
switch ( unit )
{
case QgsSymbolV2::MM:
return "MM";
case QgsSymbolV2::MapUnit:
return "MapUnit";
default:
return "MM";
}
}

QgsSymbolV2::OutputUnit QgsSymbolLayerV2Utils::decodeOutputUnit( QString str )
{
if ( str == "MM" )
{
return QgsSymbolV2::MM;
}
else if ( str == "MapUnit" )
{
return QgsSymbolV2::MapUnit;
}

// milimeters are default
return QgsSymbolV2::MM;
}

QIcon QgsSymbolLayerV2Utils::symbolPreviewIcon( QgsSymbolV2* symbol, QSize size )
{
return QIcon( symbolPreviewPixmap( symbol, size ) );
Expand Down Expand Up @@ -343,7 +371,6 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
}

QString symbolType = element.attribute( "type" );
QString unitString = element.attribute( "outputUnit", "MM" );

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

if ( unitString == "MM" )
{
symbol->setOutputUnit( QgsSymbolV2::MM );
}
else
{
symbol->setOutputUnit( QgsSymbolV2::MapUnit );
}
symbol->setOutputUnit( decodeOutputUnit( element.attribute( "outputUnit" ) ) );

return symbol;
}

Expand Down Expand Up @@ -409,12 +430,7 @@ QDomElement QgsSymbolLayerV2Utils::saveSymbol( QString name, QgsSymbolV2* symbol
QDomElement symEl = doc.createElement( "symbol" );
symEl.setAttribute( "type", _nameForSymbolType( symbol->type() ) );
symEl.setAttribute( "name", name );
QString unitString = "MM";
if ( symbol->outputUnit() == QgsSymbolV2::MapUnit )
{
unitString = "MapUnit";
}
symEl.setAttribute( "outputUnit", unitString );
symEl.setAttribute( "outputUnit", encodeOutputUnit( symbol->outputUnit() ) );
QgsDebugMsg( "num layers " + QString::number( symbol->symbolLayerCount() ) );
for ( int i = 0; i < symbol->symbolLayerCount(); i++ )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -44,6 +44,9 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
static QString encodePoint( QPointF point );
static QPointF decodePoint( QString str );

static QString encodeOutputUnit( QgsSymbolV2::OutputUnit unit );
static QgsSymbolV2::OutputUnit decodeOutputUnit( QString str );

static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );
Expand Down

0 comments on commit 7505309

Please sign in to comment.