Skip to content
Permalink
Browse files
Limit canvas redraws when working with vector layer undo stack
- Fix unreported bug where clicking on group in legend would clear previously selected vector layer's undo stack
- Ensure empty view is created on project load (cosmetic)
  • Loading branch information
dakcarto committed Feb 11, 2013
1 parent 8feb84a commit 2de2f2327e3cb77192a2f07a43a71f2853649e2d
Showing with 18 additions and 16 deletions.
  1. +14 −11 src/app/qgsundowidget.cpp
  2. +1 −1 src/core/qgsvectorlayer.cpp
  3. +3 −4 src/core/qgsvectorlayereditbuffer.cpp
@@ -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 );
}
}

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

0 comments on commit 2de2f23

Please sign in to comment.