Skip to content
Permalink
Browse files
Fix #12655 copy/paste style between different vector layer geometry t…
…ypes
  • Loading branch information
Hvitnov committed May 21, 2015
1 parent df039ee commit 10759252820dbdf344e7fc51123db05f07574e33
Showing with 51 additions and 1 deletion.
  1. +50 −1 src/app/qgisapp.cpp
  2. +1 −0 src/core/qgsmaplayer.h
@@ -6489,6 +6489,7 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
{
QgsMapLayer *selectionLayer = sourceLayer ? sourceLayer : activeLayer();

if ( selectionLayer )
{
QDomImplementation DomImplementation;
@@ -6499,6 +6500,26 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
QDomElement rootNode = doc.createElement( "qgis" );
rootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
doc.appendChild( rootNode );

/*
* 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 ) )
{
@@ -6515,12 +6536,19 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
mActionPasteStyle->setEnabled( true );
}
}
/**
\param destinatioLayer The layer that the clipboard will be pasted to
(defaults to the active layer on the legend)
*/


void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
{
{

QgsMapLayer *selectionLayer = destinationLayer ? destinationLayer : activeLayer();
if ( selectionLayer )
{

if ( clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
{
QDomDocument doc( "qgis" );
@@ -6537,7 +6565,28 @@ void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
QMessageBox::Ok );
return;
}

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

//Test for matching geometry type on vector layers when pasting
if (selectionLayer->type() == QgsMapLayer::LayerType::VectorLayer)
{
QgsVectorLayer *selectionVectorLayer = static_cast<QgsVectorLayer*>(selectionLayer);
int pasteLayerGeometryType = doc.elementsByTagName("layerGeometryType").item(0).toElement().text().toInt();

if ( selectionVectorLayer->geometryType() != pasteLayerGeometryType )
{
QMessageBox::information( this,
tr( "Error" ),
tr( "Cannot paste style to layers that have a different geometry type" )
.arg( errorMsg ),
QMessageBox::Ok );
return;
}
}



if ( !selectionLayer->readSymbology( rootNode, errorMsg ) )
{
QMessageBox::information( this,
@@ -354,6 +354,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
{ Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }



/** Read the symbology for the current layer from the Dom node supplied.
* @param node node that will contain the symbology definition for this layer.
* @param errorMessage reference to string that will be updated with any error messages

0 comments on commit 1075925

Please sign in to comment.