diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index 48e7da0c1b9..b4f2f15c12c 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -614,6 +614,9 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag ) return myErrorMessage; } + //also restore custom properties (for labeling-ng) + readCustomProperties( myRoot, "labeling" ); + return ""; } @@ -653,6 +656,9 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag 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 @@ void QgsMapLayer::removeCustomProperty( const QString& key ) 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 @@ void QgsMapLayer::readCustomProperties( QDomNode & layerNode ) 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::const_iterator it = mCustomProperties.begin(); it != mCustomProperties.end(); ++it ) + for ( QMap::const_iterator it = mCustomProperties.constBegin(); it != mCustomProperties.constEnd(); ++it ) { QDomElement propElement = doc.createElement( "property" ); propElement.setAttribute( "key", it.key() ); diff --git a/src/core/qgsmaplayer.h b/src/core/qgsmaplayer.h index 38459199da2..6544cf15edb 100644 --- a/src/core/qgsmaplayer.h +++ b/src/core/qgsmaplayer.h @@ -373,11 +373,12 @@ class CORE_EXPORT QgsMapLayer : public QObject 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 );