Skip to content

Commit 115cc48

Browse files
committedJan 5, 2016
Merge pull request #2627 from SebDieBln/FixNewStyleGroup
Initialize a style group upon creation instead of upon renaming (fixes #14050)
2 parents 90eaba9 + 62cc59c commit 115cc48

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed
 

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -950,32 +950,41 @@ void QgsStyleV2ManagerDialog::addGroup()
950950
}
951951

952952
QString itemName;
953-
QVariant itemData;
954953
bool isGroup = true;
955954

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" )
958957
{
958+
// create a smart group
959+
959960
QgsSmartGroupEditorDialog dlg( mStyle, this );
960961
if ( dlg.exec() == QDialog::Rejected )
961962
return;
962-
int id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
963+
id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
963964
if ( !id )
964965
return;
965-
itemData = QVariant( id );
966966
itemName = dlg.smartgroupName();
967967
isGroup = false;
968968
}
969969
else
970970
{
971+
// create a simple child-group to the selected
972+
971973
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+
}
973983
}
974984

975-
// Else create a simple child-group to the selected
976985
QStandardItem *parentItem = model->itemFromIndex( parentIndex );
977986
QStandardItem *childItem = new QStandardItem( itemName );
978-
childItem->setData( itemData );
987+
childItem->setData( id );
979988
parentItem->appendRow( childItem );
980989

981990
groupTree->setCurrentIndex( childItem->index() );
@@ -1026,43 +1035,15 @@ void QgsStyleV2ManagerDialog::groupRenamed( QStandardItem * item )
10261035
{
10271036
QString data = item->data( Qt::UserRole + 1 ).toString();
10281037
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" )
10301041
{
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 );
10531043
}
10541044
else
10551045
{
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 );
10661047
}
10671048
}
10681049

0 commit comments

Comments
 (0)
Please sign in to comment.