Showing with 41 additions and 26 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +11 −4 src/app/qgsmaptoolshowhidelabels.cpp
  3. +14 −11 src/app/qgsundowidget.cpp
  4. +8 −4 src/core/qgsvectorlayer.cpp
  5. +4 −2 src/core/qgsvectorlayer.h
  6. +3 −4 src/core/qgsvectorlayereditbuffer.cpp
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5449,7 +5449,7 @@ void QgisApp::cancelEdits( QgsMapLayer *layer, bool leaveEditable, bool triggerR
mSaveRollbackInProgress = true;

mMapCanvas->freeze( true );
if ( !vlayer->rollBack() )
if ( !vlayer->rollBack( !leaveEditable ) )
{
mSaveRollbackInProgress = false;
QMessageBox::information( 0,
Expand Down
15 changes: 11 additions & 4 deletions src/app/qgsmaptoolshowhidelabels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,15 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )

QgsDebugMsg( "Number of selected labels or features: " + QString::number( selectedFeatIds.size() ) );

if ( selectedFeatIds.isEmpty() )
{
return;
}

bool labelChanged = false;
QString editTxt = doHide ? tr( "Hid labels" ) : tr( "Showed labels" );

vlayer->beginEditCommand( editTxt );
foreach ( const QgsFeatureId &fid, selectedFeatIds )
{
if ( showHideLabel( vlayer, fid, doHide ) )
Expand All @@ -167,11 +173,16 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )
labelChanged = true;
}
}
vlayer->endEditCommand();

if ( labelChanged )
{
mCanvas->refresh();
}
else
{
vlayer->destroyEditCommand();
}
}

bool QgsMapToolShowHideLabels::selectedFeatures( QgsVectorLayer* vlayer,
Expand Down Expand Up @@ -294,14 +305,10 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer,
}

// different attribute value, edit table
QString editTxt = hide ? tr( "Hid label" ) : tr( "Showed label" );
vlayer->beginEditCommand( editTxt );
if ( !vlayer->changeAttributeValue( fid, showCol, curVal, false ) )
{
QgsDebugMsg( "Failed write to attribute table" );
vlayer->endEditCommand();
return false;
}
vlayer->endEditCommand();
return true;
}
25 changes: 14 additions & 11 deletions src/app/qgsundowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ void QgsUndoWidget::destroyStack()
{
if ( mUndoStack != NULL )
{
mUndoStack->clear();
// do not clear undo stack here, just null pointer
mUndoStack = NULL;
}
if ( mUndoView != NULL )
{
mUndoView->close();
mUndoView = NULL;
delete mUndoView;
mUndoView = new QUndoView( dockWidgetContents );
gridLayout->addWidget( mUndoView, 0, 0, 1, 2 );
}
}

Expand Down Expand Up @@ -99,23 +101,24 @@ void QgsUndoWidget::indexChanged( int curIndx )
// when individually redoing, differentiate between last redo and a new command added to stack
bool lastRedo = ( mPreviousIndex == ( mPreviousCount - 1 ) && mPreviousCount == curCount && !canRedo );

bool debugThis = false;
if ( debugThis && offset != 0 )
if ( offset != 0 )
{
// '= Rendering =' text is for filtering log results to also only show canvas rendering event
QgsDebugMsg( QString( "= Rendering = curIndx : %1" ).arg( curIndx ) );
QgsDebugMsg( QString( "= Rendering = offset : %1" ).arg( offset ) );
QgsDebugMsg( QString( "= Rendering = curCount: %1" ).arg( curCount ) );
QgsDebugMsg( QString( "curIndx : %1" ).arg( curIndx ) );
QgsDebugMsg( QString( "offset : %1" ).arg( offset ) );
QgsDebugMsg( QString( "curCount: %1" ).arg( curCount ) );
if ( lastRedo )
QgsDebugMsg( QString( "= Rendering = lastRedo: true" ) );
QgsDebugMsg( QString( "lastRedo: true" ) );
}

// avoid canvas refresh when only a command was added to stack (i.e. no user undo/redo action)
// or when user has clicked back in view history then added a new command to the stack
// avoid canvas redraws when only new command was added to stack (i.e. no user undo/redo action)
// or when user has clicked back in QUndoView history then added a new command to the stack
if ( offset > 1 || ( offset == 1 && ( canRedo || lastRedo ) ) )
{
if ( mMapCanvas )
{
QgsDebugMsg( QString( "trigger redraw" ) );
mMapCanvas->refresh();
}
}

mPreviousIndex = curIndx;
Expand Down
12 changes: 8 additions & 4 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ bool QgsVectorLayer::startEditing()
mEditBuffer = new QgsVectorLayerEditBuffer( this );
// forward signals
connect( mEditBuffer, SIGNAL( layerModified() ), this, SIGNAL( layerModified() ) ); // TODO[MD]: necessary?
connect( mEditBuffer, SIGNAL( layerModified() ), this, SLOT( triggerRepaint() ) ); // TODO[MD]: works well?
//connect( mEditBuffer, SIGNAL( layerModified() ), this, SLOT( triggerRepaint() ) ); // TODO[MD]: works well?
connect( mEditBuffer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SIGNAL( featureAdded( QgsFeatureId ) ) );
connect( mEditBuffer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SIGNAL( featureDeleted( QgsFeatureId ) ) );
connect( mEditBuffer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ) );
Expand Down Expand Up @@ -3326,7 +3326,7 @@ const QStringList &QgsVectorLayer::commitErrors()
return mCommitErrors;
}

bool QgsVectorLayer::rollBack()
bool QgsVectorLayer::rollBack( bool deleteBuffer )
{
if ( !mEditBuffer )
{
Expand All @@ -3344,8 +3344,12 @@ bool QgsVectorLayer::rollBack()

updateFields();

delete mEditBuffer;
mEditBuffer = 0;
if ( deleteBuffer )
{
delete mEditBuffer;
mEditBuffer = 0;
undoStack()->clear();
}
emit editingStopped();

// invalidate the cache so the layer updates properly to show its original
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
bool commitChanges();
const QStringList &commitErrors();

/** Stop editing and discard the edits */
bool rollBack();
/** Stop editing and discard the edits
* @param deleteBuffer whether to delete editing buffer (added in 1.9)
*/
bool rollBack( bool deleteBuffer = true );

/**get edit type*/
EditType editType( int idx );
Expand Down
7 changes: 3 additions & 4 deletions src/core/qgsvectorlayereditbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,9 @@ void QgsVectorLayerEditBuffer::rollBack()
if ( !isModified() )
return;

while ( L->undoStack()->canUndo() )
{
L->undoStack()->undo();
}
// limit canvas redraws to one by jumping to beginning of stack
// see QgsUndoWidget::indexChanged
L->undoStack()->setIndex( 0 );

Q_ASSERT( mAddedAttributes.isEmpty() );
Q_ASSERT( mDeletedAttributeIds.isEmpty() );
Expand Down