Skip to content

Commit ab489f5

Browse files
author
Arunmozhi
committed
fixed the groupTree bugs
1 parent 63eba56 commit ab489f5

File tree

2 files changed

+79
-43
lines changed

2 files changed

+79
-43
lines changed

src/gui/symbology-ng/qgsstylev2managerdialog.cpp

+72-43
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
7575
listItems->setModel( model );
7676

7777
connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
78-
// TODO take up the selectiopn model for the symbols
79-
// connect currentChanged signal to a slot which would populate the tags for that symbol
80-
// as comma seperated values in tagLineEdit and fill the mTagList
81-
//
8278
connect( listItems->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
8379
this, SLOT( symbolSelected( const QModelIndex& ) ) );
8480

@@ -173,10 +169,12 @@ void QgsStyleV2ManagerDialog::populateList()
173169

174170
if ( itemType < 3 )
175171
{
172+
enableSymbolInputs( true );
176173
groupChanged( groupTree->selectionModel()->currentIndex() );
177174
}
178175
else if ( itemType == 3 )
179176
{
177+
enableSymbolInputs( false );
180178
populateColorRamps();
181179
}
182180
else
@@ -627,7 +625,7 @@ void QgsStyleV2ManagerDialog::populateGroups()
627625
model->appendRow( group );
628626

629627
QStandardItem *tag = new QStandardItem( "Smart Groups" );
630-
tag->setData( "tags" );
628+
tag->setData( "smartgroups" );
631629
tag->setEditable( false );
632630
// TODO populate/build smart groups
633631
model->appendRow( tag );
@@ -654,30 +652,42 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
654652
QStringList groupSymbols;
655653

656654
QString category = index.data( Qt::UserRole + 1 ).toString();
657-
if ( category == "all" || category == "groups" || category == "tags" )
655+
if ( category == "all" || category == "groups" || category == "smartgroups" )
658656
{
657+
enableGroupInputs( false );
658+
if ( category == "groups" || category == "smartgroups" )
659+
{
660+
btnAddGroup->setEnabled( true );
661+
}
659662
symbolNames = mStyle->symbolNames();
660663
}
661664
else if ( category == "recent" )
662665
{
663666
// TODO add session symbols
667+
enableGroupInputs( false );
664668
symbolNames = QStringList();
665669
}
666670
else if ( category == "project" )
667671
{
668672
// TODO add project symbols
673+
enableGroupInputs( false );
669674
symbolNames = QStringList();
670675
}
671676
else
672677
{
673678
//determine groups and tags
674-
if ( index.parent().data( Qt::UserRole + 1 ) == "tags" )
679+
if ( index.parent().data( Qt::UserRole + 1 ) == "smartgroups" )
675680
{
676-
int tagId = index.data( Qt::UserRole + 1 ).toInt();
677-
symbolNames = mStyle->symbolsWithTag( tagId );
681+
// TODO
682+
// create a new Menu with smart group specific functions
683+
// and set it to the btnManageGroups
678684
}
679685
else // then it must be a group
680686
{
687+
if ( index.data() == "Ungrouped" )
688+
enableGroupInputs( false );
689+
else
690+
enableGroupInputs( true );
681691
int groupId = index.data( Qt::UserRole + 1 ).toInt();
682692
symbolNames = mStyle->symbolsOfGroup( groupId );
683693
if ( mGrouppingMode && groupId )
@@ -710,7 +720,7 @@ void QgsStyleV2ManagerDialog::addGroup()
710720
}
711721

712722
// Violation 2: Creating a nested tag
713-
if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() == "tags" )
723+
if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
714724
{
715725
int err = QMessageBox::critical( this, tr( "Operation Not Allowed" ),
716726
tr( "Creation of nested Smart Groups are not allowed\n"
@@ -736,7 +746,7 @@ void QgsStyleV2ManagerDialog::removeGroup()
736746

737747
// Violation: removing system groups
738748
QString data = index.data( Qt::UserRole + 1 ).toString();
739-
if ( data == "all" || data == "recent" || data == "project" || data == "groups" || data == "tags" || index.data() == "Ungrouped" )
749+
if ( data == "all" || data == "recent" || data == "project" || data == "groups" || data == "smartgroups" || index.data() == "Ungrouped" )
740750
{
741751
int err = QMessageBox::critical( this, tr( "Invalid slection" ),
742752
tr( "Cannot delete system defined categories.\n"
@@ -746,7 +756,7 @@ void QgsStyleV2ManagerDialog::removeGroup()
746756
}
747757

748758
QStandardItem *parentItem = model->itemFromIndex( index.parent() );
749-
if ( parentItem->data( Qt::UserRole + 1 ).toString() == "tags" )
759+
if ( parentItem->data( Qt::UserRole + 1 ).toString() == "smartgroups" )
750760
{
751761
mStyle->remove( TagEntity, index.data( Qt::UserRole + 1 ).toInt() );
752762
}
@@ -773,7 +783,7 @@ void QgsStyleV2ManagerDialog::groupRenamed( QStandardItem * item )
773783
if ( data == "newgroup" )
774784
{
775785
int id;
776-
if ( item->parent()->data( Qt::UserRole + 1 ).toString() == "tags" )
786+
if ( item->parent()->data( Qt::UserRole + 1 ).toString() == "smartgroups" )
777787
{
778788
id = mStyle->addTag( item->text() );
779789
}
@@ -803,7 +813,7 @@ void QgsStyleV2ManagerDialog::groupRenamed( QStandardItem * item )
803813
{
804814
int id = item->data( Qt::UserRole + 1 ).toInt();
805815
QString name = item->text();
806-
if ( item->parent()->data( Qt::UserRole + 1 ) == "tags" )
816+
if ( item->parent()->data( Qt::UserRole + 1 ) == "smartgroups" )
807817
{
808818
mStyle->rename( TagEntity, id, name );
809819
}
@@ -837,20 +847,7 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
837847
btnAddGroup->setEnabled( true );
838848
btnRemoveGroup->setEnabled( true );
839849
// disabel all items except groups in groupTree
840-
for( int i = 0; i < treeModel->rowCount(); i++ )
841-
{
842-
if( treeModel->item( i )->text() == "Smart Groups" )
843-
{
844-
for( int j = 0; j < treeModel->item( i )->rowCount(); j++ )
845-
{
846-
treeModel->item( i )->child( j )->setEnabled( true );
847-
}
848-
}
849-
if ( treeModel->item( i )->text() != "Groups" )
850-
{
851-
treeModel->item( i )->setEnabled( true );
852-
}
853-
}
850+
enableItemsForGroupingMode( true );
854851
groupChanged( groupTree->currentIndex() );
855852
// Finally: Reconnect all Symbol editing functionalities
856853
connect( treeModel, SIGNAL( itemChanged( QStandardItem* ) ),
@@ -860,7 +857,6 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
860857
}
861858
else
862859
{
863-
mGrouppingMode = true;
864860
bool validGroup = false;
865861
// determine whether it is a valid group
866862
QModelIndex present = groupTree->currentIndex();
@@ -876,6 +872,8 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
876872
}
877873
if ( !validGroup )
878874
return;
875+
876+
mGrouppingMode = true;
879877
// Change the text menu
880878
senderAction->setText( "Finish Grouping" );
881879

@@ -894,20 +892,7 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
894892
btnAddGroup->setEnabled( false );
895893
btnRemoveGroup->setEnabled( false );
896894
// disabel all items except groups in groupTree
897-
for( int i = 0; i < treeModel->rowCount(); i++ )
898-
{
899-
if( treeModel->item( i )->text() == "Smart Groups" )
900-
{
901-
for( int j = 0; j < treeModel->item( i )->rowCount(); j++ )
902-
{
903-
treeModel->item( i )->child( j )->setEnabled( false );
904-
}
905-
}
906-
if ( treeModel->item( i )->text() != "Groups" )
907-
{
908-
treeModel->item( i )->setEnabled( false );
909-
}
910-
}
895+
enableItemsForGroupingMode( false );
911896
groupChanged( groupTree->currentIndex() );
912897

913898
// Connect to slot which handles regrouping
@@ -986,8 +971,52 @@ void QgsStyleV2ManagerDialog::tagsChanged()
986971

987972
void QgsStyleV2ManagerDialog::symbolSelected( const QModelIndex& index )
988973
{
974+
// Populate the tags for the symbol
989975
tagsLineEdit->clear();
990976
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
991977
mTagList = mStyle->tagsOfSymbol( item->data().toString() );
992978
tagsLineEdit->setText( mTagList.join( "," ) );
993979
}
980+
981+
void QgsStyleV2ManagerDialog::enableSymbolInputs( bool enable )
982+
{
983+
groupTree->setEnabled( enable );
984+
tagBtn->setEnabled( enable );
985+
btnAddGroup->setEnabled( enable );
986+
btnRemoveGroup->setEnabled( enable );
987+
btnManageGroups->setEnabled( enable );
988+
searchBox->setEnabled( enable );
989+
tagsLineEdit->setEnabled( enable );
990+
}
991+
992+
void QgsStyleV2ManagerDialog::enableGroupInputs( bool enable )
993+
{
994+
btnAddGroup->setEnabled( enable );
995+
btnRemoveGroup->setEnabled( enable );
996+
btnManageGroups->setEnabled( enable );
997+
}
998+
999+
void QgsStyleV2ManagerDialog::enableItemsForGroupingMode( bool enable )
1000+
{
1001+
QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
1002+
for( int i = 0; i < treeModel->rowCount(); i++ )
1003+
{
1004+
if ( treeModel->item( i )->text() != "Groups" )
1005+
{
1006+
treeModel->item( i )->setEnabled( enable );
1007+
}
1008+
if ( treeModel->item( i )->text() == "Groups" )
1009+
{
1010+
treeModel->item( i )->setEnabled( enable );
1011+
treeModel->item( i )->child( treeModel->item( i )->rowCount() - 1 )->setEnabled( enable );
1012+
}
1013+
if( treeModel->item( i )->text() == "Smart Groups" )
1014+
{
1015+
for( int j = 0; j < treeModel->item( i )->rowCount(); j++ )
1016+
{
1017+
treeModel->item( i )->child( j )->setEnabled( enable );
1018+
}
1019+
}
1020+
}
1021+
1022+
}

src/gui/symbology-ng/qgsstylev2managerdialog.h

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
101101
bool removeSymbol();
102102
bool removeColorRamp();
103103

104+
//! Enables or disbables the symbol specific inputs
105+
void enableSymbolInputs( bool );
106+
//! Enables or disables the groupTree specific inputs
107+
void enableGroupInputs( bool );
108+
//! Enables or diables the groupTree items for grouping mode
109+
void enableItemsForGroupingMode( bool );
110+
104111
QgsStyleV2* mStyle;
105112

106113
QString mStyleFilename;

0 commit comments

Comments
 (0)