Skip to content

Commit

Permalink
Fix some crashes in style manager dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 8, 2018
1 parent f979c8e commit 48dcab7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ void QgsStyleManagerDialog::setBold( QStandardItem *item )

void QgsStyleManagerDialog::populateGroups()
{
if ( mBlockGroupUpdates )
return;

QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
model->clear();

Expand Down Expand Up @@ -1082,7 +1085,13 @@ int QgsStyleManagerDialog::addTag()
tr( "Tag name already exists in your symbol database." ) );
return 0;
}

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

if ( !id )
{
QMessageBox::critical( this, tr( "Add Tag" ),
Expand Down Expand Up @@ -1118,7 +1127,13 @@ int QgsStyleManagerDialog::addSmartgroup()
QgsSmartGroupEditorDialog dlg( mStyle, this );
if ( dlg.exec() == QDialog::Rejected )
return 0;

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

if ( !id )
return 0;
itemName = dlg.smartgroupName();
Expand Down Expand Up @@ -1148,6 +1163,11 @@ void QgsStyleManagerDialog::removeGroup()
}

QStandardItem *parentItem = model->itemFromIndex( index.parent() );

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology/qgsstylemanagerdialog.h
Original file line number Diff line number Diff line change
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;

};

Expand Down

0 comments on commit 48dcab7

Please sign in to comment.