Skip to content

Commit bd06cda

Browse files
author
mhugent
committed
Read / write labeling-ng to qml files
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14830 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 461978a commit bd06cda

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/core/qgsmaplayer.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
614614
return myErrorMessage;
615615
}
616616

617+
//also restore custom properties (for labeling-ng)
618+
readCustomProperties( myRoot, "labeling" );
619+
617620
return "";
618621
}
619622

@@ -653,6 +656,9 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
653656
return tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
654657
}
655658

659+
//save customproperties (for labeling ng)
660+
writeCustomProperties( myRootNode, myDocument );
661+
656662
// check if the uri is a file or ends with .qml,
657663
// which indicates that it should become one
658664
// everything else goes to the database
@@ -804,7 +810,7 @@ void QgsMapLayer::removeCustomProperty( const QString& key )
804810
mCustomProperties.remove( key );
805811
}
806812

807-
void QgsMapLayer::readCustomProperties( QDomNode & layerNode )
813+
void QgsMapLayer::readCustomProperties( QDomNode & layerNode, const QString& keyStartsWith )
808814
{
809815
QDomNode propsNode = layerNode.namedItem( "customproperties" );
810816
if ( propsNode.isNull() ) // no properties stored...
@@ -822,17 +828,20 @@ void QgsMapLayer::readCustomProperties( QDomNode & layerNode )
822828
QDomElement propElement = propNode.toElement();
823829

824830
QString key = propElement.attribute( "key" );
825-
QString value = propElement.attribute( "value" );
826-
mCustomProperties[key] = QVariant( value );
831+
if ( key.isEmpty() || key.startsWith( keyStartsWith ) )
832+
{
833+
QString value = propElement.attribute( "value" );
834+
mCustomProperties[key] = QVariant( value );
835+
}
827836
}
828837

829838
}
830839

831-
void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & doc )
840+
void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const
832841
{
833842
QDomElement propsElement = doc.createElement( "customproperties" );
834843

835-
for ( QMap<QString, QVariant>::const_iterator it = mCustomProperties.begin(); it != mCustomProperties.end(); ++it )
844+
for ( QMap<QString, QVariant>::const_iterator it = mCustomProperties.constBegin(); it != mCustomProperties.constEnd(); ++it )
836845
{
837846
QDomElement propElement = doc.createElement( "property" );
838847
propElement.setAttribute( "key", it.key() );

src/core/qgsmaplayer.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
373373
virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
374374

375375

376-
/** Read custom properties from project file. Added in v1.4 */
377-
void readCustomProperties( QDomNode & layerNode );
376+
/** Read custom properties from project file. Added in v1.4
377+
@param keyStartsWith reads only properties starting with the specified string (or all if the string is empty)*/
378+
void readCustomProperties( QDomNode & layerNode, const QString& keyStartsWith = "" );
378379

379380
/** Write custom properties to project file. Added in v1.4 */
380-
void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc );
381+
void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
381382

382383
/** debugging member - invoked when a connect() is made to this object */
383384
void connectNotify( const char * signal );

0 commit comments

Comments
 (0)