Skip to content

Commit d081341

Browse files
committedSep 14, 2015
Slightly improved keyboard navigation in variable editor
1 parent 0a60bab commit d081341

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎src/gui/qgsvariableeditorwidget.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,38 @@ void QgsVariableEditorTree::editNext( const QModelIndex& index )
585585
}
586586
}
587587

588+
QModelIndex QgsVariableEditorTree::moveCursor( QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers )
589+
{
590+
if ( cursorAction == QAbstractItemView::MoveNext )
591+
{
592+
QModelIndex index = currentIndex();
593+
if ( index.isValid() )
594+
{
595+
if ( index.column() + 1 < model()->columnCount() )
596+
return index.sibling( index.row(), index.column() + 1 );
597+
else if ( index.row() + 1 < model()->rowCount( index.parent() ) )
598+
return index.sibling( index.row() + 1, 0 );
599+
else
600+
return QModelIndex();
601+
}
602+
}
603+
else if ( cursorAction == QAbstractItemView::MovePrevious )
604+
{
605+
QModelIndex index = currentIndex();
606+
if ( index.isValid() )
607+
{
608+
if ( index.column() >= 1 )
609+
return index.sibling( index.row(), index.column() - 1 );
610+
else if ( index.row() >= 1 )
611+
return index.sibling( index.row() - 1, model()->columnCount() - 1 );
612+
else
613+
return QModelIndex();
614+
}
615+
}
616+
617+
return QTreeWidget::moveCursor( cursorAction, modifiers );
618+
}
619+
588620
void QgsVariableEditorTree::keyPressEvent( QKeyEvent *event )
589621
{
590622
switch ( event->key() )

‎src/gui/qgsvariableeditorwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class QgsVariableEditorTree : public QTreeWidget
186186
void toggleContextExpanded( QTreeWidgetItem *item );
187187
void editNext( const QModelIndex &index );
188188

189+
QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) override;
190+
189191
static QIcon mExpandIcon;
190192

191193
private:

0 commit comments

Comments
 (0)
Please sign in to comment.