Skip to content
Permalink
Browse files

Private attributes

  • Loading branch information
pblottiere committed Oct 17, 2017
1 parent 82ba8ad commit 8a4382a47334097b4bc966f4321f5f9fcbfc16a2
@@ -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

@@ -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

};

@@ -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();
}
@@ -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();
}
}
@@ -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;
};

0 comments on commit 8a4382a

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