Skip to content
Permalink
Browse files

Read / write labeling-ng to qml files

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14830 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Dec 2, 2010
1 parent 461978a commit bd06cdabaa0d4f384bd9aeddd1273f94889bcab3
Showing with 18 additions and 8 deletions.
  1. +14 −5 src/core/qgsmaplayer.cpp
  2. +4 −3 src/core/qgsmaplayer.h
@@ -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<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() );
@@ -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 );

0 comments on commit bd06cda

Please sign in to comment.
You can’t perform that action at this time.