Navigation Menu

Skip to content

Commit

Permalink
Read / write labeling-ng to qml files
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14830 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 2, 2010
1 parent 9d8d09b commit 1ca1199
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -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 "";
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...
Expand All @@ -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() );
Expand Down
7 changes: 4 additions & 3 deletions src/core/qgsmaplayer.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 1ca1199

Please sign in to comment.