@@ -82,7 +82,12 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
82
82
{
83
83
groupTree->setExpanded ( groupModel->indexFromItem ( groupModel->item ( i )), true );
84
84
}
85
- connect ( groupTree->selectionModel (), SIGNAL ( currentChanged ( const QModelIndex&, const QModelIndex& ) ), this , SLOT ( groupChanged ( const QModelIndex& ) ) );
85
+ connect ( groupTree->selectionModel (), SIGNAL ( currentChanged ( const QModelIndex&, const QModelIndex& ) ),
86
+ this , SLOT ( groupChanged ( const QModelIndex& ) ) );
87
+ connect ( groupModel, SIGNAL ( itemChanged ( QStandardItem* ) ), this , SLOT ( groupRenamed ( QStandardItem* ) ) );
88
+
89
+ connect ( btnAddGroup, SIGNAL ( clicked () ), this , SLOT ( addGroup () ) );
90
+ connect ( btnRemoveGroup, SIGNAL ( clicked () ), this , SLOT ( removeGroup () ) );
86
91
87
92
connect ( tabItemType, SIGNAL ( currentChanged ( int ) ), this , SLOT ( populateList () ) );
88
93
@@ -578,25 +583,30 @@ void QgsStyleV2ManagerDialog::populateGroups()
578
583
model->clear ();
579
584
580
585
QStandardItem *allSymbols = new QStandardItem ( " All Symbols" );
581
- allSymbols->setData ( QVariant ( " all" ) );
586
+ allSymbols->setData ( " all" );
587
+ allSymbols->setEditable ( false );
582
588
model->appendRow ( allSymbols );
583
589
584
590
QStandardItem *projectSymbols = new QStandardItem ( " Project Symbols" );
585
591
projectSymbols->setData ( " project" );
592
+ projectSymbols->setEditable ( false );
586
593
model->appendRow ( projectSymbols );
587
594
588
595
QStandardItem *recent = new QStandardItem ( " Recently Used" );
589
- recent->setData ( QVariant ( " recent" ) );
596
+ recent->setData ( " recent" );
597
+ recent->setEditable ( false );
590
598
model->appendRow ( recent );
591
599
592
600
QStandardItem *group = new QStandardItem ( " " ); // require empty name to get first order groups
593
- group->setData ( QVariant ( " groups" ) );
601
+ group->setData ( " groups" );
602
+ group->setEditable ( false );
594
603
buildGroupTree ( group );
595
604
group->setText ( " Groups" );// set title later
596
605
model->appendRow ( group );
597
606
598
607
QStandardItem *tag = new QStandardItem ( " Smart Groups" );
599
- tag->setData ( QVariant ( " tags" ) );
608
+ tag->setData ( " tags" );
609
+ tag->setEditable ( false );
600
610
buildTagTree ( tag );
601
611
model->appendRow ( tag );
602
612
@@ -609,7 +619,7 @@ void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
609
619
while ( i != groups.constEnd () )
610
620
{
611
621
QStandardItem *item = new QStandardItem ( i.value () );
612
- item->setData ( QVariant ( i.key () ) );
622
+ item->setData ( i.key () );
613
623
parent->appendRow ( item );
614
624
buildGroupTree ( item );
615
625
++i;
@@ -618,12 +628,12 @@ void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
618
628
619
629
void QgsStyleV2ManagerDialog::buildTagTree ( QStandardItem* &parent )
620
630
{
621
- QgsSymbolTagMap tags;
631
+ QgsSymbolTagMap tags = mStyle -> symbolTags () ;
622
632
QgsSymbolTagMap::const_iterator i = tags.constBegin ();
623
633
while ( i != tags.constEnd () )
624
634
{
625
635
QStandardItem *item = new QStandardItem ( i.value () );
626
- item->setData ( QVariant ( i.key () ) );
636
+ item->setData ( i.key () );
627
637
parent->appendRow ( item );
628
638
++i;
629
639
}
@@ -685,3 +695,123 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
685
695
}
686
696
}
687
697
698
+ void QgsStyleV2ManagerDialog::addGroup ()
699
+ {
700
+ QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model () );
701
+ QModelIndex parentIndex = groupTree->currentIndex ();
702
+
703
+ // Violation 1: Creating sub-groups of system defined groups
704
+ QString parentData = parentIndex.data ( Qt::UserRole + 1 ).toString ();
705
+ if ( parentData == " all" || parentData == " recent" || parentData == " project" )
706
+ {
707
+ int err = QMessageBox::critical ( this , tr ( " Invalid Selection" ),
708
+ tr ( " The parent group you have selected is not user editable.\n "
709
+ " Kindly select a Group or Smart Group." ));
710
+ if ( err )
711
+ return ;
712
+ }
713
+
714
+ // Violation 2: Creating a nested tag
715
+ if ( parentIndex.parent ().data ( Qt::UserRole + 1 ).toString () == " tags" )
716
+ {
717
+ int err = QMessageBox::critical ( this , tr ( " Operation Not Allowed" ),
718
+ tr ( " Creation of nested Smart Groups are not allowed\n "
719
+ " Select the 'Smart Group' to create a new group." ) );
720
+ if ( err )
721
+ return ;
722
+ }
723
+
724
+ // No violation
725
+ QStandardItem *parentItem = model->itemFromIndex ( parentIndex );
726
+ QStandardItem *childItem = new QStandardItem ( " New Group" );
727
+ childItem->setData ( QVariant ( " newgroup" ) );
728
+ parentItem->appendRow ( childItem );
729
+
730
+ groupTree->setCurrentIndex ( childItem->index () );
731
+ groupTree->edit ( childItem->index () );
732
+ }
733
+
734
+ void QgsStyleV2ManagerDialog::removeGroup ()
735
+ {
736
+ QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model () );
737
+ QModelIndex index = groupTree->currentIndex ();
738
+
739
+ // Violation: removing system groups
740
+ QString data = index .data ( Qt::UserRole + 1 ).toString ();
741
+ if ( data == " all" || data == " recent" || data == " project" || data == " groups" || data == " tags" )
742
+ {
743
+ int err = QMessageBox::critical ( this , tr ( " Invalid slection" ),
744
+ tr ( " Cannot delete system defined categories.\n "
745
+ " Kindly select a group or smart group you might want to delete." ));
746
+ if ( err )
747
+ return ;
748
+ }
749
+
750
+ QStandardItem *parentItem = model->itemFromIndex ( index .parent () );
751
+ if ( parentItem->data ( Qt::UserRole + 1 ).toString () == " tags" )
752
+ {
753
+ mStyle ->remove ( TagEntity, index .data ( Qt::UserRole + 1 ).toInt () );
754
+ }
755
+ else
756
+ {
757
+ mStyle ->remove ( GroupEntity, index .data ( Qt::UserRole + 1 ).toInt () );
758
+ QStandardItem *item = model->itemFromIndex ( index );
759
+ if ( item->hasChildren () )
760
+ {
761
+ QStandardItem *parent = item->parent ();
762
+ for ( int i = 0 ; i < item->rowCount (); i++ )
763
+ {
764
+ parent->appendRow ( item->takeChild ( i ) );
765
+ }
766
+ }
767
+ }
768
+ parentItem->removeRow ( index .row () );
769
+ }
770
+
771
+ void QgsStyleV2ManagerDialog::groupRenamed ( QStandardItem * item )
772
+ {
773
+ QString data = item->data ( Qt::UserRole + 1 ).toString ();
774
+ QgsDebugMsg ( " Symbol group edited: data=" + data + " text=" + item->text () );
775
+ if ( data == " newgroup" )
776
+ {
777
+ int id;
778
+ if ( item->parent ()->data ( Qt::UserRole + 1 ).toString () == " tags" )
779
+ {
780
+ id = mStyle ->addTag ( item->text () );
781
+ }
782
+ else if ( item->parent ()->data ( Qt::UserRole + 1 ).toString () == " groups" )
783
+ {
784
+ id = mStyle ->addGroup ( item->text () );
785
+ }
786
+ else
787
+ {
788
+ int parentid = item->parent ()->data ( Qt::UserRole + 1 ).toInt ();
789
+ id = mStyle ->addGroup ( item->text (), parentid );
790
+ }
791
+ if ( !id )
792
+ {
793
+ QMessageBox::critical ( this , tr ( " Error!" ),
794
+ tr ( " New group could not be created.\n "
795
+ " There was a problem with your symbol database." ) );
796
+ item->parent ()->removeRow ( item->row () );
797
+ return ;
798
+ }
799
+ else
800
+ {
801
+ item->setData ( id );
802
+ }
803
+ }
804
+ else
805
+ {
806
+ int id = item->data ( Qt::UserRole + 1 ).toInt ();
807
+ QString name = item->text ();
808
+ if ( item->parent ()->data ( Qt::UserRole + 1 ) == " tags" )
809
+ {
810
+ mStyle ->rename ( TagEntity, id, name );
811
+ }
812
+ else
813
+ {
814
+ mStyle ->rename ( GroupEntity, id, name );
815
+ }
816
+ }
817
+ }
0 commit comments