Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[StyleManager] change context-menu handling to signal/slot mechanism
Both context-menus affected: Group-Tree and Item-List
  • Loading branch information
SebDieBln committed Jan 6, 2016
1 parent e6214b6 commit 3b30a8c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 21 deletions.
1 change: 1 addition & 0 deletions python/gui/symbology-ng/qgsstylev2managerdialog.sip
Expand Up @@ -66,6 +66,7 @@ class QgsStyleV2ManagerDialog : QDialog

protected slots:
bool addColorRamp( QAction* action );
void groupSelectedSymbols();

protected:

Expand Down
46 changes: 25 additions & 21 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -114,9 +114,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
connect( groupSymbols, SIGNAL( triggered() ), this, SLOT( groupSymbolsAction() ) );
connect( editSmartgroup, SIGNAL( triggered() ), this, SLOT( editSmartgroupAction() ) );

connect( btnAddGroup, SIGNAL( clicked() ), this, SLOT( addGroup() ) );
connect( btnRemoveGroup, SIGNAL( clicked() ), this, SLOT( removeGroup() ) );

connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
tagsLineEdit->installEventFilter( this );

Expand Down Expand Up @@ -147,6 +144,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
mGroupListMenu->setEnabled( false );
mGroupMenu->addMenu( mGroupListMenu );
actnUngroup->setData( 0 );
connect( actnUngroup, SIGNAL( triggered( bool ) ), this, SLOT( groupSelectedSymbols() ) );
mGroupMenu->addAction( actnUngroup );
mGroupMenu->addSeparator()->setParent( this );
mGroupMenu->addAction( actnRemoveItem );
Expand All @@ -155,6 +153,15 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
mGroupMenu->addAction( actnExportAsPNG );
mGroupMenu->addAction( actnExportAsSVG );

// Context menu for the group tree
mGroupTreeContextMenu = new QMenu( this );
connect( actnEditSmartGroup, SIGNAL( triggered( bool ) ), this, SLOT( editSmartgroupAction() ) );
mGroupTreeContextMenu->addAction( actnEditSmartGroup );
connect( actnAddGroup, SIGNAL( triggered( bool ) ), this, SLOT( addGroup() ) );
mGroupTreeContextMenu->addAction( actnAddGroup );
connect( actnRemoveGroup, SIGNAL( triggered( bool ) ), this, SLOT( removeGroup() ) );
mGroupTreeContextMenu->addAction( actnRemoveGroup );

on_tabItemType_currentChanged( 0 );
}

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

QMenu groupMenu;
actnEditSmartGroup->setVisible( false );
actnAddGroup->setVisible( false );
actnRemoveGroup->setVisible( false );

if ( index.parent().isValid() && ( index.data().toString() != "Ungrouped" ) )
{
if ( index.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
{
groupMenu.addAction( tr( "Edit smart group" ) );
actnEditSmartGroup->setVisible( true );
}
else
{
groupMenu.addAction( tr( "Add group" ) );
actnAddGroup->setVisible( true );
}
groupMenu.addAction( tr( "Remove group" ) );
actnRemoveGroup->setVisible( true );
}
else if ( index.data( Qt::UserRole + 1 ) == "groups" || index.data( Qt::UserRole + 1 ) == "smartgroups" )
{
groupMenu.addAction( tr( "Add group" ) );
actnAddGroup->setVisible( true );
}


QAction* selectedItem = groupMenu.exec( globalPos );

if ( selectedItem )
{
if ( selectedItem->text() == tr( "Add group" ) )
addGroup();
else if ( selectedItem->text() == tr( "Remove group" ) )
removeGroup();
else if ( selectedItem->text() == tr( "Edit smart group" ) )
editSmartgroupAction();
}
mGroupTreeContextMenu->popup( globalPos );
}

void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
Expand All @@ -1363,10 +1361,16 @@ void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
{
a = new QAction( mStyle->groupName( groupId ), mGroupListMenu );
a->setData( groupId );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( groupSelectedSymbols() ) );
mGroupListMenu->addAction( a );
}

QAction* selectedItem = mGroupMenu->exec( globalPos );
mGroupMenu->popup( globalPos );
}

void QgsStyleV2ManagerDialog::groupSelectedSymbols()
{
QAction* selectedItem = qobject_cast<QAction*>( sender() );

if ( selectedItem )
{
Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -92,6 +92,7 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV

protected slots:
bool addColorRamp( QAction* action );
void groupSelectedSymbols();

protected:

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

//! Context menu for the group tree
QMenu* mGroupTreeContextMenu;

//! Menu for the "Add item" toolbutton when in colorramp mode
QMenu* mMenuBtnAddItemColorRamp;
};
Expand Down
55 changes: 55 additions & 0 deletions src/ui/qgsstylev2managerdialogbase.ui
Expand Up @@ -461,6 +461,29 @@ QMenu::item:selected { background-color: gray; } */
<string>Ungroup</string>
</property>
</action>
<action name="actnEditSmartGroup">
<property name="text">
<string>Edit smart group...</string>
</property>
</action>
<action name="actnAddGroup">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
</property>
<property name="text">
<string>Add group</string>
</property>
</action>
<action name="actnRemoveGroup">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
</property>
<property name="text">
<string>Remove group</string>
</property>
</action>
<action name="actnExportAsPNG">
<property name="enabled">
<bool>false</bool>
Expand Down Expand Up @@ -533,5 +556,37 @@ QMenu::item:selected { background-color: gray; } */
</hint>
</hints>
</connection>
<connection>
<sender>btnAddGroup</sender>
<signal>clicked()</signal>
<receiver>actnAddGroup</receiver>
<slot>trigger()</slot>
<hints>
<hint type="sourcelabel">
<x>46</x>
<y>362</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
<connection>
<sender>btnRemoveGroup</sender>
<signal>clicked()</signal>
<receiver>actnRemoveGroup</receiver>
<slot>trigger()</slot>
<hints>
<hint type="sourcelabel">
<x>133</x>
<y>362</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 3b30a8c

Please sign in to comment.