[QGIS Commit] r14830 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Dec 2 17:22:06 EST 2010


Author: mhugent
Date: 2010-12-02 14:22:06 -0800 (Thu, 02 Dec 2010)
New Revision: 14830

Modified:
   trunk/qgis/src/core/qgsmaplayer.cpp
   trunk/qgis/src/core/qgsmaplayer.h
Log:
Read / write labeling-ng to qml files

Modified: trunk/qgis/src/core/qgsmaplayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.cpp	2010-12-02 21:35:43 UTC (rev 14829)
+++ trunk/qgis/src/core/qgsmaplayer.cpp	2010-12-02 22:22:06 UTC (rev 14830)
@@ -614,6 +614,9 @@
     return myErrorMessage;
   }
 
+  //also restore custom properties (for labeling-ng)
+  readCustomProperties( myRoot, "labeling" );
+
   return "";
 }
 
@@ -653,6 +656,9 @@
     return tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
   }
 
+  //save customproperties (for labeling ng)
+  writeCustomProperties( myRootNode, myDocument );
+
   // check if the uri is a file or ends with .qml,
   // which indicates that it should become one
   // everything else goes to the database
@@ -804,7 +810,7 @@
   mCustomProperties.remove( key );
 }
 
-void QgsMapLayer::readCustomProperties( QDomNode & layerNode )
+void QgsMapLayer::readCustomProperties( QDomNode & layerNode, const QString& keyStartsWith )
 {
   QDomNode propsNode = layerNode.namedItem( "customproperties" );
   if ( propsNode.isNull() ) // no properties stored...
@@ -822,17 +828,20 @@
     QDomElement propElement = propNode.toElement();
 
     QString key = propElement.attribute( "key" );
-    QString value = propElement.attribute( "value" );
-    mCustomProperties[key] = QVariant( value );
+    if ( key.isEmpty() || key.startsWith( keyStartsWith ) )
+    {
+      QString value = propElement.attribute( "value" );
+      mCustomProperties[key] = QVariant( value );
+    }
   }
 
 }
 
-void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & doc )
+void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const
 {
   QDomElement propsElement = doc.createElement( "customproperties" );
 
-  for ( QMap<QString, QVariant>::const_iterator it = mCustomProperties.begin(); it != mCustomProperties.end(); ++it )
+  for ( QMap<QString, QVariant>::const_iterator it = mCustomProperties.constBegin(); it != mCustomProperties.constEnd(); ++it )
   {
     QDomElement propElement = doc.createElement( "property" );
     propElement.setAttribute( "key", it.key() );

Modified: trunk/qgis/src/core/qgsmaplayer.h
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.h	2010-12-02 21:35:43 UTC (rev 14829)
+++ trunk/qgis/src/core/qgsmaplayer.h	2010-12-02 22:22:06 UTC (rev 14830)
@@ -373,11 +373,12 @@
     virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
 
 
-    /** Read custom properties from project file. Added in v1.4 */
-    void readCustomProperties( QDomNode & layerNode );
+    /** Read custom properties from project file. Added in v1.4
+        @param keyStartsWith reads only properties starting with the specified string (or all if the string is empty)*/
+    void readCustomProperties( QDomNode & layerNode, const QString& keyStartsWith = "" );
 
     /** Write custom properties to project file. Added in v1.4 */
-    void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc );
+    void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
 
     /** debugging member - invoked when a connect() is made to this object */
     void connectNotify( const char * signal );



More information about the QGIS-commit mailing list