Skip to content
Permalink
Browse files

Change canCommitChanges to allowCommit flag

  • Loading branch information
m-kuhn committed Sep 26, 2018
1 parent d2bb3d6 commit cda4950dd886009b90ca0a4c12869ebbf63de8fc
Showing with 106 additions and 6 deletions.
  1. +45 −0 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +16 −6 src/core/qgsvectorlayer.cpp
  3. +45 −0 src/core/qgsvectorlayer.h
@@ -2236,6 +2236,44 @@ Test if an edit command is active
%Docstring
Configuration and logic to apply automatically on any edit happening on this layer.

.. versionadded:: 3.4
%End

bool allowCommit()() const;
%Docstring
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 :py:func:`commitChanges`, this flag is checked just after the

.. seealso:: :py:func:`beforeCommitChanges`

.. versionadded:: 3.4
%End

void setAllowCommit()( bool allowCommit() );
%Docstring
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 :py:func:`commitChanges`, this flag is checked just after the

.. seealso:: :py:func:`beforeCommitChanges`

.. versionadded:: 3.4
%End

@@ -2332,6 +2370,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;
@@ -2924,15 +2924,11 @@ bool QgsVectorLayer::commitChanges()
return false;
}

bool canCommit = true;

emit canCommitChanges( &canCommit );
emit beforeCommitChanges();

if ( !canCommit )
if ( !mAllowCommit )
return false;

emit beforeCommitChanges();

bool success = mEditBuffer->commitChanges( mCommitErrors );

if ( success )
@@ -4853,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,42 @@ 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.
*
* \since QGIS 3.4
*/
bool allowCommit()() 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.
*
* \since QGIS 3.4
*/
void setAllowCommit()( bool allowCommit() );

public slots:

/**
@@ -2102,6 +2138,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;

@@ -2512,6 +2555,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

std::unique_ptr<QgsGeometryOptions> mGeometryOptions;

bool mAllowCommit = true;

friend class QgsVectorLayerFeatureSource;
};

0 comments on commit cda4950

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