Skip to content

Commit b186f83

Browse files
committed
in actions tab activate buttons only when appropriate (fixes #4785)
1 parent 5941806 commit b186f83

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

src/app/qgsattributeactiondialog.cpp

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7782
void 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

9299
void 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+
257290
void QgsAttributeActionDialog::insertField()
258291
{
259292
// Convert the selected field to an expression and
@@ -289,10 +322,14 @@ void QgsAttributeActionDialog::apply()
289322
void 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

298335
void QgsAttributeActionDialog::rowSelected( int row )

src/app/qgsattributeactiondialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class QgsAttributeActionDialog: public QWidget, private Ui::QgsAttributeActionDi
5555
void update();
5656
void itemSelectionChanged();
5757

58+
private slots:
59+
void updateButtons();
60+
5861
private:
5962

6063
void insertRow( int row, QgsAction::ActionType type, const QString &name, const QString &action, bool capture );

0 commit comments

Comments
 (0)