diff --git a/python/core/qgsvectorlayerundopassthroughcommand.sip b/python/core/qgsvectorlayerundopassthroughcommand.sip index 29c950da762..33ce8cb5fc0 100644 --- a/python/core/qgsvectorlayerundopassthroughcommand.sip +++ b/python/core/qgsvectorlayerundopassthroughcommand.sip @@ -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 }; diff --git a/src/core/qgsvectorlayerundopassthroughcommand.cpp b/src/core/qgsvectorlayerundopassthroughcommand.cpp index e7d47a92a0f..7bcffe85427 100644 --- a/src/core/qgsvectorlayerundopassthroughcommand.cpp +++ b/src/core/qgsvectorlayerundopassthroughcommand.cpp @@ -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(); } } diff --git a/src/core/qgsvectorlayerundopassthroughcommand.h b/src/core/qgsvectorlayerundopassthroughcommand.h index 61c8b0c3711..fc06c65895e 100644 --- a/src/core/qgsvectorlayerundopassthroughcommand.h +++ b/src/core/qgsvectorlayerundopassthroughcommand.h @@ -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; };