1 /* tabnav_tree_view.cpp
2 * Tree view with saner tab navigation functionality.
3 *
4 * Copyright 2016 Peter Wu <peter@lekensteyn.nl>
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13 #include "tabnav_tree_view.h"
14
TabnavTreeView(QWidget * parent)15 TabnavTreeView::TabnavTreeView(QWidget *parent) : QTreeView(parent)
16 {
17 }
18
19 // Note: if a QTableView is used, then this is not needed anymore since Tab
20 // works as "expected" (move to next cell instead of row).
21 // Note 2: this does not help with fields with no widget (like filename).
moveCursor(CursorAction cursorAction,Qt::KeyboardModifiers modifiers)22 QModelIndex TabnavTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
23 {
24 QModelIndex current = currentIndex();
25 // If an item is currently selected, interpret Next/Previous. Otherwise,
26 // fallback to the default selection (e.g. first row for Next).
27 if (current.isValid()) {
28 if (cursorAction == MoveNext) {
29 if (current.column() < model()->columnCount()) {
30 return current.sibling(current.row(), current.column() + 1);
31 }
32 return current;
33 } else if (cursorAction == MovePrevious) {
34 if (current.column() > 0) {
35 return current.sibling(current.row(), current.column() - 1);
36 }
37 return current;
38 }
39 }
40
41 return QTreeView::moveCursor(cursorAction, modifiers);
42 }
43
44 /*!
45 \fn void TabnavTreeView::currentItemChanged(QModelIndex *current, QModelIndex *previous)
46
47 This signal is emitted whenever the current item changes.
48
49 \a previous is the item that previously had the focus; \a current is the
50 new current item.
51 */
52
currentChanged(const QModelIndex & current,const QModelIndex & previous)53 void TabnavTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
54 {
55 QTreeView::currentChanged(current, previous);
56 emit currentItemChanged(current, previous);
57 }
58