diff options
author | Peter Wu <peter@lekensteyn.nl> | 2017-07-09 02:15:25 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-07-15 06:17:38 +0000 |
commit | b992e69c19a4fac968ef7a95d0c439638687a72d (patch) | |
tree | 5a4d2f48489ece29e295717a356d7dbb9b336824 /ui/qt | |
parent | bc7198e40e21c81a36a06f1c5566160e395eb0a5 (diff) |
Qt: implement saner tab navigation for coloring rules dialog
The default QTreeView/QTreeWidget behavior for (Shift-)Tab navigation is
to select the previous/next row. For data entries with multiple columns
(such as the UAT dialog or the coloring rules dialog), column
navigation is closer to what a user would expect, so implement that.
Bug: 13856
Change-Id: Ib585030380f894e0be214a95107cb264afac7eee
Reviewed-on: https://code.wireshark.org/review/22561
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | ui/qt/Makefile.am | 2 | ||||
-rw-r--r-- | ui/qt/coloring_rules_dialog.ui | 9 | ||||
-rw-r--r-- | ui/qt/tabnav_tree_widget.cpp | 68 | ||||
-rw-r--r-- | ui/qt/tabnav_tree_widget.h | 54 |
5 files changed, 134 insertions, 1 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 085dc9a635..1ddcacf3a9 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -161,6 +161,7 @@ set(WIRESHARK_QT_HEADERS simple_statistics_dialog.h stock_icon_tool_button.h supported_protocols_dialog.h + tabnav_tree_widget.h tap_parameter_dialog.h tcp_stream_dialog.h time_shift_dialog.h @@ -340,6 +341,7 @@ set(WIRESHARK_QT_SRC stock_icon.cpp stock_icon_tool_button.cpp supported_protocols_dialog.cpp + tabnav_tree_widget.cpp tap_parameter_dialog.cpp tcp_stream_dialog.cpp time_shift_dialog.cpp diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am index 8c88d61bbd..bd3b1cbcd3 100644 --- a/ui/qt/Makefile.am +++ b/ui/qt/Makefile.am @@ -292,6 +292,7 @@ MOC_HDRS = \ stats_tree_dialog.h \ stock_icon_tool_button.h \ supported_protocols_dialog.h \ + tabnav_tree_widget.h \ tap_parameter_dialog.h \ tcp_stream_dialog.h \ time_shift_dialog.h \ @@ -585,6 +586,7 @@ WIRESHARK_QT_SRC = \ stock_icon.cpp \ stock_icon_tool_button.cpp \ supported_protocols_dialog.cpp \ + tabnav_tree_widget.cpp \ tap_parameter_dialog.cpp \ tcp_stream_dialog.cpp \ time_shift_dialog.cpp \ diff --git a/ui/qt/coloring_rules_dialog.ui b/ui/qt/coloring_rules_dialog.ui index e2c338ffeb..a8098bae7b 100644 --- a/ui/qt/coloring_rules_dialog.ui +++ b/ui/qt/coloring_rules_dialog.ui @@ -15,7 +15,7 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QTreeWidget" name="coloringRulesTreeWidget"> + <widget class="TabnavTreeWidget" name="coloringRulesTreeWidget"> <property name="selectionMode"> <enum>QAbstractItemView::ExtendedSelection</enum> </property> @@ -175,6 +175,13 @@ </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>TabnavTreeWidget</class> + <extends>QTreeWidget</extends> + <header>tabnav_tree_widget.h</header> + </customwidget> + </customwidgets> <resources> <include location="../../image/toolbar.qrc"/> </resources> diff --git a/ui/qt/tabnav_tree_widget.cpp b/ui/qt/tabnav_tree_widget.cpp new file mode 100644 index 0000000000..3d07a1cf35 --- /dev/null +++ b/ui/qt/tabnav_tree_widget.cpp @@ -0,0 +1,68 @@ +/* tabnav_tree_widget.cpp + * Tree widget with saner tab navigation properties. + * + * Copyright 2017 Peter Wu <peter@lekensteyn.nl> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "tabnav_tree_widget.h" + +// Copy on UatTreeView, modified to use QTreeWidget instead of QTreeView. + +TabnavTreeWidget::TabnavTreeWidget(QWidget *parent) : QTreeWidget(parent) +{ +} + +// Note: if a QTableWidget is used, then this is not needed anymore since Tab +// works as "expected" (move to next cell instead of row). +// Note 2: this does not help with fields with no widget (like filename). +QModelIndex TabnavTreeWidget::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) +{ + QModelIndex current = currentIndex(); + // If an item is currently selected, interpret Next/Previous. Otherwise, + // fallback to the default selection (e.g. first row for Next). + if (current.isValid()) { + if (cursorAction == MoveNext) { + if (current.column() < model()->columnCount()) { + return current.sibling(current.row(), current.column() + 1); + } + return current; + } else if (cursorAction == MovePrevious) { + if (current.column() > 0) { + return current.sibling(current.row(), current.column() - 1); + } + return current; + } + } + + return QTreeView::moveCursor(cursorAction, modifiers); +} + +/* * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/tabnav_tree_widget.h b/ui/qt/tabnav_tree_widget.h new file mode 100644 index 0000000000..781f8ecae7 --- /dev/null +++ b/ui/qt/tabnav_tree_widget.h @@ -0,0 +1,54 @@ +/* tabnav_tree_widget.h + * Tree widget with saner tab navigation properties. + * + * Copyright 2017 Peter Wu <peter@lekensteyn.nl> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef TABNAV_TREE_WIDGET_H +#define TABNAV_TREE_WIDGET_H + +#include <config.h> +#include <QTreeWidget> + +/** + * Like QTreeWidget, but instead of changing to the next row (same column) when + * pressing Tab while editing, change to the next column (same row). + */ +class TabnavTreeWidget : public QTreeWidget +{ + Q_OBJECT +public: + TabnavTreeWidget(QWidget *parent = 0); + QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); +}; +#endif // TABNAV_TREE_WIDGET_H + +/* * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |