From c9361120f0a7544d0fc95a24d0e51aaaaf09c89a Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Mon, 26 Aug 2019 16:30:05 +0200 Subject: Qt: Remove unnecessary code for context menus This code is no longer required, as context menus should be bound to local events. As for "Reloading LUA plugins" - the keyboard shortcut would be able to trigger while the menu is open, except Qt explicitely prevents that Change-Id: Id18a3a17d62bae1ff547a6ef96772e12a2535219 Reviewed-on: https://code.wireshark.org/review/34371 Petri-Dish: Roland Knall Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- ui/qt/main_window_slots.cpp | 1 - ui/qt/packet_list.cpp | 54 +++++++++++++++++------------------ ui/qt/packet_list.h | 1 - ui/qt/proto_tree.cpp | 69 +++++++++++++++++++++------------------------ ui/qt/proto_tree.h | 2 -- 5 files changed, 59 insertions(+), 68 deletions(-) diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 21a6d5477e..aab4c23384 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1470,7 +1470,6 @@ void MainWindow::reloadLuaPlugins() closePacketDialogs(); // Preferences may have been deleted so close all widgets using prefs - proto_tree_->closeContextMenu(); main_ui_->preferenceEditorFrame->animatedHide(); wsApp->readConfigurationFiles(true); diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 3e52a027a9..ee4ba6d47f 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -486,23 +486,23 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event) FrameInformation * frameData = new FrameInformation(new CaptureFile(this, cap_file_), packet_list_model_->getRowFdata(ctxIndex.row())); - ctx_menu_.clear(); + QMenu ctx_menu(this); // XXX We might want to reimplement setParent() and fill in the context // menu there. - ctx_menu_.addAction(window()->findChild("actionEditMarkPacket")); - ctx_menu_.addAction(window()->findChild("actionEditIgnorePacket")); - ctx_menu_.addAction(window()->findChild("actionEditSetTimeReference")); - ctx_menu_.addAction(window()->findChild("actionEditTimeShift")); - ctx_menu_.addAction(window()->findChild("actionEditPacketComment")); + ctx_menu.addAction(window()->findChild("actionEditMarkPacket")); + ctx_menu.addAction(window()->findChild("actionEditIgnorePacket")); + ctx_menu.addAction(window()->findChild("actionEditSetTimeReference")); + ctx_menu.addAction(window()->findChild("actionEditTimeShift")); + ctx_menu.addAction(window()->findChild("actionEditPacketComment")); - ctx_menu_.addSeparator(); + ctx_menu.addSeparator(); - ctx_menu_.addAction(window()->findChild("actionViewEditResolvedName")); - ctx_menu_.addSeparator(); + ctx_menu.addAction(window()->findChild("actionViewEditResolvedName")); + ctx_menu.addSeparator(); QMenu *main_menu_item = window()->findChild("menuApplyAsFilter"); - QMenu *submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + QMenu *submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); submenu->addAction(window()->findChild("actionAnalyzeAAFSelected")); submenu->addAction(window()->findChild("actionAnalyzeAAFNotSelected")); submenu->addAction(window()->findChild("actionAnalyzeAAFAndSelected")); @@ -511,8 +511,8 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event) submenu->addAction(window()->findChild("actionAnalyzeAAFOrNotSelected")); main_menu_item = window()->findChild("menuPrepareAFilter"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); submenu->addAction(window()->findChild("actionAnalyzePAFSelected")); submenu->addAction(window()->findChild("actionAnalyzePAFNotSelected")); submenu->addAction(window()->findChild("actionAnalyzePAFAndSelected")); @@ -524,34 +524,34 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event) main_menu_item = window()->findChild(conv_menu_name); conv_menu_.setTitle(main_menu_item->title()); conv_menu_.setObjectName(conv_menu_name); - ctx_menu_.addMenu(&conv_menu_); + ctx_menu.addMenu(&conv_menu_); const char *colorize_menu_name = "menuColorizeConversation"; main_menu_item = window()->findChild(colorize_menu_name); colorize_menu_.setTitle(main_menu_item->title()); colorize_menu_.setObjectName(colorize_menu_name); - ctx_menu_.addMenu(&colorize_menu_); + ctx_menu.addMenu(&colorize_menu_); main_menu_item = window()->findChild("menuSCTP"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); submenu->addAction(window()->findChild("actionSCTPAnalyseThisAssociation")); submenu->addAction(window()->findChild("actionSCTPShowAllAssociations")); submenu->addAction(window()->findChild("actionSCTPFilterThisAssociation")); main_menu_item = window()->findChild("menuFollow"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); submenu->addAction(window()->findChild("actionAnalyzeFollowTCPStream")); submenu->addAction(window()->findChild("actionAnalyzeFollowUDPStream")); submenu->addAction(window()->findChild("actionAnalyzeFollowTLSStream")); submenu->addAction(window()->findChild("actionAnalyzeFollowHTTPStream")); - ctx_menu_.addSeparator(); + ctx_menu.addSeparator(); main_menu_item = window()->findChild("menuEditCopy"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); QAction * action = submenu->addAction(tr("Summary as Text")); action->setData(copy_summary_text_); @@ -572,13 +572,13 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event) copyEntries->setParent(submenu); frameData->setParent(submenu); - ctx_menu_.addSeparator(); - ctx_menu_.addMenu(&proto_prefs_menu_); + ctx_menu.addSeparator(); + ctx_menu.addMenu(&proto_prefs_menu_); decode_as_ = window()->findChild("actionAnalyzeDecodeAs"); - ctx_menu_.addAction(decode_as_); + ctx_menu.addAction(decode_as_); // "Print" not ported intentionally action = window()->findChild("actionViewShowPacketInNewWindow"); - ctx_menu_.addAction(action); + ctx_menu.addAction(action); decode_as_->setData(QVariant::fromValue(true)); @@ -588,7 +588,7 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event) else emit frameSelected(-1); - ctx_menu_.exec(event->globalPos()); + ctx_menu.exec(event->globalPos()); decode_as_->setData(QVariant()); } diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h index 65694286e6..e8be4b5b6a 100644 --- a/ui/qt/packet_list.h +++ b/ui/qt/packet_list.h @@ -88,7 +88,6 @@ private: PacketListHeader * packet_list_header_; ProtoTree *proto_tree_; capture_file *cap_file_; - QMenu ctx_menu_; QMenu conv_menu_; QMenu colorize_menu_; ProtocolPreferencesMenu proto_prefs_menu_; diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index 80c4607d68..81dbd45bfd 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -101,11 +101,6 @@ void ProtoTree::clear() { updateContentWidth(); } -void ProtoTree::closeContextMenu() -{ - ctx_menu_.close(); -} - void ProtoTree::protoTreeContextMenu(QContextMenuEvent * event) { QMenu ctxMenu(this); @@ -306,20 +301,20 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) return; } - ctx_menu_.clear(); + QMenu ctx_menu(this); QMenu *main_menu_item, *submenu; 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(); + 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(); action = window()->findChild("actionAnalyzeCreateAColumn"); - ctx_menu_.addAction(action); - ctx_menu_.addSeparator(); + ctx_menu.addAction(action); + ctx_menu.addSeparator(); QModelIndex index = indexAt(event->pos()); FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode()); @@ -327,14 +322,14 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) epan_dissect_t *edt = cap_file_ ? cap_file_->edt : edt_; char * selectedfilter = proto_construct_match_selected_string(finfo.fieldInfo(), edt); bool can_match_selected = proto_can_match_selected(finfo.fieldInfo(), edt); - main_menu_item = new QMenu(tr("Apply as Filter"), &ctx_menu_); - QActionGroup * group = FilterAction::createFilterGroup(selectedfilter, false, can_match_selected, &ctx_menu_); + main_menu_item = new QMenu(tr("Apply as Filter"), &ctx_menu); + QActionGroup * group = FilterAction::createFilterGroup(selectedfilter, false, can_match_selected, &ctx_menu); main_menu_item->addActions(group->actions()); - ctx_menu_.addMenu(main_menu_item); - main_menu_item = new QMenu(tr("Prepare as Filter"), &ctx_menu_); - group = FilterAction::createFilterGroup(selectedfilter, true, can_match_selected, &ctx_menu_); + ctx_menu.addMenu(main_menu_item); + main_menu_item = new QMenu(tr("Prepare as Filter"), &ctx_menu); + group = FilterAction::createFilterGroup(selectedfilter, true, can_match_selected, &ctx_menu); main_menu_item->addActions(group->actions()); - ctx_menu_.addMenu(main_menu_item); + ctx_menu.addMenu(main_menu_item); if ( selectedfilter ) wmem_free(Q_NULLPTR, selectedfilter); @@ -345,23 +340,23 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) conv_menu_.addAction(action); } - ctx_menu_.addMenu(&conv_menu_); + ctx_menu.addMenu(&conv_menu_); colorize_menu_.setTitle(tr("Colorize with Filter")); - ctx_menu_.addMenu(&colorize_menu_); + ctx_menu.addMenu(&colorize_menu_); main_menu_item = window()->findChild("menuFollow"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); submenu->addAction(window()->findChild("actionAnalyzeFollowTCPStream")); submenu->addAction(window()->findChild("actionAnalyzeFollowUDPStream")); submenu->addAction(window()->findChild("actionAnalyzeFollowTLSStream")); submenu->addAction(window()->findChild("actionAnalyzeFollowHTTPStream")); - ctx_menu_.addSeparator(); + ctx_menu.addSeparator(); main_menu_item = window()->findChild("menuEditCopy"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu_); - ctx_menu_.addMenu(submenu); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); submenu->addAction(window()->findChild("actionCopyAllVisibleItems")); submenu->addAction(window()->findChild("actionCopyAllVisibleSelectedTreeItems")); submenu->addAction(window()->findChild("actionEditCopyDescription")); @@ -376,23 +371,23 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) submenu->addActions(copyEntries->actions()); action = window()->findChild("actionAnalyzeShowPacketBytes"); - ctx_menu_.addAction(action); + ctx_menu.addAction(action); action = window()->findChild("actionFileExportPacketBytes"); - ctx_menu_.addAction(action); + ctx_menu.addAction(action); - ctx_menu_.addSeparator(); + ctx_menu.addSeparator(); action = window()->findChild("actionContextWikiProtocolPage"); - ctx_menu_.addAction(action); + ctx_menu.addAction(action); action = window()->findChild("actionContextFilterFieldReference"); - ctx_menu_.addAction(action); - ctx_menu_.addMenu(&proto_prefs_menu_); - ctx_menu_.addSeparator(); + ctx_menu.addAction(action); + ctx_menu.addMenu(&proto_prefs_menu_); + ctx_menu.addSeparator(); decode_as_ = window()->findChild("actionAnalyzeDecodeAs"); - ctx_menu_.addAction(decode_as_); + ctx_menu.addAction(decode_as_); - ctx_menu_.addAction(window()->findChild("actionGoGoToLinkedPacket")); - ctx_menu_.addAction(window()->findChild("actionContextShowLinkedPacketInNewWindow")); + ctx_menu.addAction(window()->findChild("actionGoGoToLinkedPacket")); + ctx_menu.addAction(window()->findChild("actionContextShowLinkedPacketInNewWindow")); // The "text only" header field will not give preferences for the selected protocol. // Use parent in this case. @@ -405,7 +400,7 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) decode_as_->setData(QVariant::fromValue(true)); - ctx_menu_.exec(event->globalPos()); + ctx_menu.exec(event->globalPos()); decode_as_->setData(QVariant()); } diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h index 4fee161cc8..e4794796d8 100644 --- a/ui/qt/proto_tree.h +++ b/ui/qt/proto_tree.h @@ -36,7 +36,6 @@ public: void autoScrollTo(const QModelIndex &index); void goToHfid(int hfid); void clear(); - void closeContextMenu(); void restoreSelectedField(); QString toString(const QModelIndex &start_idx = QModelIndex()) const; @@ -59,7 +58,6 @@ protected: private: ProtoTreeModel *proto_tree_model_; - QMenu ctx_menu_; QMenu conv_menu_; QMenu colorize_menu_; ProtocolPreferencesMenu proto_prefs_menu_; -- cgit v1.2.3