Skip to content
Permalink
Browse files

in actions tab activate buttons only when appropriate (fixes #4785)

  • Loading branch information
brushtyler committed Jan 13, 2012
1 parent 5941806 commit b186f83fdd18672c45513962d4c598483a5bc108
Showing with 47 additions and 7 deletions.
  1. +44 −7 src/app/qgsattributeactiondialog.cpp
  2. +3 −0 src/app/qgsattributeactiondialog.h
@@ -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() ) );
@@ -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 )
@@ -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()
@@ -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 )
@@ -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 )
@@ -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();
}
}

@@ -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
@@ -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 )
@@ -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 );

0 comments on commit b186f83

Please sign in to comment.
You can’t perform that action at this time.