Skip to content
Permalink
Browse files

Merge pull request #8034 from m-kuhn/canCommitChanges

Add QgsVectorLayer::allowCommit property
  • Loading branch information
m-kuhn committed Oct 5, 2018
2 parents e86693a + 3522518 commit e25d6347c675310c5b5d701c75dc62e5187fdeed
Showing with 75 additions and 0 deletions.
  1. +9 −0 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +17 −0 src/core/qgsvectorlayer.cpp
  3. +49 −0 src/core/qgsvectorlayer.h
@@ -2239,6 +2239,8 @@ Configuration and logic to apply automatically on any edit happening on this lay
.. versionadded:: 3.4
%End



public slots:

void select( QgsFeatureId featureId );
@@ -2332,6 +2334,13 @@ This signal is emitted when selection was changed
void layerModified();
%Docstring
This signal is emitted when modifications has been done on layer
%End

void allowCommitChanged();
%Docstring
Emitted whenever the allowCommitChanged() property of this layer changes.

.. versionadded:: 3.4
%End

void beforeModifiedCheck() const;
@@ -2926,6 +2926,9 @@ bool QgsVectorLayer::commitChanges()

emit beforeCommitChanges();

if ( !mAllowCommit )
return false;

bool success = mEditBuffer->commitChanges( mCommitErrors );

if ( success )
@@ -4846,6 +4849,20 @@ QgsAbstractVectorLayerLabeling *QgsVectorLayer::readLabelingFromCustomProperties
return labeling;
}

bool QgsVectorLayer::allowCommit() const
{
return mAllowCommit;
}

void QgsVectorLayer::setAllowCommit( bool allowCommit )
{
if ( mAllowCommit == allowCommit )
return;

mAllowCommit = allowCommit;
emit allowCommitChanged();
}

QgsGeometryOptions *QgsVectorLayer::geometryOptions() const
{
return mGeometryOptions.get();
@@ -2010,6 +2010,46 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
QgsGeometryOptions *geometryOptions() const;

/**
* Controls, if the layer is allowed to commit changes. If this is set to false
* it will not be possible to commit changes on this layer. This can be used to
* define checks on a layer that need to be pass before the layer can be saved.
* If you use this API, make sure that:
*
* - the user is visibly informed that his changes were not saved and what he needs
* to do in order to be able to save the changes.
*
* - to set the property back to true, once the user has fixed his data.
*
* When calling \see commitChanges(), this flag is checked just after the
* \see beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
*
* \note Not available in Python bindings
*
* \since QGIS 3.4
*/
bool allowCommit() const SIP_SKIP;

/**
* Controls, if the layer is allowed to commit changes. If this is set to false
* it will not be possible to commit changes on this layer. This can be used to
* define checks on a layer that need to be pass before the layer can be saved.
* If you use this API, make sure that:
*
* - the user is visibly informed that his changes were not saved and what he needs
* to do in order to be able to save the changes.
*
* - to set the property back to true, once the user has fixed his data.
*
* When calling \see commitChanges(), this flag is checked just after the
* \see beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
*
* \note Not available in Python bindings
*
* \since QGIS 3.4
*/
void setAllowCommit( bool allowCommit ) SIP_SKIP;

public slots:

/**
@@ -2102,6 +2142,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! This signal is emitted when modifications has been done on layer
void layerModified();

/**
* Emitted whenever the allowCommitChanged() property of this layer changes.
*
* \since QGIS 3.4
*/
void allowCommitChanged();

//! Is emitted, when layer is checked for modifications. Use for last-minute additions
void beforeModifiedCheck() const;

@@ -2502,6 +2549,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

std::unique_ptr<QgsGeometryOptions> mGeometryOptions;

bool mAllowCommit = true;

friend class QgsVectorLayerFeatureSource;
};

0 comments on commit e25d634

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