|
16 | 16 | #include "qgsstylemanagerdialog.h"
|
17 | 17 | #include "qgsstylesavedialog.h"
|
18 | 18 |
|
19 |
| -#include "qgsstyle.h" |
20 | 19 | #include "qgssymbol.h"
|
21 | 20 | #include "qgssymbollayerutils.h"
|
22 | 21 | #include "qgscolorramp.h"
|
@@ -296,9 +295,28 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
|
296 | 295 | QStringList rampTypes;
|
297 | 296 | rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" );
|
298 | 297 | rampTypes << tr( "Catalog: ColorBrewer" );
|
| 298 | + |
| 299 | + mMenuBtnAddItemAll = new QMenu( this ); |
299 | 300 | 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(); |
300 | 312 | 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 ); |
301 | 317 | mMenuBtnAddItemColorRamp->addAction( new QAction( rampType, this ) );
|
| 318 | + } |
| 319 | + |
302 | 320 | connect( mMenuBtnAddItemColorRamp, &QMenu::triggered,
|
303 | 321 | this, static_cast<bool ( QgsStyleManagerDialog::* )( QAction * )>( &QgsStyleManagerDialog::addColorRamp ) );
|
304 | 322 | }
|
@@ -417,7 +435,20 @@ void QgsStyleManagerDialog::tabItemType_currentChanged( int )
|
417 | 435 | // when in Color Ramp tab, add menu to add item button and hide "Export symbols as PNG/SVG"
|
418 | 436 | const bool isSymbol = currentItemType() != 3;
|
419 | 437 | 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 | + |
421 | 452 | actnExportAsPNG->setVisible( isSymbol );
|
422 | 453 | actnExportAsSVG->setVisible( isSymbol );
|
423 | 454 |
|
@@ -701,12 +732,12 @@ void QgsStyleManagerDialog::addItem()
|
701 | 732 | }
|
702 | 733 | }
|
703 | 734 |
|
704 |
| -bool QgsStyleManagerDialog::addSymbol() |
| 735 | +bool QgsStyleManagerDialog::addSymbol( int symbolType ) |
705 | 736 | {
|
706 | 737 | // create new symbol with current type
|
707 | 738 | QgsSymbol *symbol = nullptr;
|
708 | 739 | QString name = tr( "new symbol" );
|
709 |
| - switch ( currentItemType() ) |
| 740 | + switch ( symbolType == -1 ? currentItemType() : symbolType ) |
710 | 741 | {
|
711 | 742 | case QgsSymbol::Marker:
|
712 | 743 | symbol = new QgsMarkerSymbol();
|
|
0 commit comments