Skip to content
Permalink
Browse files

Refactored output unit encoding/decoding to their own functions

git-svn-id: http://svn.osgeo.org/qgis/trunk@12762 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jan 14, 2010
1 parent 95c2fdd commit 7505309ba6290451bb8541231ae4154b82a361d1
Showing with 34 additions and 15 deletions.
  1. +31 −15 src/core/symbology-ng/qgssymbollayerv2utils.cpp
  2. +3 −0 src/core/symbology-ng/qgssymbollayerv2utils.h
@@ -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 ) );
@@ -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" )
@@ -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;
}

@@ -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++ )
{
@@ -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 );

0 comments on commit 7505309

Please sign in to comment.