Skip to content

Commit 48dcab7

Browse files
committed
Fix some crashes in style manager dialog
1 parent f979c8e commit 48dcab7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/gui/symbology/qgsstylemanagerdialog.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ void QgsStyleManagerDialog::setBold( QStandardItem *item )
902902

903903
void QgsStyleManagerDialog::populateGroups()
904904
{
905+
if ( mBlockGroupUpdates )
906+
return;
907+
905908
QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
906909
model->clear();
907910

@@ -1082,7 +1085,13 @@ int QgsStyleManagerDialog::addTag()
10821085
tr( "Tag name already exists in your symbol database." ) );
10831086
return 0;
10841087
}
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;
10851092
id = mStyle->addTag( itemName );
1093+
mBlockGroupUpdates = false;
1094+
10861095
if ( !id )
10871096
{
10881097
QMessageBox::critical( this, tr( "Add Tag" ),
@@ -1118,7 +1127,13 @@ int QgsStyleManagerDialog::addSmartgroup()
11181127
QgsSmartGroupEditorDialog dlg( mStyle, this );
11191128
if ( dlg.exec() == QDialog::Rejected )
11201129
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;
11211134
id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
1135+
mBlockGroupUpdates = false;
1136+
11221137
if ( !id )
11231138
return 0;
11241139
itemName = dlg.smartgroupName();
@@ -1148,6 +1163,11 @@ void QgsStyleManagerDialog::removeGroup()
11481163
}
11491164

11501165
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+
11511171
if ( parentItem->data( Qt::UserRole + 1 ).toString() == QLatin1String( "smartgroups" ) )
11521172
{
11531173
mStyle->remove( QgsStyle::SmartgroupEntity, index.data( Qt::UserRole + 1 ).toInt() );
@@ -1156,6 +1176,8 @@ void QgsStyleManagerDialog::removeGroup()
11561176
{
11571177
mStyle->remove( QgsStyle::TagEntity, index.data( Qt::UserRole + 1 ).toInt() );
11581178
}
1179+
1180+
mBlockGroupUpdates = false;
11591181
parentItem->removeRow( index.row() );
11601182
}
11611183

src/gui/symbology/qgsstylemanagerdialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
199199
//! Menu for the "Add item" toolbutton when in colorramp mode
200200
QMenu *mMenuBtnAddItemColorRamp = nullptr;
201201

202-
202+
bool mBlockGroupUpdates = false;
203203

204204
};
205205

0 commit comments

Comments
 (0)