Skip to content

Commit eb5ba34

Browse files
committedDec 2, 2012
Add 'Save All Edits' action to layers menu and digitizing toolbar
1 parent 45a933a commit eb5ba34

File tree

7 files changed

+68
-2
lines changed

7 files changed

+68
-2
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<file>themes/default/mActionSaveAsPDF.png</file>
144144
<file>themes/default/mActionSaveAsSVG.png</file>
145145
<file>themes/default/mActionSaveEdits.png</file>
146+
<file>themes/default/mActionSaveAllEdits.png</file>
146147
<file>themes/default/mActionSaveMapAsImage.png</file>
147148
<file>themes/default/mActionScaleBar.png</file>
148149
<file>themes/default/mActionSelectedToTop.png</file>
@@ -350,6 +351,7 @@
350351
<file>themes/gis/mActionSaveAsPDF.png</file>
351352
<file>themes/gis/mActionSaveAsSVG.png</file>
352353
<file>themes/gis/mActionSaveEdits.png</file>
354+
<file>themes/gis/mActionSaveAllEdits.png</file>
353355
<file>themes/gis/mActionSaveMapAsImage.png</file>
354356
<file>themes/gis/mActionScaleBar.png</file>
355357
<file>themes/gis/mActionSelectedToTop.png</file>
945 Bytes
Loading
1.31 KB
Loading

‎src/app/legend/qgslegendlayer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ void QgsLegendLayer::updateAfterLayerModification()
601601
}
602602
void QgsLegendLayer::updateAfterLayerModification( bool onlyGeomChanged )
603603
{
604+
QgisApp::instance()->actionSaveAllEdits()->setEnabled(
605+
QgisApp::instance()->unsavedEditableLayers().count() > 0 );
606+
604607
if ( onlyGeomChanged )
605608
{
606609
return;

‎src/app/qgisapp.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ void QgisApp::createActions()
949949
connect( mActionOpenTable, SIGNAL( triggered() ), this, SLOT( attributeTable() ) );
950950
connect( mActionToggleEditing, SIGNAL( triggered() ), this, SLOT( toggleEditing() ) );
951951
connect( mActionSaveEdits, SIGNAL( triggered() ), this, SLOT( saveEdits() ) );
952+
connect( mActionSaveAllEdits, SIGNAL( triggered() ), this, SLOT( saveAllEdits() ) );
952953
connect( mActionLayerSaveAs, SIGNAL( triggered() ), this, SLOT( saveAsFile() ) );
953954
connect( mActionLayerSelectionSaveAs, SIGNAL( triggered() ), this, SLOT( saveSelectionAsVectorFile() ) );
954955
connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
@@ -1650,6 +1651,7 @@ void QgisApp::setTheme( QString theThemeName )
16501651
mActionDraw->setIcon( QgsApplication::getThemeIcon( "/mActionDraw.png" ) );
16511652
mActionToggleEditing->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.png" ) );
16521653
mActionSaveEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveEdits.png" ) );
1654+
mActionSaveAllEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveAllEdits.png" ) );
16531655
mActionCutFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionEditCut.png" ) );
16541656
mActionCopyFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionEditCopy.png" ) );
16551657
mActionPasteFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionEditPaste.png" ) );
@@ -5099,6 +5101,38 @@ void QgisApp::saveEdits( QgsMapLayer *layer )
50995101

51005102
vlayer->startEditing();
51015103
vlayer->triggerRepaint();
5104+
5105+
actionSaveAllEdits()->setEnabled( unsavedEditableLayers().count() > 0 );
5106+
}
5107+
5108+
void QgisApp::saveAllEdits()
5109+
{
5110+
if ( mMapCanvas && mMapCanvas->isDrawing() )
5111+
return;
5112+
5113+
foreach ( QgsMapLayer * layer, unsavedEditableLayers() )
5114+
{
5115+
saveEdits( layer );
5116+
}
5117+
}
5118+
5119+
QList<QgsMapLayer *> QgisApp::unsavedEditableLayers() const
5120+
{
5121+
QList<QgsMapLayer*> unsavedLayers;
5122+
// use legend layers (instead of registry) so message listing mirrors its order
5123+
QList<QgsMapLayer*> layers = mMapLegend->layers();
5124+
if ( layers.count() > 0 )
5125+
{
5126+
foreach ( QgsMapLayer* layer, layers )
5127+
{
5128+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
5129+
if ( vl && vl->isEditable() && vl->isModified() )
5130+
{
5131+
unsavedLayers.append( vl );
5132+
}
5133+
}
5134+
}
5135+
return unsavedLayers;
51025136
}
51035137

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

5137-
51385171
bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
51395172
{
51405173
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -7090,6 +7123,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
70907123
mActionOpenTable->setEnabled( false );
70917124
mActionToggleEditing->setEnabled( false );
70927125
mActionSaveEdits->setEnabled( false );
7126+
mActionSaveAllEdits->setEnabled( false );
70937127
mActionLayerSaveAs->setEnabled( false );
70947128
mActionLayerSelectionSaveAs->setEnabled( false );
70957129
mActionLayerProperties->setEnabled( false );

‎src/app/qgisapp.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
291291
QAction *actionOpenTable() { return mActionOpenTable; }
292292
QAction *actionToggleEditing() { return mActionToggleEditing; }
293293
QAction *actionSaveEdits() { return mActionSaveEdits; }
294+
QAction *actionSaveAllEdits() { return mActionSaveAllEdits; }
294295
QAction *actionLayerSaveAs() { return mActionLayerSaveAs; }
295296
QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
296297
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
@@ -377,6 +378,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
377378
//! returns pointer to map legend
378379
QgsLegend *legend();
379380

381+
/** Return vector layers with unsaved provider edits
382+
* @returns list of layers in legend order, or empty list
383+
* @note added in 1.9 */
384+
QList<QgsMapLayer *> unsavedEditableLayers() const;
385+
380386
#ifdef Q_OS_WIN
381387
//! ugly hack
382388
void skipNextContextMenuEvent();
@@ -550,7 +556,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
550556
//! Remove a layer from the map and legend
551557
void removeLayer();
552558
/** Duplicate map layer(s) in legend
553-
* @note added in 2.0 */
559+
* @note added in 1.9 */
554560
void duplicateLayers( const QList<QgsMapLayer *> lyrList = QList<QgsMapLayer *>() );
555561
//! Set CRS of a layer
556562
void setLayerCRS();
@@ -774,6 +780,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
774780
//! save current edits and start new transaction
775781
void saveEdits();
776782

783+
/** Save all edits and start new transactions
784+
* @note added in 1.9 */
785+
void saveAllEdits();
786+
777787
//! change layer subset of current vector layer
778788
void layerSubsetString();
779789

‎src/ui/qgisapp.ui

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<addaction name="separator"/>
165165
<addaction name="mActionOpenTable"/>
166166
<addaction name="mActionSaveEdits"/>
167+
<addaction name="mActionSaveAllEdits"/>
167168
<addaction name="mActionToggleEditing"/>
168169
<addaction name="mActionLayerSaveAs"/>
169170
<addaction name="mActionLayerSelectionSaveAs"/>
@@ -279,6 +280,7 @@
279280
<attribute name="toolBarBreak">
280281
<bool>true</bool>
281282
</attribute>
283+
<addaction name="mActionSaveAllEdits"/>
282284
<addaction name="mActionToggleEditing"/>
283285
<addaction name="mActionSaveEdits"/>
284286
<addaction name="mActionAddFeature"/>
@@ -1849,6 +1851,21 @@ Acts on currently active editable layer</string>
18491851
<string>SVG annotation</string>
18501852
</property>
18511853
</action>
1854+
<action name="mActionSaveAllEdits">
1855+
<property name="icon">
1856+
<iconset resource="../../images/images.qrc">
1857+
<normaloff>:/images/themes/default/mActionSaveAllEdits.png</normaloff>:/images/themes/default/mActionSaveAllEdits.png</iconset>
1858+
</property>
1859+
<property name="text">
1860+
<string>Save All Edits</string>
1861+
</property>
1862+
<property name="toolTip">
1863+
<string>Save All Edits</string>
1864+
</property>
1865+
<property name="statusTip">
1866+
<string>Save edits to editing layers, but continue editing</string>
1867+
</property>
1868+
</action>
18521869
</widget>
18531870
<resources>
18541871
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.