Skip to content
Permalink
Browse files

[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 df1d47b86ad94c74d714a862473c68e91593c019
@@ -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
@@ -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<bool ( QgsStyleManagerDialog::* )( QAction * )>( &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();
@@ -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;

0 comments on commit df1d47b

Please sign in to comment.
You can’t perform that action at this time.