diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-01-30 14:59:35 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-01-31 04:54:36 +0000 |
commit | 47e1798762478ae19354297e5a95d46487cafd42 (patch) | |
tree | cbce2a3fd69d82cd935a59ea15d60b9bd7afdb08 /ui/qt/proto_tree.cpp | |
parent | 55e74ba841126797b2a5b82142fb1db8f61a1288 (diff) |
Qt: Byte view and proto tree fixes.
Select our byte field only when we enter marked / locked mode.
Emit fieldSelected from autoScrollTo so that we always set the marked
protocol.
Don't clobber the current index in saveSelectedField.
Change-Id: I967b20608f991a5f3e6a0979b1f702f874ce27b4
Reviewed-on: https://code.wireshark.org/review/25521
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/proto_tree.cpp')
-rw-r--r-- | ui/qt/proto_tree.cpp | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index ccd407d567..ae5f0c49b6 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -32,7 +32,6 @@ #include <QWindow> #endif - // To do: // - Fix "apply as filter" behavior. @@ -283,6 +282,22 @@ void ProtoTree::autoScrollTo(const QModelIndex &index) return; } + // Find and highlight the protocol bytes. select above won't call + // selectionChanged if the current and selected indexes are the same + // so we do this here. + FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode(), this); + if (finfo.isValid()) { + QModelIndex parent = index; + while (parent.isValid() && parent.parent().isValid()) { + parent = parent.parent(); + } + if (parent.isValid()) { + FieldInformation parent_finfo(proto_tree_model_->protoNodeFromIndex(parent).protoNode()); + finfo.setParentField(parent_finfo.fieldInfo()); + } + emit fieldSelected(&finfo); + } + ScrollHint scroll_hint = PositionAtTop; if (prefs.gui_auto_scroll_percentage > 66) { scroll_hint = PositionAtBottom; @@ -305,44 +320,7 @@ void ProtoTree::selectionChanged(const QItemSelection &selected, const QItemSele if (selected.isEmpty()) return; QModelIndex index = selected.indexes().first(); - - FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode(), this); - if (!finfo.isValid()) return; - - // Find and highlight the protocol bytes - QModelIndex parent = index; - while (parent.isValid() && parent.parent().isValid()) { - parent = parent.parent(); - } - if (parent.isValid()) { - FieldInformation parent_finfo(proto_tree_model_->protoNodeFromIndex(parent).protoNode()); - finfo.setParentField(parent_finfo.fieldInfo()); - } - - if ( finfo.isValid() ) - { - saveSelectedField(index); - emit fieldSelected(&finfo); - } - // else the GTK+ version pushes an empty string as described below. - /* - * Don't show anything if the field name is zero-length; - * the pseudo-field for text-only items is such - * a field, and we don't want "Text (text)" showing up - * on the status line if you've selected such a field. - * - * XXX - there are zero-length fields for which we *do* - * want to show the field name. - * - * XXX - perhaps the name and abbrev field should be null - * pointers rather than null strings for that pseudo-field, - * but we'd have to add checks for null pointers in some - * places if we did that. - * - * Or perhaps text-only items should have -1 as the field - * index, with no pseudo-field being used, but that might - * also require special checks for -1 to be added. - */ + saveSelectedField(index); } void ProtoTree::syncExpanded(const QModelIndex &index) { @@ -468,11 +446,12 @@ void ProtoTree::selectedFieldChanged(FieldInformation *finfo) void ProtoTree::saveSelectedField(QModelIndex &index) { selected_hfid_path_.clear(); - while (index.isValid()) { - FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode()); + QModelIndex save_index = index; + while (save_index.isValid()) { + FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(save_index).protoNode()); if (!finfo.isValid()) break; - selected_hfid_path_.prepend(QPair<int,int>(index.row(), finfo.headerInfo().id)); - index = index.parent(); + selected_hfid_path_.prepend(QPair<int,int>(save_index.row(), finfo.headerInfo().id)); + save_index = save_index.parent(); } } |