Skip to content

Commit db3c93c

Browse files
authoredNov 22, 2017
Merge pull request #5691 from elpaso/bugfix-17507-gpkg-filtered-edit
[app][bugfix] Update layer editable state when filter is changed
2 parents 059c997 + d775a0d commit db3c93c

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8928,27 +8928,20 @@ void QgisApp::layerSubsetString()
89288928
}
89298929

89308930
// launch the query builder
8931-
QgsQueryBuilder *qb = new QgsQueryBuilder( vlayer, this );
8931+
std::unique_ptr<QgsQueryBuilder> qb( new QgsQueryBuilder( vlayer, this ) );
89328932
QString subsetBefore = vlayer->subsetString();
89338933

89348934
// Set the sql in the query builder to the same in the prop dialog
89358935
// (in case the user has already changed it)
89368936
qb->setSql( vlayer->subsetString() );
8937-
// Open the query builder
8938-
if ( qb->exec() )
8937+
// Open the query builder and refresh symbology if sql has changed
8938+
// Note: repaintRequested is emitted directly from QgsQueryBuilder
8939+
// when the sql is set in the layer.
8940+
if ( qb->exec() && ( subsetBefore != qb->sql() ) && mLayerTreeView )
89398941
{
8940-
if ( subsetBefore != qb->sql() )
8941-
{
8942-
vlayer->triggerRepaint();
8943-
if ( mLayerTreeView )
8944-
{
8945-
mLayerTreeView->refreshLayerSymbology( vlayer->id() );
8946-
}
8947-
}
8942+
mLayerTreeView->refreshLayerSymbology( vlayer->id() );
8943+
activateDeactivateLayerRelatedActions( vlayer );
89488944
}
8949-
8950-
// delete the query builder object
8951-
delete qb;
89528945
}
89538946

89548947
void QgisApp::saveLastMousePosition( const QgsPointXY &p )
@@ -11097,14 +11090,13 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *> &layers )
1109711090
connect( vlayer, &QgsVectorLayer::labelingFontNotFound, this, &QgisApp::labelingFontNotFound );
1109811091

1109911092
QgsVectorDataProvider *vProvider = vlayer->dataProvider();
11100-
if ( vProvider && vProvider->capabilities() & QgsVectorDataProvider::EditingCapabilities )
11101-
{
11102-
connect( vlayer, &QgsVectorLayer::layerModified, this, &QgisApp::updateLayerModifiedActions );
11103-
connect( vlayer, &QgsVectorLayer::editingStarted, this, &QgisApp::layerEditStateChanged );
11104-
connect( vlayer, &QgsVectorLayer::editingStopped, this, &QgisApp::layerEditStateChanged );
11105-
connect( vlayer, &QgsVectorLayer::readOnlyChanged, this, &QgisApp::layerEditStateChanged );
11106-
}
11107-
11093+
// Do not check for layer editing capabilities because they may change
11094+
// (for example when subsetString is added/removed) and signals need to
11095+
// be in place in order to update the GUI
11096+
connect( vlayer, &QgsVectorLayer::layerModified, this, &QgisApp::updateLayerModifiedActions );
11097+
connect( vlayer, &QgsVectorLayer::editingStarted, this, &QgisApp::layerEditStateChanged );
11098+
connect( vlayer, &QgsVectorLayer::editingStopped, this, &QgisApp::layerEditStateChanged );
11099+
connect( vlayer, &QgsVectorLayer::readOnlyChanged, this, &QgisApp::layerEditStateChanged );
1110811100
connect( vlayer, &QgsVectorLayer::raiseError, this, &QgisApp::onLayerError );
1110911101

1111011102
provider = vProvider;

‎src/app/qgisapp.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,13 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
689689
//! mark project dirty
690690
void markDirty();
691691

692-
void layersWereAdded( const QList<QgsMapLayer *> & );
692+
/**
693+
* \brief layersWereAdded is triggered when layers were added
694+
* This method loops through the list of \a layers and connect all
695+
* application signals that need to listen to layer events.
696+
* \param layers list of map layers that have been added
697+
*/
698+
void layersWereAdded( const QList<QgsMapLayer *> &layers );
693699

694700
/* layer will be removed - changed from removingLayer to removingLayers
695701
in 1.8.

‎src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
226226
{
227227
menu->addAction( toggleEditingAction );
228228
toggleEditingAction->setChecked( vlayer->isEditable() );
229+
toggleEditingAction->setEnabled( true );
229230
}
230231
if ( saveLayerEditsAction && vlayer->isModified() )
231232
{

‎src/gui/editorwidgets/core/qgseditorwidgetwrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
346346
QString mConstraintFailureReason;
347347

348348
//! The current constraint result
349-
ConstraintResult mConstraintResult;
349+
ConstraintResult mConstraintResult = ConstraintResultPass;
350350

351351
//! The current constraint result
352-
bool mConstraintResultVisible;
352+
bool mConstraintResultVisible = false;
353353

354354
int mFieldIdx;
355355
QgsFeature mFeature;

‎src/gui/qgsaggregatetoolbutton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class GUI_EXPORT QgsAggregateToolButton : public QToolButton
8989
private:
9090
void updateAvailableAggregates();
9191
QMenu *mMenu = nullptr;
92-
QVariant::Type mType;
92+
QVariant::Type mType = QVariant::Invalid;
9393
bool mActive = false;
9494
QString mAggregate;
9595
QList<QgsAggregateCalculator::AggregateInfo> mAvailableAggregates;

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,15 @@ bool QgsOgrProvider::setSubsetString( const QString &theSQL, bool updateFeatureC
573573
}
574574

575575
// check the validity of the layer
576-
QgsDebugMsg( "checking validity" );
576+
QgsDebugMsgLevel( "checking validity", 4 );
577577
loadFields();
578-
QgsDebugMsg( "Done checking validity" );
578+
QgsDebugMsgLevel( "Done checking validity", 4 );
579579

580580
invalidateCachedExtent( false );
581581

582+
// Changing the filter may change capabilities
583+
computeCapabilities();
584+
582585
emit dataChanged();
583586

584587
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.