Navigation Menu

Skip to content

Commit

Permalink
[FEATURE] When browsing a style from the browser panel, allow copying
Browse files Browse the repository at this point in the history
symbols to the default style from the right click menu and share button

Allows users to easily transfer symbols and ramps from a style xml
file directly to their local style database.
  • Loading branch information
nyalldawson committed Jan 16, 2019
1 parent dd00777 commit a1b44c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Expand Up @@ -203,9 +203,17 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
shareMenu->addAction( importAction );
connect( importAction, &QAction::triggered, this, &QgsStyleManagerDialog::importItems );
}
if ( mStyle != QgsStyle::defaultStyle() )
{
mActionCopyToDefault = new QAction( tr( "Copy Item(s) to Default Style…" ), this );
shareMenu->addAction( mActionCopyToDefault );
connect( mActionCopyToDefault, &QAction::triggered, this, &QgsStyleManagerDialog::copyItemsToDefault );
}

shareMenu->addSeparator();
shareMenu->addAction( actnExportAsPNG );
shareMenu->addAction( actnExportAsSVG );

connect( actnExportAsPNG, &QAction::triggered, this, &QgsStyleManagerDialog::exportItemsPNG );
connect( actnExportAsSVG, &QAction::triggered, this, &QgsStyleManagerDialog::exportItemsSVG );
connect( exportAction, &QAction::triggered, this, &QgsStyleManagerDialog::exportItems );
Expand Down Expand Up @@ -320,6 +328,10 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
btnAddTag->setVisible( false );
btnManageGroups->setVisible( false );
}
if ( mActionCopyToDefault )
{
mGroupMenu->addAction( mActionCopyToDefault );
}
mGroupMenu->addAction( actnExportAsPNG );
mGroupMenu->addAction( actnExportAsSVG );

Expand Down Expand Up @@ -410,6 +422,18 @@ void QgsStyleManagerDialog::tabItemType_currentChanged( int )
populateList();
}

void QgsStyleManagerDialog::copyItemsToDefault()
{
const QList< ItemDetails > items = selectedItems();
if ( !items.empty() )
{
auto cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
copyItems( items, mStyle, QgsStyle::defaultStyle(), this, cursorOverride, true, QStringList(), false, false );
QMessageBox::information( this, tr( "Import Symbols" ),
tr( "Symbols successfully imported." ) );
}
}

int QgsStyleManagerDialog::selectedItemType()
{
QModelIndex index = listItems->selectionModel()->currentIndex();
Expand Down Expand Up @@ -1556,6 +1580,8 @@ void QgsStyleManagerDialog::selectedSymbolsChanged( const QItemSelection &select
actnDetag->setDisabled( nothingSelected || mReadOnly );
actnExportAsPNG->setDisabled( nothingSelected );
actnExportAsSVG->setDisabled( nothingSelected );
if ( mActionCopyToDefault )
mActionCopyToDefault->setDisabled( nothingSelected );
actnEditItem->setDisabled( nothingSelected || mReadOnly );
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.h
Expand Up @@ -317,6 +317,8 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan

void tabItemType_currentChanged( int );

void copyItemsToDefault();

private:
int selectedItemType();

Expand Down Expand Up @@ -365,6 +367,8 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
//! Menu for the "Add item" toolbutton when in colorramp mode
QMenu *mMenuBtnAddItemColorRamp = nullptr;

QAction *mActionCopyToDefault = nullptr;

int mBlockGroupUpdates = 0;

bool mReadOnly = false;
Expand Down

0 comments on commit a1b44c9

Please sign in to comment.