[QGIS Commit] r9747 - in trunk/qgis: python/core src/core src/core/composer src/core/raster src/core/renderer src/core/symbology

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Dec 6 22:10:00 EST 2008


Author: jef
Date: 2008-12-06 22:10:00 -0500 (Sat, 06 Dec 2008)
New Revision: 9747

Modified:
   trunk/qgis/python/core/qgsmaplayer.sip
   trunk/qgis/python/core/qgsrasterlayer.sip
   trunk/qgis/python/core/qgssymbol.sip
   trunk/qgis/python/core/qgsvectorlayer.sip
   trunk/qgis/src/core/composer/qgscomposeritem.cpp
   trunk/qgis/src/core/composer/qgscomposeritem.h
   trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp
   trunk/qgis/src/core/composer/qgscomposeritemgroup.h
   trunk/qgis/src/core/composer/qgscomposerlabel.cpp
   trunk/qgis/src/core/composer/qgscomposerlabel.h
   trunk/qgis/src/core/composer/qgscomposerlegend.cpp
   trunk/qgis/src/core/composer/qgscomposerlegend.h
   trunk/qgis/src/core/composer/qgscomposermap.cpp
   trunk/qgis/src/core/composer/qgscomposermap.h
   trunk/qgis/src/core/composer/qgscomposerpicture.cpp
   trunk/qgis/src/core/composer/qgscomposerpicture.h
   trunk/qgis/src/core/composer/qgscomposerscalebar.cpp
   trunk/qgis/src/core/composer/qgscomposerscalebar.h
   trunk/qgis/src/core/composer/qgslegendmodel.cpp
   trunk/qgis/src/core/composer/qgslegendmodel.h
   trunk/qgis/src/core/qgsattributeaction.cpp
   trunk/qgis/src/core/qgsattributeaction.h
   trunk/qgis/src/core/qgsgeometry.cpp
   trunk/qgis/src/core/qgslabel.cpp
   trunk/qgis/src/core/qgslabel.h
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/core/qgsvectorlayer.h
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
   trunk/qgis/src/core/renderer/qgscontinuouscolorrenderer.cpp
   trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp
   trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp
   trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
   trunk/qgis/src/core/symbology/qgssymbol.cpp
   trunk/qgis/src/core/symbology/qgssymbol.h
Log:
new fix for #1162 restoring lost qml features

Modified: trunk/qgis/python/core/qgsmaplayer.sip
===================================================================
--- trunk/qgis/python/core/qgsmaplayer.sip	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/python/core/qgsmaplayer.sip	2008-12-07 03:10:00 UTC (rev 9747)
@@ -142,7 +142,7 @@
 
        @returns true if successful
     */
-    bool writeXML(QDomNode & layer_node, QDomDocument & document);
+    bool writeXML(QDomNode & layer_node, QDomDocument & document) const;
 
     /** Read the symbology for the current layer from the Dom node supplied. 
      * @param QDomNode node that will contain the symbology definition for this layer.

Modified: trunk/qgis/python/core/qgsrasterlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsrasterlayer.sip	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/python/core/qgsrasterlayer.sip	2008-12-07 03:10:00 UTC (rev 9747)
@@ -489,7 +489,7 @@
     bool readXml( QDomNode & layer_node );
 
     /** \brief Write the symbology for the layer into the docment provided */
-    bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
+    bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage );
 
     /** \brief Write layer specific state to project file Dom node */
     bool writeXml( QDomNode & layer_node, QDomDocument & doc );

Modified: trunk/qgis/python/core/qgssymbol.sip
===================================================================
--- trunk/qgis/python/core/qgssymbol.sip	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/python/core/qgssymbol.sip	2008-12-07 03:10:00 UTC (rev 9747)
@@ -70,10 +70,10 @@
 
     /**Writes the contents of the symbol to a configuration file
      @ return true in case of success*/
-    virtual bool writeXML( QDomNode & item, QDomDocument & document ) const;
+    virtual bool writeXML( QDomNode & item, QDomDocument & document, const QgsVectorLayer *vl ) const;
     /**Reads the contents of the symbol from a configuration file
      @ return true in case of success*/
-    virtual bool readXML( QDomNode & symbol );
+    virtual bool readXML( QDomNode & symbol, const QgsVectorLayer *vl );
     /**Returns if this symbol is point/ line or polygon*/
     QGis::GeometryType type() const;
 

Modified: trunk/qgis/python/core/qgsvectorlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorlayer.sip	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/python/core/qgsvectorlayer.sip	2008-12-07 03:10:00 UTC (rev 9747)
@@ -127,7 +127,7 @@
    * @param errorMessage reference to string that will be updated with any error messages
    *  @return true in case of success.
    */
-  bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const;
+  bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage);
 
   /**
    * Number of features in the layer. This is necessary if features are

Modified: trunk/qgis/src/core/composer/qgscomposeritem.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposeritem.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -92,7 +92,7 @@
 
 bool QgsComposerItem::removeSettings( void )  { return true; }
 
-bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc )
+bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) const
 {
   if ( itemElem.isNull() )
   {

Modified: trunk/qgis/src/core/composer/qgscomposeritem.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposeritem.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -89,10 +89,10 @@
      * @param node is Dom node corresponding to 'Composer' tag
      * @param temp write template file
      */
-    virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) = 0;
+    virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
 
     /**Writes parameter that are not subclass specific in document. Usually called from writeXML methods of subclasses*/
-    bool _writeXML( QDomElement& itemElem, QDomDocument& doc );
+    bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
 
     /** sets state from Dom document
      * @param itemElem is Dom node corresponding to item tag

Modified: trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -164,7 +164,7 @@
   }
 }
 
-bool QgsComposerItemGroup::writeXML( QDomElement& elem, QDomDocument & doc )
+bool QgsComposerItemGroup::writeXML( QDomElement& elem, QDomDocument & doc ) const
 {
   return true; //soon...
 }

Modified: trunk/qgis/src/core/composer/qgscomposeritemgroup.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritemgroup.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposeritemgroup.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -45,7 +45,7 @@
        * @param elem is Dom element corresponding to 'Composer' tag
        * @param temp write template file
        */
-    bool writeXML( QDomElement& elem, QDomDocument & doc );
+    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
     /** sets state from Dom document
        * @param itemElem is Dom node corresponding to item tag

Modified: trunk/qgis/src/core/composer/qgscomposerlabel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlabel.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerlabel.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -80,7 +80,7 @@
   return mFont;
 }
 
-bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc )
+bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const
 {
   if ( elem.isNull() )
   {

Modified: trunk/qgis/src/core/composer/qgscomposerlabel.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlabel.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerlabel.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -45,7 +45,7 @@
        * @param node is Dom node corresponding to 'Composer' tag
        * @param temp write template file
        */
-    bool writeXML( QDomElement& elem, QDomDocument & doc );
+    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
     /** sets state from Dom document
        * @param node is Dom node corresponding to 'ComposerLabel' tag

Modified: trunk/qgis/src/core/composer/qgscomposerlegend.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegend.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerlegend.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -95,38 +95,38 @@
   //draw only visible layer items
   QgsMapRenderer* theMapRenderer = mComposition->mapRenderer();
   QStringList visibleLayerIds;
-  if(theMapRenderer)
-    {
-      visibleLayerIds = theMapRenderer->layerSet();
-    }
-  
+  if ( theMapRenderer )
+  {
+    visibleLayerIds = theMapRenderer->layerSet();
+  }
 
+
   for ( int i = 0; i < numLayerItems; ++i )
   {
     currentLayerItem = rootItem->child( i );
     if ( currentLayerItem )
     {
       QString currentLayerId = currentLayerItem->data().toString();
-      if(visibleLayerIds.contains(currentLayerId))
-	{
-	  //Let the user omit the layer title item by having an empty layer title string
-	  if(!currentLayerItem->text().isEmpty())
-	    {
-	      currentYCoordinate += mLayerSpace;
-	      currentYCoordinate += fontAscentMillimeters( mLayerFont );
+      if ( visibleLayerIds.contains( currentLayerId ) )
+      {
+        //Let the user omit the layer title item by having an empty layer title string
+        if ( !currentLayerItem->text().isEmpty() )
+        {
+          currentYCoordinate += mLayerSpace;
+          currentYCoordinate += fontAscentMillimeters( mLayerFont );
 
-	      //draw layer Item
-	      if ( painter )
-		{
-		  drawText( painter, mBoxSpace, currentYCoordinate, currentLayerItem->text(), mLayerFont );
-		}
-	    }
+          //draw layer Item
+          if ( painter )
+          {
+            drawText( painter, mBoxSpace, currentYCoordinate, currentLayerItem->text(), mLayerFont );
+          }
+        }
 
-	  maxXCoord = std::max( maxXCoord, 2 * mBoxSpace + textWidthMillimeters( mLayerFont, currentLayerItem->text() ) );
+        maxXCoord = std::max( maxXCoord, 2 * mBoxSpace + textWidthMillimeters( mLayerFont, currentLayerItem->text() ) );
 
-	  //and child items
-	  drawLayerChildItems( painter, currentLayerItem, currentYCoordinate, maxXCoord );
-	}
+        //and child items
+        drawLayerChildItems( painter, currentLayerItem, currentYCoordinate, maxXCoord );
+      }
     }
   }
 
@@ -148,15 +148,15 @@
   size.setWidth( maxXCoord );
 
   //adjust box if width or height is to small
-  if(painter && currentYCoordinate > rect().width())
-    {
-      setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), currentYCoordinate));
-    }
-  if(painter && maxXCoord > rect().height())
-    {
-      setSceneRect( QRectF( transform().dx(), transform().dy(), maxXCoord, rect().height()));
-    }
-  
+  if ( painter && currentYCoordinate > rect().width() )
+  {
+    setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), currentYCoordinate ) );
+  }
+  if ( painter && maxXCoord > rect().height() )
+  {
+    setSceneRect( QRectF( transform().dx(), transform().dy(), maxXCoord, rect().height() ) );
+  }
+
   return size;
 }
 
@@ -402,7 +402,7 @@
   update();
 }
 
-bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc )
+bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
 {
   if ( elem.isNull() )
   {

Modified: trunk/qgis/src/core/composer/qgscomposerlegend.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegend.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerlegend.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -85,7 +85,7 @@
        * @param elem is Dom element corresponding to 'Composer' tag
        * @param temp write template file
        */
-    bool writeXML( QDomElement& elem, QDomDocument & doc );
+    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
     /** sets state from Dom document
        * @param itemElem is Dom node corresponding to item tag

Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -466,7 +466,7 @@
   }
 }
 
-bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc )
+bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
 {
   if ( elem.isNull() )
   {
@@ -497,8 +497,11 @@
   extentElem.setAttribute( "ymax", QString::number( mExtent.yMaximum() ) );
   composerMapElem.appendChild( extentElem );
 
+#if 0
+  // why is saving the map changing anything about the cache?
   mCacheUpdated = false;
   mNumCachedLayers = 0;
+#endif
 
   elem.appendChild( composerMapElem );
   return _writeXML( composerMapElem, doc );

Modified: trunk/qgis/src/core/composer/qgscomposermap.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposermap.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -125,7 +125,7 @@
      * @param elem is Dom element corresponding to 'Composer' tag
      * @param temp write template file
      */
-    bool writeXML( QDomElement& elem, QDomDocument & doc );
+    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
     /** sets state from Dom document
      * @param itemElem is Dom node corresponding to 'ComposerMap' tag

Modified: trunk/qgis/src/core/composer/qgscomposerpicture.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerpicture.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerpicture.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -137,10 +137,10 @@
     }
   }
 
-  if(mMode != Unknown) //make sure we start with a new QImage
-    {
-      setSceneRect(QRectF(transform().dx(), transform().dy(), rect().width(), rect().height()));
-    }
+  if ( mMode != Unknown ) //make sure we start with a new QImage
+  {
+    setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), rect().height() ) );
+  }
   emit settingsChanged();
 }
 
@@ -202,7 +202,7 @@
   return mSourceFile.fileName();
 }
 
-bool QgsComposerPicture::writeXML( QDomElement& elem, QDomDocument & doc )
+bool QgsComposerPicture::writeXML( QDomElement& elem, QDomDocument & doc ) const
 {
   if ( elem.isNull() )
   {

Modified: trunk/qgis/src/core/composer/qgscomposerpicture.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerpicture.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerpicture.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -51,7 +51,7 @@
        * @param node is Dom node corresponding to 'Composer' tag
        * @param temp write template file
        */
-    bool writeXML( QDomElement& elem, QDomDocument & doc );
+    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
     /** sets state from Dom document
       * @param itemElem is Dom node corresponding to item tag

Modified: trunk/qgis/src/core/composer/qgscomposerscalebar.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerscalebar.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerscalebar.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -264,7 +264,7 @@
   update();
 }
 
-bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc )
+bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) const
 {
   if ( elem.isNull() )
   {

Modified: trunk/qgis/src/core/composer/qgscomposerscalebar.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerscalebar.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgscomposerscalebar.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -106,7 +106,7 @@
        * @param elem is Dom element corresponding to 'Composer' tag
        * @param temp write template file
        */
-    bool writeXML( QDomElement& elem, QDomDocument & doc );
+    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
     /** sets state from Dom document
        * @param itemElem is Dom node corresponding to item tag

Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -479,7 +479,7 @@
   return currentSymbolItem;
 }
 
-bool QgsLegendModel::writeXML( QDomElement& composerLegendElem, QDomDocument& doc )
+bool QgsLegendModel::writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const
 {
   if ( composerLegendElem.isNull() )
   {
@@ -518,7 +518,7 @@
       {
         QDomElement vectorClassElem = doc.createElement( "VectorClassificationItem" );
         vectorClassElem.setAttribute( "text", currentClassificationItem->text() );
-        symbol->writeXML( vectorClassElem, doc );
+        symbol->writeXML( vectorClassElem, doc, 0 );
         newLayerItem.appendChild( vectorClassElem );
         continue;
       }
@@ -601,7 +601,7 @@
           {
             QgsSymbol* symbol = new QgsSymbol( vectorLayer->geometryType() );
             QDomNode symbolNode = symbolNodeList.at( 0 );
-            symbol->readXML( symbolNode );
+            symbol->readXML( symbolNode, vectorLayer );
             childItem->setData( QVariant::fromValue(( void* )symbol ) );
 
             //add icon

Modified: trunk/qgis/src/core/composer/qgslegendmodel.h
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/composer/qgslegendmodel.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -49,7 +49,7 @@
     void updateVectorClassificationItem( QStandardItem* classificationItem, QgsSymbol* symbol, QString itemText );
     void updateRasterClassificationItem( QStandardItem* classificationItem );
 
-    bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc );
+    bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const;
     bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
 
   public slots:

Modified: trunk/qgis/src/core/qgsattributeaction.cpp
===================================================================
--- trunk/qgis/src/core/qgsattributeaction.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgsattributeaction.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -135,8 +135,10 @@
   return true;
 }
 
-bool QgsAttributeAction::readXML( QDomNode& layer_node )
+bool QgsAttributeAction::readXML( const QDomNode& layer_node )
 {
+  mActions.clear();
+
   QDomNode aaNode = layer_node.namedItem( "attributeactions" );
 
   if ( !aaNode.isNull() )

Modified: trunk/qgis/src/core/qgsattributeaction.h
===================================================================
--- trunk/qgis/src/core/qgsattributeaction.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgsattributeaction.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -121,7 +121,7 @@
     bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
 
     //! Reads the actions in in XML format
-    bool readXML( QDomNode& layer_node );
+    bool readXML( const QDomNode& layer_node );
 
   private:
 

Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -2616,14 +2616,14 @@
   //Fill GEOS Polygons of the feature into list
   QVector<const GEOSGeometry*> polygonList;
 
-  if ( this->wkbType() == QGis::WKBPolygon )
+  if ( wkbType() == QGis::WKBPolygon )
   {
     if ( type != GEOS_POLYGON )
       return 1;
 
     polygonList << mGeos;
   }
-  else if ( this->wkbType() == QGis::WKBMultiPolygon )
+  else if ( wkbType() == QGis::WKBMultiPolygon )
   {
     if ( type != GEOS_MULTIPOLYGON )
       return 1;
@@ -2754,12 +2754,12 @@
 
   GEOSGeometry *newPolygon = createGeosPolygon( rings );
 
-  if ( this->wkbType() == QGis::WKBPolygon )
+  if ( wkbType() == QGis::WKBPolygon )
   {
     GEOSGeom_destroy( mGeos );
     mGeos = newPolygon;
   }
-  else if ( this->wkbType() == QGis::WKBMultiPolygon )
+  else if ( wkbType() == QGis::WKBMultiPolygon )
   {
     QVector<GEOSGeometry*> newPolygons;
 
@@ -5003,21 +5003,21 @@
   return unionGeometry;
 }
 
-int QgsGeometry::numberOfGeometries(GEOSGeometry* g) const
+int QgsGeometry::numberOfGeometries( GEOSGeometry* g ) const
 {
-  if(!g)
+  if ( !g )
   {
     return 0;
   }
-  int geometryType = GEOSGeomTypeId(g);
-  if(geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING
-     || geometryType == GEOS_POLYGON)
+  int geometryType = GEOSGeomTypeId( g );
+  if ( geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING
+       || geometryType == GEOS_POLYGON )
   {
     return 1;
   }
 
   //calling GEOSGetNumGeometries is save for multi types and collections also in geos2
-  return GEOSGetNumGeometries(g);
+  return GEOSGetNumGeometries( g );
 }
 
 int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitResult )

Modified: trunk/qgis/src/core/qgslabel.cpp
===================================================================
--- trunk/qgis/src/core/qgslabel.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgslabel.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -47,9 +47,9 @@
   "$Id$";
 
 QgsLabel::QgsLabel( const QgsFieldMap & fields )
-: mMinScale(0 ),
-  mMaxScale(100000000),
-  mScaleBasedVisibility(false)
+    : mMinScale( 0 ),
+    mMaxScale( 100000000 ),
+    mScaleBasedVisibility( false )
 {
   mField = fields;
   mLabelFieldIdx.resize( LabelFieldCount );
@@ -461,7 +461,7 @@
   painter->restore();
 }
 
-void QgsLabel::addRequiredFields( QgsAttributeList& fields )
+void QgsLabel::addRequiredFields( QgsAttributeList& fields ) const
 {
   for ( uint i = 0; i < LabelFieldCount; i++ )
   {
@@ -501,7 +501,7 @@
   mLabelFieldIdx[attr] = fieldIndex;
 }
 
-QString QgsLabel::labelField( int attr )
+QString QgsLabel::labelField( int attr ) const
 {
   if ( attr > LabelFieldCount )
     return QString();
@@ -636,7 +636,7 @@
 
           point.p.set( pts[dims*( i-1 )]   + k * dx,
                        pts[dims*( i-1 )+1] + k * dy );
-          point.angle = atan2(dy,dx)*180.0*M_1_PI;
+          point.angle = atan2( dy, dx ) * 180.0 * M_1_PI;
           break;
         }
 
@@ -692,15 +692,34 @@
   return geom;
 }
 
-static int _elementFieldIndex( QDomElement& el )
+bool QgsLabel::readLabelField( QDomElement &el, int attr, QString prefix = "field" )
 {
-  QString str = el.attribute( "field", "" );
-  if ( str == "" )
-    return -1;
-  else
-    return str.toInt();
+  QString name = prefix + "name";
+
+  if ( el.hasAttribute( name ) )
+  {
+    name = el.attribute( name );
+
+    int i;
+    for ( i = 0; i < mField.size() && mField[i].name() != name; i++ )
+      ;
+
+    if ( i < mField.size() )
+    {
+      mLabelFieldIdx[attr] = i;
+      return true;
+    }
+  }
+  else if ( el.hasAttribute( prefix ) )
+  {
+    mLabelFieldIdx[attr] = el.attribute( prefix ).toInt();
+  }
+
+  mLabelFieldIdx[attr] = -1;
+  return false;
 }
 
+
 void QgsLabel::readXML( const QDomNode& node )
 {
   QgsDebugMsg( " called for layer label properties, got node " + node.nodeName() );
@@ -722,7 +741,7 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setText( el.attribute( "text", "" ) );
-    setLabelField( Text, _elementFieldIndex( el ) );
+    readLabelField( el, Text );
   }
 
   /* Family */
@@ -736,7 +755,7 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setFamily( el.attribute( "name", "" ) );
-    setLabelField( Family, _elementFieldIndex( el ) );
+    readLabelField( el, Family );
   }
 
   /* Size */
@@ -749,17 +768,16 @@
   else
   {
     el = scratchNode.toElement();
-    if ( !el.hasAttribute( "unitfield" ) )
+    if ( !el.hasAttribute( "unitfieldname" ) )
     {
       type = QgsLabelAttributes::unitsCode( el.attribute( "units", "" ) );
       mLabelAttributes->setSize( el.attribute( "value", "0.0" ).toDouble(), type );
     }
     else
     {
-      QString str = el.attribute( "unitfield", "" );
-      setLabelField( SizeType, str == "" ? -1 : str.toInt() );
+      readLabelField( el, SizeType, "unitfield" );
     }
-    setLabelField( Size, _elementFieldIndex( el ) );
+    readLabelField( el, Size );
   }
 
   /* Bold */
@@ -773,7 +791,7 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setBold(( bool )el.attribute( "on", "0" ).toInt() );
-    setLabelField( Bold, _elementFieldIndex( el ) );
+    readLabelField( el, Bold );
   }
 
   /* Italic */
@@ -787,7 +805,7 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setItalic(( bool )el.attribute( "on", "0" ).toInt() );
-    setLabelField( Italic, _elementFieldIndex( el ) );
+    readLabelField( el, Italic );
   }
 
   /* Underline */
@@ -801,7 +819,7 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setUnderline(( bool )el.attribute( "on", "0" ).toInt() );
-    setLabelField( Underline, _elementFieldIndex( el ) );
+    readLabelField( el, Underline );
   }
 
   /* Color */
@@ -821,7 +839,7 @@
 
     mLabelAttributes->setColor( QColor( red, green, blue ) );
 
-    setLabelField( Color, _elementFieldIndex( el ) );
+    readLabelField( el, Color );
   }
 
   /* X */
@@ -834,7 +852,7 @@
   else
   {
     el = scratchNode.toElement();
-    setLabelField( XCoordinate, _elementFieldIndex( el ) );
+    readLabelField( el, XCoordinate );
   }
 
   /* Y */
@@ -847,7 +865,7 @@
   else
   {
     el = scratchNode.toElement();
-    setLabelField( YCoordinate, _elementFieldIndex( el ) );
+    readLabelField( el, YCoordinate );
   }
 
 
@@ -869,8 +887,8 @@
     yoffset = el.attribute( "y", "0.0" ).toDouble();
 
     mLabelAttributes->setOffset( xoffset, yoffset, type );
-    setLabelField( XOffset, el.attribute( "xfield", "0" ).toInt() );
-    setLabelField( YOffset, el.attribute( "yfield", "0" ).toInt() );
+    readLabelField( el, XOffset, "xfield" );
+    readLabelField( el, YOffset, "yfield" );
   }
 
   /* Angle */
@@ -884,8 +902,8 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setAngle( el.attribute( "value", "0.0" ).toDouble() );
-    setLabelField( Angle, _elementFieldIndex( el ) );
-    mLabelAttributes->setAutoAngle( el.attribute( "auto", "0" )=="1" );
+    readLabelField( el, Angle );
+    mLabelAttributes->setAutoAngle( el.attribute( "auto", "0" ) == "1" );
   }
 
   /* Alignment */
@@ -899,7 +917,7 @@
   {
     el = scratchNode.toElement();
     mLabelAttributes->setAlignment( QgsLabelAttributes::alignmentCode( el.attribute( "value", "" ) ) );
-    setLabelField( Alignment, _elementFieldIndex( el ) );
+    readLabelField( el, Alignment );
   }
 
 
@@ -919,7 +937,7 @@
     blue = el.attribute( "blue", "0" ).toInt();
 
     mLabelAttributes->setBufferColor( QColor( red, green, blue ) );
-    setLabelField( BufferColor, _elementFieldIndex( el ) );
+    readLabelField( el, BufferColor );
   }
 
   scratchNode = node.namedItem( "buffersize" );
@@ -934,7 +952,7 @@
 
     type = QgsLabelAttributes::unitsCode( el.attribute( "units", "" ) );
     mLabelAttributes->setBufferSize( el.attribute( "value", "0.0" ).toDouble(), type );
-    setLabelField( BufferSize, _elementFieldIndex( el ) );
+    readLabelField( el, BufferSize );
   }
 
   scratchNode = node.namedItem( "bufferenabled" );
@@ -948,7 +966,7 @@
     el = scratchNode.toElement();
 
     mLabelAttributes->setBufferEnabled(( bool )el.attribute( "on", "0" ).toInt() );
-    setLabelField( BufferEnabled, _elementFieldIndex( el ) );
+    readLabelField( el, BufferEnabled );
   }
 
   scratchNode = node.namedItem( "multilineenabled" );
@@ -962,30 +980,29 @@
     el = scratchNode.toElement();
 
     mLabelAttributes->setMultilineEnabled(( bool )el.attribute( "on", "0" ).toInt() );
-    setLabelField( MultilineEnabled, _elementFieldIndex( el ) );
+    readLabelField( el, MultilineEnabled );
   }
 
 } // QgsLabel::readXML()
 
 
 
-void QgsLabel::writeXML( QDomNode & layer_node,
-                         QDomDocument & document )
+void QgsLabel::writeXML( QDomNode & layer_node, QDomDocument & document ) const
 {
   QDomElement labelattributes = document.createElement( "labelattributes" );
 
   // Text
   QDomElement label = document.createElement( "label" );
-  label.setAttribute("text", mLabelAttributes->text() );
+  label.setAttribute( "text", mLabelAttributes->text() );
   if ( mLabelAttributes->textIsSet() && mLabelFieldIdx[Text] != -1 )
   {
-    label.setAttribute("field", mLabelFieldIdx[Text] );
+    label.setAttribute( "fieldname", labelField( Text ) );
   }
   else
   {
-    label.setAttribute("field", "" );
+    label.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(label);
+  labelattributes.appendChild( label );
 
   // Family
   QDomElement family = document.createElement( "family" );
@@ -993,299 +1010,299 @@
   {
     if ( mLabelFieldIdx[Family] != -1 )
     {
-      family.setAttribute("name", mLabelAttributes->family() );
-      family.setAttribute("field", mLabelFieldIdx[Family] );
+      family.setAttribute( "name", mLabelAttributes->family() );
+      family.setAttribute( "fieldname", labelField( Family ) );
     }
     else
     {
-      family.setAttribute("name", mLabelAttributes->family() );
-      family.setAttribute("field", "" );
+      family.setAttribute( "name", mLabelAttributes->family() );
+      family.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    family.setAttribute("name", "Arial");
-    family.setAttribute("field", "");
+    family.setAttribute( "name", "Arial" );
+    family.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(family);
+  labelattributes.appendChild( family );
 
   // size and units
   QDomElement size = document.createElement( "size" );
-  size.setAttribute("value", mLabelAttributes->size());
+  size.setAttribute( "value", mLabelAttributes->size() );
   if ( mLabelAttributes->sizeIsSet() )
   {
     if ( mLabelFieldIdx[Size] != -1 )
     {
       if ( mLabelFieldIdx[SizeType] != -1 )
       {
-        size.setAttribute("unitfield", mLabelFieldIdx[SizeType] );
+        size.setAttribute( "unitfieldname", labelField( SizeType ) );
       }
       else
       {
-        size.setAttribute("units", QgsLabelAttributes::unitsName( mLabelAttributes->sizeType() ) );
+        size.setAttribute( "units", QgsLabelAttributes::unitsName( mLabelAttributes->sizeType() ) );
       }
-      size.setAttribute("field", mLabelFieldIdx[Size] );
+      size.setAttribute( "fieldname", labelField( Size ) );
     }
     else
     {
-      size.setAttribute("units", QgsLabelAttributes::unitsName( mLabelAttributes->sizeType() ) );
-      size.setAttribute("field", "" );
+      size.setAttribute( "units", QgsLabelAttributes::unitsName( mLabelAttributes->sizeType() ) );
+      size.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    size.setAttribute("value", "12");
-    size.setAttribute("units", "Points");
-    size.setAttribute("field", "");
+    size.setAttribute( "value", "12" );
+    size.setAttribute( "units", "Points" );
+    size.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(size);
+  labelattributes.appendChild( size );
 
   // bold
-  QDomElement bold = document.createElement("bold");
+  QDomElement bold = document.createElement( "bold" );
   if ( mLabelAttributes->boldIsSet() )
   {
     bold.setAttribute( "on", mLabelAttributes->bold() );
     if ( mLabelFieldIdx[Bold] != -1 )
     {
-      bold.setAttribute( "field", mLabelFieldIdx[Bold] );
+      bold.setAttribute( "fieldname", labelField( Bold ) );
     }
     else
     {
-      bold.setAttribute( "field", "" );
+      bold.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    bold.setAttribute("on", 0);
-    bold.setAttribute("field", 0);
+    bold.setAttribute( "on", 0 );
+    bold.setAttribute( "fieldname", 0 );
   }
-  labelattributes.appendChild(bold);
+  labelattributes.appendChild( bold );
 
   // italics
-  QDomElement italic = document.createElement("italic");
+  QDomElement italic = document.createElement( "italic" );
   if ( mLabelAttributes->italicIsSet() )
   {
-    italic.setAttribute("on", mLabelAttributes->italic());
+    italic.setAttribute( "on", mLabelAttributes->italic() );
     if ( mLabelFieldIdx[Italic] != -1 )
     {
-      italic.setAttribute("field", mLabelFieldIdx[Italic]);
+      italic.setAttribute( "fieldname", labelField( Italic ) );
     }
     else
     {
-      italic.setAttribute("field", "");
+      italic.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    italic.setAttribute("on", "0");
-    italic.setAttribute("field", "");
+    italic.setAttribute( "on", "0" );
+    italic.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(italic);
+  labelattributes.appendChild( italic );
 
   // underline
-  QDomElement underline = document.createElement("underline");
+  QDomElement underline = document.createElement( "underline" );
   if ( mLabelAttributes->underlineIsSet() )
   {
-    underline.setAttribute("on", mLabelAttributes->underline());
+    underline.setAttribute( "on", mLabelAttributes->underline() );
     if ( mLabelFieldIdx[Underline] != -1 )
     {
-      underline.setAttribute("field", mLabelFieldIdx[Underline] );
+      underline.setAttribute( "fieldname", labelField( Underline ) );
     }
     else
     {
-      underline.setAttribute("field", "" );
+      underline.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    underline.setAttribute("on", 0 );
-    underline.setAttribute("field", "" );
+    underline.setAttribute( "on", 0 );
+    underline.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(underline);
+  labelattributes.appendChild( underline );
 
   // color
-  QDomElement color = document.createElement("color");
+  QDomElement color = document.createElement( "color" );
   if ( mLabelAttributes->colorIsSet() )
   {
-    color.setAttribute("red", mLabelAttributes->color().red());
-    color.setAttribute("green", mLabelAttributes->color().green());
-    color.setAttribute("blue", mLabelAttributes->color().blue());
+    color.setAttribute( "red", mLabelAttributes->color().red() );
+    color.setAttribute( "green", mLabelAttributes->color().green() );
+    color.setAttribute( "blue", mLabelAttributes->color().blue() );
     if ( mLabelFieldIdx[Color] != -1 )
     {
-      color.setAttribute("field", mLabelFieldIdx[Color]);
+      color.setAttribute( "fieldname", labelField( Color ) );
     }
     else
     {
-      color.setAttribute("field", "");
+      color.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    color.setAttribute("red", 0);
-    color.setAttribute("green", 0);
-    color.setAttribute("blue", 0);
-    color.setAttribute("field", "");
+    color.setAttribute( "red", 0 );
+    color.setAttribute( "green", 0 );
+    color.setAttribute( "blue", 0 );
+    color.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(color);
+  labelattributes.appendChild( color );
 
   /* X */
-  QDomElement x = document.createElement("x");
+  QDomElement x = document.createElement( "x" );
   if ( mLabelFieldIdx[XCoordinate] != -1 )
   {
-    x.setAttribute("field", mLabelFieldIdx[XCoordinate] );
+    x.setAttribute( "fieldname", labelField( XCoordinate ) );
   }
   else
   {
-    x.setAttribute("field", "" );
+    x.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(x);
+  labelattributes.appendChild( x );
 
   /* Y */
-  QDomElement y = document.createElement("y");
+  QDomElement y = document.createElement( "y" );
   if ( mLabelFieldIdx[YCoordinate] != -1 )
   {
-    y.setAttribute("field", mLabelFieldIdx[YCoordinate] );
+    y.setAttribute( "fieldname", labelField( YCoordinate ) );
   }
   else
   {
-    y.setAttribute("field", "" );
+    y.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(y);
+  labelattributes.appendChild( y );
 
   // offset
   if ( mLabelAttributes->offsetIsSet() )
   {
-    QDomElement offset = document.createElement("offset");
-    offset.setAttribute("units", QgsLabelAttributes::unitsName( mLabelAttributes->offsetType() ) );
-    offset.setAttribute("x", mLabelAttributes->xOffset() );
-    offset.setAttribute("xfield", mLabelFieldIdx[XOffset] );
-    offset.setAttribute("y", mLabelAttributes->yOffset());
-    offset.setAttribute("yfield", mLabelFieldIdx[YOffset]);
-    labelattributes.appendChild(offset);
+    QDomElement offset = document.createElement( "offset" );
+    offset.setAttribute( "units", QgsLabelAttributes::unitsName( mLabelAttributes->offsetType() ) );
+    offset.setAttribute( "x", mLabelAttributes->xOffset() );
+    offset.setAttribute( "xfieldname", labelField( XOffset ) );
+    offset.setAttribute( "y", mLabelAttributes->yOffset() );
+    offset.setAttribute( "yfieldname", labelField( YOffset ) );
+    labelattributes.appendChild( offset );
   }
 
   // Angle
-  QDomElement angle = document.createElement("angle");
+  QDomElement angle = document.createElement( "angle" );
   if ( mLabelAttributes->angleIsSet() )
   {
-    angle.setAttribute("value", mLabelAttributes->angle() );
+    angle.setAttribute( "value", mLabelAttributes->angle() );
     if ( mLabelFieldIdx[Angle] != -1 )
     {
-      angle.setAttribute("field", mLabelFieldIdx[Angle] );
+      angle.setAttribute( "fieldname", labelField( Angle ) );
     }
     else
     {
-      angle.setAttribute("field", "" );
+      angle.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    angle.setAttribute("value", "" );
-    angle.setAttribute("field", "" );
+    angle.setAttribute( "value", "" );
+    angle.setAttribute( "fieldname", "" );
   }
-  angle.setAttribute("auto", mLabelAttributes->angleIsAuto() ? "1" : "0");
-  labelattributes.appendChild(angle);
+  angle.setAttribute( "auto", mLabelAttributes->angleIsAuto() ? "1" : "0" );
+  labelattributes.appendChild( angle );
 
   // alignment
   if ( mLabelAttributes->alignmentIsSet() )
   {
-    QDomElement alignment = document.createElement("alignment");
-    alignment.setAttribute("value", QgsLabelAttributes::alignmentName( mLabelAttributes->alignment() ) );
-    alignment.setAttribute("field", mLabelFieldIdx[Alignment] );
-    labelattributes.appendChild(alignment);
+    QDomElement alignment = document.createElement( "alignment" );
+    alignment.setAttribute( "value", QgsLabelAttributes::alignmentName( mLabelAttributes->alignment() ) );
+    alignment.setAttribute( "fieldname", labelField( Alignment ) );
+    labelattributes.appendChild( alignment );
   }
 
   // buffer color
-  QDomElement buffercolor = document.createElement("buffercolor");
+  QDomElement buffercolor = document.createElement( "buffercolor" );
   if ( mLabelAttributes->bufferColorIsSet() )
   {
-    buffercolor.setAttribute("red", mLabelAttributes->bufferColor().red());
-    buffercolor.setAttribute("green", mLabelAttributes->bufferColor().green());
-    buffercolor.setAttribute("blue", mLabelAttributes->bufferColor().blue());
+    buffercolor.setAttribute( "red", mLabelAttributes->bufferColor().red() );
+    buffercolor.setAttribute( "green", mLabelAttributes->bufferColor().green() );
+    buffercolor.setAttribute( "blue", mLabelAttributes->bufferColor().blue() );
     if ( mLabelFieldIdx[BufferColor] != -1 )
     {
-      buffercolor.setAttribute("field", mLabelFieldIdx[BufferColor] );
+      buffercolor.setAttribute( "fieldname", labelField( BufferColor ) );
     }
     else
     {
-      buffercolor.setAttribute("field", "" );
+      buffercolor.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    buffercolor.setAttribute("red", "" );
-    buffercolor.setAttribute("green", "" );
-    buffercolor.setAttribute("blue", "" );
-    buffercolor.setAttribute("field", "" );
+    buffercolor.setAttribute( "red", "" );
+    buffercolor.setAttribute( "green", "" );
+    buffercolor.setAttribute( "blue", "" );
+    buffercolor.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(buffercolor);
+  labelattributes.appendChild( buffercolor );
 
   // buffer size
-  QDomElement buffersize = document.createElement("buffersize");
+  QDomElement buffersize = document.createElement( "buffersize" );
   if ( mLabelAttributes->bufferSizeIsSet() )
   {
-    buffersize.setAttribute("value", mLabelAttributes->bufferSize() );
-    buffersize.setAttribute("units", QgsLabelAttributes::unitsName( mLabelAttributes->bufferSizeType() ) );
+    buffersize.setAttribute( "value", mLabelAttributes->bufferSize() );
+    buffersize.setAttribute( "units", QgsLabelAttributes::unitsName( mLabelAttributes->bufferSizeType() ) );
     if ( mLabelFieldIdx[BufferSize] != -1 )
     {
-      buffersize.setAttribute("field", mLabelFieldIdx[BufferSize] );
+      buffersize.setAttribute( "fieldname", labelField( BufferSize ) );
     }
     else
     {
-      buffersize.setAttribute("field", "" );
+      buffersize.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    buffersize.setAttribute("value", "");
-    buffersize.setAttribute("units", "");
-    buffersize.setAttribute("field", "");
+    buffersize.setAttribute( "value", "" );
+    buffersize.setAttribute( "units", "" );
+    buffersize.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(buffersize);
+  labelattributes.appendChild( buffersize );
 
   // buffer enabled
-  QDomElement bufferenabled = document.createElement("bufferenabled");
+  QDomElement bufferenabled = document.createElement( "bufferenabled" );
   if ( mLabelAttributes->bufferEnabled() )
   {
-    bufferenabled.setAttribute("on", mLabelAttributes->bufferEnabled());
+    bufferenabled.setAttribute( "on", mLabelAttributes->bufferEnabled() );
     if ( mLabelFieldIdx[BufferEnabled] != -1 )
     {
-      bufferenabled.setAttribute("field", mLabelFieldIdx[BufferEnabled] );
+      bufferenabled.setAttribute( "fieldname", labelField( BufferEnabled ) );
     }
     else
     {
-      bufferenabled.setAttribute("field", "" );
+      bufferenabled.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    bufferenabled.setAttribute("on", "" );
-    bufferenabled.setAttribute("field", "" );
+    bufferenabled.setAttribute( "on", "" );
+    bufferenabled.setAttribute( "fieldname", "" );
   }
   labelattributes.appendChild( bufferenabled );
 
   // multiline enabled
-  QDomElement multilineenabled = document.createElement("multilineenabled");
+  QDomElement multilineenabled = document.createElement( "multilineenabled" );
   if ( mLabelAttributes->multilineEnabled() )
   {
-    multilineenabled.setAttribute("on", mLabelAttributes->multilineEnabled());
+    multilineenabled.setAttribute( "on", mLabelAttributes->multilineEnabled() );
     if ( mLabelFieldIdx[MultilineEnabled] != -1 )
     {
-      multilineenabled.setAttribute("field", mLabelFieldIdx[MultilineEnabled] );
+      multilineenabled.setAttribute( "fieldname", labelField( MultilineEnabled ) );
     }
     else
     {
-      multilineenabled.setAttribute("field", "" );
+      multilineenabled.setAttribute( "fieldname", "" );
     }
   }
   else
   {
-    multilineenabled.setAttribute("on", "" );
-    multilineenabled.setAttribute("field", "" );
+    multilineenabled.setAttribute( "on", "" );
+    multilineenabled.setAttribute( "fieldname", "" );
   }
-  labelattributes.appendChild(multilineenabled);
+  labelattributes.appendChild( multilineenabled );
 
-  layer_node.appendChild(labelattributes);
+  layer_node.appendChild( labelattributes );
 }
 
 void QgsLabel::setScaleBasedVisibility( bool theVisibilityFlag )
@@ -1293,7 +1310,7 @@
   mScaleBasedVisibility = theVisibilityFlag;
 }
 
-bool QgsLabel::scaleBasedVisibility()
+bool QgsLabel::scaleBasedVisibility() const
 {
   return mScaleBasedVisibility;
 }
@@ -1303,7 +1320,7 @@
   mMinScale = theMinScale;
 }
 
-float QgsLabel::minScale()
+float QgsLabel::minScale() const
 {
   return mMinScale;
 }
@@ -1313,7 +1330,7 @@
   mMaxScale = theMaxScale;
 }
 
-float QgsLabel::maxScale()
+float QgsLabel::maxScale() const
 {
   return mMaxScale;
 }

Modified: trunk/qgis/src/core/qgslabel.h
===================================================================
--- trunk/qgis/src/core/qgslabel.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgslabel.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -27,6 +27,7 @@
 
 class QDomNode;
 class QDomDocument;
+class QDomElement;
 class QString;
 class QPainter;
 class QPaintDevice;
@@ -84,7 +85,8 @@
       LabelFieldCount
     };
 
-    struct labelpoint {
+    struct labelpoint
+    {
       QgsPoint p;
       double angle;
     };
@@ -103,10 +105,10 @@
     void readXML( const QDomNode& node );
 
     /** Writes the contents of the renderer to a configuration file */
-    void writeXML( QDomNode & label_node, QDomDocument & document );
+    void writeXML( QDomNode & label_node, QDomDocument & document ) const;
 
     //! add vector of required fields to existing list of fields
-    void addRequiredFields( QgsAttributeList& fields );
+    void addRequiredFields( QgsAttributeList& fields ) const;
 
     //! Set available fields
     void setFields( const QgsFieldMap & fields );
@@ -120,8 +122,11 @@
     //! Set label field
     void setLabelField( int attr, int fieldIndex );
 
+    //! Set label field by name
+    bool setLabelFieldName( int attr, QString name );
+
     //! label field
-    QString labelField( int attr );
+    QString labelField( int attr ) const;
 
     /** Get field value if : 1) field name is not empty
      *                       2) field exists
@@ -132,15 +137,15 @@
 
     /** Accessor and mutator for the minimum scale member */
     void setMinScale( float theMinScale );
-    float minScale();
+    float minScale() const;
 
     /** Accessor and mutator for the maximum scale member */
     void setMaxScale( float theMaxScale );
-    float maxScale();
+    float maxScale() const;
 
     /** Accessor and mutator for the scale based visilibility flag */
     void setScaleBasedVisibility( bool theVisibilityFlag );
-    bool scaleBasedVisibility();
+    bool scaleBasedVisibility() const;
 
   private:
     /** Does the actual rendering of a label at the given point
@@ -155,6 +160,8 @@
                       double ang,
                       int width, int height, int alignment, double sizeScale = 1.0, double rasterScaleFactor = 1.0 );
 
+    bool readLabelField( QDomElement &el, int attr, QString prefix );
+
     /** Get label point for simple feature in map units */
     void labelPoint( std::vector<labelpoint>&, QgsFeature &feature );
 

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -287,9 +287,9 @@
   QgsDebugMsg( "Starting draw of labels" );
 
   if ( mRenderer && mLabelOn &&
-       (!label()->scaleBasedVisibility() ||
-        (label()->minScale()<=rendererContext.rendererScale() &&
-                              rendererContext.rendererScale()<=label()->maxScale())) )
+       ( !label()->scaleBasedVisibility() ||
+         ( label()->minScale() <= rendererContext.rendererScale() &&
+           rendererContext.rendererScale() <= label()->maxScale() ) ) )
   {
     QgsAttributeList attributes = mRenderer->classificationAttributes();
 
@@ -823,7 +823,7 @@
 void QgsVectorLayer::deselect( int number, bool emitSignal )
 {
   mSelectedFeatureIds.remove( number );
-  
+
   if ( emitSignal )
   {
     emit selectionChanged();
@@ -1969,12 +1969,17 @@
   return mLabel;
 }
 
+const QgsLabel *QgsVectorLayer::label() const
+{
+  return mLabel;
+}
+
 void QgsVectorLayer::enableLabels( bool on )
 {
   mLabelOn = on;
 }
 
-bool QgsVectorLayer::hasLabelsEnabled( void )
+bool QgsVectorLayer::hasLabelsEnabled( void ) const
 {
   return mLabelOn;
 }
@@ -2017,9 +2022,6 @@
 {
   QgsDebugMsg( QString( "Datasource in QgsVectorLayer::readXml: " ) + mDataSource.toLocal8Bit().data() );
 
-  // process the attribute actions
-  mActions->readXML( layer_node );
-
   //process provider key
   QDomNode pkeyNode = layer_node.namedItem( "provider" );
 
@@ -2060,87 +2062,13 @@
     mDataProvider->setEncoding( encodingNode.toElement().text() );
   }
 
-  // get and set the display field if it exists.
-  QDomNode displayFieldNode = layer_node.namedItem( "displayfield" );
-  if ( !displayFieldNode.isNull() )
-  {
-    QDomElement e = displayFieldNode.toElement();
-    setDisplayField( e.text() );
-  }
-
-  // use scale dependent visibility flag
-  QDomElement e = layer_node.toElement();
-  label()->setScaleBasedVisibility( e.attribute( "scaleBasedLabelVisibilityFlag", "0") == "1" );
-  label()->setMinScale( e.attribute( "minLabelScale", "1" ).toFloat() );
-  label()->setMaxScale( e.attribute( "maxLabelScale", "100000000" ).toFloat() );
-
-  QDomNode editTypesNode = layer_node.namedItem( "edittypes" );
-  if ( !editTypesNode.isNull() )
-  {
-    QDomNodeList editTypeNodes = editTypesNode.childNodes();
-
-    for ( int i = 0; i < editTypeNodes.size(); i++ )
-    {
-      QDomNode editTypeNode = editTypeNodes.at( i );
-      QDomElement editTypeElement = editTypeNode.toElement();
-
-      QString name = editTypeElement.attribute( "name" );
-
-      EditType editType = ( EditType ) editTypeElement.attribute( "type" ).toInt();
-      mEditTypes.insert( name, editType );
-
-      if ( editType == ValueMap && editTypeNode.hasChildNodes() )
-      {
-        mValueMaps.insert( name, QMap<QString, QVariant>() );
-
-        QDomNodeList valueMapNodes = editTypeNode.childNodes();
-        for ( int j = 0; j < valueMapNodes.size(); j++ )
-        {
-          QDomElement value = valueMapNodes.at( j ).toElement();
-          mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
-        }
-      }
-      else if ( editType == EditRange || editType == SliderRange )
-      {
-        QVariant min = editTypeElement.attribute( "min" );
-        QVariant max = editTypeElement.attribute( "max" );
-        QVariant step = editTypeElement.attribute( "step" );
-
-        mRanges[ name ] = RangeData( min, max, step );
-      }
-    }
-  }
-
   QString errorMsg;
   if ( !readSymbology( layer_node, errorMsg ) )
   {
     return false;
   }
 
-  // Test if labeling is on or off
-  QDomNode labelnode = layer_node.namedItem( "label" );
-  QDomElement element = labelnode.toElement();
-  int hasLabelsEnabled = element.text().toInt();
-  if ( hasLabelsEnabled < 1 )
-  {
-    enableLabels( false );
-  }
-  else
-  {
-    enableLabels( true );
-  }
 
-  QgsDebugMsg( "Testing if qgsvectorlayer can call label readXML routine" );
-
-
-  QDomNode labelattributesnode = layer_node.namedItem( "labelattributes" );
-
-  if ( !labelattributesnode.isNull() )
-  {
-    QgsDebugMsg( "qgsvectorlayer calling label readXML routine" );
-    mLabel->readXML( labelattributesnode );
-  }
-
   return mValid;               // should be true if read successfully
 
 } // void QgsVectorLayer::readXml
@@ -2250,42 +2178,178 @@
   // set the geometry type
   mapLayerNode.setAttribute( "geometry", QGis::qgisVectorGeometryType[type()] );
 
-  // use scale dependent visibility flag
-  mapLayerNode.setAttribute( "scaleBasedLabelVisibilityFlag", label()->scaleBasedVisibility() ? 1 : 0 );
-  mapLayerNode.setAttribute( "minLabelScale", label()->minScale() );
-  mapLayerNode.setAttribute( "maxLabelScale", label()->maxScale() );
-
   // add provider node
-
   QDomElement provider  = document.createElement( "provider" );
   QDomText providerText = document.createTextNode( providerType() );
   provider.appendChild( providerText );
   layer_node.appendChild( provider );
 
-  //provider encoding
-  QDomElement encoding = document.createElement( "encoding" );
-  QDomText encodingText = document.createTextNode( mDataProvider->encoding() );
-  encoding.appendChild( encodingText );
-  layer_node.appendChild( encoding );
+  // renderer specific settings
 
+  QString errorMsg;
+  if ( !writeSymbology( layer_node, document, errorMsg ) )
+  {
+    return false;
+  }
+
+
+  return true;
+} // bool QgsVectorLayer::writeXml
+
+bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage )
+{
+  // process the attribute actions
+  mActions->readXML( node );
+
+  // get and set the display field if it exists.
+  QDomNode displayFieldNode = node.namedItem( "displayfield" );
+  if ( !displayFieldNode.isNull() )
+  {
+    QDomElement e = displayFieldNode.toElement();
+    setDisplayField( e.text() );
+  }
+
+  // use scale dependent visibility flag
+  QDomElement e = node.toElement();
+  label()->setScaleBasedVisibility( e.attribute( "scaleBasedLabelVisibilityFlag", "0" ) == "1" );
+  label()->setMinScale( e.attribute( "minLabelScale", "1" ).toFloat() );
+  label()->setMaxScale( e.attribute( "maxLabelScale", "100000000" ).toFloat() );
+
+  mEditTypes.clear();
+  QDomNode editTypesNode = node.namedItem( "edittypes" );
+  if ( !editTypesNode.isNull() )
+  {
+    QDomNodeList editTypeNodes = editTypesNode.childNodes();
+
+    for ( int i = 0; i < editTypeNodes.size(); i++ )
+    {
+      QDomNode editTypeNode = editTypeNodes.at( i );
+      QDomElement editTypeElement = editTypeNode.toElement();
+
+      QString name = editTypeElement.attribute( "name" );
+
+      EditType editType = ( EditType ) editTypeElement.attribute( "type" ).toInt();
+      mEditTypes.insert( name, editType );
+
+      if ( editType == ValueMap && editTypeNode.hasChildNodes() )
+      {
+        mValueMaps.insert( name, QMap<QString, QVariant>() );
+
+        QDomNodeList valueMapNodes = editTypeNode.childNodes();
+        for ( int j = 0; j < valueMapNodes.size(); j++ )
+        {
+          QDomElement value = valueMapNodes.at( j ).toElement();
+          mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
+        }
+      }
+      else if ( editType == EditRange || editType == SliderRange )
+      {
+        QVariant min = editTypeElement.attribute( "min" );
+        QVariant max = editTypeElement.attribute( "max" );
+        QVariant step = editTypeElement.attribute( "step" );
+
+        mRanges[ name ] = RangeData( min, max, step );
+      }
+    }
+  }
+
+  // create and bind a renderer to this layer
+
+  QDomNode singlenode = node.namedItem( "singlesymbol" );
+  QDomNode graduatednode = node.namedItem( "graduatedsymbol" );
+  QDomNode continuousnode = node.namedItem( "continuoussymbol" );
+  QDomNode uniquevaluenode = node.namedItem( "uniquevalue" );
+
+  QgsRenderer * renderer = 0;
+  int returnCode = 1;
+
+  if ( !singlenode.isNull() )
+  {
+    renderer = new QgsSingleSymbolRenderer( geometryType() );
+    returnCode = renderer->readXML( singlenode, *this );
+  }
+  else if ( !graduatednode.isNull() )
+  {
+    renderer = new QgsGraduatedSymbolRenderer( geometryType() );
+    returnCode = renderer->readXML( graduatednode, *this );
+  }
+  else if ( !continuousnode.isNull() )
+  {
+    renderer = new QgsContinuousColorRenderer( geometryType() );
+    returnCode = renderer->readXML( continuousnode, *this );
+  }
+  else if ( !uniquevaluenode.isNull() )
+  {
+    renderer = new QgsUniqueValueRenderer( geometryType() );
+    returnCode = renderer->readXML( uniquevaluenode, *this );
+  }
+
+  if ( !renderer )
+  {
+    return false;
+  }
+
+  if ( returnCode == 1 )
+  {
+    errorMessage = tr( "No renderer object" ); delete renderer; return false;
+  }
+  else if ( returnCode == 2 )
+  {
+    errorMessage = tr( "Classification field not found" ); delete renderer; return false;
+  }
+
+  mRenderer = renderer;
+
+  // Test if labeling is on or off
+  QDomNode labelnode = node.namedItem( "label" );
+  QDomElement element = labelnode.toElement();
+  int hasLabelsEnabled = element.text().toInt();
+  if ( hasLabelsEnabled < 1 )
+  {
+    enableLabels( false );
+  }
+  else
+  {
+    enableLabels( true );
+  }
+
+  QDomNode labelattributesnode = node.namedItem( "labelattributes" );
+
+  if ( !labelattributesnode.isNull() )
+  {
+    QgsDebugMsg( "qgsvectorlayer calling label readXML routine" );
+    mLabel->readXML( labelattributesnode );
+  }
+
+  return true;
+}
+
+bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const
+{
+  // use scale dependent visibility flag
+  QDomElement mapLayerNode = node.toElement();
+  mapLayerNode.setAttribute( "scaleBasedLabelVisibilityFlag", label()->scaleBasedVisibility() ? 1 : 0 );
+  mapLayerNode.setAttribute( "minLabelScale", label()->minScale() );
+  mapLayerNode.setAttribute( "maxLabelScale", label()->maxScale() );
+
   //classification field(s)
   QgsAttributeList attributes = mRenderer->classificationAttributes();
   const QgsFieldMap providerFields = mDataProvider->fields();
   for ( QgsAttributeList::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
   {
-    QDomElement classificationElement = document.createElement( "classificationattribute" );
-    QDomText classificationText = document.createTextNode( providerFields[*it].name() );
+    QDomElement classificationElement = doc.createElement( "classificationattribute" );
+    QDomText classificationText = doc.createTextNode( providerFields[*it].name() );
     classificationElement.appendChild( classificationText );
-    layer_node.appendChild( classificationElement );
+    node.appendChild( classificationElement );
   }
 
   if ( mEditTypes.size() > 0 )
   {
-    QDomElement editTypesElement = document.createElement( "edittypes" );
+    QDomElement editTypesElement = doc.createElement( "edittypes" );
 
     for ( QMap<QString, EditType>::const_iterator it = mEditTypes.begin(); it != mEditTypes.end(); ++it )
     {
-      QDomElement editTypeElement = document.createElement( "edittype" );
+      QDomElement editTypeElement = doc.createElement( "edittype" );
       editTypeElement.setAttribute( "name", it.key() );
       editTypeElement.setAttribute( "type", it.value() );
 
@@ -2297,7 +2361,7 @@
 
           for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); vmit++ )
           {
-            QDomElement value = document.createElement( "valuepair" );
+            QDomElement value = doc.createElement( "valuepair" );
             value.setAttribute( "key", vmit.key() );
             value.setAttribute( "value", vmit.value().toString() );
             editTypeElement.appendChild( value );
@@ -2317,21 +2381,19 @@
       editTypesElement.appendChild( editTypeElement );
     }
 
-    layer_node.appendChild( editTypesElement );
+    node.appendChild( editTypesElement );
   }
 
   // add the display field
-
-  QDomElement dField  = document.createElement( "displayfield" );
-  QDomText dFieldText = document.createTextNode( displayField() );
+  QDomElement dField  = doc.createElement( "displayfield" );
+  QDomText dFieldText = doc.createTextNode( displayField() );
   dField.appendChild( dFieldText );
-  layer_node.appendChild( dField );
+  node.appendChild( dField );
 
   // add label node
+  QDomElement label  = doc.createElement( "label" );
+  QDomText labelText = doc.createTextNode( "" );
 
-  QDomElement label  = document.createElement( "label" );
-  QDomText labelText = document.createTextNode( "" );
-
   if ( hasLabelsEnabled() )
   {
     labelText.setData( "1" );
@@ -2342,17 +2404,22 @@
   }
   label.appendChild( labelText );
 
-  layer_node.appendChild( label );
+  node.appendChild( label );
 
   // add attribute actions
+  mActions->writeXML( node, doc );
 
-  mActions->writeXML( layer_node, document );
-
-  // renderer specific settings
-
-  QString errorMsg;
-  if ( !writeSymbology( layer_node, document, errorMsg ) )
+  const QgsRenderer * myRenderer = renderer();
+  if ( myRenderer )
   {
+    if ( !myRenderer->writeXML( node, doc, *this ) )
+    {
+      return false;
+    }
+  }
+  else
+  {
+    QgsDebugMsg( "no renderer" );
     return false;
   }
 
@@ -2362,94 +2429,25 @@
   // XXX therefore becomes a candidate to be generalized into a separate
   // XXX function.  I think.
 
-  QgsLabel * myLabel = this->label();
+  const QgsLabel *myLabel = this->label();
 
   if ( myLabel )
   {
     QString fieldname = myLabel->labelField( QgsLabel::Text );
     if ( fieldname != "" )
     {
-      dField  = document.createElement( "labelfield" );
-      dFieldText = document.createTextNode( fieldname );
+      dField  = doc.createElement( "labelfield" );
+      dFieldText = doc.createTextNode( fieldname );
       dField.appendChild( dFieldText );
-      layer_node.appendChild( dField );
+      node.appendChild( dField );
     }
 
-    myLabel->writeXML( layer_node, document );
+    myLabel->writeXML( node, doc );
   }
 
   return true;
-} // bool QgsVectorLayer::writeXml
-
-bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage )
-{
-  // create and bind a renderer to this layer
-
-  QDomNode singlenode = node.namedItem( "singlesymbol" );
-  QDomNode graduatednode = node.namedItem( "graduatedsymbol" );
-  QDomNode continuousnode = node.namedItem( "continuoussymbol" );
-  QDomNode uniquevaluenode = node.namedItem( "uniquevalue" );
-
-  QgsRenderer * renderer = 0;
-  int returnCode = 1;
-
-  if ( !singlenode.isNull() )
-  {
-    renderer = new QgsSingleSymbolRenderer( geometryType() );
-    returnCode = renderer->readXML( singlenode, *this );
-  }
-  else if ( !graduatednode.isNull() )
-  {
-    renderer = new QgsGraduatedSymbolRenderer( geometryType() );
-    returnCode = renderer->readXML( graduatednode, *this );
-  }
-  else if ( !continuousnode.isNull() )
-  {
-    renderer = new QgsContinuousColorRenderer( geometryType() );
-    returnCode = renderer->readXML( continuousnode, *this );
-  }
-  else if ( !uniquevaluenode.isNull() )
-  {
-    renderer = new QgsUniqueValueRenderer( geometryType() );
-    returnCode = renderer->readXML( uniquevaluenode, *this );
-  }
-
-  if ( !renderer )
-  {
-    return false;
-  }
-
-  if ( returnCode == 1 )
-  {
-    errorMessage = tr( "No renderer object" ); delete renderer; return false;
-  }
-  else if ( returnCode == 2 )
-  {
-    errorMessage = tr( "Classification field not found" ); delete renderer; return false;
-  }
-
-  mRenderer = renderer;
-  return true;
 }
 
-bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const
-{
-  const QgsRenderer * myRenderer = renderer();
-  if ( myRenderer )
-  {
-    if ( !myRenderer->writeXML( node, doc, *this ) )
-    {
-      return false;
-    }
-  }
-  else
-  {
-    QgsDebugMsg( QString( "%1:%2 no renderer" ).arg( __FILE__ ).arg( __LINE__ ) );
-    return false;
-  }
-  return true;
-}
-
 bool QgsVectorLayer::changeAttributeValue( int fid, int field, QVariant value, bool emitSignal )
 {
   if ( !isEditable() )
@@ -2551,7 +2549,7 @@
   return true;
 }
 
-const QgsFieldMap &QgsVectorLayer::pendingFields()
+const QgsFieldMap &QgsVectorLayer::pendingFields() const
 {
   return isEditable() ? mUpdatedFields : mDataProvider->fields();
 }

Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/qgsvectorlayer.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -119,6 +119,8 @@
     /** Get the label object associated with this layer */
     QgsLabel *label();
 
+    const QgsLabel *label() const;
+
     QgsAttributeAction* actions() { return mActions; }
 
     /** The number of features that are selected in this layer */
@@ -321,7 +323,7 @@
     void enableLabels( bool on );
 
     /** Label is on */
-    bool hasLabelsEnabled( void );
+    bool hasLabelsEnabled( void ) const;
 
     /** Returns true if the provider is in editing mode */
     virtual bool isEditable() const;
@@ -358,7 +360,7 @@
     void drawLabels( QgsRenderContext& rendererContext );
 
     /** returns field list in the to-be-committed state */
-    const QgsFieldMap &pendingFields();
+    const QgsFieldMap &pendingFields() const;
 
     /** returns list of attributes */
     QgsAttributeList pendingAllAttributesList();
@@ -424,7 +426,7 @@
   public slots:
     /** Select feature by its ID, optionally emit signal selectionChanged() */
     void select( int featureId, bool emitSignal = TRUE );
-    
+
     /** Deselect feature by its ID, optionally emit signal selectionChanged() */
     void deselect( int featureId, bool emitSignal = TRUE );
 

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -982,8 +982,8 @@
 
   if ( theTryInternalFlag )
   {
-    QString myCompressionType = QString( GDALGetMetadataItem(  mGdalDataset, "COMPRESSION", "IMAGE_STRUCTURE" ) );
-    if( "JPEG" == myCompressionType )
+    QString myCompressionType = QString( GDALGetMetadataItem( mGdalDataset, "COMPRESSION", "IMAGE_STRUCTURE" ) );
+    if ( "JPEG" == myCompressionType )
     {
       return "ERROR_JPEG_COMPRESSION";
     }
@@ -2145,7 +2145,7 @@
       myQPainter.setPen( Qt::black );
     }
     myQPainter.setFont( myQFont );
-    myQPainter.drawText( 25, myHeight - 10, this->name() );
+    myQPainter.drawText( 25, myHeight - 10, name() );
     //
     // finish up
     //
@@ -2172,7 +2172,7 @@
   const int myerLabelSpacing = 5;
   int myImageHeight = (( myFontHeight + ( myerLabelSpacing * 2 ) ) * theLabelCount );
   //these next two vars are not used anywhere so commented out for now
-  //int myLongestLabelWidth =  myQFontMetrics.width(this->name());
+  //int myLongestLabelWidth =  myQFontMetrics.width(name());
   //const int myHorizontalLabelSpacing = 5;
   const int myColourBarWidth = 10;
   //
@@ -2377,7 +2377,7 @@
     myQPainter2.setPen( Qt::black );
   }
   myQPainter2.setFont( myQFont );
-  myQPainter2.drawText( 25, myImageHeight - 10, this->name() );
+  myQPainter2.drawText( 25, myImageHeight - 10, name() );
   //
   // finish up
   //
@@ -4947,7 +4947,7 @@
   /* Abort if out of memory */
   if ( data == NULL )
   {
-    QgsDebugMsg( "Layer " + this->name() + " couldn't allocate enough memory. Ignoring" );
+    QgsDebugMsg( "Layer " + name() + " couldn't allocate enough memory. Ignoring" );
   }
   else
   {

Modified: trunk/qgis/src/core/renderer/qgscontinuouscolorrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgscontinuouscolorrenderer.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/renderer/qgscontinuouscolorrenderer.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -203,7 +203,7 @@
   {
     return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
   }
-  this->setClassificationField( classificationId );
+  setClassificationField( classificationId );
 
   //polygon outline
   QDomNode polyoutlinenode = rnode.namedItem( "polygonoutline" );
@@ -223,16 +223,16 @@
   if ( ! lsymbolnode.isNull() )
   {
     QgsSymbol* lsy = new QgsSymbol( mGeometryType );
-    lsy->readXML( lsymbolnode );
-    this->setMinimumSymbol( lsy );
+    lsy->readXML( lsymbolnode, &vl );
+    setMinimumSymbol( lsy );
   }
   QDomNode uppernode = rnode.namedItem( "highestsymbol" );
   QDomNode usymbolnode = uppernode.namedItem( "symbol" );
   if ( ! usymbolnode.isNull() )
   {
     QgsSymbol* usy = new QgsSymbol( mGeometryType );
-    usy->readXML( usymbolnode );
-    this->setMaximumSymbol( usy );
+    usy->readXML( usymbolnode, &vl );
+    setMaximumSymbol( usy );
   }
   vl.setRenderer( this );
   return 0;
@@ -265,7 +265,7 @@
     classificationFieldName = field_it.value().name();
   }
   bool returnval = true;
-#ifndef WIN32
+
   QDomElement continuoussymbol = document.createElement( "continuoussymbol" );
   layer_node.appendChild( continuoussymbol );
   QDomElement classificationfield = document.createElement( "classificationfield" );
@@ -284,15 +284,15 @@
   continuoussymbol.appendChild( lowestsymbol );
   if ( mMinimumSymbol )
   {
-    mMinimumSymbol->writeXML( lowestsymbol, document );
+    mMinimumSymbol->writeXML( lowestsymbol, document, &vl );
   }
   QDomElement highestsymbol = document.createElement( "highestsymbol" );
   continuoussymbol.appendChild( highestsymbol );
   if ( mMaximumSymbol )
   {
-    mMaximumSymbol->writeXML( highestsymbol, document );
+    mMaximumSymbol->writeXML( highestsymbol, document, &vl );
   }
-#endif
+
   return returnval;
 }
 

Modified: trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -246,14 +246,14 @@
   {
     return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
   }
-  this->setClassificationField( classificationId );
+  setClassificationField( classificationId );
 
   QDomNode symbolnode = rnode.namedItem( "symbol" );
   while ( !symbolnode.isNull() )
   {
     QgsSymbol* sy = new QgsSymbol( mGeometryType );
-    sy->readXML( symbolnode );
-    this->addSymbol( sy );
+    sy->readXML( symbolnode, &vl );
+    addSymbol( sy );
 
     symbolnode = symbolnode.nextSibling();
   }
@@ -343,19 +343,17 @@
   }
 
   QString classificationFieldName;
-  QgsFieldMap::const_iterator field_it = theProvider->fields().find( mClassificationField );
-  if ( field_it != theProvider->fields().constEnd() )
+  if ( vl.pendingFields().contains( mClassificationField ) )
   {
-    classificationFieldName = field_it.value().name();
+    classificationFieldName = vl.pendingFields()[ mClassificationField ].name();
   }
 
-
   QDomText classificationfieldtxt = document.createTextNode( classificationFieldName );
   classificationfield.appendChild( classificationfieldtxt );
   graduatedsymbol.appendChild( classificationfield );
   for ( QList<QgsSymbol*>::const_iterator it = mSymbols.begin(); it != mSymbols.end(); ++it )
   {
-    if ( !( *it )->writeXML( graduatedsymbol, document ) )
+    if ( !( *it )->writeXML( graduatedsymbol, document, &vl ) )
     {
       returnval = false;
     }

Modified: trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -169,12 +169,12 @@
   }
   else
   {
-    sy->readXML( synode );
+    sy->readXML( synode, &vl );
   }
   updateSymbolAttributes();
 
   //create a renderer and add it to the vector layer
-  this->addSymbol( sy );
+  addSymbol( sy );
   vl.setRenderer( this );
   return 0;
 }
@@ -187,7 +187,7 @@
 
   if ( mSymbol )
   {
-    returnval = mSymbol->writeXML( singlesymbol, document );
+    returnval = mSymbol->writeXML( singlesymbol, document, &vl );
   }
   return returnval;
 }

Modified: trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -210,13 +210,13 @@
   {
     return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
   }
-  this->setClassificationField( classificationId );
+  setClassificationField( classificationId );
 
   QDomNode symbolnode = rnode.namedItem( "symbol" );
   while ( !symbolnode.isNull() )
   {
     QgsSymbol* msy = new QgsSymbol( mGeometryType );
-    msy->readXML( symbolnode );
+    msy->readXML( symbolnode, &vl );
     insertValue( msy->lowerValue(), msy );
     symbolnode = symbolnode.nextSibling();
   }
@@ -296,7 +296,7 @@
   uniquevalue.appendChild( classificationfield );
   for ( QMap<QString, QgsSymbol*>::const_iterator it = mSymbols.begin();it != mSymbols.end();++it )
   {
-    if ( !( it.value()->writeXML( uniquevalue, document ) ) )
+    if ( !( it.value()->writeXML( uniquevalue, document, &vl ) ) )
     {
       returnval = false;
     }

Modified: trunk/qgis/src/core/symbology/qgssymbol.cpp
===================================================================
--- trunk/qgis/src/core/symbology/qgssymbol.cpp	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/symbology/qgssymbol.cpp	2008-12-07 03:10:00 UTC (rev 9747)
@@ -24,6 +24,7 @@
 #include "qgssymbologyutils.h"
 #include "qgsmarkercatalogue.h"
 #include "qgsapplication.h"
+#include "qgsvectorlayer.h"
 
 #include <QPainter>
 #include <QDomNode>
@@ -130,7 +131,6 @@
 
 QgsSymbol::~QgsSymbol()
 {
-
 }
 
 
@@ -422,83 +422,82 @@
   mCacheUpToDate2 = true;
 }
 
-bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document ) const
+void QgsSymbol::appendField( QDomElement &symbol, QDomDocument &document, const QgsVectorLayer &vl, QString name, int idx ) const
 {
+  appendText( symbol, document, name, vl.pendingFields().contains( idx ) ? vl.pendingFields()[idx].name() : "" );
+}
+
+void QgsSymbol::appendText( QDomElement &symbol, QDomDocument &document, QString name, QString value ) const
+{
+  QDomElement node = document.createElement( name );
+  QDomText txt = document.createTextNode( value );
+  symbol.appendChild( node );
+  node.appendChild( txt );
+}
+
+bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document, const QgsVectorLayer *vl ) const
+{
   bool returnval = false;
   returnval = true; // no error checking yet
   QDomElement symbol = document.createElement( "symbol" );
   item.appendChild( symbol );
 
-  QDomElement lowervalue = document.createElement( "lowervalue" );
-  QDomText lowervaluetxt = document.createTextNode( mLowerValue );
-  symbol.appendChild( lowervalue );
-  lowervalue.appendChild( lowervaluetxt );
+  appendText( symbol, document, "lowervalue", mLowerValue );
+  appendText( symbol, document, "uppervalue", mUpperValue );
+  appendText( symbol, document, "label", mLabel );
+  appendText( symbol, document, "pointsymbol", pointSymbolName() );
+  appendText( symbol, document, "pointsize", QString::number( pointSize() ) );
 
-  QDomElement uppervalue = document.createElement( "uppervalue" );
-  QDomText uppervaluetxt = document.createTextNode( mUpperValue );
-  symbol.appendChild( uppervalue );
-  uppervalue.appendChild( uppervaluetxt );
+  if ( vl )
+  {
+    appendField( symbol, document, *vl, "rotationclassificationfieldname", mRotationClassificationField );
+    appendField( symbol, document, *vl, "scaleclassificationfieldname", mScaleClassificationField );
+  }
 
-  QDomElement label = document.createElement( "label" );
-  QDomText labeltxt = document.createTextNode( mLabel );
-  symbol.appendChild( label );
-  label.appendChild( labeltxt );
-
-  QDomElement pointsymbol = document.createElement( "pointsymbol" );
-  QDomText pointsymboltxt = document.createTextNode( pointSymbolName() );
-  symbol.appendChild( pointsymbol );
-  pointsymbol.appendChild( pointsymboltxt );
-
-  QDomElement pointsize = document.createElement( "pointsize" );
-  QDomText pointsizetxt = document.createTextNode( QString::number( pointSize() ) );
-  symbol.appendChild( pointsize );
-  pointsize.appendChild( pointsizetxt );
-
-  QDomElement rotationclassificationfield = document.createElement( "rotationclassificationfield" );
-  QDomText rotationclassificationfieldtxt = document.createTextNode( QString::number( mRotationClassificationField ) );
-  rotationclassificationfield.appendChild( rotationclassificationfieldtxt );
-  symbol.appendChild( rotationclassificationfield );
-
-  QDomElement scaleclassificationfield = document.createElement( "scaleclassificationfield" );
-  QDomText scaleclassificationfieldtxt = document.createTextNode( QString::number( mScaleClassificationField ) );
-  scaleclassificationfield.appendChild( scaleclassificationfieldtxt );
-  symbol.appendChild( scaleclassificationfield );
-
-
   QDomElement outlinecolor = document.createElement( "outlinecolor" );
   outlinecolor.setAttribute( "red", QString::number( mPen.color().red() ) );
   outlinecolor.setAttribute( "green", QString::number( mPen.color().green() ) );
   outlinecolor.setAttribute( "blue", QString::number( mPen.color().blue() ) );
   symbol.appendChild( outlinecolor );
-  QDomElement outlinestyle = document.createElement( "outlinestyle" );
-  QDomText outlinestyletxt = document.createTextNode( QgsSymbologyUtils::penStyle2QString( mPen.style() ) );
-  outlinestyle.appendChild( outlinestyletxt );
-  symbol.appendChild( outlinestyle );
-  QDomElement outlinewidth = document.createElement( "outlinewidth" );
-  QDomText outlinewidthtxt = document.createTextNode( QString::number( mPen.widthF() ) );
-  outlinewidth.appendChild( outlinewidthtxt );
-  symbol.appendChild( outlinewidth );
+
+  appendText( symbol, document, "outlinestyle", QgsSymbologyUtils::penStyle2QString( mPen.style() ) );
+  appendText( symbol, document, "outlinewidth", QString::number( mPen.widthF() ) );
+
   QDomElement fillcolor = document.createElement( "fillcolor" );
   fillcolor.setAttribute( "red", QString::number( mBrush.color().red() ) );
   fillcolor.setAttribute( "green", QString::number( mBrush.color().green() ) );
   fillcolor.setAttribute( "blue", QString::number( mBrush.color().blue() ) );
   symbol.appendChild( fillcolor );
-  QDomElement fillpattern = document.createElement( "fillpattern" );
-  QDomText fillpatterntxt = document.createTextNode( QgsSymbologyUtils::brushStyle2QString( mBrush.style() ) );
-  fillpattern.appendChild( fillpatterntxt );
-  symbol.appendChild( fillpattern );
-  fillpattern.appendChild( fillpatterntxt );
 
-  QDomElement texturepath = document.createElement( "texturepath" );
-  QDomText texturepathtxt = document.createTextNode( mTextureFilePath );
-  symbol.appendChild( texturepath );
-  texturepath.appendChild( texturepathtxt );
+  appendText( symbol, document, "fillpattern", QgsSymbologyUtils::brushStyle2QString( mBrush.style() ) );
+  appendText( symbol, document, "texturepath", mTextureFilePath );
 
   return returnval;
 }
 
-bool QgsSymbol::readXML( QDomNode & synode )
+int QgsSymbol::readFieldName( QDomNode &synode, QString name, const QgsVectorLayer &vl )
 {
+  QDomNode node = synode.namedItem( name + "name" );
+
+  if ( !node.isNull() )
+  {
+    const QgsFieldMap &fields = vl.pendingFields();
+    QString name = node.toElement().text();
+
+    int i;
+    for ( i = 0; i < fields.size() && fields[i].name() != name; i++ )
+      ;
+
+    return i < fields.size() ? i : -1;
+  }
+
+  node = synode.namedItem( name );
+
+  return node.isNull() ? -1 : node.toElement().text().toInt();
+}
+
+bool QgsSymbol::readXML( QDomNode &synode, const QgsVectorLayer *vl )
+{
   // Legacy project file formats didn't have support for pointsymbol nor
   // pointsize Dom elements.  Therefore we should check whether these
   // actually exist.
@@ -540,24 +539,17 @@
     setPointSize( psizeelement.text().toFloat() );
   }
 
-  mRotationClassificationField = -1;
-  mScaleClassificationField = -1;
-
-  QDomNode classnode = synode.namedItem( "rotationclassificationfield" );
-  if ( !classnode.isNull() )
+  if ( vl )
   {
-    mRotationClassificationField = classnode.toElement().text().toInt();
-    QgsDebugMsg( "Found rotationfield: " + QString::number( rotationClassificationField() ) );
+    mRotationClassificationField = readFieldName( synode, "rotationclassificationfield", *vl );
+    mScaleClassificationField = readFieldName( synode, "scaleclassificationfield", *vl );
   }
-
-  classnode = synode.namedItem( "scaleclassificationfield" );
-  if ( !classnode.isNull() )
+  else
   {
-    mScaleClassificationField = classnode.toElement().text().toInt();
-    QgsDebugMsg( "Found scalefield: " + QString::number( scaleClassificationField() ) );
+    mRotationClassificationField = -1;
+    mScaleClassificationField = -1;
   }
 
-
   QDomNode outlcnode = synode.namedItem( "outlinecolor" );
   QDomElement oulcelement = outlcnode.toElement();
   int red = oulcelement.attribute( "red" ).toInt();
@@ -611,4 +603,3 @@
 {
   mScaleClassificationField = field;
 }
-

Modified: trunk/qgis/src/core/symbology/qgssymbol.h
===================================================================
--- trunk/qgis/src/core/symbology/qgssymbol.h	2008-12-06 11:22:19 UTC (rev 9746)
+++ trunk/qgis/src/core/symbology/qgssymbol.h	2008-12-07 03:10:00 UTC (rev 9747)
@@ -26,7 +26,10 @@
 
 class QDomNode;
 class QDomDocument;
+class QDomElement;
 
+class QgsVectorLayer;
+
 /**Encapsulates settings for drawing (QPen, QBrush, Point symbol) and classification
   (lower value, upper value)*/
 class CORE_EXPORT QgsSymbol
@@ -113,10 +116,10 @@
 
     /**Writes the contents of the symbol to a configuration file
       @ return true in case of success*/
-    virtual bool writeXML( QDomNode & item, QDomDocument & document ) const;
+    virtual bool writeXML( QDomNode & item, QDomDocument & document, const QgsVectorLayer *vl ) const;
     /**Reads the contents of the symbol from a configuration file
       @ return true in case of success*/
-    virtual bool readXML( QDomNode & symbol );
+    virtual bool readXML( QDomNode & symbol, const QgsVectorLayer *vl );
     /**Returns if this symbol is point/ line or polygon*/
     QGis::GeometryType type() const {return mType;}
 
@@ -125,11 +128,13 @@
     /**Sets the number of the rotation classicifation field
     \param field the number of the field to classify for rotation*/
     void setRotationClassificationField( int field );
+
     /**Returns the number of the scale classification field*/
     int scaleClassificationField() const;
     /**Sets the number of the scale classicifation field
     \param field the number of the field to classify for scale*/
     void setScaleClassificationField( int field );
+
   protected:
 
     /**Lower value for classification*/
@@ -192,6 +197,12 @@
     /**Index of the classification fields (it must be a numerical field index)*/
     int mRotationClassificationField;
     int mScaleClassificationField;
+
+  private:
+    int readFieldName( QDomNode &synode, QString name, const QgsVectorLayer &vl );
+    void appendField( QDomElement &symbol, QDomDocument &document, const QgsVectorLayer &vl, QString name, int idx ) const;
+    void appendText( QDomElement &symbol, QDomDocument &document, QString name, QString value ) const;
+
 };
 
 inline void QgsSymbol::setBrush( QBrush b )



More information about the QGIS-commit mailing list