Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[gui] Fix style manager's add button when the 'all' tab is selected
  • Loading branch information
nirvn committed Jan 25, 2019
1 parent 4022c5f commit df1d47b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Expand Up @@ -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
Expand Down
39 changes: 35 additions & 4 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Expand Up @@ -16,7 +16,6 @@
#include "qgsstylemanagerdialog.h"
#include "qgsstylesavedialog.h"

#include "qgsstyle.h"
#include "qgssymbol.h"
#include "qgssymbollayerutils.h"
#include "qgscolorramp.h"
Expand Down Expand Up @@ -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<bool ( QgsStyleManagerDialog::* )( QAction * )>( &QgsStyleManagerDialog::addColorRamp ) );
}
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/gui/symbology/qgsstylemanagerdialog.h
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit df1d47b

Please sign in to comment.