aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/filter_action.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/filter_action.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/filter_action.cpp')
-rw-r--r--ui/qt/filter_action.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/ui/qt/filter_action.cpp b/ui/qt/filter_action.cpp
index 5c5db557f5..490350d1df 100644
--- a/ui/qt/filter_action.cpp
+++ b/ui/qt/filter_action.cpp
@@ -9,6 +9,9 @@
#include "filter_action.h"
+#include <ui/qt/wireshark_application.h>
+#include <ui/qt/main_window.h>
+
FilterAction::FilterAction(QObject *parent, FilterAction::Action action, FilterAction::ActionType type, FilterAction::ActionDirection direction) :
QAction(parent),
action_(action),
@@ -176,6 +179,55 @@ const QString FilterAction::actionDirectionName(ActionDirection direction) {
}
}
+QActionGroup * FilterAction::createFilterGroup(QString filter, bool prepare, bool enabled, QWidget * parent)
+{
+ if ( filter.isEmpty() )
+ return Q_NULLPTR;
+
+ FilterAction * filterAction = new FilterAction(parent, prepare ? FilterAction::ActionPrepare : FilterAction::ActionApply);
+
+ QActionGroup * group = new QActionGroup(parent);
+ group->setProperty("filter", filter);
+ group->setProperty("filterAction", prepare ? FilterAction::ActionPrepare : FilterAction::ActionApply);
+ QAction * action = group->addAction(tr("Selected"));
+ action->setProperty("filterType", FilterAction::ActionTypePlain);
+ action = group->addAction(tr("Not Selected"));
+ action->setProperty("filterType", FilterAction::ActionTypeNot);
+ action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "and Selected"));
+ action->setProperty("filterType", FilterAction::ActionTypeAnd);
+ action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "or Selected"));
+ action->setProperty("filterType", FilterAction::ActionTypeOr);
+ action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "and not Selected"));
+ action->setProperty("filterType", FilterAction::ActionTypeAndNot);
+ action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "or not Selected"));
+ action->setProperty("filterType", FilterAction::ActionTypeOrNot);
+ group->setEnabled(enabled);
+ connect(group, &QActionGroup::triggered, filterAction, &FilterAction::groupTriggered);
+
+ return group;
+}
+
+void FilterAction::groupTriggered(QAction * action)
+{
+ if ( action && wsApp )
+ {
+ if ( action->property("filterType").canConvert<FilterAction::ActionType>() &&
+ sender()->property("filterAction").canConvert<FilterAction::Action>() )
+ {
+ FilterAction::Action act = sender()->property("filterAction").value<FilterAction::Action>();
+ FilterAction::ActionType type = action->property("filterType").value<FilterAction::ActionType>();
+ QString filter = sender()->property("filter").toString();
+
+ QWidget * mainWin = wsApp->mainWindow();
+ if ( qobject_cast<MainWindow *>(mainWin) )
+ {
+ MainWindow * mw = qobject_cast<MainWindow *>(mainWin);
+ mw->setDisplayFilter(filter, act, type);
+ }
+ }
+ }
+}
+
/*
* Editor modelines
*