diff options
-rw-r--r-- | ui/qt/proto_tree.cpp | 28 | ||||
-rw-r--r-- | ui/qt/proto_tree.h | 2 |
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 *); |