@@ -902,6 +902,9 @@ void QgsStyleManagerDialog::setBold( QStandardItem *item )
902
902
903
903
void QgsStyleManagerDialog::populateGroups ()
904
904
{
905
+ if ( mBlockGroupUpdates )
906
+ return ;
907
+
905
908
QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model () );
906
909
model->clear ();
907
910
@@ -1082,7 +1085,13 @@ int QgsStyleManagerDialog::addTag()
1082
1085
tr ( " Tag name already exists in your symbol database." ) );
1083
1086
return 0 ;
1084
1087
}
1088
+
1089
+ // block the auto-repopulation of groups when the style emits groupsModified
1090
+ // instead, we manually update the model items for better state retention
1091
+ mBlockGroupUpdates = true ;
1085
1092
id = mStyle ->addTag ( itemName );
1093
+ mBlockGroupUpdates = false ;
1094
+
1086
1095
if ( !id )
1087
1096
{
1088
1097
QMessageBox::critical ( this , tr ( " Add Tag" ),
@@ -1118,7 +1127,13 @@ int QgsStyleManagerDialog::addSmartgroup()
1118
1127
QgsSmartGroupEditorDialog dlg ( mStyle , this );
1119
1128
if ( dlg.exec () == QDialog::Rejected )
1120
1129
return 0 ;
1130
+
1131
+ // block the auto-repopulation of groups when the style emits groupsModified
1132
+ // instead, we manually update the model items for better state retention
1133
+ mBlockGroupUpdates = true ;
1121
1134
id = mStyle ->addSmartgroup ( dlg.smartgroupName (), dlg.conditionOperator (), dlg.conditionMap () );
1135
+ mBlockGroupUpdates = false ;
1136
+
1122
1137
if ( !id )
1123
1138
return 0 ;
1124
1139
itemName = dlg.smartgroupName ();
@@ -1148,6 +1163,11 @@ void QgsStyleManagerDialog::removeGroup()
1148
1163
}
1149
1164
1150
1165
QStandardItem *parentItem = model->itemFromIndex ( index .parent () );
1166
+
1167
+ // block the auto-repopulation of groups when the style emits groupsModified
1168
+ // instead, we manually update the model items for better state retention
1169
+ mBlockGroupUpdates = true ;
1170
+
1151
1171
if ( parentItem->data ( Qt::UserRole + 1 ).toString () == QLatin1String ( " smartgroups" ) )
1152
1172
{
1153
1173
mStyle ->remove ( QgsStyle::SmartgroupEntity, index .data ( Qt::UserRole + 1 ).toInt () );
@@ -1156,6 +1176,8 @@ void QgsStyleManagerDialog::removeGroup()
1156
1176
{
1157
1177
mStyle ->remove ( QgsStyle::TagEntity, index .data ( Qt::UserRole + 1 ).toInt () );
1158
1178
}
1179
+
1180
+ mBlockGroupUpdates = false ;
1159
1181
parentItem->removeRow ( index .row () );
1160
1182
}
1161
1183
0 commit comments