[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
This commit is contained in:
wonder 2009-10-22 13:39:00 +00:00
parent 6497f1043c
commit 24e34caadb
4 changed files with 136 additions and 92 deletions

View File

@ -31,7 +31,7 @@
#include "qgssearchquerybuilder.h" #include "qgssearchquerybuilder.h"
#include "qgslogger.h" #include "qgslogger.h"
#include "qgsmapcanvas.h" #include "qgsmapcanvas.h"
#include "qgsfieldcalculator.h"
class QgsAttributeTableDock : public QDockWidget class QgsAttributeTableDock : public QDockWidget
{ {
@ -87,9 +87,12 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mZoomMapToSelectedRowsButton->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) ); mZoomMapToSelectedRowsButton->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
mInvertSelectionButton->setIcon( getThemeIcon( "/mActionInvertSelection.png" ) ); mInvertSelectionButton->setIcon( getThemeIcon( "/mActionInvertSelection.png" ) );
mToggleEditingButton->setIcon( getThemeIcon( "/mActionToggleEditing.png" ) ); mToggleEditingButton->setIcon( getThemeIcon( "/mActionToggleEditing.png" ) );
mOpenFieldCalculator->setIcon( getThemeIcon( "/mActionCalculateField.png" ) );
// toggle editing // toggle editing
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
mToggleEditingButton->setCheckable( true ); mToggleEditingButton->setCheckable( true );
mToggleEditingButton->setEnabled( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ); mToggleEditingButton->setEnabled( canChangeAttributes );
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );
// info from table to application // info from table to application
connect( this, SIGNAL( editingToggled( QgsMapLayer * ) ), QgisApp::instance(), SLOT( toggleEditing( QgsMapLayer * ) ) ); connect( this, SIGNAL( editingToggled( QgsMapLayer * ) ), QgisApp::instance(), SLOT( toggleEditing( QgsMapLayer * ) ) );
@ -522,6 +525,9 @@ void QgsAttributeTableDialog::editingToggled()
mToggleEditingButton->setChecked( mLayer->isEditable() ); mToggleEditingButton->setChecked( mLayer->isEditable() );
mToggleEditingButton->blockSignals( false ); mToggleEditingButton->blockSignals( false );
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );
// (probably reload data if user stopped editing - possible revert) // (probably reload data if user stopped editing - possible revert)
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) ); mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );
@ -548,3 +554,13 @@ void QgsAttributeTableDialog::revert()
mModel->revert(); mModel->revert();
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) ); 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() ) );
}
}

View File

@ -132,6 +132,10 @@ class QgsAttributeTableDialog : public QDialog, private Ui::QgsAttributeTableDia
* Starts editing mode * Starts editing mode
*/ */
void startEditing(); void startEditing();
/**
* Opens field calculator dialog
*/
void on_mOpenFieldCalculator_clicked();
signals: signals:
/** /**

View File

@ -130,6 +130,8 @@ void QgsFieldCalculator::accept()
bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked ); bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds(); QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();
// block layerModified signals (that would trigger table update)
mVectorLayer->blockSignals( true );
mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), QgsRectangle(), false, false ); mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), QgsRectangle(), false, false );
while ( mVectorLayer->nextFeature( feature ) ) while ( mVectorLayer->nextFeature( feature ) )
@ -157,6 +159,10 @@ void QgsFieldCalculator::accept()
mVectorLayer->changeAttributeValue( feature.id(), attributeId, value.string(), false ); 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 ) if ( !calculationSuccess )

View File

@ -1,7 +1,8 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsAttributeTableDialog</class> <class>QgsAttributeTableDialog</class>
<widget class="QDialog" name="QgsAttributeTableDialog" > <widget class="QDialog" name="QgsAttributeTableDialog">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,229 +10,246 @@
<height>570</height> <height>570</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Attribute Table</string> <string>Attribute Table</string>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout">
<property name="leftMargin" > <property name="horizontalSpacing">
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>2</number> <number>2</number>
</property> </property>
<property name="verticalSpacing" > <property name="verticalSpacing">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0" > <property name="margin">
<widget class="QgsAttributeTableView" name="mView" > <number>0</number>
<property name="alternatingRowColors" > </property>
<item row="0" column="0">
<widget class="QgsAttributeTableView" name="mView">
<property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" > <item row="1" column="0">
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<item> <item>
<widget class="QToolButton" name="mRemoveSelectionButton" > <widget class="QToolButton" name="mRemoveSelectionButton">
<property name="toolTip" > <property name="toolTip">
<string>Unselect all</string> <string>Unselect all</string>
</property> </property>
<property name="text" > <property name="text">
<string/> <string/>
</property> </property>
<property name="icon" > <property name="icon">
<iconset>../../images/themes/default/mActionUnselectAttributes.png</iconset> <iconset>
<normaloff>../../images/themes/default/mActionUnselectAttributes.png</normaloff>../../images/themes/default/mActionUnselectAttributes.png</iconset>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>18</width> <width>18</width>
<height>18</height> <height>18</height>
</size> </size>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="mSelectedToTopButton" > <widget class="QToolButton" name="mSelectedToTopButton">
<property name="toolTip" > <property name="toolTip">
<string>Move selection to top</string> <string>Move selection to top</string>
</property> </property>
<property name="text" > <property name="text">
<string/> <string/>
</property> </property>
<property name="icon" > <property name="icon">
<iconset>../../images/themes/default/mActionSelectedToTop.png</iconset> <iconset>
<normaloff>../../images/themes/default/mActionSelectedToTop.png</normaloff>../../images/themes/default/mActionSelectedToTop.png</iconset>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>18</width> <width>18</width>
<height>18</height> <height>18</height>
</size> </size>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+T</string> <string>Ctrl+T</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="mInvertSelectionButton" > <widget class="QToolButton" name="mInvertSelectionButton">
<property name="toolTip" > <property name="toolTip">
<string>Invert selection</string> <string>Invert selection</string>
</property> </property>
<property name="text" > <property name="text">
<string/> <string/>
</property> </property>
<property name="icon" > <property name="icon">
<iconset>../../images/themes/default/mActionInvertSelection.png</iconset> <iconset>
<normaloff>../../images/themes/default/mActionInvertSelection.png</normaloff>../../images/themes/default/mActionInvertSelection.png</iconset>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>18</width> <width>18</width>
<height>18</height> <height>18</height>
</size> </size>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+S</string> <string>Ctrl+S</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="mCopySelectedRowsButton" > <widget class="QToolButton" name="mCopySelectedRowsButton">
<property name="toolTip" > <property name="toolTip">
<string>Copy selected rows to clipboard (Ctrl+C)</string> <string>Copy selected rows to clipboard (Ctrl+C)</string>
</property> </property>
<property name="whatsThis" > <property name="whatsThis">
<string>Copies the selected rows to the clipboard</string> <string>Copies the selected rows to the clipboard</string>
</property> </property>
<property name="text" > <property name="text">
<string/> <string/>
</property> </property>
<property name="icon" > <property name="icon">
<iconset>../../images/themes/default/mActionEditCopy.png</iconset> <iconset>
<normaloff>../../images/themes/default/mActionEditCopy.png</normaloff>../../images/themes/default/mActionEditCopy.png</iconset>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>18</width> <width>18</width>
<height>18</height> <height>18</height>
</size> </size>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+C</string> <string>Ctrl+C</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="mZoomMapToSelectedRowsButton" > <widget class="QToolButton" name="mZoomMapToSelectedRowsButton">
<property name="toolTip" > <property name="toolTip">
<string>Zoom map to the selected rows (Ctrl-J)</string> <string>Zoom map to the selected rows (Ctrl-J)</string>
</property> </property>
<property name="whatsThis" > <property name="whatsThis">
<string>Zoom map to the selected rows</string> <string>Zoom map to the selected rows</string>
</property> </property>
<property name="text" > <property name="text">
<string/> <string/>
</property> </property>
<property name="icon" > <property name="icon">
<iconset>../../images/themes/default/mActionZoomToSelected.png</iconset> <iconset>
<normaloff>../../images/themes/default/mActionZoomToSelected.png</normaloff>../../images/themes/default/mActionZoomToSelected.png</iconset>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>18</width> <width>18</width>
<height>18</height> <height>18</height>
</size> </size>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+J</string> <string>Ctrl+J</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="mToggleEditingButton" > <widget class="QToolButton" name="mToggleEditingButton">
<property name="toolTip" > <property name="toolTip">
<string>Toggle editing mode</string> <string>Toggle editing mode</string>
</property> </property>
<property name="whatsThis" > <property name="whatsThis">
<string>Click to toggle table editing</string> <string>Click to toggle table editing</string>
</property> </property>
<property name="text" > <property name="text">
<string/> <string/>
</property> </property>
<property name="icon" > <property name="icon">
<iconset>../../images/themes/default/mActionToggleEditing.png</iconset> <iconset>
<normaloff>../../images/themes/default/mActionToggleEditing.png</normaloff>../../images/themes/default/mActionToggleEditing.png</iconset>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>18</width> <width>18</width>
<height>18</height> <height>18</height>
</size> </size>
</property> </property>
<property name="checkable" > <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="searchFor" > <widget class="QToolButton" name="mOpenFieldCalculator">
<property name="text" > <property name="toolTip">
<string>Open field calculator</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>../../images/themes/default/mActionCalculateField.png</normaloff>../../images/themes/default/mActionCalculateField.png</iconset>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="searchFor">
<property name="text">
<string>Look for</string> <string>Look for</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="query" /> <widget class="QLineEdit" name="query"/>
</item> </item>
<item> <item>
<widget class="QLabel" name="searchIn" > <widget class="QLabel" name="searchIn">
<property name="text" > <property name="text">
<string>in</string> <string>in</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="columnBox" /> <widget class="QComboBox" name="columnBox"/>
</item> </item>
<item> <item>
<widget class="QPushButton" name="searchButton" > <widget class="QPushButton" name="searchButton">
<property name="text" > <property name="text">
<string>&amp;Search</string> <string>&amp;Search</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="0" > <item row="2" column="0">
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<item> <item>
<widget class="QCheckBox" name="cbxShowSelectedOnly" > <widget class="QCheckBox" name="cbxShowSelectedOnly">
<property name="text" > <property name="text">
<string>Show selected records only</string> <string>Show selected records only</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="cbxSearchSelectedOnly" > <widget class="QCheckBox" name="cbxSearchSelectedOnly">
<property name="text" > <property name="text">
<string>Search selected records only</string> <string>Search selected records only</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -240,18 +258,18 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="label" > <widget class="QLabel" name="label">
<property name="text" > <property name="text">
<string>Advanced search</string> <string>Advanced search</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="mAdvancedSearchButton" > <widget class="QToolButton" name="mAdvancedSearchButton">
<property name="text" > <property name="text">
<string>...</string> <string>...</string>
</property> </property>
<property name="iconSize" > <property name="iconSize">
<size> <size>
<width>12</width> <width>12</width>
<height>12</height> <height>12</height>