Skip to content

Commit df1d47b

Browse files
authoredJan 25, 2019
[gui] Fix style manager's add button when the 'all' tab is selected
1 parent 4022c5f commit df1d47b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed
 

‎python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Populates the list view with color ramps of the current type with the given name
279279
int currentItemType();
280280
QString currentItemName();
281281

282-
bool addSymbol();
282+
bool addSymbol( int symbolType = -1 );
283283
%Docstring
284284
add a new symbol to style
285285
%End

‎src/gui/symbology/qgsstylemanagerdialog.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "qgsstylemanagerdialog.h"
1717
#include "qgsstylesavedialog.h"
1818

19-
#include "qgsstyle.h"
2019
#include "qgssymbol.h"
2120
#include "qgssymbollayerutils.h"
2221
#include "qgscolorramp.h"
@@ -296,9 +295,28 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
296295
QStringList rampTypes;
297296
rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" );
298297
rampTypes << tr( "Catalog: ColorBrewer" );
298+
299+
mMenuBtnAddItemAll = new QMenu( this );
299300
mMenuBtnAddItemColorRamp = new QMenu( this );
301+
302+
QAction *item = new QAction( tr( "Marker" ), this );
303+
connect( item, &QAction::triggered, this, [ = ]( bool ) { addSymbol( QgsSymbol::Marker ); } );
304+
mMenuBtnAddItemAll->addAction( item );
305+
item = new QAction( tr( "Line" ), this );
306+
connect( item, &QAction::triggered, this, [ = ]( bool ) { addSymbol( QgsSymbol::Line ); } );
307+
mMenuBtnAddItemAll->addAction( item );
308+
item = new QAction( tr( "Fill" ), this );
309+
connect( item, &QAction::triggered, this, [ = ]( bool ) { addSymbol( QgsSymbol::Fill ); } );
310+
mMenuBtnAddItemAll->addAction( item );
311+
mMenuBtnAddItemAll->addSeparator();
300312
for ( const QString &rampType : qgis::as_const( rampTypes ) )
313+
{
314+
item = new QAction( rampType, this );
315+
connect( item, &QAction::triggered, this, [ = ]( bool ) { addColorRamp( item ); } );
316+
mMenuBtnAddItemAll->addAction( item );
301317
mMenuBtnAddItemColorRamp->addAction( new QAction( rampType, this ) );
318+
}
319+
302320
connect( mMenuBtnAddItemColorRamp, &QMenu::triggered,
303321
this, static_cast<bool ( QgsStyleManagerDialog::* )( QAction * )>( &QgsStyleManagerDialog::addColorRamp ) );
304322
}
@@ -417,7 +435,20 @@ void QgsStyleManagerDialog::tabItemType_currentChanged( int )
417435
// when in Color Ramp tab, add menu to add item button and hide "Export symbols as PNG/SVG"
418436
const bool isSymbol = currentItemType() != 3;
419437
searchBox->setPlaceholderText( isSymbol ? tr( "Filter symbols…" ) : tr( "Filter color ramps…" ) );
420-
btnAddItem->setMenu( isSymbol || mReadOnly ? nullptr : mMenuBtnAddItemColorRamp );
438+
439+
if ( !mReadOnly && !isSymbol ) // color ramp tab
440+
{
441+
btnAddItem->setMenu( mMenuBtnAddItemColorRamp );
442+
}
443+
else if ( !mReadOnly && tabItemType->currentIndex() == 0 ) // all symbols tab
444+
{
445+
btnAddItem->setMenu( mMenuBtnAddItemAll );
446+
}
447+
else
448+
{
449+
btnAddItem->setMenu( nullptr );
450+
}
451+
421452
actnExportAsPNG->setVisible( isSymbol );
422453
actnExportAsSVG->setVisible( isSymbol );
423454

@@ -701,12 +732,12 @@ void QgsStyleManagerDialog::addItem()
701732
}
702733
}
703734

704-
bool QgsStyleManagerDialog::addSymbol()
735+
bool QgsStyleManagerDialog::addSymbol( int symbolType )
705736
{
706737
// create new symbol with current type
707738
QgsSymbol *symbol = nullptr;
708739
QString name = tr( "new symbol" );
709-
switch ( currentItemType() )
740+
switch ( symbolType == -1 ? currentItemType() : symbolType )
710741
{
711742
case QgsSymbol::Marker:
712743
symbol = new QgsMarkerSymbol();

‎src/gui/symbology/qgsstylemanagerdialog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
297297
QString currentItemName();
298298

299299
//! add a new symbol to style
300-
bool addSymbol();
300+
bool addSymbol( int symbolType = -1 );
301301
//! add a new color ramp to style
302302
bool addColorRamp();
303303

@@ -381,6 +381,9 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
381381
//! Menu for the "Add item" toolbutton when in colorramp mode
382382
QMenu *mMenuBtnAddItemColorRamp = nullptr;
383383

384+
//! Menu for the "Add item" toolbutton when in all symbols mode
385+
QMenu *mMenuBtnAddItemAll = nullptr;
386+
384387
QAction *mActionCopyToDefault = nullptr;
385388

386389
int mBlockGroupUpdates = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.