Skip to content

Commit

Permalink
[georeferencer] Add basic keyboard interface for the CPL list widget (#…
Browse files Browse the repository at this point in the history
…40335)

- Pressing the del key will delete the selected point
- Pressing the space key will toggle the enabled state
of the selected point
- Pressing the up/down/left/right keys will move selection
aroud
  • Loading branch information
nirvn committed Nov 30, 2020
1 parent 1c1d718 commit ceb53ce
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
73 changes: 72 additions & 1 deletion src/app/georeferencer/qgsgcplistwidget.cpp
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/

#include <QKeyEvent>
#include <QHeaderView>
#include <QDoubleSpinBox>
#include <QLineEdit>
Expand Down Expand Up @@ -41,7 +42,7 @@ QgsGCPListWidget::QgsGCPListWidget( QWidget *parent )
setSortingEnabled( true );

setContextMenuPolicy( Qt::CustomContextMenu );
setFocusPolicy( Qt::NoFocus );
setFocusPolicy( Qt::ClickFocus );

verticalHeader()->hide();
setAlternatingRowColors( true );
Expand Down Expand Up @@ -136,6 +137,76 @@ void QgsGCPListWidget::itemClicked( QModelIndex index )
mPrevColumn = index.column();
}

void QgsGCPListWidget::keyPressEvent( QKeyEvent *e )
{
if ( e->key() == Qt::Key_Delete )
{
QModelIndex index = currentIndex();
if ( index.isValid() )
{
removeRow();
if ( model()->rowCount() > 0 )
{
setCurrentIndex( model()->index( index.row() == model()->rowCount() ? index.row() - 1 : index.row(), index.column() ) );
return;
}
}
}
else if ( e->key() == Qt::Key_Space )
{
QModelIndex index = currentIndex();
if ( index.isValid() )
{
QModelIndex sourceIndex = static_cast<const QSortFilterProxyModel *>( model() )->mapToSource( index );
QgsGeorefDataPoint *p = mGCPList->at( sourceIndex.row() );
p->setEnabled( !p->isEnabled() );

mGCPListModel->updateModel();
emit pointEnabled( p, sourceIndex.row() );
adjustTableContent();
setCurrentIndex( model()->index( index.row(), index.column() ) );
return;
}
}
else if ( e->key() == Qt::Key_Up )
{
QModelIndex index = currentIndex();
if ( index.isValid() && index.row() > 0 )
{
setCurrentIndex( model()->index( index.row() - 1, index.column() ) );
return;
}
}
else if ( e->key() == Qt::Key_Down )
{
QModelIndex index = currentIndex();
if ( index.isValid() && index.row() < ( model()->rowCount() - 1 ) )
{
setCurrentIndex( model()->index( index.row() + 1, index.column() ) );
return;
}
}
else if ( e->key() == Qt::Key_Left )
{
QModelIndex index = currentIndex();
if ( index.isValid() && index.column() > 0 )
{
setCurrentIndex( model()->index( index.row(), index.column() - 1 ) );
return;
}
}
else if ( e->key() == Qt::Key_Right )
{
QModelIndex index = currentIndex();
if ( index.isValid() && index.column() < ( model()->columnCount() - 1 ) )
{
setCurrentIndex( model()->index( index.row(), index.column() + 1 ) );
return;
}
}
e->ignore();
}

void QgsGCPListWidget::updateItemCoords( QWidget *editor )
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>( editor );
Expand Down
2 changes: 2 additions & 0 deletions src/app/georeferencer/qgsgcplistwidget.h
Expand Up @@ -40,6 +40,8 @@ class QgsGCPListWidget : public QTableView
void updateGCPList();
void closeEditors();

void keyPressEvent( QKeyEvent *e ) override;

public slots:
// This slot is called by the list view if an item is double-clicked
void itemDoubleClicked( QModelIndex index );
Expand Down

0 comments on commit ceb53ce

Please sign in to comment.