Skip to content
Permalink
Browse files
apply #3721: add save edits button to attribute table
  • Loading branch information
jef-n committed May 5, 2011
1 parent b8642a9 commit 22c7246ac8b46ad97867723d823a66bfc3a26d14
@@ -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" ) );
@@ -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() );
@@ -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() ) );
@@ -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;
@@ -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
*/
@@ -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
@@ -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;

@@ -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();
@@ -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/>
@@ -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">
@@ -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.