Private attributes

This commit is contained in:
Blottiere Paul 2017-10-17 14:33:45 +01:00
parent 82ba8ad062
commit 8a4382a473
3 changed files with 71 additions and 17 deletions

View File

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

View File

@ -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;
if ( mError.isEmpty() )
QString savePointId = mTransaction->createSavepoint( errorMessage );
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();
}
}

View File

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