Skip to content
Permalink
Browse files

Moved export/import vector geometry type to QgsMaplayer

  • Loading branch information
SebDieBln committed Nov 21, 2015
1 parent ff3a622 commit efeacaab9655bc67106fcdbad2b4adb49aa9ddec
Showing with 31 additions and 32 deletions.
  1. +0 −32 src/app/qgisapp.cpp
  2. +31 −0 src/core/qgsmaplayer.cpp
@@ -6812,24 +6812,6 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
rootNode.setAttribute( "minimumScale", QString::number( selectionLayer->minimumScale() ) );
rootNode.setAttribute( "maximumScale", QString::number( selectionLayer->maximumScale() ) );

/*
* Check to see if the layer is vector - in which case we should also copy its geometryType
* to avoid eventually pasting to a layer with a different geometry
*/
if ( selectionLayer->type() == 0 )
{
//Getting the selectionLayer geometry
QgsVectorLayer *SelectionGeometry = static_cast<QgsVectorLayer*>( selectionLayer );
QString geoType = QString::number( SelectionGeometry->geometryType() );

//Adding geometryinformation
QDomElement layerGeometryType = doc.createElement( "layerGeometryType" );
QDomText type = doc.createTextNode( geoType );

layerGeometryType.appendChild( type );
rootNode.appendChild( layerGeometryType );
}

QString errorMsg;
if ( !selectionLayer->writeSymbology( rootNode, doc, errorMsg ) )
{
@@ -6871,20 +6853,6 @@ void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )

QDomElement rootNode = doc.firstChildElement( "qgis" );

//Test for matching geometry type on vector layers when pasting
if ( selectionLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *selectionVectorLayer = static_cast<QgsVectorLayer*>( selectionLayer );
int pasteLayerGeometryType = doc.elementsByTagName( "layerGeometryType" ).item( 0 ).toElement().text().toInt();
if ( selectionVectorLayer->geometryType() != pasteLayerGeometryType )
{
messageBar()->pushMessage( tr( "Cannot paste style to layer with a different geometry type" ),
tr( "Your copied style does not match the layer you are pasting to" ),
QgsMessageBar::INFO, messageTimeout() );
return;
}
}

if ( !selectionLayer->readSymbology( rootNode, errorMsg ) )
{
messageBar()->pushMessage( errorMsg,
@@ -1173,6 +1173,18 @@ bool QgsMapLayer::importNamedStyle( QDomDocument& myDocument, QString& myErrorMe
return false;
}

//Test for matching geometry type on vector layers when applying, if geometry type is given in the style
if ( type() == QgsMapLayer::VectorLayer && !myRoot.firstChildElement( "layerGeometryType" ).isNull() )
{
QgsVectorLayer *vl = static_cast<QgsVectorLayer*>( this );
int importLayerGeometryType = myRoot.firstChildElement( "layerGeometryType" ).text().toInt();
if ( vl->geometryType() != importLayerGeometryType )
{
myErrorMessage = tr( "Cannot apply style to layer with a different geometry type" );
return false;
}
}

// use scale dependent visibility flag
setScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
@@ -1220,6 +1232,25 @@ void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg )
errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
return;
}

/*
* Check to see if the layer is vector - in which case we should also export its geometryType
* to avoid eventually pasting to a layer with a different geometry
*/
if ( type() == QgsMapLayer::VectorLayer )
{
//Getting the selectionLayer geometry
QgsVectorLayer *vl = static_cast<QgsVectorLayer*>( this );
QString geoType = QString::number( vl->geometryType() );

//Adding geometryinformation
QDomElement layerGeometryType = myDocument.createElement( "layerGeometryType" );
QDomText type = myDocument.createTextNode( geoType );

layerGeometryType.appendChild( type );
myRootNode.appendChild( layerGeometryType );
}

doc = myDocument;
}

0 comments on commit efeacaa

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