Skip to content

Commit

Permalink
Add 'Save All Edits' action to layers menu and digitizing toolbar
Browse files Browse the repository at this point in the history
  • 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.
2 changes: 2 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Binary file added images/themes/default/mActionSaveAllEdits.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/gis/mActionSaveAllEdits.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/app/legend/qgslegendlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ void QgsLegendLayer::updateAfterLayerModification()
}
void QgsLegendLayer::updateAfterLayerModification( bool onlyGeomChanged )
{
QgisApp::instance()->actionSaveAllEdits()->setEnabled(
QgisApp::instance()->unsavedEditableLayers().count() > 0 );

if ( onlyGeomChanged )
{
return;
Expand Down
36 changes: 35 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -5134,7 +5168,6 @@ void QgisApp::layerSubsetString()
delete qb;
}


bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
Expand Down Expand Up @@ -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 );
Expand Down
12 changes: 11 additions & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
17 changes: 17 additions & 0 deletions src/ui/qgisapp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -279,6 +280,7 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionSaveAllEdits"/>
<addaction name="mActionToggleEditing"/>
<addaction name="mActionSaveEdits"/>
<addaction name="mActionAddFeature"/>
Expand Down Expand Up @@ -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"/>
Expand Down

0 comments on commit eb5ba34

Please sign in to comment.