Skip to content

Commit

Permalink
in actions tab activate buttons only when appropriate (fixes #4785)
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Jan 13, 2012
1 parent 5941806 commit b186f83
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
51 changes: 44 additions & 7 deletions src/app/qgsattributeactiondialog.cpp
Expand Up @@ -44,6 +44,9 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions,

connect( attributeActionTable, SIGNAL( itemSelectionChanged() ),
this, SLOT( itemSelectionChanged() ) );
connect( actionName, SIGNAL( textChanged( QString ) ), this, SLOT( updateButtons() ) );
connect( actionAction, SIGNAL( textChanged( QString ) ), this, SLOT( updateButtons() ) );

connect( moveUpButton, SIGNAL( clicked() ), this, SLOT( moveUp() ) );
connect( moveDownButton, SIGNAL( clicked() ), this, SLOT( moveDown() ) );
connect( removeButton, SIGNAL( clicked() ), this, SLOT( remove() ) );
Expand Down Expand Up @@ -72,6 +75,8 @@ void QgsAttributeActionDialog::init()
const QgsAction action = ( *mActions )[i];
insertRow( i, action.type(), action.name(), action.action(), action.capture() );
}

updateButtons();
}

void QgsAttributeActionDialog::insertRow( int row, QgsAction::ActionType type, const QString &name, const QString &action, bool capture )
Expand All @@ -87,6 +92,8 @@ void QgsAttributeActionDialog::insertRow( int row, QgsAction::ActionType type, c
item->setFlags( item->flags() & ~( Qt::ItemIsEditable | Qt::ItemIsUserCheckable ) );
item->setCheckState( capture ? Qt::Checked : Qt::Unchecked );
attributeActionTable->setItem( row, 3, item );

updateButtons();
}

void QgsAttributeActionDialog::moveUp()
Expand All @@ -97,7 +104,7 @@ void QgsAttributeActionDialog::moveUp()
QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
if ( !selection.isEmpty() )
{
row1 = attributeActionTable->row( selection.first() );
row1 = selection.first()->row();
}

if ( row1 > 0 )
Expand All @@ -118,7 +125,7 @@ void QgsAttributeActionDialog::moveDown()
QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
if ( !selection.isEmpty() )
{
row1 = attributeActionTable->row( selection.first() );
row1 = selection.first()->row();
}

if ( row1 < attributeActionTable->rowCount() - 1 )
Expand Down Expand Up @@ -181,13 +188,15 @@ void QgsAttributeActionDialog::remove()
if ( !selection.isEmpty() )
{
// Remove the selected row.
int row = attributeActionTable->row( selection.first() );
int row = selection.first()->row();
attributeActionTable->removeRow( row );

// And select the row below the one that was selected or the last one.
if ( row >= attributeActionTable->rowCount() )
row = attributeActionTable->rowCount() - 1;
attributeActionTable->selectRow( row );

updateButtons();
}
}

Expand Down Expand Up @@ -249,11 +258,35 @@ void QgsAttributeActionDialog::update()
QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
if ( !selection.isEmpty() )
{
int i = attributeActionTable->row( selection.first() );
insert( i );
insert( selection.first()->row() );
}
}

void QgsAttributeActionDialog::updateButtons()
{
bool validNewAction = !actionName->text().isEmpty() && !actionAction->text().isEmpty();

QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
bool hasSelection = !selection.isEmpty();

if ( hasSelection )
{
int row = selection.first()->row();
moveUpButton->setEnabled( row >= 1 );
moveDownButton->setEnabled( row >= 0 && row < attributeActionTable->rowCount() - 1 );
}
else
{
moveUpButton->setEnabled( false );
moveDownButton->setEnabled( false );
}

removeButton->setEnabled( hasSelection );

insertButton->setEnabled( validNewAction );
updateButton->setEnabled( hasSelection && validNewAction );
}

void QgsAttributeActionDialog::insertField()
{
// Convert the selected field to an expression and
Expand Down Expand Up @@ -289,10 +322,14 @@ void QgsAttributeActionDialog::apply()
void QgsAttributeActionDialog::itemSelectionChanged()
{
QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
if ( !selection.isEmpty() )
bool hasSelection = !selection.isEmpty();
if ( hasSelection )
{
rowSelected( attributeActionTable->row( selection.first() ) );
int row = selection.first()->row();
rowSelected( row );
}

updateButtons();
}

void QgsAttributeActionDialog::rowSelected( int row )
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsattributeactiondialog.h
Expand Up @@ -55,6 +55,9 @@ class QgsAttributeActionDialog: public QWidget, private Ui::QgsAttributeActionDi
void update();
void itemSelectionChanged();

private slots:
void updateButtons();

private:

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

0 comments on commit b186f83

Please sign in to comment.