Skip to content

Commit e6214b6

Browse files
committed
[StyleManager] add items to the context menu
'Edit item', 'Remove item(s)', 'Export to PNG...' and 'Export to SVG...'
1 parent b32f124 commit e6214b6

File tree

2 files changed

+84
-16
lines changed

2 files changed

+84
-16
lines changed

src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,23 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
6262
connect( listItems, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editItem() ) );
6363

6464
connect( btnAddItem, SIGNAL( clicked() ), this, SLOT( addItem() ) );
65-
connect( btnEditItem, SIGNAL( clicked() ), this, SLOT( editItem() ) );
66-
connect( btnRemoveItem, SIGNAL( clicked() ), this, SLOT( removeItem() ) );
65+
connect( actnEditItem, SIGNAL( triggered( bool ) ), this, SLOT( editItem() ) );
66+
connect( actnRemoveItem, SIGNAL( triggered( bool ) ), this, SLOT( removeItem() ) );
6767

68-
btnRemoveItem->setEnabled( false );
68+
btnRemoveItem->setDefaultAction( actnRemoveItem );
69+
btnEditItem->setDefaultAction( actnEditItem );
6970

7071
QMenu *shareMenu = new QMenu( tr( "Share menu" ), this );
71-
QAction *exportAsPNGAction = shareMenu->addAction( tr( "Export selected symbols as PNG" ) );
72-
QAction *exportAsSVGAction = shareMenu->addAction( tr( "Export selected symbols as SVG" ) );
72+
shareMenu->addAction( actnExportAsPNG );
73+
shareMenu->addAction( actnExportAsSVG );
7374
QAction *exportAction = new QAction( tr( "Export..." ), this );
7475
shareMenu->addAction( exportAction );
7576
QAction *importAction = new QAction( tr( "Import..." ), this );
7677
shareMenu->addAction( importAction );
77-
exportAsPNGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
78-
exportAsPNGAction->setEnabled( false );
79-
exportAsSVGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
80-
exportAsSVGAction->setEnabled( false );
8178
exportAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
8279
importAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingImport.svg" ) ) );
83-
connect( exportAsPNGAction, SIGNAL( triggered() ), this, SLOT( exportItemsPNG() ) );
84-
connect( exportAsSVGAction, SIGNAL( triggered() ), this, SLOT( exportItemsSVG() ) );
80+
connect( actnExportAsPNG, SIGNAL( triggered() ), this, SLOT( exportItemsPNG() ) );
81+
connect( actnExportAsSVG, SIGNAL( triggered() ), this, SLOT( exportItemsSVG() ) );
8582
connect( exportAction, SIGNAL( triggered() ), this, SLOT( exportItems() ) );
8683
connect( importAction, SIGNAL( triggered() ), this, SLOT( importItems() ) );
8784
btnShare->setMenu( shareMenu );
@@ -151,6 +148,12 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
151148
mGroupMenu->addMenu( mGroupListMenu );
152149
actnUngroup->setData( 0 );
153150
mGroupMenu->addAction( actnUngroup );
151+
mGroupMenu->addSeparator()->setParent( this );
152+
mGroupMenu->addAction( actnRemoveItem );
153+
mGroupMenu->addAction( actnEditItem );
154+
mGroupMenu->addSeparator()->setParent( this );
155+
mGroupMenu->addAction( actnExportAsPNG );
156+
mGroupMenu->addAction( actnExportAsSVG );
154157

155158
on_tabItemType_currentChanged( 0 );
156159
}
@@ -213,8 +216,8 @@ void QgsStyleV2ManagerDialog::on_tabItemType_currentChanged( int )
213216
// when in Color Ramp tab, add menu to add item button and hide "Export symbols as PNG/SVG"
214217
bool flag = currentItemType() != 3;
215218
btnAddItem->setMenu( flag ? nullptr : mMenuBtnAddItemColorRamp );
216-
btnShare->menu()->actions().at( 0 )->setVisible( flag );
217-
btnShare->menu()->actions().at( 1 )->setVisible( flag );
219+
actnExportAsPNG->setVisible( flag );
220+
actnExportAsSVG->setVisible( flag );
218221

219222
// set icon and grid size, depending on type
220223
if ( currentItemType() == 1 || currentItemType() == 3 )
@@ -1233,18 +1236,20 @@ void QgsStyleV2ManagerDialog::symbolSelected( const QModelIndex& index )
12331236
mTagList = mStyle->tagsOfSymbol( type, item->data().toString() );
12341237
tagsLineEdit->setText( mTagList.join( "," ) );
12351238
}
1239+
1240+
actnEditItem->setEnabled( index.isValid() && !mGrouppingMode );
12361241
}
12371242

12381243
void QgsStyleV2ManagerDialog::selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected )
12391244
{
12401245
Q_UNUSED( selected );
12411246
Q_UNUSED( deselected );
12421247
bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
1243-
btnRemoveItem->setDisabled( nothingSelected );
1248+
actnRemoveItem->setDisabled( nothingSelected );
12441249
mGroupListMenu->setDisabled( nothingSelected );
12451250
actnUngroup->setDisabled( nothingSelected );
1246-
btnShare->menu()->actions().at( 0 )->setDisabled( nothingSelected );
1247-
btnShare->menu()->actions().at( 1 )->setDisabled( nothingSelected );
1251+
actnExportAsPNG->setDisabled( nothingSelected );
1252+
actnExportAsSVG->setDisabled( nothingSelected );
12481253
}
12491254

12501255
void QgsStyleV2ManagerDialog::enableSymbolInputs( bool enable )
@@ -1300,6 +1305,9 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
13001305
w->setEnabled( enable );
13011306
}
13021307

1308+
// The actions
1309+
actnRemoveItem->setEnabled( enable );
1310+
actnEditItem->setEnabled( enable );
13031311
}
13041312

13051313
void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )

src/ui/qgsstylev2managerdialogbase.ui

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,36 @@ QMenu::item:selected { background-color: gray; } */
420420
</widget>
421421
</item>
422422
</layout>
423+
<action name="actnRemoveItem">
424+
<property name="enabled">
425+
<bool>false</bool>
426+
</property>
427+
<property name="icon">
428+
<iconset resource="../../images/images.qrc">
429+
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
430+
</property>
431+
<property name="text">
432+
<string>Remove item(s)</string>
433+
</property>
434+
<property name="toolTip">
435+
<string>Remove item(s)</string>
436+
</property>
437+
</action>
438+
<action name="actnEditItem">
439+
<property name="enabled">
440+
<bool>false</bool>
441+
</property>
442+
<property name="icon">
443+
<iconset resource="../../images/images.qrc">
444+
<normaloff>:/images/themes/default/mActionProjectProperties.png</normaloff>:/images/themes/default/mActionProjectProperties.png</iconset>
445+
</property>
446+
<property name="text">
447+
<string>Edit item...</string>
448+
</property>
449+
<property name="toolTip">
450+
<string>Edit item</string>
451+
</property>
452+
</action>
423453
<action name="actnUngroup">
424454
<property name="enabled">
425455
<bool>false</bool>
@@ -431,6 +461,36 @@ QMenu::item:selected { background-color: gray; } */
431461
<string>Ungroup</string>
432462
</property>
433463
</action>
464+
<action name="actnExportAsPNG">
465+
<property name="enabled">
466+
<bool>false</bool>
467+
</property>
468+
<property name="icon">
469+
<iconset resource="../../images/images.qrc">
470+
<normaloff>:/images/themes/default/mActionSharingExport.svg</normaloff>:/images/themes/default/mActionSharingExport.svg</iconset>
471+
</property>
472+
<property name="text">
473+
<string>Export selected symbol(s) as PNG...</string>
474+
</property>
475+
<property name="toolTip">
476+
<string>Export selected symbo(s) as PNG</string>
477+
</property>
478+
</action>
479+
<action name="actnExportAsSVG">
480+
<property name="enabled">
481+
<bool>false</bool>
482+
</property>
483+
<property name="icon">
484+
<iconset resource="../../images/images.qrc">
485+
<normaloff>:/images/themes/default/mActionSharingExport.svg</normaloff>:/images/themes/default/mActionSharingExport.svg</iconset>
486+
</property>
487+
<property name="text">
488+
<string>Export selected symbol(s) as SVG...</string>
489+
</property>
490+
<property name="toolTip">
491+
<string>Export selected symbol(s) as SVG</string>
492+
</property>
493+
</action>
434494
</widget>
435495
<customwidgets>
436496
<customwidget>

0 commit comments

Comments
 (0)