Skip to content
Permalink
Browse files

[BUGFIX] The way layer's shortname is write in QGIS project and used …

…in QGIS Server
  • Loading branch information
rldhont committed Apr 21, 2016
1 parent d31c6c3 commit 849a75671ad69cbdece9dceefb78a316293f9db6
Showing with 26 additions and 15 deletions.
  1. +25 −14 src/core/qgsmaplayer.cpp
  2. +1 −1 src/server/qgsserverprojectparser.cpp
@@ -70,6 +70,9 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mLayerName = capitaliseLayerName( mLayerOrigName );
QgsDebugMsg( "display name: '" + mLayerName + '\'' );

mShortName = "";
//mShortName.replace( QRegExp( "[\\W]" ), "_" );

// Generate the unique ID of this layer
QDateTime dt = QDateTime::currentDateTime();
mID = lyrname + dt.toString( "yyyyMMddhhmmsszzz" );
@@ -659,26 +662,34 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
QDomElement layerName = document.createElement( "layername" );
QDomText layerNameText = document.createTextNode( originalName() );
layerName.appendChild( layerNameText );
layerElement.appendChild( layerName );

// layer short name
QDomElement layerShortName = document.createElement( "shortname" );
QDomText layerShortNameText = document.createTextNode( shortName() );
layerShortName.appendChild( layerShortNameText );
if ( !mShortName.isEmpty() )
{
QDomElement layerShortName = document.createElement( "shortname" );
QDomText layerShortNameText = document.createTextNode( mShortName );
layerShortName.appendChild( layerShortNameText );
layerElement.appendChild( layerShortName );
}

// layer title
QDomElement layerTitle = document.createElement( "title" );
QDomText layerTitleText = document.createTextNode( title() );
layerTitle.appendChild( layerTitleText );
if ( !mTitle.isEmpty() )
{
QDomElement layerTitle = document.createElement( "title" );
QDomText layerTitleText = document.createTextNode( mTitle );
layerTitle.appendChild( layerTitleText );
layerElement.appendChild( layerTitle );
}

// layer abstract
QDomElement layerAbstract = document.createElement( "abstract" );
QDomText layerAbstractText = document.createTextNode( abstract() );
layerAbstract.appendChild( layerAbstractText );

layerElement.appendChild( layerName );
layerElement.appendChild( layerShortName );
layerElement.appendChild( layerTitle );
layerElement.appendChild( layerAbstract );
if ( !mAbstract.isEmpty() )
{
QDomElement layerAbstract = document.createElement( "abstract" );
QDomText layerAbstractText = document.createTextNode( mAbstract );
layerAbstract.appendChild( layerAbstractText );
layerElement.appendChild( layerAbstract );
}

// layer keyword list
QStringList keywordStringList = keywordList().split( ',' );
@@ -50,7 +50,7 @@ QgsServerProjectParser::QgsServerProjectParser( QDomDocument* xmlDoc, const QStr
currentElement = layerNodeList.at( i ).toElement();
mProjectLayerElements.push_back( currentElement );
QString lName = layerShortName( currentElement );
if ( lName.isNull() )
if ( lName.isEmpty() )
lName = layerName( currentElement );
mProjectLayerElementsByName.insert( lName, currentElement );
mProjectLayerElementsById.insert( layerId( currentElement ), currentElement );

2 comments on commit 849a756

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Apr 22, 2016

@rldhont Thanks for the fix.
Is there no risk involved in omitting these nodes when writing to the project? E.g. that a project saved with 2.14.2 will be incompatible with 2.14.1?
It would be nice if you could include some rationale for changes in the commit message, I'm still not sure why these changes were required.

@rldhont

This comment has been minimized.

Copy link
Contributor Author

@rldhont rldhont replied Apr 22, 2016

the element shortname, title or abstract are only for QGIS Server. No need to add empty element in QGIS Project.
The important part of the fix is:

 -      if ( lName.isNull() )
+      if ( lName.isEmpty() )

If QGIS Server found an empty shortname element, it used the empty string has layername. Now it used layername is shortname is empty.

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