31
31
#include " qgssearchquerybuilder.h"
32
32
#include " qgslogger.h"
33
33
#include " qgsmapcanvas.h"
34
-
34
+ # include " qgsfieldcalculator.h "
35
35
36
36
class QgsAttributeTableDock : public QDockWidget
37
37
{
@@ -87,9 +87,12 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
87
87
mZoomMapToSelectedRowsButton ->setIcon ( getThemeIcon ( " /mActionZoomToSelected.png" ) );
88
88
mInvertSelectionButton ->setIcon ( getThemeIcon ( " /mActionInvertSelection.png" ) );
89
89
mToggleEditingButton ->setIcon ( getThemeIcon ( " /mActionToggleEditing.png" ) );
90
+ mOpenFieldCalculator ->setIcon ( getThemeIcon ( " /mActionCalculateField.png" ) );
90
91
// toggle editing
92
+ bool canChangeAttributes = mLayer ->dataProvider ()->capabilities () & QgsVectorDataProvider::ChangeAttributeValues;
91
93
mToggleEditingButton ->setCheckable ( true );
92
- mToggleEditingButton ->setEnabled ( mLayer ->dataProvider ()->capabilities () & QgsVectorDataProvider::ChangeAttributeValues );
94
+ mToggleEditingButton ->setEnabled ( canChangeAttributes );
95
+ mOpenFieldCalculator ->setEnabled ( canChangeAttributes && mLayer ->isEditable () );
93
96
94
97
// info from table to application
95
98
connect ( this , SIGNAL ( editingToggled ( QgsMapLayer * ) ), QgisApp::instance (), SLOT ( toggleEditing ( QgsMapLayer * ) ) );
@@ -522,6 +525,9 @@ void QgsAttributeTableDialog::editingToggled()
522
525
mToggleEditingButton ->setChecked ( mLayer ->isEditable () );
523
526
mToggleEditingButton ->blockSignals ( false );
524
527
528
+ bool canChangeAttributes = mLayer ->dataProvider ()->capabilities () & QgsVectorDataProvider::ChangeAttributeValues;
529
+ mOpenFieldCalculator ->setEnabled ( canChangeAttributes && mLayer ->isEditable () );
530
+
525
531
// (probably reload data if user stopped editing - possible revert)
526
532
mModel ->reload ( mModel ->index ( 0 , 0 ), mModel ->index ( mModel ->rowCount (), mModel ->columnCount () ) );
527
533
@@ -548,3 +554,13 @@ void QgsAttributeTableDialog::revert()
548
554
mModel ->revert ();
549
555
mModel ->reload ( mModel ->index ( 0 , 0 ), mModel ->index ( mModel ->rowCount (), mModel ->columnCount () ) );
550
556
}
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
+ }
0 commit comments