@@ -950,32 +950,41 @@ void QgsStyleV2ManagerDialog::addGroup()
950
950
}
951
951
952
952
QString itemName;
953
- QVariant itemData;
954
953
bool isGroup = true ;
955
954
956
- // create a smart group if that is selected
957
- if ( parentIndex. data ( Qt::UserRole + 1 ). toString () == " smartgroups" )
955
+ int id;
956
+ if ( parentData == " smartgroups" )
958
957
{
958
+ // create a smart group
959
+
959
960
QgsSmartGroupEditorDialog dlg ( mStyle , this );
960
961
if ( dlg.exec () == QDialog::Rejected )
961
962
return ;
962
- int id = mStyle ->addSmartgroup ( dlg.smartgroupName (), dlg.conditionOperator (), dlg.conditionMap () );
963
+ id = mStyle ->addSmartgroup ( dlg.smartgroupName (), dlg.conditionOperator (), dlg.conditionMap () );
963
964
if ( !id )
964
965
return ;
965
- itemData = QVariant ( id );
966
966
itemName = dlg.smartgroupName ();
967
967
isGroup = false ;
968
968
}
969
969
else
970
970
{
971
+ // create a simple child-group to the selected
972
+
971
973
itemName = QString ( tr ( " New Group" ) );
972
- itemData = QVariant ( " newgroup" );
974
+ int parentid = ( parentData == " groups" ) ? 0 : parentData.toInt (); // parentid is 0 for top-level groups
975
+ id = mStyle ->addGroup ( itemName, parentid );
976
+ if ( !id )
977
+ {
978
+ QMessageBox::critical ( this , tr ( " Error!" ),
979
+ tr ( " New group could not be created.\n "
980
+ " There was a problem with your symbol database." ) );
981
+ return ;
982
+ }
973
983
}
974
984
975
- // Else create a simple child-group to the selected
976
985
QStandardItem *parentItem = model->itemFromIndex ( parentIndex );
977
986
QStandardItem *childItem = new QStandardItem ( itemName );
978
- childItem->setData ( itemData );
987
+ childItem->setData ( id );
979
988
parentItem->appendRow ( childItem );
980
989
981
990
groupTree->setCurrentIndex ( childItem->index () );
@@ -1026,43 +1035,15 @@ void QgsStyleV2ManagerDialog::groupRenamed( QStandardItem * item )
1026
1035
{
1027
1036
QString data = item->data ( Qt::UserRole + 1 ).toString ();
1028
1037
QgsDebugMsg ( " Symbol group edited: data=" + data + " text=" + item->text () );
1029
- if ( data == " newgroup" )
1038
+ int id = item->data ( Qt::UserRole + 1 ).toInt ();
1039
+ QString name = item->text ();
1040
+ if ( item->parent ()->data ( Qt::UserRole + 1 ) == " smartgroups" )
1030
1041
{
1031
- int id;
1032
- if ( item->parent ()->data ( Qt::UserRole + 1 ).toString () == " groups" )
1033
- {
1034
- id = mStyle ->addGroup ( item->text () );
1035
- }
1036
- else
1037
- {
1038
- int parentid = item->parent ()->data ( Qt::UserRole + 1 ).toInt ();
1039
- id = mStyle ->addGroup ( item->text (), parentid );
1040
- }
1041
- if ( !id )
1042
- {
1043
- QMessageBox::critical ( this , tr ( " Error!" ),
1044
- tr ( " New group could not be created.\n "
1045
- " There was a problem with your symbol database." ) );
1046
- item->parent ()->removeRow ( item->row () );
1047
- return ;
1048
- }
1049
- else
1050
- {
1051
- item->setData ( id );
1052
- }
1042
+ mStyle ->rename ( QgsStyleV2::SmartgroupEntity, id, name );
1053
1043
}
1054
1044
else
1055
1045
{
1056
- int id = item->data ( Qt::UserRole + 1 ).toInt ();
1057
- QString name = item->text ();
1058
- if ( item->parent ()->data ( Qt::UserRole + 1 ) == " smartgroups" )
1059
- {
1060
- mStyle ->rename ( QgsStyleV2::SmartgroupEntity, id, name );
1061
- }
1062
- else
1063
- {
1064
- mStyle ->rename ( QgsStyleV2::GroupEntity, id, name );
1065
- }
1046
+ mStyle ->rename ( QgsStyleV2::GroupEntity, id, name );
1066
1047
}
1067
1048
}
1068
1049
0 commit comments