Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minimize canvas refreshes during save/rollback/cancel current edits a…
…ctions
  • Loading branch information
dakcarto committed Jan 18, 2013
1 parent 814d8e0 commit 923aa5f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
36 changes: 24 additions & 12 deletions src/app/qgisapp.cpp
Expand Up @@ -5271,10 +5271,10 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )

void QgisApp::saveActiveLayerEdits()
{
saveEdits( activeLayer() );
saveEdits( activeLayer(), true, true );
}

void QgisApp::saveEdits( QgsMapLayer *layer, bool leaveEditable )
void QgisApp::saveEdits( QgsMapLayer *layer, bool leaveEditable, bool triggerRepaint )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer || !vlayer->isEditable() || !vlayer->isModified() )
Expand All @@ -5297,10 +5297,13 @@ void QgisApp::saveEdits( QgsMapLayer *layer, bool leaveEditable )
{
vlayer->startEditing();
}
vlayer->triggerRepaint();
if ( triggerRepaint )
{
vlayer->triggerRepaint();
}
}

void QgisApp::cancelEdits( QgsMapLayer *layer, bool leaveEditable )
void QgisApp::cancelEdits( QgsMapLayer *layer, bool leaveEditable, bool triggerRepaint )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer || !vlayer->isEditable() )
Expand All @@ -5326,7 +5329,10 @@ void QgisApp::cancelEdits( QgsMapLayer *layer, bool leaveEditable )
{
vlayer->startEditing();
}
vlayer->triggerRepaint();
if ( triggerRepaint )
{
vlayer->triggerRepaint();
}
}

void QgisApp::saveEdits()
Expand All @@ -5336,8 +5342,9 @@ void QgisApp::saveEdits()

foreach ( QgsMapLayer * layer, mMapLegend->selectedLayers() )
{
saveEdits( layer );
saveEdits( layer, true, false );
}
mMapCanvas->refresh();
activateDeactivateLayerRelatedActions( activeLayer() );
}

Expand All @@ -5354,8 +5361,9 @@ void QgisApp::saveAllEdits( bool verifyAction )

foreach ( QgsMapLayer * layer, editableLayers( true ) )
{
saveEdits( layer );
saveEdits( layer, true, false );
}
mMapCanvas->refresh();
activateDeactivateLayerRelatedActions( activeLayer() );
}

Expand All @@ -5366,8 +5374,9 @@ void QgisApp::rollbackEdits()

foreach ( QgsMapLayer * layer, mMapLegend->selectedLayers() )
{
cancelEdits( layer );
cancelEdits( layer, true, false );
}
mMapCanvas->refresh();
activateDeactivateLayerRelatedActions( activeLayer() );
}

Expand All @@ -5384,8 +5393,9 @@ void QgisApp::rollbackAllEdits( bool verifyAction )

foreach ( QgsMapLayer * layer, editableLayers( true ) )
{
cancelEdits( layer );
cancelEdits( layer, true, false );
}
mMapCanvas->refresh();
activateDeactivateLayerRelatedActions( activeLayer() );
}

Expand All @@ -5396,8 +5406,9 @@ void QgisApp::cancelEdits()

foreach ( QgsMapLayer * layer, mMapLegend->selectedLayers() )
{
cancelEdits( layer, false );
cancelEdits( layer, false, false );
}
mMapCanvas->refresh();
activateDeactivateLayerRelatedActions( activeLayer() );
}

Expand All @@ -5414,12 +5425,13 @@ void QgisApp::cancelAllEdits( bool verifyAction )

foreach ( QgsMapLayer * layer, editableLayers() )
{
cancelEdits( layer, false );
cancelEdits( layer, false, false );
}
mMapCanvas->refresh();
activateDeactivateLayerRelatedActions( activeLayer() );
}

bool QgisApp::verifyEditsActionDialog( QString act, QString upon )
bool QgisApp::verifyEditsActionDialog( const QString& act, const QString& upon )
{
bool res = false;
switch ( QMessageBox::information( 0,
Expand Down
16 changes: 11 additions & 5 deletions src/app/qgisapp.h
Expand Up @@ -456,12 +456,18 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
* @note added in 1.9 */
void saveActiveLayerEdits();

//! Save edits of a layer
void saveEdits( QgsMapLayer *layer, bool leaveEditable = true );
/** Save edits of a layer
* @param leaveEditable leave the layer in editing mode when done (added in QGIS 1.9)
* @param triggerRepaint send layer signal to repaint canvas when done (added in QGIS 1.9)
*/
void saveEdits( QgsMapLayer *layer, bool leaveEditable = true, bool triggerRepaint = true );

/** Cancel edits for a layer
* @note added in 1.9 */
void cancelEdits( QgsMapLayer *layer, bool leaveEditable = true );
* @param leaveEditable leave the layer in editing mode when done
* @param triggerRepaint send layer signal to repaint canvas when done
* @note added in 1.9
*/
void cancelEdits( QgsMapLayer *layer, bool leaveEditable = true, bool triggerRepaint = true );

//! Save current edits for selected layer(s) and start new transaction(s)
void saveEdits();
Expand Down Expand Up @@ -839,7 +845,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

/** Dialog for verification of action on many edits
* @note added in 1.9 */
bool verifyEditsActionDialog( QString act, QString upon );
bool verifyEditsActionDialog( const QString& act, const QString& upon );

/** Update gui actions/menus when layers are modified
* @note added in 1.9 */
Expand Down

0 comments on commit 923aa5f

Please sign in to comment.