diff options
author | Roland Knall <rknall@gmail.com> | 2019-08-29 13:26:18 +0200 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2019-08-29 11:44:16 +0000 |
commit | 862e2acdd94ca38e9310f4ec9509a1108346f2bc (patch) | |
tree | b4726992a38fdf392b7096b1408bb1aabcda84d1 /ui/qt | |
parent | 6e240e6727279d47c4060695f3afaaf8e37949a3 (diff) |
Qt: Extend filterbutton context menu
The filterbutton context menu allows for appending the filter
button expression to an already existing display filter and
copying the filterbutton filter expression to the clipboard
Bug: 15980
Change-Id: I7b24007e597b9a9800729339926378d0ff264c73
Reviewed-on: https://code.wireshark.org/review/34394
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/filter_action.cpp | 24 | ||||
-rw-r--r-- | ui/qt/filter_action.h | 2 | ||||
-rw-r--r-- | ui/qt/widgets/display_filter_edit.cpp | 60 | ||||
-rw-r--r-- | ui/qt/widgets/display_filter_edit.h | 4 | ||||
-rw-r--r-- | ui/qt/widgets/filter_expression_toolbar.cpp | 18 |
5 files changed, 43 insertions, 65 deletions
diff --git a/ui/qt/filter_action.cpp b/ui/qt/filter_action.cpp index 97602f1fcc..ca884a8e95 100644 --- a/ui/qt/filter_action.cpp +++ b/ui/qt/filter_action.cpp @@ -255,6 +255,30 @@ void FilterAction::groupTriggered(QAction * action) } } +QAction * FilterAction::copyFilterAction(QString filter, QWidget *par) +{ + FilterAction * filterAction = new FilterAction(par, ActionCopy); + QAction * action = new QAction(QObject::tr("Copy"), par); + action->setProperty("filter", qVariantFromValue(filter)); + connect(action, &QAction::triggered, filterAction, &FilterAction::copyActionTriggered); + + if ( filter.isEmpty() ) + action->setEnabled(false); + + return action; +} + +void FilterAction::copyActionTriggered() +{ + QAction * sendAction = qobject_cast<QAction *>(sender()); + if ( ! sendAction ) + return; + + QString filter = sendAction->property("filter").toString(); + if ( filter.length() > 0 ) + wsApp->clipboard()->setText(filter); +} + /* * Editor modelines * diff --git a/ui/qt/filter_action.h b/ui/qt/filter_action.h index fe640cbe82..a3a4c2d5ee 100644 --- a/ui/qt/filter_action.h +++ b/ui/qt/filter_action.h @@ -74,6 +74,7 @@ public: static QActionGroup * createFilterGroup(QString filter, bool prepare, bool enabled, QWidget * parent); static QMenu * createFilterMenu(FilterAction::Action act, QString filter, bool enabled, QWidget * parent); + static QAction * copyFilterAction(QString filter, QWidget *par); signals: @@ -86,6 +87,7 @@ private: private slots: void groupTriggered(QAction *); + void copyActionTriggered(); }; diff --git a/ui/qt/widgets/display_filter_edit.cpp b/ui/qt/widgets/display_filter_edit.cpp index 50fe74f5a0..6308305597 100644 --- a/ui/qt/widgets/display_filter_edit.cpp +++ b/ui/qt/widgets/display_filter_edit.cpp @@ -23,6 +23,7 @@ #include <ui/qt/widgets/syntax_line_edit.h> #include <ui/qt/utils/wireshark_mime_data.h> #include <ui/qt/models/pref_models.h> +#include <ui/qt/filter_action.h> #include "wireshark_application.h" #include <QAction> @@ -615,63 +616,10 @@ void DisplayFilterEdit::createFilterTextDropMenu(QDropEvent *event, bool prepare if ( filterText.isEmpty() ) return; - QMenu applyMenu(this); + FilterAction::Action filterAct = prepare ? FilterAction::ActionPrepare : FilterAction::ActionApply; + QMenu * applyMenu = FilterAction::createFilterMenu(filterAct, filterText, true, this); - QAction * selAction = applyMenu.addAction(tr("Selected")); - selAction->setData(QString("%1").arg(filterText)); - selAction->setProperty("clear", qVariantFromValue(true)); - connect(selAction, &QAction::triggered, this, &DisplayFilterEdit::dropActionMenuEvent); - - QAction * notSelAction = applyMenu.addAction(tr("Not Selected")); - notSelAction->setData(QString("!(%1)").arg(filterText)); - notSelAction->setProperty("clear", qVariantFromValue(true)); - connect(notSelAction, &QAction::triggered, this, &DisplayFilterEdit::dropActionMenuEvent); - - if ( this->text().length() > 0 ) - { - QAction * andAction = applyMenu.addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "and Selected")); - andAction->setData(QString("&& %1").arg(filterText)); - connect(andAction, &QAction::triggered, this, &DisplayFilterEdit::dropActionMenuEvent); - - QAction * orAction = applyMenu.addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "or Selected")); - orAction->setData(QString("|| %1").arg(filterText)); - connect(orAction, &QAction::triggered, this, &DisplayFilterEdit::dropActionMenuEvent); - - QAction * andNotAction = applyMenu.addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "and not Selected")); - andNotAction->setData(QString("&& !(%1)").arg(filterText)); - connect(andNotAction, &QAction::triggered, this, &DisplayFilterEdit::dropActionMenuEvent); - - QAction * orNotAction = applyMenu.addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "or not Selected")); - orNotAction->setData(QString("|| !(%1)").arg(filterText)); - connect(orNotAction, &QAction::triggered, this, &DisplayFilterEdit::dropActionMenuEvent); - } - - foreach ( QAction * action, applyMenu.actions() ) - action->setProperty("prepare", qVariantFromValue(prepare)); - - applyMenu.exec(this->mapToGlobal(event->pos())); - -} - -void DisplayFilterEdit::dropActionMenuEvent() -{ - QAction * sendAction = qobject_cast<QAction *>(sender()); - if ( ! sendAction ) - return; - - QString value = sendAction->data().toString(); - bool prepare = sendAction->property("prepare").toBool(); - - QString filterText; - if ( sendAction->property("clear").toBool() ) - filterText = value; - else - filterText = QString("((%1) %2)").arg(this->text()).arg(value); - setText(filterText); - - // Holding down the Shift key will only prepare filter. - if ( ! prepare ) - applyDisplayFilter(); + applyMenu->exec(this->mapToGlobal(event->pos())); } /* diff --git a/ui/qt/widgets/display_filter_edit.h b/ui/qt/widgets/display_filter_edit.h index 85ea801433..7e5bcd68bb 100644 --- a/ui/qt/widgets/display_filter_edit.h +++ b/ui/qt/widgets/display_filter_edit.h @@ -77,10 +77,6 @@ signals: void filterPackets(QString new_filter, bool force); void showPreferencesDialog(QString pane_name); -private slots: - - void dropActionMenuEvent(); - }; #endif // DISPLAYFILTEREDIT_H diff --git a/ui/qt/widgets/filter_expression_toolbar.cpp b/ui/qt/widgets/filter_expression_toolbar.cpp index 89cf3b648f..b12c508cd5 100644 --- a/ui/qt/widgets/filter_expression_toolbar.cpp +++ b/ui/qt/widgets/filter_expression_toolbar.cpp @@ -11,6 +11,7 @@ #include <ui/qt/utils/color_utils.h> #include <ui/qt/utils/qt_ui_utils.h> #include <ui/qt/models/uat_model.h> +#include <ui/qt/filter_action.h> #include <ui/qt/wireshark_application.h> #include <epan/filter_expressions.h> @@ -70,11 +71,11 @@ void FilterExpressionToolBar::onCustomMenuHandler(const QPoint& pos) QMenu * filterMenu = new QMenu(this); - QAction *actFilter = filterMenu->addAction(tr("Filter Button Preferences...")); - connect(actFilter, &QAction::triggered, this, &FilterExpressionToolBar::toolBarShowPreferences); - actFilter->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); - actFilter->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); - actFilter->setData(filterAction->data()); + QString filterText = filterAction->property(dfe_property_expression_).toString(); + filterMenu->addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, filterText, true, this)); + filterMenu->addMenu(FilterAction::createFilterMenu(FilterAction::ActionPrepare, filterText, true, this)); + filterMenu->addSeparator(); + filterMenu->addAction(FilterAction::copyFilterAction(filterText, this)); filterMenu->addSeparator(); QAction * actEdit = filterMenu->addAction(tr("Edit")); connect(actEdit, &QAction::triggered, this, &FilterExpressionToolBar::editFilter); @@ -91,6 +92,13 @@ void FilterExpressionToolBar::onCustomMenuHandler(const QPoint& pos) actRemove->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); actRemove->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); actRemove->setData(filterAction->data()); + filterMenu->addSeparator(); + QAction *actFilter = filterMenu->addAction(tr("Filter Button Preferences...")); + connect(actFilter, &QAction::triggered, this, &FilterExpressionToolBar::toolBarShowPreferences); + actFilter->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); + actFilter->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); + actFilter->setData(filterAction->data()); + filterMenu->exec(mapToGlobal(pos)); } |