Skip to content
Permalink
Browse files

[UPDATE] Added field calculator also to attribute table to make it ea…

…sier to discover.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11829 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Oct 22, 2009
1 parent d727f91 commit 466f4590800beff994371d239b854c15189ae108
@@ -31,7 +31,7 @@
#include "qgssearchquerybuilder.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"

#include "qgsfieldcalculator.h"

class QgsAttributeTableDock : public QDockWidget
{
@@ -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 * ) ) );
@@ -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() ) );

@@ -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() ) );
}
}
@@ -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:
/**
@@ -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 ) )
@@ -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 )

0 comments on commit 466f459

Please sign in to comment.
You can’t perform that action at this time.