|
39 | 39 | #include "qgssymbolselectordialog.h"
|
40 | 40 | #include "qgssinglesymbolrenderer.h"
|
41 | 41 | #include "qgsmaplayerstylecategoriesmodel.h"
|
| 42 | +#include "qgsxmlutils.h" |
| 43 | + |
42 | 44 |
|
43 | 45 |
|
44 | 46 | QgsAppLayerTreeViewMenuProvider::QgsAppLayerTreeViewMenuProvider( QgsLayerTreeView *view, QgsMapCanvas *canvas )
|
@@ -349,24 +351,38 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
349 | 351 | {
|
350 | 352 | if ( layer->type() == QgsMapLayer::VectorLayer )
|
351 | 353 | {
|
352 |
| - QMenu *pasteStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) ); |
353 |
| - pasteStyleMenu->setToolTipsVisible( true ); |
354 |
| - |
355 |
| - QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( pasteStyleMenu ); |
356 |
| - model->setShowAllCategories( true ); |
357 |
| - for ( int row = 0; row < model->rowCount(); ++row ) |
| 354 | + QDomDocument doc( QStringLiteral( "qgis" ) ); |
| 355 | + QString errorMsg; |
| 356 | + int errorLine, errorColumn; |
| 357 | + if ( doc.setContent( app->clipboard()->data( QGSCLIPBOARD_STYLE_MIME ), false, &errorMsg, &errorLine, &errorColumn ) ) |
358 | 358 | {
|
359 |
| - QModelIndex index = model->index( row, 0 ); |
360 |
| - QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>(); |
361 |
| - QString name = model->data( index, Qt::DisplayRole ).toString(); |
362 |
| - QString tooltip = model->data( index, Qt::ToolTipRole ).toString(); |
363 |
| - QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>(); |
364 |
| - QAction *copyAction = new QAction( icon, name, pasteStyleMenu ); |
365 |
| - copyAction->setToolTip( tooltip ); |
366 |
| - connect( copyAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} ); |
367 |
| - pasteStyleMenu->addAction( copyAction ); |
368 |
| - if ( category == QgsMapLayer::AllStyleCategories ) |
369 |
| - pasteStyleMenu->addSeparator(); |
| 359 | + QDomElement myRoot = doc.firstChildElement( QStringLiteral( "qgis" ) ); |
| 360 | + if ( !myRoot.isNull() ) |
| 361 | + { |
| 362 | + QMenu *pasteStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) ); |
| 363 | + pasteStyleMenu->setToolTipsVisible( true ); |
| 364 | + |
| 365 | + QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories ); |
| 366 | + |
| 367 | + QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( pasteStyleMenu ); |
| 368 | + model->setShowAllCategories( true ); |
| 369 | + for ( int row = 0; row < model->rowCount(); ++row ) |
| 370 | + { |
| 371 | + QModelIndex index = model->index( row, 0 ); |
| 372 | + QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>(); |
| 373 | + QString name = model->data( index, Qt::DisplayRole ).toString(); |
| 374 | + QString tooltip = model->data( index, Qt::ToolTipRole ).toString(); |
| 375 | + QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>(); |
| 376 | + QAction *pasteAction = new QAction( icon, name, pasteStyleMenu ); |
| 377 | + pasteAction->setToolTip( tooltip ); |
| 378 | + connect( pasteAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} ); |
| 379 | + pasteStyleMenu->addAction( pasteAction ); |
| 380 | + if ( category == QgsMapLayer::AllStyleCategories ) |
| 381 | + pasteStyleMenu->addSeparator(); |
| 382 | + else |
| 383 | + pasteAction->setEnabled( sourceCategories.testFlag( category ) ); |
| 384 | + } |
| 385 | + } |
370 | 386 | }
|
371 | 387 | }
|
372 | 388 | else
|
|
0 commit comments