Skip to content
Permalink
Browse files
Add 'Save All Edits' action to layers menu and digitizing toolbar
  • Loading branch information
dakcarto committed Dec 2, 2012
1 parent 45a933a commit eb5ba34
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
@@ -143,6 +143,7 @@
<file>themes/default/mActionSaveAsPDF.png</file>
<file>themes/default/mActionSaveAsSVG.png</file>
<file>themes/default/mActionSaveEdits.png</file>
<file>themes/default/mActionSaveAllEdits.png</file>
<file>themes/default/mActionSaveMapAsImage.png</file>
<file>themes/default/mActionScaleBar.png</file>
<file>themes/default/mActionSelectedToTop.png</file>
@@ -350,6 +351,7 @@
<file>themes/gis/mActionSaveAsPDF.png</file>
<file>themes/gis/mActionSaveAsSVG.png</file>
<file>themes/gis/mActionSaveEdits.png</file>
<file>themes/gis/mActionSaveAllEdits.png</file>
<file>themes/gis/mActionSaveMapAsImage.png</file>
<file>themes/gis/mActionScaleBar.png</file>
<file>themes/gis/mActionSelectedToTop.png</file>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -601,6 +601,9 @@ void QgsLegendLayer::updateAfterLayerModification()
}
void QgsLegendLayer::updateAfterLayerModification( bool onlyGeomChanged )
{
QgisApp::instance()->actionSaveAllEdits()->setEnabled(
QgisApp::instance()->unsavedEditableLayers().count() > 0 );

if ( onlyGeomChanged )
{
return;
@@ -949,6 +949,7 @@ void QgisApp::createActions()
connect( mActionOpenTable, SIGNAL( triggered() ), this, SLOT( attributeTable() ) );
connect( mActionToggleEditing, SIGNAL( triggered() ), this, SLOT( toggleEditing() ) );
connect( mActionSaveEdits, SIGNAL( triggered() ), this, SLOT( saveEdits() ) );
connect( mActionSaveAllEdits, SIGNAL( triggered() ), this, SLOT( saveAllEdits() ) );
connect( mActionLayerSaveAs, SIGNAL( triggered() ), this, SLOT( saveAsFile() ) );
connect( mActionLayerSelectionSaveAs, SIGNAL( triggered() ), this, SLOT( saveSelectionAsVectorFile() ) );
connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
@@ -1650,6 +1651,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionDraw->setIcon( QgsApplication::getThemeIcon( "/mActionDraw.png" ) );
mActionToggleEditing->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.png" ) );
mActionSaveEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveEdits.png" ) );
mActionSaveAllEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveAllEdits.png" ) );
mActionCutFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionEditCut.png" ) );
mActionCopyFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionEditCopy.png" ) );
mActionPasteFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionEditPaste.png" ) );
@@ -5099,6 +5101,38 @@ void QgisApp::saveEdits( QgsMapLayer *layer )

vlayer->startEditing();
vlayer->triggerRepaint();

actionSaveAllEdits()->setEnabled( unsavedEditableLayers().count() > 0 );
}

void QgisApp::saveAllEdits()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
return;

foreach ( QgsMapLayer * layer, unsavedEditableLayers() )
{
saveEdits( layer );
}
}

QList<QgsMapLayer *> QgisApp::unsavedEditableLayers() const
{
QList<QgsMapLayer*> unsavedLayers;
// use legend layers (instead of registry) so message listing mirrors its order
QList<QgsMapLayer*> layers = mMapLegend->layers();
if ( layers.count() > 0 )
{
foreach ( QgsMapLayer* layer, layers )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( vl && vl->isEditable() && vl->isModified() )
{
unsavedLayers.append( vl );
}
}
}
return unsavedLayers;
}

void QgisApp::layerSubsetString()
@@ -5134,7 +5168,6 @@ void QgisApp::layerSubsetString()
delete qb;
}


bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -7090,6 +7123,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionOpenTable->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionSaveEdits->setEnabled( false );
mActionSaveAllEdits->setEnabled( false );
mActionLayerSaveAs->setEnabled( false );
mActionLayerSelectionSaveAs->setEnabled( false );
mActionLayerProperties->setEnabled( false );
@@ -291,6 +291,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionOpenTable() { return mActionOpenTable; }
QAction *actionToggleEditing() { return mActionToggleEditing; }
QAction *actionSaveEdits() { return mActionSaveEdits; }
QAction *actionSaveAllEdits() { return mActionSaveAllEdits; }
QAction *actionLayerSaveAs() { return mActionLayerSaveAs; }
QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
@@ -377,6 +378,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! returns pointer to map legend
QgsLegend *legend();

/** Return vector layers with unsaved provider edits
* @returns list of layers in legend order, or empty list
* @note added in 1.9 */
QList<QgsMapLayer *> unsavedEditableLayers() const;

#ifdef Q_OS_WIN
//! ugly hack
void skipNextContextMenuEvent();
@@ -550,7 +556,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Remove a layer from the map and legend
void removeLayer();
/** Duplicate map layer(s) in legend
* @note added in 2.0 */
* @note added in 1.9 */
void duplicateLayers( const QList<QgsMapLayer *> lyrList = QList<QgsMapLayer *>() );
//! Set CRS of a layer
void setLayerCRS();
@@ -774,6 +780,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! save current edits and start new transaction
void saveEdits();

/** Save all edits and start new transactions
* @note added in 1.9 */
void saveAllEdits();

//! change layer subset of current vector layer
void layerSubsetString();

@@ -164,6 +164,7 @@
<addaction name="separator"/>
<addaction name="mActionOpenTable"/>
<addaction name="mActionSaveEdits"/>
<addaction name="mActionSaveAllEdits"/>
<addaction name="mActionToggleEditing"/>
<addaction name="mActionLayerSaveAs"/>
<addaction name="mActionLayerSelectionSaveAs"/>
@@ -279,6 +280,7 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionSaveAllEdits"/>
<addaction name="mActionToggleEditing"/>
<addaction name="mActionSaveEdits"/>
<addaction name="mActionAddFeature"/>
@@ -1849,6 +1851,21 @@ Acts on currently active editable layer</string>
<string>SVG annotation</string>
</property>
</action>
<action name="mActionSaveAllEdits">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSaveAllEdits.png</normaloff>:/images/themes/default/mActionSaveAllEdits.png</iconset>
</property>
<property name="text">
<string>Save All Edits</string>
</property>
<property name="toolTip">
<string>Save All Edits</string>
</property>
<property name="statusTip">
<string>Save edits to editing layers, but continue editing</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit eb5ba34

Please sign in to comment.