Skip to content

Commit

Permalink
[UPDATE] Added field calculator also to attribute table to make it ea…
Browse files Browse the repository at this point in the history
…sier to discover.

git-svn-id: http://svn.osgeo.org/qgis/trunk@11829 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Oct 22, 2009
1 parent 6497f10 commit 24e34ca
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 91 deletions.
20 changes: 18 additions & 2 deletions src/app/attributetable/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "qgssearchquerybuilder.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"

#include "qgsfieldcalculator.h"

class QgsAttributeTableDock : public QDockWidget
{
Expand Down Expand Up @@ -87,9 +87,12 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mZoomMapToSelectedRowsButton->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
mInvertSelectionButton->setIcon( getThemeIcon( "/mActionInvertSelection.png" ) );
mToggleEditingButton->setIcon( getThemeIcon( "/mActionToggleEditing.png" ) );
mOpenFieldCalculator->setIcon( getThemeIcon( "/mActionCalculateField.png" ) );
// toggle editing
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
mToggleEditingButton->setCheckable( true );
mToggleEditingButton->setEnabled( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues );
mToggleEditingButton->setEnabled( canChangeAttributes );
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );

// info from table to application
connect( this, SIGNAL( editingToggled( QgsMapLayer * ) ), QgisApp::instance(), SLOT( toggleEditing( QgsMapLayer * ) ) );
Expand Down Expand Up @@ -522,6 +525,9 @@ void QgsAttributeTableDialog::editingToggled()
mToggleEditingButton->setChecked( mLayer->isEditable() );
mToggleEditingButton->blockSignals( false );

bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );

// (probably reload data if user stopped editing - possible revert)
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );

Expand All @@ -548,3 +554,13 @@ void QgsAttributeTableDialog::revert()
mModel->revert();
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );
}

void QgsAttributeTableDialog::on_mOpenFieldCalculator_clicked()
{
QgsFieldCalculator calc( mLayer );
if ( calc.exec() )
{
// update model - a field has been added or updated
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );
}
}
4 changes: 4 additions & 0 deletions src/app/attributetable/qgsattributetabledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ class QgsAttributeTableDialog : public QDialog, private Ui::QgsAttributeTableDia
* Starts editing mode
*/
void startEditing();
/**
* Opens field calculator dialog
*/
void on_mOpenFieldCalculator_clicked();

signals:
/**
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ void QgsFieldCalculator::accept()
bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();

// block layerModified signals (that would trigger table update)
mVectorLayer->blockSignals( true );

mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), QgsRectangle(), false, false );
while ( mVectorLayer->nextFeature( feature ) )
Expand Down Expand Up @@ -157,6 +159,10 @@ void QgsFieldCalculator::accept()
mVectorLayer->changeAttributeValue( feature.id(), attributeId, value.string(), false );
}

// stop blocking layerModified signals and make sure that one layerModified signal is emitted
mVectorLayer->blockSignals( true );
mVectorLayer->setModified( true, false );

}

if ( !calculationSuccess )
Expand Down
Loading

0 comments on commit 24e34ca

Please sign in to comment.