aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-01-14 12:23:07 -0800
committerRoland Knall <rknall@gmail.com>2018-01-15 08:41:23 +0000
commit2f31016e6c292899c36f90c736c0c84fbe9ee539 (patch)
tree071cd06e698f35d881c38390e6219538f44241dd /ui/qt
parente2ab8151b6255dce8f3e841f9b17e487f4ba05d2 (diff)
Qt: Expand subtrees when a packet is selected.
ProtoTree::rowsInserted was expanding top-level items properly but not subtrees. Make sure we do so. Bug: 14340 Change-Id: I6c73fd09643b52d43014352816d0dd4838dbcb1d Reviewed-on: https://code.wireshark.org/review/25316 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/proto_tree.cpp28
-rw-r--r--ui/qt/proto_tree.h2
2 files changed, 27 insertions, 3 deletions
diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp
index 6ce06c6196..902a52df2c 100644
--- a/ui/qt/proto_tree.cpp
+++ b/ui/qt/proto_tree.cpp
@@ -236,6 +236,7 @@ void ProtoTree::setMonospaceFont(const QFont &mono_font)
void ProtoTree::setRootNode(proto_node *root_node) {
setFont(mono_font_);
+ reset(); // clears expandedIndexes.
proto_tree_model_->setRootNode(root_node);
updateContentWidth();
}
@@ -570,14 +571,35 @@ bool ProtoTree::eventFilter(QObject * obj, QEvent * event)
return QTreeView::eventFilter(obj, event);
}
+void ProtoTree::foreachSyncExpansion(proto_node *node, gpointer proto_tree_ptr)
+{
+ if (!tree_expanded(node->finfo->tree_type)) {
+ return;
+ }
+
+ ProtoTree *proto_tree = static_cast<ProtoTree *>(proto_tree_ptr);
+ if (!proto_tree) {
+ return;
+ }
+
+ ProtoNode expand_node = ProtoNode(node);
+ proto_tree->setExpanded(proto_tree->proto_tree_model_->indexFromProtoNode(expand_node), true);
+ proto_tree_children_foreach(node, foreachSyncExpansion, proto_tree_ptr);
+}
+
+// We track item expansion using proto.c:tree_is_expanded. QTreeView
+// tracks it using QTreeViewPrivate::expandedIndexes. When we're handed
+// a new tree, clear expandedIndexes (which we do above in setRootNode)
+// and repopulate it by walking the tree and calling
+// QTreeView::setExpanded.
void ProtoTree::rowsInserted(const QModelIndex &parent, int start, int end)
{
for (int row = start; row <= end; row++) {
QModelIndex index = proto_tree_model_->index(row, 0, parent);
- if (proto_tree_model_->protoNodeFromIndex(index).isExpanded()) {
- QTreeView::setExpanded(index, true);
- }
+ ProtoNode row_node = proto_tree_model_->protoNodeFromIndex(index);
+ proto_tree_children_foreach(row_node.protoNode(), foreachSyncExpansion, this);
}
+ QTreeView::rowsInserted(parent, start, end);
}
/*
diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h
index 6254e62521..57729623c1 100644
--- a/ui/qt/proto_tree.h
+++ b/ui/qt/proto_tree.h
@@ -23,6 +23,7 @@
#include <QMenu>
class ProtoTreeModel;
+class ProtoNode;
class ProtoTree : public QTreeView
{
@@ -62,6 +63,7 @@ private:
capture_file *cap_file_;
void saveSelectedField(QModelIndex &index);
+ static void foreachSyncExpansion(proto_node *node, gpointer proto_tree_ptr);
signals:
void fieldSelected(FieldInformation *);