Skip to content

Commit

Permalink
Reinstate Save Active Layer Edits action
Browse files Browse the repository at this point in the history
- 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 ba5b90a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/gui/qgisinterface.sip
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/app/legend/qgslegendlayer.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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() )
Expand Down
25 changes: 25 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.cpp
Expand Up @@ -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(); }
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgisinterface.h
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -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"/>
Expand Down Expand Up @@ -282,6 +283,7 @@
</attribute>
<addaction name="mActionAllEdits"/>
<addaction name="mActionToggleEditing"/>
<addaction name="mActionSaveLayerEdits"/>
<addaction name="mActionAddFeature"/>
<addaction name="mActionMoveFeature"/>
<addaction name="mActionNodeTool"/>
Expand Down Expand Up @@ -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"/>
Expand Down

0 comments on commit ba5b90a

Please sign in to comment.