Skip to content

Commit

Permalink
apply #3721: add save edits button to attribute table
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 5, 2011
1 parent b8642a9 commit 22c7246
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/app/attributetable/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mZoomMapToSelectedRowsButton->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
mInvertSelectionButton->setIcon( getThemeIcon( "/mActionInvertSelection.png" ) );
mToggleEditingButton->setIcon( getThemeIcon( "/mActionToggleEditing.png" ) );
mSaveEditsButton->setIcon( getThemeIcon( "/mActionSaveEdits.png" ) );
mDeleteSelectedButton->setIcon( getThemeIcon( "/mActionDeleteSelected.png" ) );
mOpenFieldCalculator->setIcon( getThemeIcon( "/mActionCalculateField.png" ) );
mAddAttribute->setIcon( getThemeIcon( "/mActionNewAttribute.png" ) );
Expand All @@ -101,9 +102,12 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
bool canAddAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes;
bool canDeleteAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteAttributes;
bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures;

mToggleEditingButton->setCheckable( true );
mToggleEditingButton->setChecked( mLayer->isEditable() );
mToggleEditingButton->setEnabled( canChangeAttributes && !mLayer->isReadOnly() );

mSaveEditsButton->setEnabled( canChangeAttributes && mLayer->isEditable() );
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );
mDeleteSelectedButton->setEnabled( canDeleteFeatures && mLayer->isEditable() );
mAddAttribute->setEnabled( canAddAttributes && mLayer->isEditable() );
Expand All @@ -113,6 +117,8 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid

// info from table to application
connect( this, SIGNAL( editingToggled( QgsMapLayer * ) ), QgisApp::instance(), SLOT( toggleEditing( QgsMapLayer * ) ) );
connect( this, SIGNAL( saveEdits( QgsMapLayer * ) ), QgisApp::instance(), SLOT( saveEdits( QgsMapLayer * ) ) );

// info from layer to table
connect( mLayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
connect( mLayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
Expand Down Expand Up @@ -683,10 +689,16 @@ void QgsAttributeTableDialog::on_mToggleEditingButton_toggled()
emit editingToggled( mLayer );
}

void QgsAttributeTableDialog::on_mSaveEditsButton_clicked()
{
emit saveEdits( mLayer );
}

void QgsAttributeTableDialog::editingToggled()
{
mToggleEditingButton->blockSignals( true );
mToggleEditingButton->setChecked( mLayer->isEditable() );
mSaveEditsButton->setEnabled( mLayer->isEditable() );
mToggleEditingButton->blockSignals( false );

bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
Expand Down
12 changes: 11 additions & 1 deletion src/app/attributetable/qgsattributetabledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class QgsAttributeTableDialog : public QDialog, private Ui::QgsAttributeTableDia
* Toggles editing mode
*/
void on_mToggleEditingButton_toggled();
/**
* Saves edits
*/
void on_mSaveEditsButton_clicked();
/**
* Inverts selection
*/
Expand Down Expand Up @@ -160,11 +164,17 @@ class QgsAttributeTableDialog : public QDialog, private Ui::QgsAttributeTableDia

signals:
/**
* Informs that editing mode ha been toggled
* Informs that editing mode has been toggled
* @param layer layer that has been toggled
*/
void editingToggled( QgsMapLayer *layer );

/**
* Informs that edits should be saved
* @param layer layer whose edits are to be saved
*/
void saveEdits( QgsMapLayer *layer );

protected:
/**
* Handle closing of the window
Expand Down
10 changes: 9 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4174,7 +4174,15 @@ void QgisApp::saveEdits()
if ( mMapCanvas && mMapCanvas->isDrawing() )
return;

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( activeLayer() ); // FIXME: save edits of all selected layers
foreach( QgsMapLayer * layer, mMapLegend->selectedLayers() )
{
saveEdits( layer );
}
}

void QgisApp::saveEdits( QgsMapLayer *layer )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer || !vlayer->isEditable() || !vlayer->isModified() )
return;

Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! starts/stops editing mode of a layer
bool toggleEditing( QgsMapLayer *layer, bool allowCancel = true );

//! save edits of a layer
void saveEdits( QgsMapLayer *layer );

//! save current vector layer
void saveAsVectorFile();
void saveSelectionAsVectorFile();
Expand Down
50 changes: 48 additions & 2 deletions src/ui/qgsattributetabledialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<item>
<widget class="QToolButton" name="mInvertSelectionButton">
<property name="toolTip">
<string>Invert selection (Ctrl+S)</string>
<string>Invert selection (Ctrl+R)</string>
</property>
<property name="text">
<string/>
Expand Down Expand Up @@ -243,6 +243,35 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mSaveEditsButton">
<property name="toolTip">
<string>Save Edits (Ctrl+S)</string>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>../../images/themes/default/mActionSaveEdits.png</normaloff>../../images/themes/default/mActionSaveEdits.png</iconset>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mDeleteSelectedButton">
<property name="toolTip">
Expand Down Expand Up @@ -410,5 +439,22 @@
<tabstop>mOpenFieldCalculator</tabstop>
</tabstops>
<resources/>
<connections/>
<connections>
<connection>
<sender>mToggleEditingButton</sender>
<signal>toggled(bool)</signal>
<receiver>mSaveEditsButton</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>192</x>
<y>504</y>
</hint>
<hint type="destinationlabel">
<x>214</x>
<y>501</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 22c7246

Please sign in to comment.