Skip to content
Permalink
Browse files

Add QgsVectorLayer::canCommitChanges

to control if changes can be saved or not. This signal is emitted before a layer is being saved and if a connected slot marks the canCommit variable as False, the layer will not be saved
  • Loading branch information
m-kuhn committed Sep 26, 2018
1 parent 5157406 commit a56deacf546a5527f46dd074b6f1f1fa6824bbed
Showing with 27 additions and 0 deletions.
  1. +10 −0 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +7 −0 src/core/qgsvectorlayer.cpp
  3. +10 −0 src/core/qgsvectorlayer.h
@@ -2352,6 +2352,16 @@ Is emitted, when editing on this layer has started
void editingStopped();
%Docstring
Is emitted, when edited changes successfully have been written to the data provider
%End

void canCommitChanges( bool &canCommit );
%Docstring
Emitted when a layer wants to commit changes to the data provider.
Can be used to prevent the layer from being saved by setting ``canCommit`` to false.

It is the developers responsibility to inform the user about this in a suitable manner.

.. versionadded:: 3.4
%End

void beforeCommitChanges();
@@ -2924,6 +2924,13 @@ bool QgsVectorLayer::commitChanges()
return false;
}

bool canCommit = true;

emit canCommitChanges( canCommit );

if ( !canCommit )
return false;

emit beforeCommitChanges();

bool success = mEditBuffer->commitChanges( mCommitErrors );
@@ -2114,6 +2114,16 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Is emitted, when edited changes successfully have been written to the data provider
void editingStopped();

/**
* Emitted when a layer wants to commit changes to the data provider.
* Can be used to prevent the layer from being saved by setting \a canCommit to false.
*
* It is the developers responsibility to inform the user about this in a suitable manner.
*
* \since QGIS 3.4
*/
void canCommitChanges( bool &canCommit );

//! Is emitted, before changes are committed to the data provider
void beforeCommitChanges();

0 comments on commit a56deac

Please sign in to comment.
You can’t perform that action at this time.