Skip to content

Commit b9c64c6

Browse files
committed
Fix crash when editing smart group in style manager dialog
1 parent 68b7e79 commit b9c64c6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/gui/symbology/qgsstylemanagerdialog.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,9 @@ int QgsStyleManagerDialog::addTag()
10881088

10891089
// block the auto-repopulation of groups when the style emits groupsModified
10901090
// instead, we manually update the model items for better state retention
1091-
mBlockGroupUpdates = true;
1091+
mBlockGroupUpdates++;
10921092
id = mStyle->addTag( itemName );
1093-
mBlockGroupUpdates = false;
1093+
mBlockGroupUpdates--;
10941094

10951095
if ( !id )
10961096
{
@@ -1130,9 +1130,9 @@ int QgsStyleManagerDialog::addSmartgroup()
11301130

11311131
// block the auto-repopulation of groups when the style emits groupsModified
11321132
// instead, we manually update the model items for better state retention
1133-
mBlockGroupUpdates = true;
1133+
mBlockGroupUpdates++;
11341134
id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
1135-
mBlockGroupUpdates = false;
1135+
mBlockGroupUpdates--;
11361136

11371137
if ( !id )
11381138
return 0;
@@ -1166,7 +1166,7 @@ void QgsStyleManagerDialog::removeGroup()
11661166

11671167
// block the auto-repopulation of groups when the style emits groupsModified
11681168
// instead, we manually update the model items for better state retention
1169-
mBlockGroupUpdates = true;
1169+
mBlockGroupUpdates++;
11701170

11711171
if ( parentItem->data( Qt::UserRole + 1 ).toString() == QLatin1String( "smartgroups" ) )
11721172
{
@@ -1177,7 +1177,7 @@ void QgsStyleManagerDialog::removeGroup()
11771177
mStyle->remove( QgsStyle::TagEntity, index.data( Qt::UserRole + 1 ).toInt() );
11781178
}
11791179

1180-
mBlockGroupUpdates = false;
1180+
mBlockGroupUpdates--;
11811181
parentItem->removeRow( index.row() );
11821182
}
11831183

@@ -1186,6 +1186,7 @@ void QgsStyleManagerDialog::groupRenamed( QStandardItem *item )
11861186
QgsDebugMsg( QStringLiteral( "Symbol group edited: data=%1 text=%2" ).arg( item->data( Qt::UserRole + 1 ).toString(), item->text() ) );
11871187
int id = item->data( Qt::UserRole + 1 ).toInt();
11881188
QString name = item->text();
1189+
mBlockGroupUpdates++;
11891190
if ( item->parent()->data( Qt::UserRole + 1 ) == "smartgroups" )
11901191
{
11911192
mStyle->rename( QgsStyle::SmartgroupEntity, id, name );
@@ -1194,6 +1195,7 @@ void QgsStyleManagerDialog::groupRenamed( QStandardItem *item )
11941195
{
11951196
mStyle->rename( QgsStyle::TagEntity, id, name );
11961197
}
1198+
mBlockGroupUpdates--;
11971199
}
11981200

11991201
void QgsStyleManagerDialog::tagSymbolsAction()
@@ -1548,8 +1550,10 @@ void QgsStyleManagerDialog::editSmartgroupAction()
15481550
if ( dlg.exec() == QDialog::Rejected )
15491551
return;
15501552

1553+
mBlockGroupUpdates++;
15511554
mStyle->remove( QgsStyle::SmartgroupEntity, item->data().toInt() );
15521555
int id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
1556+
mBlockGroupUpdates--;
15531557
if ( !id )
15541558
{
15551559
QMessageBox::critical( this, tr( "Edit Smart Group" ),

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-
bool mBlockGroupUpdates = false;
202+
int mBlockGroupUpdates = 0;
203203

204204
};
205205

0 commit comments

Comments
 (0)