From df1d47b86ad94c74d714a862473c68e91593c019 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Fri, 25 Jan 2019 19:38:28 +0700 Subject: [PATCH] [gui] Fix style manager's add button when the 'all' tab is selected --- .../symbology/qgsstylemanagerdialog.sip.in | 2 +- src/gui/symbology/qgsstylemanagerdialog.cpp | 39 +++++++++++++++++-- src/gui/symbology/qgsstylemanagerdialog.h | 5 ++- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in b/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in index 337933bfb1e..d50317de96e 100644 --- a/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in +++ b/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in @@ -279,7 +279,7 @@ Populates the list view with color ramps of the current type with the given name int currentItemType(); QString currentItemName(); - bool addSymbol(); + bool addSymbol( int symbolType = -1 ); %Docstring add a new symbol to style %End diff --git a/src/gui/symbology/qgsstylemanagerdialog.cpp b/src/gui/symbology/qgsstylemanagerdialog.cpp index 00dd69fdab2..224ddebcb29 100644 --- a/src/gui/symbology/qgsstylemanagerdialog.cpp +++ b/src/gui/symbology/qgsstylemanagerdialog.cpp @@ -16,7 +16,6 @@ #include "qgsstylemanagerdialog.h" #include "qgsstylesavedialog.h" -#include "qgsstyle.h" #include "qgssymbol.h" #include "qgssymbollayerutils.h" #include "qgscolorramp.h" @@ -296,9 +295,28 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent, QStringList rampTypes; rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" ); rampTypes << tr( "Catalog: ColorBrewer" ); + + mMenuBtnAddItemAll = new QMenu( this ); mMenuBtnAddItemColorRamp = new QMenu( this ); + + QAction *item = new QAction( tr( "Marker" ), this ); + connect( item, &QAction::triggered, this, [ = ]( bool ) { addSymbol( QgsSymbol::Marker ); } ); + mMenuBtnAddItemAll->addAction( item ); + item = new QAction( tr( "Line" ), this ); + connect( item, &QAction::triggered, this, [ = ]( bool ) { addSymbol( QgsSymbol::Line ); } ); + mMenuBtnAddItemAll->addAction( item ); + item = new QAction( tr( "Fill" ), this ); + connect( item, &QAction::triggered, this, [ = ]( bool ) { addSymbol( QgsSymbol::Fill ); } ); + mMenuBtnAddItemAll->addAction( item ); + mMenuBtnAddItemAll->addSeparator(); for ( const QString &rampType : qgis::as_const( rampTypes ) ) + { + item = new QAction( rampType, this ); + connect( item, &QAction::triggered, this, [ = ]( bool ) { addColorRamp( item ); } ); + mMenuBtnAddItemAll->addAction( item ); mMenuBtnAddItemColorRamp->addAction( new QAction( rampType, this ) ); + } + connect( mMenuBtnAddItemColorRamp, &QMenu::triggered, this, static_cast( &QgsStyleManagerDialog::addColorRamp ) ); } @@ -417,7 +435,20 @@ void QgsStyleManagerDialog::tabItemType_currentChanged( int ) // when in Color Ramp tab, add menu to add item button and hide "Export symbols as PNG/SVG" const bool isSymbol = currentItemType() != 3; searchBox->setPlaceholderText( isSymbol ? tr( "Filter symbols…" ) : tr( "Filter color ramps…" ) ); - btnAddItem->setMenu( isSymbol || mReadOnly ? nullptr : mMenuBtnAddItemColorRamp ); + + if ( !mReadOnly && !isSymbol ) // color ramp tab + { + btnAddItem->setMenu( mMenuBtnAddItemColorRamp ); + } + else if ( !mReadOnly && tabItemType->currentIndex() == 0 ) // all symbols tab + { + btnAddItem->setMenu( mMenuBtnAddItemAll ); + } + else + { + btnAddItem->setMenu( nullptr ); + } + actnExportAsPNG->setVisible( isSymbol ); actnExportAsSVG->setVisible( isSymbol ); @@ -701,12 +732,12 @@ void QgsStyleManagerDialog::addItem() } } -bool QgsStyleManagerDialog::addSymbol() +bool QgsStyleManagerDialog::addSymbol( int symbolType ) { // create new symbol with current type QgsSymbol *symbol = nullptr; QString name = tr( "new symbol" ); - switch ( currentItemType() ) + switch ( symbolType == -1 ? currentItemType() : symbolType ) { case QgsSymbol::Marker: symbol = new QgsMarkerSymbol(); diff --git a/src/gui/symbology/qgsstylemanagerdialog.h b/src/gui/symbology/qgsstylemanagerdialog.h index 449518a36fe..d81a12719ad 100644 --- a/src/gui/symbology/qgsstylemanagerdialog.h +++ b/src/gui/symbology/qgsstylemanagerdialog.h @@ -297,7 +297,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan QString currentItemName(); //! add a new symbol to style - bool addSymbol(); + bool addSymbol( int symbolType = -1 ); //! add a new color ramp to style bool addColorRamp(); @@ -381,6 +381,9 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan //! Menu for the "Add item" toolbutton when in colorramp mode QMenu *mMenuBtnAddItemColorRamp = nullptr; + //! Menu for the "Add item" toolbutton when in all symbols mode + QMenu *mMenuBtnAddItemAll = nullptr; + QAction *mActionCopyToDefault = nullptr; int mBlockGroupUpdates = 0;