Skip to content

Commit

Permalink
Private attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 25, 2017
1 parent 82ba8ad commit 8a4382a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
22 changes: 19 additions & 3 deletions python/core/qgsvectorlayerundopassthroughcommand.sip
Expand Up @@ -47,10 +47,12 @@ class QgsVectorLayerUndoPassthroughCommand : QgsVectorLayerUndoCommand
:rtype: bool
%End

bool setSavePoint();
bool setSavePoint( const QString &savePointId = QString() );
%Docstring
Set the command savepoint or set error status
error satus should be false prior to call
Set the command savepoint or set error status.
Error satus should be false prior to call. If the savepoint given in
parameter is empty, then a new one is created if none is currently
available in the transaction.
:rtype: bool
%End

Expand All @@ -59,6 +61,20 @@ class QgsVectorLayerUndoPassthroughCommand : QgsVectorLayerUndoCommand
Set error flag and append "failed" to text
%End

void setErrorMessage( const QString &errorMessage );
%Docstring
Sets the error message.

.. versionadded:: 3.0
%End

QString errorMessage() const;
%Docstring
Returns the error message or an empty string if there's none.

.. versionadded:: 3.0
:rtype: str
%End

};

Expand Down
41 changes: 32 additions & 9 deletions src/core/qgsvectorlayerundopassthroughcommand.cpp
Expand Up @@ -54,19 +54,36 @@ void QgsVectorLayerUndoPassthroughCommand::setError()
}
}

bool QgsVectorLayerUndoPassthroughCommand::setSavePoint()
void QgsVectorLayerUndoPassthroughCommand::setErrorMessage( const QString &errorMessage )
{
mError = errorMessage;
}

QString QgsVectorLayerUndoPassthroughCommand::errorMessage() const
{
return mError;
}

bool QgsVectorLayerUndoPassthroughCommand::setSavePoint( const QString &savePointId )
{
if ( !hasError() )
{
// re-create savepoint only if mRecreateSavePoint and rollBackToSavePoint as occurred
if ( mRecreateSavePoint && mBuffer->L->dataProvider()->transaction()->savePoints().indexOf( mSavePointId ) == -1 )
if ( savePointId.isEmpty() )
{
mSavePointId = mBuffer->L->dataProvider()->transaction()->createSavepoint( mSavePointId, mError );
if ( mSavePointId.isEmpty() )
// re-create savepoint only if mRecreateSavePoint and rollBackToSavePoint as occurred
if ( mRecreateSavePoint && mBuffer->L->dataProvider()->transaction()->savePoints().indexOf( mSavePointId ) == -1 )
{
setError();
mSavePointId = mBuffer->L->dataProvider()->transaction()->createSavepoint( mSavePointId, mError );
if ( mSavePointId.isEmpty() )
{
setError();
}
}
}
else
{
mSavePointId = savePointId;
}
}
return !hasError();
}
Expand Down Expand Up @@ -360,21 +377,27 @@ void QgsVectorLayerUndoPassthroughCommandUpdate::redo()
// itself. So the redo has to be executed only after an undo action.
if ( mUndone )
{
mSavePointId = mTransaction->createSavepoint( mError );
QString errorMessage;

QString savePointId = mTransaction->createSavepoint( errorMessage );

if ( mError.isEmpty() )
if ( errorMessage.isEmpty() )
{
if ( mTransaction->executeSql( mSql, mError ) )
setSavePoint( savePointId );

if ( mTransaction->executeSql( mSql, errorMessage ) )
{
mUndone = false;
}
else
{
setErrorMessage( errorMessage );
setError();
}
}
else
{
setErrorMessage( errorMessage );
setError();
}
}
Expand Down
25 changes: 20 additions & 5 deletions src/core/qgsvectorlayerundopassthroughcommand.h
Expand Up @@ -55,20 +55,35 @@ class CORE_EXPORT QgsVectorLayerUndoPassthroughCommand : public QgsVectorLayerUn
bool rollBackToSavePoint();

/**
* Set the command savepoint or set error status
* error satus should be false prior to call
* Set the command savepoint or set error status.
* Error satus should be false prior to call. If the savepoint given in
* parameter is empty, then a new one is created if none is currently
* available in the transaction.
*/
bool setSavePoint();
bool setSavePoint( const QString &savePointId = QString() );

/**
* Set error flag and append "failed" to text
*/
void setError();

QString mSavePointId;
QString mError;
/**
* Sets the error message.
*
* \since QGIS 3.0
*/
void setErrorMessage( const QString &errorMessage );

/**
* Returns the error message or an empty string if there's none.
*
* \since QGIS 3.0
*/
QString errorMessage() const;

private:
QString mSavePointId;
QString mError;
bool mHasError;
bool mRecreateSavePoint;
};
Expand Down

0 comments on commit 8a4382a

Please sign in to comment.