Skip to content

Commit 24e34ca

Browse files
author
wonder
committedOct 22, 2009
[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
1 parent 6497f10 commit 24e34ca

File tree

4 files changed

+135
-91
lines changed

4 files changed

+135
-91
lines changed
 

‎src/app/attributetable/qgsattributetabledialog.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "qgssearchquerybuilder.h"
3232
#include "qgslogger.h"
3333
#include "qgsmapcanvas.h"
34-
34+
#include "qgsfieldcalculator.h"
3535

3636
class QgsAttributeTableDock : public QDockWidget
3737
{
@@ -87,9 +87,12 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
8787
mZoomMapToSelectedRowsButton->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
8888
mInvertSelectionButton->setIcon( getThemeIcon( "/mActionInvertSelection.png" ) );
8989
mToggleEditingButton->setIcon( getThemeIcon( "/mActionToggleEditing.png" ) );
90+
mOpenFieldCalculator->setIcon( getThemeIcon( "/mActionCalculateField.png" ) );
9091
// toggle editing
92+
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
9193
mToggleEditingButton->setCheckable( true );
92-
mToggleEditingButton->setEnabled( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues );
94+
mToggleEditingButton->setEnabled( canChangeAttributes );
95+
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );
9396

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

528+
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
529+
mOpenFieldCalculator->setEnabled( canChangeAttributes && mLayer->isEditable() );
530+
525531
// (probably reload data if user stopped editing - possible revert)
526532
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );
527533

@@ -548,3 +554,13 @@ void QgsAttributeTableDialog::revert()
548554
mModel->revert();
549555
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );
550556
}
557+
558+
void QgsAttributeTableDialog::on_mOpenFieldCalculator_clicked()
559+
{
560+
QgsFieldCalculator calc( mLayer );
561+
if ( calc.exec() )
562+
{
563+
// update model - a field has been added or updated
564+
mModel->reload( mModel->index( 0, 0 ), mModel->index( mModel->rowCount(), mModel->columnCount() ) );
565+
}
566+
}

‎src/app/attributetable/qgsattributetabledialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ class QgsAttributeTableDialog : public QDialog, private Ui::QgsAttributeTableDia
132132
* Starts editing mode
133133
*/
134134
void startEditing();
135+
/**
136+
* Opens field calculator dialog
137+
*/
138+
void on_mOpenFieldCalculator_clicked();
135139

136140
signals:
137141
/**

‎src/app/qgsfieldcalculator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ void QgsFieldCalculator::accept()
130130
bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
131131
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();
132132

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

134136
mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), QgsRectangle(), false, false );
135137
while ( mVectorLayer->nextFeature( feature ) )
@@ -157,6 +159,10 @@ void QgsFieldCalculator::accept()
157159
mVectorLayer->changeAttributeValue( feature.id(), attributeId, value.string(), false );
158160
}
159161

162+
// stop blocking layerModified signals and make sure that one layerModified signal is emitted
163+
mVectorLayer->blockSignals( true );
164+
mVectorLayer->setModified( true, false );
165+
160166
}
161167

162168
if ( !calculationSuccess )

‎src/ui/qgsattributetabledialog.ui

Lines changed: 107 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,237 +1,255 @@
1-
<ui version="4.0" >
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
23
<class>QgsAttributeTableDialog</class>
3-
<widget class="QDialog" name="QgsAttributeTableDialog" >
4-
<property name="geometry" >
4+
<widget class="QDialog" name="QgsAttributeTableDialog">
5+
<property name="geometry">
56
<rect>
67
<x>0</x>
78
<y>0</y>
89
<width>623</width>
910
<height>570</height>
1011
</rect>
1112
</property>
12-
<property name="windowTitle" >
13+
<property name="windowTitle">
1314
<string>Attribute Table</string>
1415
</property>
15-
<layout class="QGridLayout" >
16-
<property name="leftMargin" >
17-
<number>0</number>
18-
</property>
19-
<property name="topMargin" >
20-
<number>0</number>
21-
</property>
22-
<property name="rightMargin" >
23-
<number>0</number>
16+
<layout class="QGridLayout">
17+
<property name="horizontalSpacing">
18+
<number>2</number>
2419
</property>
25-
<property name="bottomMargin" >
20+
<property name="verticalSpacing">
2621
<number>0</number>
2722
</property>
28-
<property name="horizontalSpacing" >
29-
<number>2</number>
30-
</property>
31-
<property name="verticalSpacing" >
23+
<property name="margin">
3224
<number>0</number>
3325
</property>
34-
<item row="0" column="0" >
35-
<widget class="QgsAttributeTableView" name="mView" >
36-
<property name="alternatingRowColors" >
26+
<item row="0" column="0">
27+
<widget class="QgsAttributeTableView" name="mView">
28+
<property name="alternatingRowColors">
3729
<bool>true</bool>
3830
</property>
3931
</widget>
4032
</item>
41-
<item row="1" column="0" >
42-
<layout class="QHBoxLayout" >
33+
<item row="1" column="0">
34+
<layout class="QHBoxLayout">
4335
<item>
44-
<widget class="QToolButton" name="mRemoveSelectionButton" >
45-
<property name="toolTip" >
36+
<widget class="QToolButton" name="mRemoveSelectionButton">
37+
<property name="toolTip">
4638
<string>Unselect all</string>
4739
</property>
48-
<property name="text" >
40+
<property name="text">
4941
<string/>
5042
</property>
51-
<property name="icon" >
52-
<iconset>../../images/themes/default/mActionUnselectAttributes.png</iconset>
43+
<property name="icon">
44+
<iconset>
45+
<normaloff>../../images/themes/default/mActionUnselectAttributes.png</normaloff>../../images/themes/default/mActionUnselectAttributes.png</iconset>
5346
</property>
54-
<property name="iconSize" >
47+
<property name="iconSize">
5548
<size>
5649
<width>18</width>
5750
<height>18</height>
5851
</size>
5952
</property>
60-
<property name="shortcut" >
53+
<property name="shortcut">
6154
<string/>
6255
</property>
6356
</widget>
6457
</item>
6558
<item>
66-
<widget class="QToolButton" name="mSelectedToTopButton" >
67-
<property name="toolTip" >
59+
<widget class="QToolButton" name="mSelectedToTopButton">
60+
<property name="toolTip">
6861
<string>Move selection to top</string>
6962
</property>
70-
<property name="text" >
63+
<property name="text">
7164
<string/>
7265
</property>
73-
<property name="icon" >
74-
<iconset>../../images/themes/default/mActionSelectedToTop.png</iconset>
66+
<property name="icon">
67+
<iconset>
68+
<normaloff>../../images/themes/default/mActionSelectedToTop.png</normaloff>../../images/themes/default/mActionSelectedToTop.png</iconset>
7569
</property>
76-
<property name="iconSize" >
70+
<property name="iconSize">
7771
<size>
7872
<width>18</width>
7973
<height>18</height>
8074
</size>
8175
</property>
82-
<property name="shortcut" >
76+
<property name="shortcut">
8377
<string>Ctrl+T</string>
8478
</property>
8579
</widget>
8680
</item>
8781
<item>
88-
<widget class="QToolButton" name="mInvertSelectionButton" >
89-
<property name="toolTip" >
82+
<widget class="QToolButton" name="mInvertSelectionButton">
83+
<property name="toolTip">
9084
<string>Invert selection</string>
9185
</property>
92-
<property name="text" >
86+
<property name="text">
9387
<string/>
9488
</property>
95-
<property name="icon" >
96-
<iconset>../../images/themes/default/mActionInvertSelection.png</iconset>
89+
<property name="icon">
90+
<iconset>
91+
<normaloff>../../images/themes/default/mActionInvertSelection.png</normaloff>../../images/themes/default/mActionInvertSelection.png</iconset>
9792
</property>
98-
<property name="iconSize" >
93+
<property name="iconSize">
9994
<size>
10095
<width>18</width>
10196
<height>18</height>
10297
</size>
10398
</property>
104-
<property name="shortcut" >
99+
<property name="shortcut">
105100
<string>Ctrl+S</string>
106101
</property>
107102
</widget>
108103
</item>
109104
<item>
110-
<widget class="QToolButton" name="mCopySelectedRowsButton" >
111-
<property name="toolTip" >
105+
<widget class="QToolButton" name="mCopySelectedRowsButton">
106+
<property name="toolTip">
112107
<string>Copy selected rows to clipboard (Ctrl+C)</string>
113108
</property>
114-
<property name="whatsThis" >
109+
<property name="whatsThis">
115110
<string>Copies the selected rows to the clipboard</string>
116111
</property>
117-
<property name="text" >
112+
<property name="text">
118113
<string/>
119114
</property>
120-
<property name="icon" >
121-
<iconset>../../images/themes/default/mActionEditCopy.png</iconset>
115+
<property name="icon">
116+
<iconset>
117+
<normaloff>../../images/themes/default/mActionEditCopy.png</normaloff>../../images/themes/default/mActionEditCopy.png</iconset>
122118
</property>
123-
<property name="iconSize" >
119+
<property name="iconSize">
124120
<size>
125121
<width>18</width>
126122
<height>18</height>
127123
</size>
128124
</property>
129-
<property name="shortcut" >
125+
<property name="shortcut">
130126
<string>Ctrl+C</string>
131127
</property>
132128
</widget>
133129
</item>
134130
<item>
135-
<widget class="QToolButton" name="mZoomMapToSelectedRowsButton" >
136-
<property name="toolTip" >
131+
<widget class="QToolButton" name="mZoomMapToSelectedRowsButton">
132+
<property name="toolTip">
137133
<string>Zoom map to the selected rows (Ctrl-J)</string>
138134
</property>
139-
<property name="whatsThis" >
135+
<property name="whatsThis">
140136
<string>Zoom map to the selected rows</string>
141137
</property>
142-
<property name="text" >
138+
<property name="text">
143139
<string/>
144140
</property>
145-
<property name="icon" >
146-
<iconset>../../images/themes/default/mActionZoomToSelected.png</iconset>
141+
<property name="icon">
142+
<iconset>
143+
<normaloff>../../images/themes/default/mActionZoomToSelected.png</normaloff>../../images/themes/default/mActionZoomToSelected.png</iconset>
147144
</property>
148-
<property name="iconSize" >
145+
<property name="iconSize">
149146
<size>
150147
<width>18</width>
151148
<height>18</height>
152149
</size>
153150
</property>
154-
<property name="shortcut" >
151+
<property name="shortcut">
155152
<string>Ctrl+J</string>
156153
</property>
157154
</widget>
158155
</item>
159156
<item>
160-
<widget class="QToolButton" name="mToggleEditingButton" >
161-
<property name="toolTip" >
157+
<widget class="QToolButton" name="mToggleEditingButton">
158+
<property name="toolTip">
162159
<string>Toggle editing mode</string>
163160
</property>
164-
<property name="whatsThis" >
161+
<property name="whatsThis">
165162
<string>Click to toggle table editing</string>
166163
</property>
167-
<property name="text" >
164+
<property name="text">
168165
<string/>
169166
</property>
170-
<property name="icon" >
171-
<iconset>../../images/themes/default/mActionToggleEditing.png</iconset>
167+
<property name="icon">
168+
<iconset>
169+
<normaloff>../../images/themes/default/mActionToggleEditing.png</normaloff>../../images/themes/default/mActionToggleEditing.png</iconset>
172170
</property>
173-
<property name="iconSize" >
171+
<property name="iconSize">
174172
<size>
175173
<width>18</width>
176174
<height>18</height>
177175
</size>
178176
</property>
179-
<property name="checkable" >
177+
<property name="checkable">
180178
<bool>true</bool>
181179
</property>
182180
</widget>
183181
</item>
184182
<item>
185-
<widget class="QLabel" name="searchFor" >
186-
<property name="text" >
183+
<widget class="QToolButton" name="mOpenFieldCalculator">
184+
<property name="toolTip">
185+
<string>Open field calculator</string>
186+
</property>
187+
<property name="text">
188+
<string/>
189+
</property>
190+
<property name="icon">
191+
<iconset>
192+
<normaloff>../../images/themes/default/mActionCalculateField.png</normaloff>../../images/themes/default/mActionCalculateField.png</iconset>
193+
</property>
194+
<property name="iconSize">
195+
<size>
196+
<width>18</width>
197+
<height>18</height>
198+
</size>
199+
</property>
200+
</widget>
201+
</item>
202+
<item>
203+
<widget class="QLabel" name="searchFor">
204+
<property name="text">
187205
<string>Look for</string>
188206
</property>
189207
</widget>
190208
</item>
191209
<item>
192-
<widget class="QLineEdit" name="query" />
210+
<widget class="QLineEdit" name="query"/>
193211
</item>
194212
<item>
195-
<widget class="QLabel" name="searchIn" >
196-
<property name="text" >
213+
<widget class="QLabel" name="searchIn">
214+
<property name="text">
197215
<string>in</string>
198216
</property>
199217
</widget>
200218
</item>
201219
<item>
202-
<widget class="QComboBox" name="columnBox" />
220+
<widget class="QComboBox" name="columnBox"/>
203221
</item>
204222
<item>
205-
<widget class="QPushButton" name="searchButton" >
206-
<property name="text" >
223+
<widget class="QPushButton" name="searchButton">
224+
<property name="text">
207225
<string>&amp;Search</string>
208226
</property>
209227
</widget>
210228
</item>
211229
</layout>
212230
</item>
213-
<item row="2" column="0" >
214-
<layout class="QHBoxLayout" >
231+
<item row="2" column="0">
232+
<layout class="QHBoxLayout">
215233
<item>
216-
<widget class="QCheckBox" name="cbxShowSelectedOnly" >
217-
<property name="text" >
234+
<widget class="QCheckBox" name="cbxShowSelectedOnly">
235+
<property name="text">
218236
<string>Show selected records only</string>
219237
</property>
220238
</widget>
221239
</item>
222240
<item>
223-
<widget class="QCheckBox" name="cbxSearchSelectedOnly" >
224-
<property name="text" >
241+
<widget class="QCheckBox" name="cbxSearchSelectedOnly">
242+
<property name="text">
225243
<string>Search selected records only</string>
226244
</property>
227245
</widget>
228246
</item>
229247
<item>
230248
<spacer>
231-
<property name="orientation" >
249+
<property name="orientation">
232250
<enum>Qt::Horizontal</enum>
233251
</property>
234-
<property name="sizeHint" >
252+
<property name="sizeHint" stdset="0">
235253
<size>
236254
<width>40</width>
237255
<height>20</height>
@@ -240,18 +258,18 @@
240258
</spacer>
241259
</item>
242260
<item>
243-
<widget class="QLabel" name="label" >
244-
<property name="text" >
261+
<widget class="QLabel" name="label">
262+
<property name="text">
245263
<string>Advanced search</string>
246264
</property>
247265
</widget>
248266
</item>
249267
<item>
250-
<widget class="QToolButton" name="mAdvancedSearchButton" >
251-
<property name="text" >
268+
<widget class="QToolButton" name="mAdvancedSearchButton">
269+
<property name="text">
252270
<string>...</string>
253271
</property>
254-
<property name="iconSize" >
272+
<property name="iconSize">
255273
<size>
256274
<width>12</width>
257275
<height>12</height>

0 commit comments

Comments
 (0)
Please sign in to comment.