@@ -44,6 +44,9 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions,
4444
4545 connect ( attributeActionTable, SIGNAL ( itemSelectionChanged () ),
4646 this , SLOT ( itemSelectionChanged () ) );
47+ connect ( actionName, SIGNAL ( textChanged ( QString ) ), this , SLOT ( updateButtons () ) );
48+ connect ( actionAction, SIGNAL ( textChanged ( QString ) ), this , SLOT ( updateButtons () ) );
49+
4750 connect ( moveUpButton, SIGNAL ( clicked () ), this , SLOT ( moveUp () ) );
4851 connect ( moveDownButton, SIGNAL ( clicked () ), this , SLOT ( moveDown () ) );
4952 connect ( removeButton, SIGNAL ( clicked () ), this , SLOT ( remove () ) );
@@ -72,6 +75,8 @@ void QgsAttributeActionDialog::init()
7275 const QgsAction action = ( *mActions )[i];
7376 insertRow ( i, action.type (), action.name (), action.action (), action.capture () );
7477 }
78+
79+ updateButtons ();
7580}
7681
7782void QgsAttributeActionDialog::insertRow ( int row, QgsAction::ActionType type, const QString &name, const QString &action, bool capture )
@@ -87,6 +92,8 @@ void QgsAttributeActionDialog::insertRow( int row, QgsAction::ActionType type, c
8792 item->setFlags ( item->flags () & ~( Qt::ItemIsEditable | Qt::ItemIsUserCheckable ) );
8893 item->setCheckState ( capture ? Qt::Checked : Qt::Unchecked );
8994 attributeActionTable->setItem ( row, 3 , item );
95+
96+ updateButtons ();
9097}
9198
9299void QgsAttributeActionDialog::moveUp ()
@@ -97,7 +104,7 @@ void QgsAttributeActionDialog::moveUp()
97104 QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems ();
98105 if ( !selection.isEmpty () )
99106 {
100- row1 = attributeActionTable-> row ( selection.first () );
107+ row1 = selection.first ()-> row ( );
101108 }
102109
103110 if ( row1 > 0 )
@@ -118,7 +125,7 @@ void QgsAttributeActionDialog::moveDown()
118125 QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems ();
119126 if ( !selection.isEmpty () )
120127 {
121- row1 = attributeActionTable-> row ( selection.first () );
128+ row1 = selection.first ()-> row ( );
122129 }
123130
124131 if ( row1 < attributeActionTable->rowCount () - 1 )
@@ -181,13 +188,15 @@ void QgsAttributeActionDialog::remove()
181188 if ( !selection.isEmpty () )
182189 {
183190 // Remove the selected row.
184- int row = attributeActionTable-> row ( selection.first () );
191+ int row = selection.first ()-> row ( );
185192 attributeActionTable->removeRow ( row );
186193
187194 // And select the row below the one that was selected or the last one.
188195 if ( row >= attributeActionTable->rowCount () )
189196 row = attributeActionTable->rowCount () - 1 ;
190197 attributeActionTable->selectRow ( row );
198+
199+ updateButtons ();
191200 }
192201}
193202
@@ -249,11 +258,35 @@ void QgsAttributeActionDialog::update()
249258 QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems ();
250259 if ( !selection.isEmpty () )
251260 {
252- int i = attributeActionTable->row ( selection.first () );
253- insert ( i );
261+ insert ( selection.first ()->row () );
254262 }
255263}
256264
265+ void QgsAttributeActionDialog::updateButtons ()
266+ {
267+ bool validNewAction = !actionName->text ().isEmpty () && !actionAction->text ().isEmpty ();
268+
269+ QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems ();
270+ bool hasSelection = !selection.isEmpty ();
271+
272+ if ( hasSelection )
273+ {
274+ int row = selection.first ()->row ();
275+ moveUpButton->setEnabled ( row >= 1 );
276+ moveDownButton->setEnabled ( row >= 0 && row < attributeActionTable->rowCount () - 1 );
277+ }
278+ else
279+ {
280+ moveUpButton->setEnabled ( false );
281+ moveDownButton->setEnabled ( false );
282+ }
283+
284+ removeButton->setEnabled ( hasSelection );
285+
286+ insertButton->setEnabled ( validNewAction );
287+ updateButton->setEnabled ( hasSelection && validNewAction );
288+ }
289+
257290void QgsAttributeActionDialog::insertField ()
258291{
259292 // Convert the selected field to an expression and
@@ -289,10 +322,14 @@ void QgsAttributeActionDialog::apply()
289322void QgsAttributeActionDialog::itemSelectionChanged ()
290323{
291324 QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems ();
292- if ( !selection.isEmpty () )
325+ bool hasSelection = !selection.isEmpty ();
326+ if ( hasSelection )
293327 {
294- rowSelected ( attributeActionTable->row ( selection.first () ) );
328+ int row = selection.first ()->row ();
329+ rowSelected ( row );
295330 }
331+
332+ updateButtons ();
296333}
297334
298335void QgsAttributeActionDialog::rowSelected ( int row )
0 commit comments