Skip to content

Commit

Permalink
add source categories to disable unvailable ones for pasting style
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Oct 4, 2018
1 parent 819aaee commit 1e1d53f
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -39,6 +39,8 @@
#include "qgssymbolselectordialog.h"
#include "qgssinglesymbolrenderer.h"
#include "qgsmaplayerstylecategoriesmodel.h"
#include "qgsxmlutils.h"



QgsAppLayerTreeViewMenuProvider::QgsAppLayerTreeViewMenuProvider( QgsLayerTreeView *view, QgsMapCanvas *canvas )
Expand Down Expand Up @@ -349,24 +351,38 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QMenu *pasteStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) );
pasteStyleMenu->setToolTipsVisible( true );

QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( pasteStyleMenu );
model->setShowAllCategories( true );
for ( int row = 0; row < model->rowCount(); ++row )
QDomDocument doc( QStringLiteral( "qgis" ) );
QString errorMsg;
int errorLine, errorColumn;
if ( doc.setContent( app->clipboard()->data( QGSCLIPBOARD_STYLE_MIME ), false, &errorMsg, &errorLine, &errorColumn ) )
{
QModelIndex index = model->index( row, 0 );
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
QString name = model->data( index, Qt::DisplayRole ).toString();
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
QAction *copyAction = new QAction( icon, name, pasteStyleMenu );
copyAction->setToolTip( tooltip );
connect( copyAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} );
pasteStyleMenu->addAction( copyAction );
if ( category == QgsMapLayer::AllStyleCategories )
pasteStyleMenu->addSeparator();
QDomElement myRoot = doc.firstChildElement( QStringLiteral( "qgis" ) );
if ( !myRoot.isNull() )
{
QMenu *pasteStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) );
pasteStyleMenu->setToolTipsVisible( true );

QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories );

QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( pasteStyleMenu );
model->setShowAllCategories( true );
for ( int row = 0; row < model->rowCount(); ++row )
{
QModelIndex index = model->index( row, 0 );
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
QString name = model->data( index, Qt::DisplayRole ).toString();
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
QAction *pasteAction = new QAction( icon, name, pasteStyleMenu );
pasteAction->setToolTip( tooltip );
connect( pasteAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} );
pasteStyleMenu->addAction( pasteAction );
if ( category == QgsMapLayer::AllStyleCategories )
pasteStyleMenu->addSeparator();
else
pasteAction->setEnabled( sourceCategories.testFlag( category ) );
}
}
}
}
else
Expand Down

0 comments on commit 1e1d53f

Please sign in to comment.