aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/proto_tree.cpp
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-08-26 15:30:22 +0200
committerRoland Knall <rknall@gmail.com>2019-08-26 19:39:14 +0000
commit3870e6c0365d90f53c89a3fb5537f1b9a4d6218e (patch)
treeb765b13948feeaebe8b73224c6cc3b055b457c4e /ui/qt/proto_tree.cpp
parenta7838d940339fddd85d15cacd888369c1288b337 (diff)
Qt: Make Apply/Prepare filter independent
The context menu should only use information readily available at the point of creation. Copying actions from the mainwindow introduces a bunch of synchronization and consistency issues. This is a first step to move away from a centralized approach of managing actions, towards a distributed approach. As a side effect, this also solves the old issue of having the apply items greyed out in context menu Bug: 16001 Bug: 15323 Change-Id: I10c6df11cbab0a89386f5bf1d27759103df2a012 Reviewed-on: https://code.wireshark.org/review/34370 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/proto_tree.cpp')
-rw-r--r--ui/qt/proto_tree.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp
index 4d6c228d41..80c4607d68 100644
--- a/ui/qt/proto_tree.cpp
+++ b/ui/qt/proto_tree.cpp
@@ -21,6 +21,7 @@
#include <ui/qt/widgets/drag_label.h>
#include <ui/qt/widgets/wireshark_file_dialog.h>
#include <ui/qt/show_packet_bytes_dialog.h>
+#include <ui/qt/filter_action.h>
#include <ui/all_files_wildcard.h>
#include <ui/alert_box.h>
#include "wireshark_application.h"
@@ -320,25 +321,22 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event)
ctx_menu_.addAction(action);
ctx_menu_.addSeparator();
- main_menu_item = window()->findChild<QMenu *>("menuApplyAsFilter");
- submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
- ctx_menu_.addMenu(submenu);
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFAndSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFOrSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFAndNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFOrNotSelected"));
-
- main_menu_item = window()->findChild<QMenu *>("menuPrepareAFilter");
- submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
- ctx_menu_.addMenu(submenu);
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFAndSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFOrSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFAndNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFOrNotSelected"));
+ QModelIndex index = indexAt(event->pos());
+ FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
+
+ 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->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_);
+ main_menu_item->addActions(group->actions());
+ ctx_menu_.addMenu(main_menu_item);
+ if ( selectedfilter )
+ wmem_free(Q_NULLPTR, selectedfilter);
QMenu *main_conv_menu = window()->findChild<QMenu *>("menuConversationFilter");
conv_menu_.setTitle(main_conv_menu->title());
@@ -374,8 +372,6 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event)
submenu->addAction(window()->findChild<QAction *>("actionEditCopyAsFilter"));
submenu->addSeparator();
- QModelIndex index = indexAt(event->pos());
- FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
QActionGroup * copyEntries = DataPrinter::copyActions(this, &finfo);
submenu->addActions(copyEntries->actions());