From 145e3a5dc3ad2c8191696fa4748b1f3d8352252c Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Fri, 19 Jan 2018 11:02:07 -0800 Subject: [PATCH] Qt: Proto tree fixes Make sure ProtoTree::toString stops at the right place. Don't emit fieldSelected when we're processing a context menu event. It doesn't appear to be needed and it triggers unwanted automatic scrolling when prefs.gui_auto_scroll_on_expand is enabled. Change-Id: I351a6974d07aea6fdd3eb0b5c1975a1b8d8eb7da Reviewed-on: https://code.wireshark.org/review/25396 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- ui/qt/proto_tree.cpp | 9 ++++----- ui/qt/proto_tree.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index 12eb589c8e..ccd407d567 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -183,8 +183,6 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) decode_as_->setData(QVariant::fromValue(true)); - // Set menu sensitivity and action data. - emit fieldSelected(&finfo); ctx_menu_.exec(event->globalPos()); decode_as_->setData(QVariant()); } @@ -499,9 +497,10 @@ void ProtoTree::restoreSelectedField() autoScrollTo(cur_index); } -const QString ProtoTree::toString(const QModelIndex &index) const +const QString ProtoTree::toString(const QModelIndex &start_idx) const { - QModelIndex cur_idx = index.isValid() ? index : proto_tree_model_->index(0, 0); + QModelIndex cur_idx = start_idx.isValid() ? start_idx : proto_tree_model_->index(0, 0); + QModelIndex stop_idx = proto_tree_model_->index(cur_idx.row() + 1, 0, cur_idx.parent()); QString tree_string; int indent_level = 0; @@ -524,7 +523,7 @@ const QString ProtoTree::toString(const QModelIndex &index) const // Next parent cur_idx = proto_tree_model_->index(cur_idx.parent().row() + 1, 0, cur_idx.parent().parent()); indent_level--; - } while (cur_idx.isValid() && cur_idx != index && indent_level >= 0); + } while (cur_idx.isValid() && cur_idx.internalPointer() != stop_idx.internalPointer() && indent_level >= 0); return tree_string; } diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h index 8c6e891e22..7190eae0fb 100644 --- a/ui/qt/proto_tree.h +++ b/ui/qt/proto_tree.h @@ -38,7 +38,7 @@ public: void clear(); void closeContextMenu(); void restoreSelectedField(); - const QString toString(const QModelIndex &index = QModelIndex()) const; + const QString toString(const QModelIndex &start_idx = QModelIndex()) const; protected: virtual void contextMenuEvent(QContextMenuEvent *event);