From 24e34caadbaff4acb37ea414247cfdcaa75b0ec0 Mon Sep 17 00:00:00 2001 From: wonder Date: Thu, 22 Oct 2009 13:39:00 +0000 Subject: [PATCH] [UPDATE] Added field calculator also to attribute table to make it easier to discover. git-svn-id: http://svn.osgeo.org/qgis/trunk@11829 c8812cc2-4d05-0410-92ff-de0c093fc19c --- .../qgsattributetabledialog.cpp | 20 +- .../attributetable/qgsattributetabledialog.h | 4 + src/app/qgsfieldcalculator.cpp | 6 + src/ui/qgsattributetabledialog.ui | 198 ++++++++++-------- 4 files changed, 136 insertions(+), 92 deletions(-) diff --git a/src/app/attributetable/qgsattributetabledialog.cpp b/src/app/attributetable/qgsattributetabledialog.cpp index 5cf33e7d682..1071466c41d 100644 --- a/src/app/attributetable/qgsattributetabledialog.cpp +++ b/src/app/attributetable/qgsattributetabledialog.cpp @@ -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() ) ); + } +} diff --git a/src/app/attributetable/qgsattributetabledialog.h b/src/app/attributetable/qgsattributetabledialog.h index 503f0f901a9..8dd91b8aed8 100644 --- a/src/app/attributetable/qgsattributetabledialog.h +++ b/src/app/attributetable/qgsattributetabledialog.h @@ -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: /** diff --git a/src/app/qgsfieldcalculator.cpp b/src/app/qgsfieldcalculator.cpp index 6b8ca1cdbac..e8220f5426e 100644 --- a/src/app/qgsfieldcalculator.cpp +++ b/src/app/qgsfieldcalculator.cpp @@ -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 ) diff --git a/src/ui/qgsattributetabledialog.ui b/src/ui/qgsattributetabledialog.ui index d85587f111e..ea79cb7f2a7 100644 --- a/src/ui/qgsattributetabledialog.ui +++ b/src/ui/qgsattributetabledialog.ui @@ -1,7 +1,8 @@ - + + QgsAttributeTableDialog - - + + 0 0 @@ -9,229 +10,246 @@ 570 - + Attribute Table - - - 0 - - - 0 - - - 0 - - - 0 - - + + 2 - + 0 - - - + + 0 + + + + true - - + + - - + + Unselect all - + - - ../../images/themes/default/mActionUnselectAttributes.png + + + ../../images/themes/default/mActionUnselectAttributes.png../../images/themes/default/mActionUnselectAttributes.png - + 18 18 - + - - + + Move selection to top - + - - ../../images/themes/default/mActionSelectedToTop.png + + + ../../images/themes/default/mActionSelectedToTop.png../../images/themes/default/mActionSelectedToTop.png - + 18 18 - + Ctrl+T - - + + Invert selection - + - - ../../images/themes/default/mActionInvertSelection.png + + + ../../images/themes/default/mActionInvertSelection.png../../images/themes/default/mActionInvertSelection.png - + 18 18 - + Ctrl+S - - + + Copy selected rows to clipboard (Ctrl+C) - + Copies the selected rows to the clipboard - + - - ../../images/themes/default/mActionEditCopy.png + + + ../../images/themes/default/mActionEditCopy.png../../images/themes/default/mActionEditCopy.png - + 18 18 - + Ctrl+C - - + + Zoom map to the selected rows (Ctrl-J) - + Zoom map to the selected rows - + - - ../../images/themes/default/mActionZoomToSelected.png + + + ../../images/themes/default/mActionZoomToSelected.png../../images/themes/default/mActionZoomToSelected.png - + 18 18 - + Ctrl+J - - + + Toggle editing mode - + Click to toggle table editing - + - - ../../images/themes/default/mActionToggleEditing.png + + + ../../images/themes/default/mActionToggleEditing.png../../images/themes/default/mActionToggleEditing.png - + 18 18 - + true - - + + + Open field calculator + + + + + + + ../../images/themes/default/mActionCalculateField.png../../images/themes/default/mActionCalculateField.png + + + + 18 + 18 + + + + + + + Look for - + - - + + in - + - - + + &Search - - + + - - + + Show selected records only - - + + Search selected records only - + Qt::Horizontal - + 40 20 @@ -240,18 +258,18 @@ - - + + Advanced search - - + + ... - + 12 12