[QGIS Commit] r12762 - trunk/qgis/src/core/symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jan 14 13:33:25 EST 2010


Author: wonder
Date: 2010-01-14 13:33:24 -0500 (Thu, 14 Jan 2010)
New Revision: 12762

Modified:
   trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
   trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h
Log:
Refactored output unit encoding/decoding to their own functions


Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-01-14 18:20:34 UTC (rev 12761)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-01-14 18:33:24 UTC (rev 12762)
@@ -148,6 +148,34 @@
   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 @@
   }
 
   QString symbolType = element.attribute( "type" );
-  QString unitString = element.attribute( "outputUnit", "MM" );
 
   QgsSymbolV2* symbol = 0;
   if ( symbolType == "line" )
@@ -358,14 +385,8 @@
     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 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++ )
   {

Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h	2010-01-14 18:20:34 UTC (rev 12761)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h	2010-01-14 18:33:24 UTC (rev 12762)
@@ -44,6 +44,9 @@
     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 );



More information about the QGIS-commit mailing list