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>
This commit is contained in:
parent
6e240e6727
commit
862e2acdd9
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -77,10 +77,6 @@ signals:
|
|||
void filterPackets(QString new_filter, bool force);
|
||||
void showPreferencesDialog(QString pane_name);
|
||||
|
||||
private slots:
|
||||
|
||||
void dropActionMenuEvent();
|
||||
|
||||
};
|
||||
|
||||
#endif // DISPLAYFILTEREDIT_H
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue