Skip to content

Commit 0020a6a

Browse files
author
Arunmozhi
committed
added context menu to the groupTree to +/- groups
1 parent 8ad03d2 commit 0020a6a

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/gui/symbology-ng/qgsstylev2managerdialog.cpp

+35-6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
109109
connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
110110
connect( tagBtn, SIGNAL( clicked() ), this, SLOT( tagsChanged() ) );
111111

112+
// Context menu for groupTree
113+
groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
114+
connect( groupTree, SIGNAL( customContextMenuRequested( const QPoint& ) ),
115+
this, SLOT( grouptreeContextMenu( const QPoint& ) ) );
116+
112117
}
113118

114119
void QgsStyleV2ManagerDialog::onFinished()
@@ -684,7 +689,7 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
684689
}
685690
else // then it must be a group
686691
{
687-
if ( index.data() == "Ungrouped" )
692+
if ( !index.data( Qt::UserRole + 1 ).toInt() && ( index.data() == "Ungrouped" ) )
688693
enableGroupInputs( false );
689694
else
690695
enableGroupInputs( true );
@@ -710,7 +715,8 @@ void QgsStyleV2ManagerDialog::addGroup()
710715

711716
// Violation 1: Creating sub-groups of system defined groups
712717
QString parentData = parentIndex.data( Qt::UserRole + 1 ).toString();
713-
if ( parentData == "all" || parentData == "recent" || parentData == "project" || parentIndex.data() == "Ungrouped" )
718+
if ( parentData == "all" || parentData == "recent" || parentData == "project" ||
719+
( parentIndex.data() == "Ungrouped" && parentData == "0" ) )
714720
{
715721
int err = QMessageBox::critical( this, tr( "Invalid Selection" ),
716722
tr( "The parent group you have selected is not user editable.\n"
@@ -1001,16 +1007,20 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
10011007
QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
10021008
for( int i = 0; i < treeModel->rowCount(); i++ )
10031009
{
1004-
if ( treeModel->item( i )->text() != "Groups" )
1010+
if ( treeModel->item( i )->data() != "groups" )
10051011
{
10061012
treeModel->item( i )->setEnabled( enable );
10071013
}
1008-
if ( treeModel->item( i )->text() == "Groups" )
1014+
if ( treeModel->item( i )->data() == "groups" )
10091015
{
10101016
treeModel->item( i )->setEnabled( enable );
1011-
treeModel->item( i )->child( treeModel->item( i )->rowCount() - 1 )->setEnabled( enable );
1017+
for ( int k = 0; k < treeModel->item( i )->rowCount(); k++ )
1018+
{
1019+
if ( !treeModel->item( i )->child( k )->data().toInt() )
1020+
treeModel->item( i )->child( k )->setEnabled( enable );
1021+
}
10121022
}
1013-
if( treeModel->item( i )->text() == "Smart Groups" )
1023+
if( treeModel->item( i )->data() == "smartgroups" )
10141024
{
10151025
for( int j = 0; j < treeModel->item( i )->rowCount(); j++ )
10161026
{
@@ -1020,3 +1030,22 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
10201030
}
10211031

10221032
}
1033+
1034+
void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )
1035+
{
1036+
QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1037+
1038+
QMenu groupMenu;
1039+
groupMenu.addAction( "Add Group" );
1040+
groupMenu.addAction( "Remove Group" );
1041+
1042+
QAction* selectedItem = groupMenu.exec( globalPos );
1043+
1044+
if ( selectedItem )
1045+
{
1046+
if ( selectedItem->text() == "Add Group" )
1047+
addGroup();
1048+
else if ( selectedItem->text() == "Remove Group" )
1049+
removeGroup();
1050+
}
1051+
}

src/gui/symbology-ng/qgsstylev2managerdialog.h

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
6969
//! Perform symbol specific tasks when selected
7070
void symbolSelected( const QModelIndex& );
7171

72+
//! Context menu for the groupTree
73+
void grouptreeContextMenu( const QPoint& );
74+
7275
protected:
7376

7477
//! populate combo box with known style items (symbols, color ramps)

0 commit comments

Comments
 (0)