@@ -109,6 +109,11 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
109
109
connect ( searchBox, SIGNAL ( textChanged ( QString ) ), this , SLOT ( filterSymbols ( QString ) ) );
110
110
connect ( tagBtn, SIGNAL ( clicked () ), this , SLOT ( tagsChanged () ) );
111
111
112
+ // Context menu for groupTree
113
+ groupTree->setContextMenuPolicy ( Qt::CustomContextMenu );
114
+ connect ( groupTree, SIGNAL ( customContextMenuRequested ( const QPoint& ) ),
115
+ this , SLOT ( grouptreeContextMenu ( const QPoint& ) ) );
116
+
112
117
}
113
118
114
119
void QgsStyleV2ManagerDialog::onFinished ()
@@ -684,7 +689,7 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
684
689
}
685
690
else // then it must be a group
686
691
{
687
- if ( index .data () == " Ungrouped" )
692
+ if ( ! index .data ( Qt::UserRole + 1 ). toInt () && ( index . data () == " Ungrouped" ) )
688
693
enableGroupInputs ( false );
689
694
else
690
695
enableGroupInputs ( true );
@@ -710,7 +715,8 @@ void QgsStyleV2ManagerDialog::addGroup()
710
715
711
716
// Violation 1: Creating sub-groups of system defined groups
712
717
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" ) )
714
720
{
715
721
int err = QMessageBox::critical ( this , tr ( " Invalid Selection" ),
716
722
tr ( " The parent group you have selected is not user editable.\n "
@@ -1001,16 +1007,20 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
1001
1007
QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model () );
1002
1008
for ( int i = 0 ; i < treeModel->rowCount (); i++ )
1003
1009
{
1004
- if ( treeModel->item ( i )->text () != " Groups " )
1010
+ if ( treeModel->item ( i )->data () != " groups " )
1005
1011
{
1006
1012
treeModel->item ( i )->setEnabled ( enable );
1007
1013
}
1008
- if ( treeModel->item ( i )->text () == " Groups " )
1014
+ if ( treeModel->item ( i )->data () == " groups " )
1009
1015
{
1010
1016
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
+ }
1012
1022
}
1013
- if ( treeModel->item ( i )->text () == " Smart Groups " )
1023
+ if ( treeModel->item ( i )->data () == " smartgroups " )
1014
1024
{
1015
1025
for ( int j = 0 ; j < treeModel->item ( i )->rowCount (); j++ )
1016
1026
{
@@ -1020,3 +1030,22 @@ void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
1020
1030
}
1021
1031
1022
1032
}
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
+ }
0 commit comments