Skip to content

Commit

Permalink
added context menu to the groupTree to +/- groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunmozhi committed Jul 13, 2012
1 parent 8ad03d2 commit 0020a6a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -109,6 +109,11 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
connect( tagBtn, SIGNAL( clicked() ), this, SLOT( tagsChanged() ) );

// Context menu for groupTree
groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
connect( groupTree, SIGNAL( customContextMenuRequested( const QPoint& ) ),
this, SLOT( grouptreeContextMenu( const QPoint& ) ) );

}

void QgsStyleV2ManagerDialog::onFinished()
Expand Down Expand Up @@ -684,7 +689,7 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
}
else // then it must be a group
{
if ( index.data() == "Ungrouped" )
if ( !index.data( Qt::UserRole + 1 ).toInt() && ( index.data() == "Ungrouped" ) )
enableGroupInputs( false );
else
enableGroupInputs( true );
Expand All @@ -710,7 +715,8 @@ void QgsStyleV2ManagerDialog::addGroup()

// Violation 1: Creating sub-groups of system defined groups
QString parentData = parentIndex.data( Qt::UserRole + 1 ).toString();
if ( parentData == "all" || parentData == "recent" || parentData == "project" || parentIndex.data() == "Ungrouped" )
if ( parentData == "all" || parentData == "recent" || parentData == "project" ||
( parentIndex.data() == "Ungrouped" && parentData == "0" ) )
{
int err = QMessageBox::critical( this, tr( "Invalid Selection" ),
tr( "The parent group you have selected is not user editable.\n"
Expand Down Expand Up @@ -1001,16 +1007,20 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
for( int i = 0; i < treeModel->rowCount(); i++ )
{
if ( treeModel->item( i )->text() != "Groups" )
if ( treeModel->item( i )->data() != "groups" )
{
treeModel->item( i )->setEnabled( enable );
}
if ( treeModel->item( i )->text() == "Groups" )
if ( treeModel->item( i )->data() == "groups" )
{
treeModel->item( i )->setEnabled( enable );
treeModel->item( i )->child( treeModel->item( i )->rowCount() - 1 )->setEnabled( enable );
for ( int k = 0; k < treeModel->item( i )->rowCount(); k++ )
{
if ( !treeModel->item( i )->child( k )->data().toInt() )
treeModel->item( i )->child( k )->setEnabled( enable );
}
}
if( treeModel->item( i )->text() == "Smart Groups" )
if( treeModel->item( i )->data() == "smartgroups" )
{
for( int j = 0; j < treeModel->item( i )->rowCount(); j++ )
{
Expand All @@ -1020,3 +1030,22 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
}

}

void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )
{
QPoint globalPos = groupTree->viewport()->mapToGlobal( point );

QMenu groupMenu;
groupMenu.addAction( "Add Group" );
groupMenu.addAction( "Remove Group" );

QAction* selectedItem = groupMenu.exec( globalPos );

if ( selectedItem )
{
if ( selectedItem->text() == "Add Group" )
addGroup();
else if ( selectedItem->text() == "Remove Group" )
removeGroup();
}
}
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -69,6 +69,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
//! Perform symbol specific tasks when selected
void symbolSelected( const QModelIndex& );

//! Context menu for the groupTree
void grouptreeContextMenu( const QPoint& );

protected:

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

0 comments on commit 0020a6a

Please sign in to comment.