@@ -824,6 +824,8 @@ void QgisApp::createActions()
824
824
connect ( mActionCutFeatures , SIGNAL ( triggered () ), this , SLOT ( editCut () ) );
825
825
connect ( mActionCopyFeatures , SIGNAL ( triggered () ), this , SLOT ( editCopy () ) );
826
826
connect ( mActionPasteFeatures , SIGNAL ( triggered () ), this , SLOT ( editPaste () ) );
827
+ connect ( mActionCopyStyle , SIGNAL ( triggered () ), this , SLOT ( copyStyle () ) );
828
+ connect ( mActionPasteStyle , SIGNAL ( triggered () ), this , SLOT ( pasteStyle () ) );
827
829
connect ( mActionAddFeature , SIGNAL ( triggered () ), this , SLOT ( addFeature () ) );
828
830
connect ( mActionMoveFeature , SIGNAL ( triggered () ), this , SLOT ( moveFeature () ) );
829
831
connect ( mActionReshapeFeatures , SIGNAL ( triggered () ), this , SLOT ( reshapeFeatures () ) );
@@ -4297,7 +4299,6 @@ void QgisApp::editCut( QgsMapLayer * layerContainingSelection )
4297
4299
}
4298
4300
}
4299
4301
4300
-
4301
4302
void QgisApp::editCopy ( QgsMapLayer * layerContainingSelection )
4302
4303
{
4303
4304
if ( mMapCanvas && mMapCanvas ->isDrawing () )
@@ -4376,6 +4377,76 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
4376
4377
}
4377
4378
}
4378
4379
4380
+ void QgisApp::copyStyle ( QgsMapLayer * sourceLayer )
4381
+ {
4382
+ QgsMapLayer *selectionLayer = sourceLayer ? sourceLayer : activeLayer ();
4383
+ if ( selectionLayer )
4384
+ {
4385
+ QDomImplementation DomImplementation;
4386
+ QDomDocumentType documentType =
4387
+ DomImplementation.createDocumentType (
4388
+ " qgis" , " http://mrcc.com/qgis.dtd" , " SYSTEM" );
4389
+ QDomDocument doc ( documentType );
4390
+ QDomElement rootNode = doc.createElement ( " qgis" );
4391
+ rootNode.setAttribute ( " version" , QString ( " %1" ).arg ( QGis::QGIS_VERSION ) );
4392
+ doc.appendChild ( rootNode );
4393
+ QString errorMsg;
4394
+ if ( !selectionLayer->writeSymbology ( rootNode, doc, errorMsg ) )
4395
+ {
4396
+ QMessageBox::warning ( this ,
4397
+ tr ( " Error" ),
4398
+ tr ( " Cannot copy style: %1" )
4399
+ .arg ( errorMsg ),
4400
+ QMessageBox::Ok );
4401
+ return ;
4402
+ }
4403
+ QClipboard* clipboard = QApplication::clipboard ();
4404
+ QMimeData *mimeData = new QMimeData ();
4405
+ mimeData->setData ( " application/qgis.style" , doc.toByteArray () );
4406
+ // transfers the ownership to the clipboard object
4407
+ clipboard->setMimeData ( mimeData );
4408
+ }
4409
+ }
4410
+
4411
+ void QgisApp::pasteStyle ( QgsMapLayer * destinationLayer )
4412
+ {
4413
+ QgsMapLayer *selectionLayer = destinationLayer ? destinationLayer : activeLayer ();
4414
+ if ( selectionLayer )
4415
+ {
4416
+ QClipboard* clipboard = QApplication::clipboard ();
4417
+
4418
+ const QMimeData* mimeData = clipboard->mimeData ();
4419
+ if ( mimeData->hasFormat ( " application/qgis.style" ) )
4420
+ {
4421
+ QDomDocument doc ( " qgis" );
4422
+ QString errorMsg;
4423
+ int errorLine, errorColumn;
4424
+ if ( !doc.setContent ( mimeData->data ( " application/qgis.style" ), false , &errorMsg, &errorLine, &errorColumn ) )
4425
+ {
4426
+ QMessageBox::information ( this ,
4427
+ tr ( " Error" ),
4428
+ tr ( " Cannot parse style: %1:%2:%3" )
4429
+ .arg ( errorMsg )
4430
+ .arg ( errorLine )
4431
+ .arg ( errorColumn ),
4432
+ QMessageBox::Ok );
4433
+ return ;
4434
+ }
4435
+ QDomElement rootNode = doc.firstChildElement ( " qgis" );
4436
+ if ( !selectionLayer->readSymbology ( rootNode, errorMsg ) )
4437
+ {
4438
+ QMessageBox::information ( this ,
4439
+ tr ( " Error" ),
4440
+ tr ( " Cannot read style: %1" )
4441
+ .arg ( errorMsg ),
4442
+ QMessageBox::Ok );
4443
+ return ;
4444
+ }
4445
+
4446
+ mMapLegend ->refreshLayerSymbology ( selectionLayer->id (), false );
4447
+ }
4448
+ }
4449
+ }
4379
4450
4380
4451
void QgisApp::pasteTransformations ()
4381
4452
{
@@ -6299,6 +6370,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
6299
6370
mActionCutFeatures ->setEnabled ( false );
6300
6371
mActionCopyFeatures ->setEnabled ( false );
6301
6372
mActionPasteFeatures ->setEnabled ( false );
6373
+ mActionCopyStyle ->setEnabled ( false );
6374
+ mActionPasteStyle ->setEnabled ( false );
6302
6375
6303
6376
mActionUndo ->setEnabled ( false );
6304
6377
mActionRedo ->setEnabled ( false );
@@ -6329,6 +6402,9 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
6329
6402
mActionAddToOverview ->setEnabled ( true );
6330
6403
mActionZoomToLayer ->setEnabled ( true );
6331
6404
6405
+ mActionCopyStyle ->setEnabled ( true );
6406
+ mActionPasteStyle ->setEnabled ( QApplication::clipboard ()->mimeData ()->hasFormat ( " application/qgis.style" ) );
6407
+
6332
6408
/* **********Vector layers****************/
6333
6409
if ( layer->type () == QgsMapLayer::VectorLayer )
6334
6410
{
0 commit comments