Skip to content

Commit 3b30a8c

Browse files
committedJan 6, 2016
[StyleManager] change context-menu handling to signal/slot mechanism
Both context-menus affected: Group-Tree and Item-List
1 parent e6214b6 commit 3b30a8c

File tree

4 files changed

+85
-21
lines changed

4 files changed

+85
-21
lines changed
 

‎python/gui/symbology-ng/qgsstylev2managerdialog.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class QgsStyleV2ManagerDialog : QDialog
6666

6767
protected slots:
6868
bool addColorRamp( QAction* action );
69+
void groupSelectedSymbols();
6970

7071
protected:
7172

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
114114
connect( groupSymbols, SIGNAL( triggered() ), this, SLOT( groupSymbolsAction() ) );
115115
connect( editSmartgroup, SIGNAL( triggered() ), this, SLOT( editSmartgroupAction() ) );
116116

117-
connect( btnAddGroup, SIGNAL( clicked() ), this, SLOT( addGroup() ) );
118-
connect( btnRemoveGroup, SIGNAL( clicked() ), this, SLOT( removeGroup() ) );
119-
120117
connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
121118
tagsLineEdit->installEventFilter( this );
122119

@@ -147,6 +144,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
147144
mGroupListMenu->setEnabled( false );
148145
mGroupMenu->addMenu( mGroupListMenu );
149146
actnUngroup->setData( 0 );
147+
connect( actnUngroup, SIGNAL( triggered( bool ) ), this, SLOT( groupSelectedSymbols() ) );
150148
mGroupMenu->addAction( actnUngroup );
151149
mGroupMenu->addSeparator()->setParent( this );
152150
mGroupMenu->addAction( actnRemoveItem );
@@ -155,6 +153,15 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
155153
mGroupMenu->addAction( actnExportAsPNG );
156154
mGroupMenu->addAction( actnExportAsSVG );
157155

156+
// Context menu for the group tree
157+
mGroupTreeContextMenu = new QMenu( this );
158+
connect( actnEditSmartGroup, SIGNAL( triggered( bool ) ), this, SLOT( editSmartgroupAction() ) );
159+
mGroupTreeContextMenu->addAction( actnEditSmartGroup );
160+
connect( actnAddGroup, SIGNAL( triggered( bool ) ), this, SLOT( addGroup() ) );
161+
mGroupTreeContextMenu->addAction( actnAddGroup );
162+
connect( actnRemoveGroup, SIGNAL( triggered( bool ) ), this, SLOT( removeGroup() ) );
163+
mGroupTreeContextMenu->addAction( actnRemoveGroup );
164+
158165
on_tabItemType_currentChanged( 0 );
159166
}
160167

@@ -1317,37 +1324,28 @@ void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )
13171324
QModelIndex index = groupTree->indexAt( point );
13181325
QgsDebugMsg( "Now you clicked: " + index.data().toString() );
13191326

1320-
QMenu groupMenu;
1327+
actnEditSmartGroup->setVisible( false );
1328+
actnAddGroup->setVisible( false );
1329+
actnRemoveGroup->setVisible( false );
13211330

13221331
if ( index.parent().isValid() && ( index.data().toString() != "Ungrouped" ) )
13231332
{
13241333
if ( index.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
13251334
{
1326-
groupMenu.addAction( tr( "Edit smart group" ) );
1335+
actnEditSmartGroup->setVisible( true );
13271336
}
13281337
else
13291338
{
1330-
groupMenu.addAction( tr( "Add group" ) );
1339+
actnAddGroup->setVisible( true );
13311340
}
1332-
groupMenu.addAction( tr( "Remove group" ) );
1341+
actnRemoveGroup->setVisible( true );
13331342
}
13341343
else if ( index.data( Qt::UserRole + 1 ) == "groups" || index.data( Qt::UserRole + 1 ) == "smartgroups" )
13351344
{
1336-
groupMenu.addAction( tr( "Add group" ) );
1345+
actnAddGroup->setVisible( true );
13371346
}
13381347

1339-
1340-
QAction* selectedItem = groupMenu.exec( globalPos );
1341-
1342-
if ( selectedItem )
1343-
{
1344-
if ( selectedItem->text() == tr( "Add group" ) )
1345-
addGroup();
1346-
else if ( selectedItem->text() == tr( "Remove group" ) )
1347-
removeGroup();
1348-
else if ( selectedItem->text() == tr( "Edit smart group" ) )
1349-
editSmartgroupAction();
1350-
}
1348+
mGroupTreeContextMenu->popup( globalPos );
13511349
}
13521350

13531351
void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
@@ -1363,10 +1361,16 @@ void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
13631361
{
13641362
a = new QAction( mStyle->groupName( groupId ), mGroupListMenu );
13651363
a->setData( groupId );
1364+
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( groupSelectedSymbols() ) );
13661365
mGroupListMenu->addAction( a );
13671366
}
13681367

1369-
QAction* selectedItem = mGroupMenu->exec( globalPos );
1368+
mGroupMenu->popup( globalPos );
1369+
}
1370+
1371+
void QgsStyleV2ManagerDialog::groupSelectedSymbols()
1372+
{
1373+
QAction* selectedItem = qobject_cast<QAction*>( sender() );
13701374

13711375
if ( selectedItem )
13721376
{

‎src/gui/symbology-ng/qgsstylev2managerdialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
9292

9393
protected slots:
9494
bool addColorRamp( QAction* action );
95+
void groupSelectedSymbols();
9596

9697
protected:
9798

@@ -156,6 +157,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
156157
//! Sub-menu of @c mGroupMenu, dynamically filled to show one entry for every group
157158
QMenu *mGroupListMenu;
158159

160+
//! Context menu for the group tree
161+
QMenu* mGroupTreeContextMenu;
162+
159163
//! Menu for the "Add item" toolbutton when in colorramp mode
160164
QMenu* mMenuBtnAddItemColorRamp;
161165
};

‎src/ui/qgsstylev2managerdialogbase.ui

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,29 @@ QMenu::item:selected { background-color: gray; } */
461461
<string>Ungroup</string>
462462
</property>
463463
</action>
464+
<action name="actnEditSmartGroup">
465+
<property name="text">
466+
<string>Edit smart group...</string>
467+
</property>
468+
</action>
469+
<action name="actnAddGroup">
470+
<property name="icon">
471+
<iconset resource="../../images/images.qrc">
472+
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
473+
</property>
474+
<property name="text">
475+
<string>Add group</string>
476+
</property>
477+
</action>
478+
<action name="actnRemoveGroup">
479+
<property name="icon">
480+
<iconset resource="../../images/images.qrc">
481+
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
482+
</property>
483+
<property name="text">
484+
<string>Remove group</string>
485+
</property>
486+
</action>
464487
<action name="actnExportAsPNG">
465488
<property name="enabled">
466489
<bool>false</bool>
@@ -533,5 +556,37 @@ QMenu::item:selected { background-color: gray; } */
533556
</hint>
534557
</hints>
535558
</connection>
559+
<connection>
560+
<sender>btnAddGroup</sender>
561+
<signal>clicked()</signal>
562+
<receiver>actnAddGroup</receiver>
563+
<slot>trigger()</slot>
564+
<hints>
565+
<hint type="sourcelabel">
566+
<x>46</x>
567+
<y>362</y>
568+
</hint>
569+
<hint type="destinationlabel">
570+
<x>-1</x>
571+
<y>-1</y>
572+
</hint>
573+
</hints>
574+
</connection>
575+
<connection>
576+
<sender>btnRemoveGroup</sender>
577+
<signal>clicked()</signal>
578+
<receiver>actnRemoveGroup</receiver>
579+
<slot>trigger()</slot>
580+
<hints>
581+
<hint type="sourcelabel">
582+
<x>133</x>
583+
<y>362</y>
584+
</hint>
585+
<hint type="destinationlabel">
586+
<x>-1</x>
587+
<y>-1</y>
588+
</hint>
589+
</hints>
590+
</connection>
536591
</connections>
537592
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.