Skip to content

Commit

Permalink
Fix crash when editing smart group in style manager dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 11, 2018
1 parent 68b7e79 commit b9c64c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Expand Up @@ -1088,9 +1088,9 @@ int QgsStyleManagerDialog::addTag()

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

if ( !id )
{
Expand Down Expand Up @@ -1130,9 +1130,9 @@ int QgsStyleManagerDialog::addSmartgroup()

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

if ( !id )
return 0;
Expand Down Expand Up @@ -1166,7 +1166,7 @@ void QgsStyleManagerDialog::removeGroup()

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

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

mBlockGroupUpdates = false;
mBlockGroupUpdates--;
parentItem->removeRow( index.row() );
}

Expand All @@ -1186,6 +1186,7 @@ void QgsStyleManagerDialog::groupRenamed( QStandardItem *item )
QgsDebugMsg( QStringLiteral( "Symbol group edited: data=%1 text=%2" ).arg( item->data( Qt::UserRole + 1 ).toString(), item->text() ) );
int id = item->data( Qt::UserRole + 1 ).toInt();
QString name = item->text();
mBlockGroupUpdates++;
if ( item->parent()->data( Qt::UserRole + 1 ) == "smartgroups" )
{
mStyle->rename( QgsStyle::SmartgroupEntity, id, name );
Expand All @@ -1194,6 +1195,7 @@ void QgsStyleManagerDialog::groupRenamed( QStandardItem *item )
{
mStyle->rename( QgsStyle::TagEntity, id, name );
}
mBlockGroupUpdates--;
}

void QgsStyleManagerDialog::tagSymbolsAction()
Expand Down Expand Up @@ -1548,8 +1550,10 @@ void QgsStyleManagerDialog::editSmartgroupAction()
if ( dlg.exec() == QDialog::Rejected )
return;

mBlockGroupUpdates++;
mStyle->remove( QgsStyle::SmartgroupEntity, item->data().toInt() );
int id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
mBlockGroupUpdates--;
if ( !id )
{
QMessageBox::critical( this, tr( "Edit Smart Group" ),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology/qgsstylemanagerdialog.h
Expand Up @@ -199,7 +199,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
//! Menu for the "Add item" toolbutton when in colorramp mode
QMenu *mMenuBtnAddItemColorRamp = nullptr;

bool mBlockGroupUpdates = false;
int mBlockGroupUpdates = 0;

};

Expand Down

0 comments on commit b9c64c6

Please sign in to comment.