Skip to content
Permalink
Browse files
Reinstate Save Active Layer Edits action
- Now enables/disables relative to vector layer isModified() state (gives feedback when save is finished)
- Now works with active legend layer, regardless of whether a selection exists in legend
- Add to legend contextual menu when right-clicked vector layer isModified()
  • Loading branch information
dakcarto committed Dec 31, 2012
1 parent d85ed32 commit ba5b90a16acedd8ac93f68401a978f12cfc97a0e
@@ -344,6 +344,8 @@ class QgisInterface : QObject
virtual QAction *actionOpenTable() = 0;
virtual QAction *actionToggleEditing() = 0;
/** @note added in 1.9 */
virtual QAction *actionSaveActiveLayerEdits() = 0;
/** @note added in 1.9 */
virtual QAction *actionAllEdits() = 0;
/** @note added in 1.9 */
virtual QAction *actionSaveEdits() = 0;
@@ -415,6 +415,7 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
{
QgsMapLayer *lyr = layer();
QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing();
QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits();
QAction *allEditsAction = QgisApp::instance()->actionAllEdits();

// zoom to layer extent
@@ -469,6 +470,10 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
theMenu.addAction( toggleEditingAction );
toggleEditingAction->setChecked( vlayer->isEditable() );
}
if ( saveLayerEditsAction && vlayer->isModified() )
{
theMenu.addAction( saveLayerEditsAction );
}
}

if ( allEditsAction->isEnabled() )
@@ -949,6 +949,7 @@ void QgisApp::createActions()
connect( mActionAddWfsLayer, SIGNAL( triggered() ), this, SLOT( addWfsLayer() ) );
connect( mActionOpenTable, SIGNAL( triggered() ), this, SLOT( attributeTable() ) );
connect( mActionToggleEditing, SIGNAL( triggered() ), this, SLOT( toggleEditing() ) );
connect( mActionSaveLayerEdits, SIGNAL( triggered() ), this, SLOT( saveActiveLayerEdits() ) );
connect( mActionSaveEdits, SIGNAL( triggered() ), this, SLOT( saveEdits() ) );
connect( mActionSaveAllEdits, SIGNAL( triggered() ), this, SLOT( saveAllEdits() ) );
connect( mActionRollbackEdits, SIGNAL( triggered() ), this, SLOT( rollbackEdits() ) );
@@ -1670,6 +1671,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionSponsors->setIcon( QgsApplication::getThemeIcon( "/mActionHelpSponsors.png" ) );
mActionDraw->setIcon( QgsApplication::getThemeIcon( "/mActionDraw.png" ) );
mActionToggleEditing->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.svg" ) );
mActionSaveLayerEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveAllEdits.svg" ) );
mActionAllEdits->setIcon( QgsApplication::getThemeIcon( "/mActionAllEdits.svg" ) );
mActionSaveEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveEdits.svg" ) );
mActionSaveAllEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveAllEdits.svg" ) );
@@ -5206,6 +5208,11 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
return res;
}

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

void QgisApp::saveEdits( QgsMapLayer *layer, bool leaveEditable )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -5362,6 +5369,20 @@ bool QgisApp::verifyEditsActionDialog( QString act, QString upon )

void QgisApp::updateLayerModifiedActions()
{
bool enableSaveLayerEdits = false;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
if ( vlayer )
{
QgsVectorDataProvider* dprovider = vlayer->dataProvider();
if ( dprovider )
{
enableSaveLayerEdits = ( dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues
&& vlayer->isEditable()
&& vlayer->isModified() );
}
}
mActionSaveLayerEdits->setEnabled( enableSaveLayerEdits );

mActionSaveEdits->setEnabled( mMapLegend && mMapLegend->selectedLayersEditable( true ) );
mActionRollbackEdits->setEnabled( mMapLegend && mMapLegend->selectedLayersEditable( true ) );
mActionCancelEdits->setEnabled( mMapLegend && mMapLegend->selectedLayersEditable() );
@@ -7322,6 +7343,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionOpenTable->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
mActionSaveLayerEdits->setEnabled( false );
mActionLayerSaveAs->setEnabled( false );
mActionLayerSelectionSaveAs->setEnabled( false );
mActionLayerProperties->setEnabled( false );
@@ -7413,13 +7435,15 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
bool canChangeAttributes = dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
mActionToggleEditing->setEnabled( canChangeAttributes && !vlayer->isReadOnly() );
mActionToggleEditing->setChecked( vlayer->isEditable() );
mActionSaveLayerEdits->setEnabled( canChangeAttributes && vlayer->isEditable() && vlayer->isModified() );
mUndoWidget->dockContents()->setEnabled( vlayer->isEditable() );
updateUndoActions();
}
else
{
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
mActionSaveLayerEdits->setEnabled( false );
mUndoWidget->dockContents()->setEnabled( false );
mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
@@ -7588,6 +7612,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionOpenTable->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
mActionSaveLayerEdits->setEnabled( false );
mUndoWidget->dockContents()->setEnabled( false );
mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
@@ -291,6 +291,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionOpenTable() { return mActionOpenTable; }
QAction *actionToggleEditing() { return mActionToggleEditing; }
/** @note added in 1.9 */
QAction *actionSaveActiveLayerEdits() { return mActionSaveLayerEdits; }
/** @note added in 1.9 */
QAction *actionAllEdits() { return mActionAllEdits; }
QAction *actionSaveEdits() { return mActionSaveEdits; }
/** @note added in 1.9 */
@@ -792,6 +794,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! starts/stops editing mode of a layer
bool toggleEditing( QgsMapLayer *layer, bool allowCancel = true );

/** Save edits for active vector layer and start new transactions
* @note added in 1.9 */
void saveActiveLayerEdits();

//! Save edits of a layer
void saveEdits( QgsMapLayer *layer, bool leaveEditable = true );

@@ -436,6 +436,7 @@ QAction *QgisAppInterface::actionCopyLayerStyle() { return qgis->actionCopyLayer
QAction *QgisAppInterface::actionPasteLayerStyle() { return qgis->actionPasteLayerStyle(); }
QAction *QgisAppInterface::actionOpenTable() { return qgis->actionOpenTable(); }
QAction *QgisAppInterface::actionToggleEditing() { return qgis->actionToggleEditing(); }
QAction *QgisAppInterface::actionSaveActiveLayerEdits() { return qgis->actionSaveActiveLayerEdits(); }
QAction *QgisAppInterface::actionAllEdits() { return qgis->actionAllEdits(); }
QAction *QgisAppInterface::actionSaveEdits() { return qgis->actionSaveEdits(); }
QAction *QgisAppInterface::actionSaveAllEdits() { return qgis->actionSaveAllEdits(); }
@@ -296,6 +296,8 @@ class QgisAppInterface : public QgisInterface
virtual QAction *actionOpenTable();
virtual QAction *actionToggleEditing();
/** @note added in 1.9 */
virtual QAction *actionSaveActiveLayerEdits();
/** @note added in 1.9 */
virtual QAction *actionAllEdits();
/** @note added in 1.9 */
virtual QAction *actionSaveEdits();
@@ -392,6 +392,8 @@ class GUI_EXPORT QgisInterface : public QObject
virtual QAction *actionOpenTable() = 0;
virtual QAction *actionToggleEditing() = 0;
/** @note added in 1.9 */
virtual QAction *actionSaveActiveLayerEdits() = 0;
/** @note added in 1.9 */
virtual QAction *actionAllEdits() = 0;
/** @note added in 1.9 */
virtual QAction *actionSaveEdits() = 0;
@@ -164,6 +164,7 @@
<addaction name="separator"/>
<addaction name="mActionOpenTable"/>
<addaction name="mActionToggleEditing"/>
<addaction name="mActionSaveLayerEdits"/>
<addaction name="mActionAllEdits"/>
<addaction name="separator"/>
<addaction name="mActionLayerSaveAs"/>
@@ -282,6 +283,7 @@
</attribute>
<addaction name="mActionAllEdits"/>
<addaction name="mActionToggleEditing"/>
<addaction name="mActionSaveLayerEdits"/>
<addaction name="mActionAddFeature"/>
<addaction name="mActionMoveFeature"/>
<addaction name="mActionNodeTool"/>
@@ -1940,6 +1942,18 @@ Acts on currently active editable layer</string>
<string/>
</property>
</action>
<action name="mActionSaveLayerEdits">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSaveAllEdits.svg</normaloff>:/images/themes/default/mActionSaveAllEdits.svg</iconset>
</property>
<property name="text">
<string>Save Layer Edits</string>
</property>
<property name="toolTip">
<string>Save Layer Edits</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit ba5b90a

Please sign in to comment.