From 9f7b8713fa8286611e84a68f82adc2d494b21173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Mon, 18 Dec 2017 10:25:03 +0100 Subject: Qt: Add Collapse Subtrees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This item is missing from the Qt port. Change-Id: Iacc18a7c2eb2368d6566622788a4e900868d446e Reviewed-on: https://code.wireshark.org/review/24879 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- ui/qt/main_window.cpp | 2 ++ ui/qt/main_window.ui | 15 +++++++++++++++ ui/qt/main_window_slots.cpp | 1 + ui/qt/proto_tree.cpp | 23 +++++++++++++++++++++++ ui/qt/proto_tree.h | 1 + 5 files changed, 42 insertions(+) diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 568a3ebf4c..a571370551 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -672,6 +672,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(main_ui_->actionViewExpandSubtrees, SIGNAL(triggered()), proto_tree_, SLOT(expandSubtrees())); + connect(main_ui_->actionViewCollapseSubtrees, SIGNAL(triggered()), + proto_tree_, SLOT(collapseSubtrees())); connect(main_ui_->actionViewExpandAll, SIGNAL(triggered()), proto_tree_, SLOT(expandAll())); connect(main_ui_->actionViewCollapseAll, SIGNAL(triggered()), diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index 17d5d3242c..87ecfdd379 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -369,6 +369,7 @@ + @@ -1067,6 +1068,20 @@ Shift+Right + + + false + + + Collapse Subtrees + + + Collapse the current packet detail + + + Shift+Left + + &Expand All diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index b83ad46bba..2f5ff9dc8e 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1451,6 +1451,7 @@ void MainWindow::setMenusForSelectedTreeRow(FieldInformation *finfo) { main_ui_->actionFileExportPacketBytes->setEnabled(have_packet_bytes); main_ui_->actionViewExpandSubtrees->setEnabled(have_subtree); + main_ui_->actionViewCollapseSubtrees->setEnabled(have_subtree); main_ui_->actionGoGoToLinkedPacket->setEnabled(is_framenum); diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index 2b91b1c37d..b64e89e1b9 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -60,6 +60,7 @@ ProtoTree::ProtoTree(QWidget *parent) : QAction *action; ctx_menu_.addAction(window()->findChild("actionViewExpandSubtrees")); + ctx_menu_.addAction(window()->findChild("actionViewCollapseSubtrees")); ctx_menu_.addAction(window()->findChild("actionViewExpandAll")); ctx_menu_.addAction(window()->findChild("actionViewCollapseAll")); ctx_menu_.addSeparator(); @@ -389,6 +390,28 @@ void ProtoTree::expandSubtrees() updateContentWidth(); } +void ProtoTree::collapseSubtrees() +{ + if (!selectionModel()->hasSelection()) return; + + QStack index_stack; + index_stack.push(selectionModel()->selectedIndexes().first()); + + while (!index_stack.isEmpty()) { + QModelIndex index = index_stack.pop(); + collapse(index); + int row_count = proto_tree_model_->rowCount(index); + for (int row = row_count - 1; row >= 0; row--) { + QModelIndex child = proto_tree_model_->index(row, 0, index); + if (proto_tree_model_->hasChildren(child)) { + index_stack.push(child); + } + } + } + + updateContentWidth(); +} + void ProtoTree::expandAll() { for(int i = 0; i < num_tree_types; i++) { diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h index 2a9da487c2..6254e62521 100644 --- a/ui/qt/proto_tree.h +++ b/ui/qt/proto_tree.h @@ -79,6 +79,7 @@ public slots: void expand(const QModelIndex & index); void collapse(const QModelIndex & index); void expandSubtrees(); + void collapseSubtrees(); void expandAll(); void collapseAll(); void itemDoubleClicked(const QModelIndex & index); -- cgit v1.2.3