Skip to content

Commit efeacaa

Browse files
committedNov 21, 2015
Moved export/import vector geometry type to QgsMaplayer
1 parent ff3a622 commit efeacaa

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6812,24 +6812,6 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
68126812
rootNode.setAttribute( "minimumScale", QString::number( selectionLayer->minimumScale() ) );
68136813
rootNode.setAttribute( "maximumScale", QString::number( selectionLayer->maximumScale() ) );
68146814

6815-
/*
6816-
* Check to see if the layer is vector - in which case we should also copy its geometryType
6817-
* to avoid eventually pasting to a layer with a different geometry
6818-
*/
6819-
if ( selectionLayer->type() == 0 )
6820-
{
6821-
//Getting the selectionLayer geometry
6822-
QgsVectorLayer *SelectionGeometry = static_cast<QgsVectorLayer*>( selectionLayer );
6823-
QString geoType = QString::number( SelectionGeometry->geometryType() );
6824-
6825-
//Adding geometryinformation
6826-
QDomElement layerGeometryType = doc.createElement( "layerGeometryType" );
6827-
QDomText type = doc.createTextNode( geoType );
6828-
6829-
layerGeometryType.appendChild( type );
6830-
rootNode.appendChild( layerGeometryType );
6831-
}
6832-
68336815
QString errorMsg;
68346816
if ( !selectionLayer->writeSymbology( rootNode, doc, errorMsg ) )
68356817
{
@@ -6871,20 +6853,6 @@ void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
68716853

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

6874-
//Test for matching geometry type on vector layers when pasting
6875-
if ( selectionLayer->type() == QgsMapLayer::VectorLayer )
6876-
{
6877-
QgsVectorLayer *selectionVectorLayer = static_cast<QgsVectorLayer*>( selectionLayer );
6878-
int pasteLayerGeometryType = doc.elementsByTagName( "layerGeometryType" ).item( 0 ).toElement().text().toInt();
6879-
if ( selectionVectorLayer->geometryType() != pasteLayerGeometryType )
6880-
{
6881-
messageBar()->pushMessage( tr( "Cannot paste style to layer with a different geometry type" ),
6882-
tr( "Your copied style does not match the layer you are pasting to" ),
6883-
QgsMessageBar::INFO, messageTimeout() );
6884-
return;
6885-
}
6886-
}
6887-
68886856
if ( !selectionLayer->readSymbology( rootNode, errorMsg ) )
68896857
{
68906858
messageBar()->pushMessage( errorMsg,

‎src/core/qgsmaplayer.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,18 @@ bool QgsMapLayer::importNamedStyle( QDomDocument& myDocument, QString& myErrorMe
11731173
return false;
11741174
}
11751175

1176+
//Test for matching geometry type on vector layers when applying, if geometry type is given in the style
1177+
if ( type() == QgsMapLayer::VectorLayer && !myRoot.firstChildElement( "layerGeometryType" ).isNull() )
1178+
{
1179+
QgsVectorLayer *vl = static_cast<QgsVectorLayer*>( this );
1180+
int importLayerGeometryType = myRoot.firstChildElement( "layerGeometryType" ).text().toInt();
1181+
if ( vl->geometryType() != importLayerGeometryType )
1182+
{
1183+
myErrorMessage = tr( "Cannot apply style to layer with a different geometry type" );
1184+
return false;
1185+
}
1186+
}
1187+
11761188
// use scale dependent visibility flag
11771189
setScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
11781190
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
@@ -1220,6 +1232,25 @@ void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg )
12201232
errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
12211233
return;
12221234
}
1235+
1236+
/*
1237+
* Check to see if the layer is vector - in which case we should also export its geometryType
1238+
* to avoid eventually pasting to a layer with a different geometry
1239+
*/
1240+
if ( type() == QgsMapLayer::VectorLayer )
1241+
{
1242+
//Getting the selectionLayer geometry
1243+
QgsVectorLayer *vl = static_cast<QgsVectorLayer*>( this );
1244+
QString geoType = QString::number( vl->geometryType() );
1245+
1246+
//Adding geometryinformation
1247+
QDomElement layerGeometryType = myDocument.createElement( "layerGeometryType" );
1248+
QDomText type = myDocument.createTextNode( geoType );
1249+
1250+
layerGeometryType.appendChild( type );
1251+
myRootNode.appendChild( layerGeometryType );
1252+
}
1253+
12231254
doc = myDocument;
12241255
}
12251256

0 commit comments

Comments
 (0)
Please sign in to comment.