Skip to content

Commit a56deac

Browse files
committedSep 26, 2018
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
1 parent 5157406 commit a56deac

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
 

‎python/core/auto_generated/qgsvectorlayer.sip.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,16 @@ Is emitted, when editing on this layer has started
23522352
void editingStopped();
23532353
%Docstring
23542354
Is emitted, when edited changes successfully have been written to the data provider
2355+
%End
2356+
2357+
void canCommitChanges( bool &canCommit );
2358+
%Docstring
2359+
Emitted when a layer wants to commit changes to the data provider.
2360+
Can be used to prevent the layer from being saved by setting ``canCommit`` to false.
2361+
2362+
It is the developers responsibility to inform the user about this in a suitable manner.
2363+
2364+
.. versionadded:: 3.4
23552365
%End
23562366

23572367
void beforeCommitChanges();

‎src/core/qgsvectorlayer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,13 @@ bool QgsVectorLayer::commitChanges()
29242924
return false;
29252925
}
29262926

2927+
bool canCommit = true;
2928+
2929+
emit canCommitChanges( canCommit );
2930+
2931+
if ( !canCommit )
2932+
return false;
2933+
29272934
emit beforeCommitChanges();
29282935

29292936
bool success = mEditBuffer->commitChanges( mCommitErrors );

‎src/core/qgsvectorlayer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,16 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
21142114
//! Is emitted, when edited changes successfully have been written to the data provider
21152115
void editingStopped();
21162116

2117+
/**
2118+
* Emitted when a layer wants to commit changes to the data provider.
2119+
* Can be used to prevent the layer from being saved by setting \a canCommit to false.
2120+
*
2121+
* It is the developers responsibility to inform the user about this in a suitable manner.
2122+
*
2123+
* \since QGIS 3.4
2124+
*/
2125+
void canCommitChanges( bool &canCommit );
2126+
21172127
//! Is emitted, before changes are committed to the data provider
21182128
void beforeCommitChanges();
21192129

0 commit comments

Comments
 (0)
Please sign in to comment.