Skip to content

Commit

Permalink
Merge pull request #5741 from elpaso/ogr-filter-backport
Browse files Browse the repository at this point in the history
[bugfix] Update layer editable state when filter is changed
  • Loading branch information
elpaso authored Nov 27, 2017
2 parents f206a75 + 0577b2e commit 5631094
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8273,17 +8273,13 @@ void QgisApp::layerSubsetString()
// Set the sql in the query builder to the same in the prop dialog
// (in case the user has already changed it)
qb->setSql( vlayer->subsetString() );
// Open the query builder
if ( qb->exec() )
// Open the query builder and refresh symbology if sql has changed
// Note: repaintRequested is emitted directly from QgsQueryBuilder
// when the sql is set in the layer.
if ( qb->exec() && ( subsetBefore != qb->sql() ) && mLayerTreeView )
{
if ( subsetBefore != qb->sql() )
{
vlayer->triggerRepaint();
if ( mLayerTreeView )
{
mLayerTreeView->refreshLayerSymbology( vlayer->id() );
}
}
mLayerTreeView->refreshLayerSymbology( vlayer->id() );
activateDeactivateLayerRelatedActions( vlayer );
}

// delete the query builder object
Expand Down Expand Up @@ -10257,13 +10253,12 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
connect( vlayer, SIGNAL( labelingFontNotFound( QgsVectorLayer*, QString ) ), this, SLOT( labelingFontNotFound( QgsVectorLayer*, QString ) ) );

QgsVectorDataProvider* vProvider = vlayer->dataProvider();
if ( vProvider && vProvider->capabilities() & QgsVectorDataProvider::EditingCapabilities )
{
connect( vlayer, SIGNAL( layerModified() ), this, SLOT( updateLayerModifiedActions() ) );
connect( vlayer, SIGNAL( editingStarted() ), this, SLOT( layerEditStateChanged() ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( layerEditStateChanged() ) );
}

// Do not check for layer editing capabilities because they may change
// (for example when subsetString is added/removed) and signals need to
// be in place in order to update the GUI
connect( vlayer, SIGNAL( layerModified() ), this, SLOT( updateLayerModifiedActions() ) );
connect( vlayer, SIGNAL( editingStarted() ), this, SLOT( layerEditStateChanged() ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( layerEditStateChanged() ) );
connect( vlayer, SIGNAL( raiseError( QString ) ), this, SLOT( onLayerError( QString ) ) );

provider = vProvider;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
menu->addAction( toggleEditingAction );
toggleEditingAction->setChecked( vlayer->isEditable() );
toggleEditingAction->setEnabled( true );
}
if ( saveLayerEditsAction && vlayer->isModified() )
{
Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ bool QgsOgrProvider::setSubsetString( const QString& theSQL, bool updateFeatureC

invalidateCachedExtent( false );

// Changing the filter may change capabilities
computeCapabilities();

emit dataChanged();

return true;
Expand Down

0 comments on commit 5631094

Please sign in to comment.