Showing with 43 additions and 23 deletions.
  1. +31 −14 src/app/qgisapp.cpp
  2. +11 −5 src/app/qgisapp.h
  3. +1 −4 src/app/qgsattributetabledialog.cpp
45 changes: 31 additions & 14 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5234,14 +5234,15 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
break;

case QMessageBox::Discard:
mMapCanvas->freeze( true );
if ( !vlayer->rollBack() )
{
QMessageBox::information( 0, tr( "Error" ), tr( "Problems during roll back" ) );
res = false;
}
mMapCanvas->freeze( false );

// canvas refreshes handled in QgsUndoWidget::indexChanged
//vlayer->triggerRepaint();
vlayer->triggerRepaint();
break;

default:
Expand All @@ -5250,7 +5251,9 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
}
else //layer not modified
{
mMapCanvas->freeze( true );
vlayer->rollBack();
mMapCanvas->freeze( false );
res = true;
vlayer->triggerRepaint();
}
Expand All @@ -5268,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 @@ -5294,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 @@ -5306,6 +5312,7 @@ void QgisApp::cancelEdits( QgsMapLayer *layer, bool leaveEditable )
if ( vlayer == activeLayer() && leaveEditable )
mSaveRollbackInProgress = true;

mMapCanvas->freeze( true );
if ( !vlayer->rollBack() )
{
mSaveRollbackInProgress = false;
Expand All @@ -5316,12 +5323,16 @@ void QgisApp::cancelEdits( QgsMapLayer *layer, bool leaveEditable )
.arg( vlayer->name() )
.arg( vlayer->commitErrors().join( "\n " ) ) );
}
mMapCanvas->freeze( false );

if ( leaveEditable )
{
vlayer->startEditing();
}
vlayer->triggerRepaint();
if ( triggerRepaint )
{
vlayer->triggerRepaint();
}
}

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

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

Expand All @@ -5349,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 @@ -5361,8 +5374,9 @@ void QgisApp::rollbackEdits()

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

Expand All @@ -5379,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 @@ -5391,8 +5406,9 @@ void QgisApp::cancelEdits()

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

Expand All @@ -5409,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
Original file line number Diff line number Diff line change
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
5 changes: 1 addition & 4 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() && mLayer->geometryType() == QGis::NoGeometry );
mAddFeature->setHidden( !canAddFeatures || mLayer->geometryType() != QGis::NoGeometry );

// info from table to application
connect( this, SIGNAL( saveEdits( QgsMapLayer * ) ), QgisApp::instance(), SLOT( saveEdits( QgsMapLayer * ) ) );

// info from layer to table
connect( mLayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
connect( mLayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
Expand Down Expand Up @@ -677,7 +674,7 @@ void QgsAttributeTableDialog::on_mToggleEditingButton_toggled()

void QgsAttributeTableDialog::on_mSaveEditsButton_clicked()
{
emit saveEdits( mLayer );
QgisApp::instance()->saveEdits( mLayer, true, true );
}

void QgsAttributeTableDialog::editingToggled()
Expand Down