Skip to content

Commit

Permalink
Limit canvas redraws when working with vector layer undo stack
Browse files Browse the repository at this point in the history
- 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 2de2f23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
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
2 changes: 1 addition & 1 deletion 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
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

0 comments on commit 2de2f23

Please sign in to comment.