Qt: Move FilterToolBar to a separate class
Remove all filter toolbar related stuff into a separate class and away from MainWindow Change-Id: I36d937be6c2686b16a8d494213dc740d8d28efcb Reviewed-on: https://code.wireshark.org/review/28432 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
5404cbbc7f
commit
3a514caaf1
|
@ -27,6 +27,7 @@ set(WIRESHARK_WIDGET_HEADERS
|
|||
widgets/export_objects_view.h
|
||||
widgets/elided_label.h
|
||||
widgets/field_filter_edit.h
|
||||
widgets/filter_expression_toolbar.h
|
||||
widgets/find_line_edit.h
|
||||
widgets/follow_stream_text.h
|
||||
widgets/interface_toolbar_lineedit.h
|
||||
|
@ -248,6 +249,7 @@ set(WIRESHARK_WIDGET_SRCS
|
|||
widgets/expert_info_view.cpp
|
||||
widgets/export_objects_view.cpp
|
||||
widgets/field_filter_edit.cpp
|
||||
widgets/filter_expression_toolbar.cpp
|
||||
widgets/find_line_edit.cpp
|
||||
widgets/follow_stream_text.cpp
|
||||
widgets/interface_toolbar_lineedit.cpp
|
||||
|
|
|
@ -67,7 +67,7 @@ DIAG_ON(frame-larger-than=)
|
|||
|
||||
#include <ui/qt/widgets/additional_toolbar.h>
|
||||
#include <ui/qt/widgets/display_filter_edit.h>
|
||||
#include <ui/qt/widgets/drag_drop_toolbar.h>
|
||||
#include <ui/qt/widgets/filter_expression_toolbar.h>
|
||||
|
||||
#include <ui/qt/utils/color_utils.h>
|
||||
#include <ui/qt/utils/qt_ui_utils.h>
|
||||
|
@ -400,28 +400,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
// Make sure filter expressions overflow into a menu instead of a
|
||||
// larger toolbar. We do this by adding them to a child toolbar.
|
||||
// https://bugreports.qt.io/browse/QTBUG-2472
|
||||
filter_expression_toolbar_ = new DragDropToolBar();
|
||||
// Try to draw 1-pixel-wide separator lines from the button label
|
||||
// ascent to its baseline.
|
||||
int sep_margin = (filter_expression_toolbar_->fontMetrics().height() * 0.5) - 1;
|
||||
QColor sep_color = ColorUtils::alphaBlend(filter_expression_toolbar_->palette().text(),
|
||||
filter_expression_toolbar_->palette().base(), 0.3);
|
||||
filter_expression_toolbar_->setStyleSheet(QString(
|
||||
"QToolBar { background: none; border: none; spacing: 1px; }"
|
||||
"QFrame {"
|
||||
" min-width: 1px; max-width: 1px;"
|
||||
" margin: %1px 0 %2px 0; padding: 0;"
|
||||
" background-color: %3;"
|
||||
"}"
|
||||
).arg(sep_margin).arg(sep_margin - 1).arg(sep_color.name()));
|
||||
|
||||
filter_expression_toolbar_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(filter_expression_toolbar_, SIGNAL(customContextMenuRequested(QPoint)),
|
||||
this, SLOT(filterToolbarCustomMenuHandler(QPoint)));
|
||||
connect(filter_expression_toolbar_, SIGNAL(actionMoved(QAction*, int, int)),
|
||||
this, SLOT(filterToolbarActionMoved(QAction*, int, int)));
|
||||
connect(filter_expression_toolbar_, SIGNAL(newFilterDropped(QString, QString)),
|
||||
this, SLOT(filterDropped(QString, QString)));
|
||||
filter_expression_toolbar_ = new FilterExpressionToolBar(this);
|
||||
connect(filter_expression_toolbar_, &FilterExpressionToolBar::filterPreferences, this, &MainWindow::onFilterPreferences);
|
||||
connect(filter_expression_toolbar_, &FilterExpressionToolBar::filterSelected, this, &MainWindow::onFilterSelected);
|
||||
connect(filter_expression_toolbar_, &FilterExpressionToolBar::filterEdit, this, &MainWindow::onFilterEdit);
|
||||
|
||||
main_ui_->displayFilterToolBar->addWidget(filter_expression_toolbar_);
|
||||
|
||||
|
@ -561,10 +543,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
this, SLOT(updateRecentActions()));
|
||||
connect(wsApp, SIGNAL(packetDissectionChanged()),
|
||||
this, SLOT(redissectPackets()), Qt::QueuedConnection);
|
||||
connect(wsApp, SIGNAL(appInitialized()),
|
||||
this, SLOT(filterExpressionsChanged()));
|
||||
connect(wsApp, SIGNAL(filterExpressionsChanged()),
|
||||
this, SLOT(filterExpressionsChanged()));
|
||||
|
||||
connect(wsApp, SIGNAL(checkDisplayFilter()),
|
||||
this, SLOT(checkDisplayFilter()));
|
||||
connect(wsApp, SIGNAL(fieldsChanged()),
|
||||
|
@ -595,7 +574,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(main_ui_->filterExpressionFrame, SIGNAL(showPreferencesDialog(QString)),
|
||||
this, SLOT(showPreferencesDialog(QString)));
|
||||
connect(main_ui_->filterExpressionFrame, SIGNAL(filterExpressionsChanged()),
|
||||
this, SLOT(filterExpressionsChanged()));
|
||||
filter_expression_toolbar_, SLOT(filterExpressionsChanged()));
|
||||
|
||||
/* Connect change of capture file */
|
||||
connect(this, SIGNAL(setCaptureFile(capture_file*)),
|
||||
|
|
|
@ -85,7 +85,7 @@ class WelcomePage;
|
|||
class PacketList;
|
||||
class ProtoTree;
|
||||
class WirelessFrame;
|
||||
class DragDropToolBar;
|
||||
class FilterExpressionToolBar;
|
||||
|
||||
class QAction;
|
||||
class QActionGroup;
|
||||
|
@ -186,7 +186,7 @@ private:
|
|||
QPointer<QWidget> freeze_focus_;
|
||||
QMap<QAction *, ts_type> td_actions;
|
||||
QMap<QAction *, ts_precision> tp_actions;
|
||||
DragDropToolBar *filter_expression_toolbar_;
|
||||
FilterExpressionToolBar *filter_expression_toolbar_;
|
||||
bool was_maximized_;
|
||||
|
||||
/* the following values are maintained so that the capture file name and status
|
||||
|
@ -326,16 +326,11 @@ public slots:
|
|||
void captureFileClosing();
|
||||
void captureFileClosed();
|
||||
|
||||
void filterExpressionsChanged();
|
||||
static gboolean filter_expression_add_action(const void *key, void *value, void *user_data);
|
||||
|
||||
void launchRLCGraph(bool channelKnown, guint16 ueid, guint8 rlcMode,
|
||||
guint16 channelType, guint16 channelId, guint8 direction);
|
||||
|
||||
void on_actionViewFullScreen_triggered(bool checked);
|
||||
|
||||
int uatRowIndexForFilterExpression(QString label, QString expression);
|
||||
|
||||
private slots:
|
||||
|
||||
void captureEventHandler(CaptureEvent ev);
|
||||
|
@ -382,14 +377,6 @@ private slots:
|
|||
QMenu * searchSubMenu(QString objectName);
|
||||
void activatePluginIFToolbar(bool);
|
||||
|
||||
void filterToolbarCustomMenuHandler(const QPoint& globalPos);
|
||||
void filterToolbarShowPreferences();
|
||||
void filterToolbarEditFilter();
|
||||
void filterToolbarDisableFilter();
|
||||
void filterToolbarRemoveFilter();
|
||||
void filterToolbarActionMoved(QAction * action, int oldPos, int newPos);
|
||||
void filterDropped(QString description, QString filter);
|
||||
|
||||
void startInterfaceCapture(bool valid, const QString capture_filter);
|
||||
|
||||
void applyGlobalCommandLineOptions();
|
||||
|
@ -397,7 +384,9 @@ private slots:
|
|||
|
||||
void on_actionDisplayFilterExpression_triggered();
|
||||
void on_actionNewDisplayFilterExpression_triggered();
|
||||
void displayFilterButtonClicked();
|
||||
void onFilterSelected(QString, bool);
|
||||
void onFilterPreferences();
|
||||
void onFilterEdit(int uatIndex);
|
||||
|
||||
// Handle FilterAction signals
|
||||
void queuedFilterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type);
|
||||
|
|
|
@ -175,10 +175,6 @@ DIAG_ON(frame-larger-than=)
|
|||
// Public slots
|
||||
//
|
||||
|
||||
static const char *dfe_property_ = "display filter expression"; //TODO : Fix Translate
|
||||
static const char *dfe_property_label_ = "display_filter_expression_label";
|
||||
static const char *dfe_property_expression_ = "display_filter_expression_expr";
|
||||
|
||||
bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned int type, gboolean is_tempfile)
|
||||
{
|
||||
QString file_name = "";
|
||||
|
@ -811,66 +807,6 @@ void MainWindow::captureFileClosed() {
|
|||
#endif
|
||||
}
|
||||
|
||||
struct filter_expression_data
|
||||
{
|
||||
MainWindow* window;
|
||||
bool actions_added;
|
||||
};
|
||||
|
||||
gboolean MainWindow::filter_expression_add_action(const void *key _U_, void *value, void *user_data)
|
||||
{
|
||||
filter_expression_t* fe = (filter_expression_t*)value;
|
||||
struct filter_expression_data* data = (filter_expression_data*)user_data;
|
||||
|
||||
if (!fe->enabled)
|
||||
return FALSE;
|
||||
|
||||
QAction *dfb_action = new QAction(fe->label, data->window->filter_expression_toolbar_);
|
||||
if (strlen(fe->comment) > 0)
|
||||
{
|
||||
QString tooltip = QString("%1\n%2").arg(fe->comment).arg(fe->expression);
|
||||
dfb_action->setToolTip(tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
dfb_action->setToolTip(fe->expression);
|
||||
}
|
||||
dfb_action->setData(fe->expression);
|
||||
dfb_action->setProperty(dfe_property_, true);
|
||||
dfb_action->setProperty(dfe_property_label_, QString(fe->label));
|
||||
dfb_action->setProperty(dfe_property_expression_, QString(fe->expression));
|
||||
|
||||
if (data->actions_added) {
|
||||
QFrame *sep = new QFrame();
|
||||
sep->setEnabled(false);
|
||||
data->window->filter_expression_toolbar_->addWidget(sep);
|
||||
}
|
||||
data->window->filter_expression_toolbar_->addAction(dfb_action);
|
||||
connect(dfb_action, SIGNAL(triggered()), data->window, SLOT(displayFilterButtonClicked()));
|
||||
data->actions_added = true;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MainWindow::filterExpressionsChanged()
|
||||
{
|
||||
struct filter_expression_data data;
|
||||
|
||||
data.window = this;
|
||||
data.actions_added = false;
|
||||
|
||||
// Hiding and showing seems to be the only way to get the layout to
|
||||
// work correctly in some cases. See bug 14121 for details.
|
||||
setUpdatesEnabled(false);
|
||||
filter_expression_toolbar_->hide();
|
||||
filter_expression_toolbar_->clear();
|
||||
|
||||
// XXX Add a context menu for removing and changing buttons.
|
||||
filter_expression_iterate_expressions(filter_expression_add_action, &data);
|
||||
|
||||
filter_expression_toolbar_->show();
|
||||
setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
//
|
||||
// Private slots
|
||||
//
|
||||
|
@ -1668,18 +1604,25 @@ void MainWindow::on_actionNewDisplayFilterExpression_triggered()
|
|||
main_ui_->filterExpressionFrame->addExpression(df_combo_box_->lineEdit()->text());
|
||||
}
|
||||
|
||||
void MainWindow::displayFilterButtonClicked()
|
||||
void MainWindow::onFilterSelected(QString filterText, bool prepare)
|
||||
{
|
||||
QAction *dfb_action = qobject_cast<QAction*>(sender());
|
||||
|
||||
if (!dfb_action)
|
||||
if (filterText.length() <= 0)
|
||||
return;
|
||||
|
||||
df_combo_box_->setDisplayFilter(dfb_action->data().toString());
|
||||
df_combo_box_->setDisplayFilter(filterText);
|
||||
// Holding down the Shift key will only prepare filter.
|
||||
if (!(QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
|
||||
if (!prepare)
|
||||
df_combo_box_->applyDisplayFilter();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onFilterPreferences()
|
||||
{
|
||||
emit showPreferencesDialog(PrefsModel::FILTER_BUTTONS_PREFERENCE_TREE_NAME);
|
||||
}
|
||||
|
||||
void MainWindow::onFilterEdit(int uatIndex)
|
||||
{
|
||||
main_ui_->filterExpressionFrame->editExpression(uatIndex);
|
||||
}
|
||||
|
||||
void MainWindow::openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata)
|
||||
|
@ -3869,169 +3812,6 @@ void MainWindow::activatePluginIFToolbar(bool)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::filterToolbarCustomMenuHandler(const QPoint& pos)
|
||||
{
|
||||
QAction * filterAction = filter_expression_toolbar_->actionAt(pos);
|
||||
if ( ! filterAction )
|
||||
return;
|
||||
|
||||
QMenu * filterMenu = new QMenu(this);
|
||||
|
||||
QAction *actFilter = filterMenu->addAction(tr("Filter Button Preferences..."));
|
||||
connect(actFilter, SIGNAL(triggered()), this, SLOT(filterToolbarShowPreferences()));
|
||||
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->addSeparator();
|
||||
QAction * actEdit = filterMenu->addAction(tr("Edit"));
|
||||
connect(actEdit, SIGNAL(triggered()), this, SLOT(filterToolbarEditFilter()));
|
||||
actEdit->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_));
|
||||
actEdit->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_));
|
||||
actEdit->setData(filterAction->data());
|
||||
QAction * actDisable = filterMenu->addAction(tr("Disable"));
|
||||
connect(actDisable, SIGNAL(triggered()), this, SLOT(filterToolbarDisableFilter()));
|
||||
actDisable->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_));
|
||||
actDisable->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_));
|
||||
actDisable->setData(filterAction->data());
|
||||
QAction * actRemove = filterMenu->addAction(tr("Remove"));
|
||||
connect(actRemove, SIGNAL(triggered()), this, SLOT(filterToolbarRemoveFilter()));
|
||||
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->exec(filter_expression_toolbar_->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void MainWindow::filterToolbarShowPreferences()
|
||||
{
|
||||
emit showPreferencesDialog(PrefsModel::FILTER_BUTTONS_PREFERENCE_TREE_NAME);
|
||||
}
|
||||
|
||||
int MainWindow::uatRowIndexForFilterExpression(QString label, QString expression)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if ( expression.length() == 0 )
|
||||
return result;
|
||||
|
||||
UatModel * uatModel = new UatModel(this, "Display expressions");
|
||||
|
||||
QModelIndex rowIndex;
|
||||
|
||||
if ( label.length() > 0 )
|
||||
{
|
||||
for ( int cnt = 0; cnt < uatModel->rowCount() && ! rowIndex.isValid(); cnt++ )
|
||||
{
|
||||
if ( uatModel->data(uatModel->index(cnt, 1), Qt::DisplayRole).toString().compare(label) == 0 &&
|
||||
uatModel->data(uatModel->index(cnt, 2), Qt::DisplayRole).toString().compare(expression) == 0 )
|
||||
{
|
||||
rowIndex = uatModel->index(cnt, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rowIndex = uatModel->findRowForColumnContent(((QAction *)sender())->data(), 2);
|
||||
}
|
||||
|
||||
if ( rowIndex.isValid() )
|
||||
result = rowIndex.row();
|
||||
|
||||
delete uatModel;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void MainWindow::filterToolbarEditFilter()
|
||||
{
|
||||
if ( ! sender() )
|
||||
return;
|
||||
|
||||
QString label = ((QAction *)sender())->property(dfe_property_label_).toString();
|
||||
QString expr = ((QAction *)sender())->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilterExpression(label, expr);
|
||||
|
||||
if ( idx > -1 )
|
||||
main_ui_->filterExpressionFrame->editExpression(idx);
|
||||
}
|
||||
|
||||
void MainWindow::filterDropped(QString description, QString filter)
|
||||
{
|
||||
gchar* err = NULL;
|
||||
if ( filter.length() == 0 )
|
||||
return;
|
||||
|
||||
filter_expression_new(qUtf8Printable(description),
|
||||
qUtf8Printable(filter), qUtf8Printable(description), TRUE);
|
||||
|
||||
uat_save(uat_get_table_by_name("Display expressions"), &err);
|
||||
g_free(err);
|
||||
|
||||
filterExpressionsChanged();
|
||||
}
|
||||
|
||||
void MainWindow::filterToolbarDisableFilter()
|
||||
{
|
||||
gchar* err = NULL;
|
||||
|
||||
QString label = ((QAction *)sender())->property(dfe_property_label_).toString();
|
||||
QString expr = ((QAction *)sender())->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilterExpression(label, expr);
|
||||
UatModel * uatModel = new UatModel(this, "Display expressions");
|
||||
|
||||
QModelIndex rowIndex = uatModel->index(idx, 0);
|
||||
if ( rowIndex.isValid() ) {
|
||||
uatModel->setData(rowIndex, QVariant::fromValue(false));
|
||||
|
||||
uat_save(uat_get_table_by_name("Display expressions"), &err);
|
||||
g_free(err);
|
||||
filterExpressionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::filterToolbarRemoveFilter()
|
||||
{
|
||||
gchar* err = NULL;
|
||||
UatModel * uatModel = new UatModel(this, "Display expressions");
|
||||
|
||||
QString label = ((QAction *)sender())->property(dfe_property_label_).toString();
|
||||
QString expr = ((QAction *)sender())->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilterExpression(label, expr);
|
||||
|
||||
QModelIndex rowIndex = uatModel->index(idx, 0);
|
||||
if ( rowIndex.isValid() ) {
|
||||
uatModel->removeRow(rowIndex.row());
|
||||
|
||||
uat_save(uat_get_table_by_name("Display expressions"), &err);
|
||||
g_free(err);
|
||||
filterExpressionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::filterToolbarActionMoved(QAction* action, int oldPos, int newPos)
|
||||
{
|
||||
gchar* err = NULL;
|
||||
if ( oldPos == newPos )
|
||||
return;
|
||||
|
||||
QString label = action->property(dfe_property_label_).toString();
|
||||
QString expr = action->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilterExpression(label, expr);
|
||||
|
||||
if ( idx > -1 && oldPos > -1 && newPos > -1 )
|
||||
{
|
||||
uat_t * table = uat_get_table_by_name("Display expressions");
|
||||
uat_move_index(table, oldPos, newPos);
|
||||
uat_save(table, &err);
|
||||
|
||||
g_free(err);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,303 @@
|
|||
/* filter_expression_toolbar.cpp
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <ui/qt/widgets/filter_expression_toolbar.h>
|
||||
#include <ui/qt/utils/color_utils.h>
|
||||
#include <ui/qt/models/uat_model.h>
|
||||
#include <ui/qt/wireshark_application.h>
|
||||
|
||||
#include <epan/filter_expressions.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFrame>
|
||||
#include <QMenu>
|
||||
|
||||
static const char *dfe_property_ = "display filter expression"; //TODO : Fix Translate
|
||||
static const char *dfe_property_label_ = "display_filter_expression_label";
|
||||
static const char *dfe_property_expression_ = "display_filter_expression_expr";
|
||||
|
||||
struct filter_expression_data
|
||||
{
|
||||
FilterExpressionToolBar* toolbar;
|
||||
bool actions_added;
|
||||
};
|
||||
|
||||
|
||||
FilterExpressionToolBar::FilterExpressionToolBar(QWidget * parent) :
|
||||
DragDropToolBar(parent)
|
||||
{
|
||||
// Try to draw 1-pixel-wide separator lines from the button label
|
||||
// ascent to its baseline.
|
||||
int sep_margin = (fontMetrics().height() * 0.5) - 1;
|
||||
QColor sep_color = ColorUtils::alphaBlend(palette().text(), palette().base(), 0.3);
|
||||
setStyleSheet(QString(
|
||||
"QToolBar { background: none; border: none; spacing: 1px; }"
|
||||
"QFrame {"
|
||||
" min-width: 1px; max-width: 1px;"
|
||||
" margin: %1px 0 %2px 0; padding: 0;"
|
||||
" background-color: %3;"
|
||||
"}"
|
||||
).arg(sep_margin).arg(sep_margin - 1).arg(sep_color.name()));
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect ( this, &QWidget::customContextMenuRequested, this, &FilterExpressionToolBar::onCustomMenuHandler );
|
||||
connect(this, &DragDropToolBar::actionMoved, this, &FilterExpressionToolBar::onActionMoved);
|
||||
connect(this, &DragDropToolBar::newFilterDropped, this, &FilterExpressionToolBar::onFilterDropped);
|
||||
|
||||
connect(wsApp, SIGNAL(appInitialized()),
|
||||
this, SLOT(filterExpressionsChanged()));
|
||||
connect(wsApp, SIGNAL(filterExpressionsChanged()),
|
||||
this, SLOT(filterExpressionsChanged()));
|
||||
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::onCustomMenuHandler(const QPoint& pos)
|
||||
{
|
||||
QAction * filterAction = actionAt(pos);
|
||||
if ( ! filterAction )
|
||||
return;
|
||||
|
||||
QMenu * filterMenu = new QMenu(this);
|
||||
|
||||
QAction *actFilter = filterMenu->addAction(tr("Filter Button Preferences..."));
|
||||
connect(actFilter, SIGNAL(triggered()), this, SLOT(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->addSeparator();
|
||||
QAction * actEdit = filterMenu->addAction(tr("Edit"));
|
||||
connect(actEdit, SIGNAL(triggered()), this, SLOT(editFilter()));
|
||||
actEdit->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_));
|
||||
actEdit->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_));
|
||||
actEdit->setData(filterAction->data());
|
||||
QAction * actDisable = filterMenu->addAction(tr("Disable"));
|
||||
connect(actDisable, SIGNAL(triggered()), this, SLOT(disableFilter()));
|
||||
actDisable->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_));
|
||||
actDisable->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_));
|
||||
actDisable->setData(filterAction->data());
|
||||
QAction * actRemove = filterMenu->addAction(tr("Remove"));
|
||||
connect(actRemove, SIGNAL(triggered()), this, SLOT(removeFilter()));
|
||||
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->exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::filterExpressionsChanged()
|
||||
{
|
||||
struct filter_expression_data data;
|
||||
|
||||
data.toolbar = this;
|
||||
data.actions_added = false;
|
||||
|
||||
// Hiding and showing seems to be the only way to get the layout to
|
||||
// work correctly in some cases. See bug 14121 for details.
|
||||
setUpdatesEnabled(false);
|
||||
hide();
|
||||
clear();
|
||||
|
||||
// XXX Add a context menu for removing and changing buttons.
|
||||
filter_expression_iterate_expressions(filter_expression_add_action, &data);
|
||||
|
||||
show();
|
||||
setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::removeFilter()
|
||||
{
|
||||
gchar* err = NULL;
|
||||
UatModel * uatModel = new UatModel(this, "Display expressions");
|
||||
|
||||
QString label = ((QAction *)sender())->property(dfe_property_label_).toString();
|
||||
QString expr = ((QAction *)sender())->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilter(label, expr);
|
||||
|
||||
QModelIndex rowIndex = uatModel->index(idx, 0);
|
||||
if ( rowIndex.isValid() ) {
|
||||
uatModel->removeRow(rowIndex.row());
|
||||
|
||||
uat_save(uat_get_table_by_name("Display expressions"), &err);
|
||||
g_free(err);
|
||||
filterExpressionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::onActionMoved(QAction* action, int oldPos, int newPos)
|
||||
{
|
||||
gchar* err = NULL;
|
||||
if ( oldPos == newPos )
|
||||
return;
|
||||
|
||||
QString label = action->property(dfe_property_label_).toString();
|
||||
QString expr = action->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilter(label, expr);
|
||||
|
||||
if ( idx > -1 && oldPos > -1 && newPos > -1 )
|
||||
{
|
||||
uat_t * table = uat_get_table_by_name("Display expressions");
|
||||
uat_move_index(table, oldPos, newPos);
|
||||
uat_save(table, &err);
|
||||
|
||||
g_free(err);
|
||||
}
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::disableFilter()
|
||||
{
|
||||
gchar* err = NULL;
|
||||
|
||||
QString label = ((QAction *)sender())->property(dfe_property_label_).toString();
|
||||
QString expr = ((QAction *)sender())->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilter(label, expr);
|
||||
UatModel * uatModel = new UatModel(this, "Display expressions");
|
||||
|
||||
QModelIndex rowIndex = uatModel->index(idx, 0);
|
||||
if ( rowIndex.isValid() ) {
|
||||
uatModel->setData(rowIndex, QVariant::fromValue(false));
|
||||
|
||||
uat_save(uat_get_table_by_name("Display expressions"), &err);
|
||||
g_free(err);
|
||||
filterExpressionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::editFilter()
|
||||
{
|
||||
if ( ! sender() )
|
||||
return;
|
||||
|
||||
QString label = ((QAction *)sender())->property(dfe_property_label_).toString();
|
||||
QString expr = ((QAction *)sender())->property(dfe_property_expression_).toString();
|
||||
|
||||
int idx = uatRowIndexForFilter(label, expr);
|
||||
|
||||
if ( idx > -1 )
|
||||
emit filterEdit(idx);
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::onFilterDropped(QString description, QString filter)
|
||||
{
|
||||
gchar* err = NULL;
|
||||
if ( filter.length() == 0 )
|
||||
return;
|
||||
|
||||
filter_expression_new(qUtf8Printable(description),
|
||||
qUtf8Printable(filter), qUtf8Printable(description), TRUE);
|
||||
|
||||
uat_save(uat_get_table_by_name("Display expressions"), &err);
|
||||
g_free(err);
|
||||
|
||||
filterExpressionsChanged();
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::toolBarShowPreferences()
|
||||
{
|
||||
emit filterPreferences();
|
||||
}
|
||||
|
||||
int FilterExpressionToolBar::uatRowIndexForFilter(QString label, QString expression)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if ( expression.length() == 0 )
|
||||
return result;
|
||||
|
||||
UatModel * uatModel = new UatModel(this, "Display expressions");
|
||||
|
||||
QModelIndex rowIndex;
|
||||
|
||||
if ( label.length() > 0 )
|
||||
{
|
||||
for ( int cnt = 0; cnt < uatModel->rowCount() && ! rowIndex.isValid(); cnt++ )
|
||||
{
|
||||
if ( uatModel->data(uatModel->index(cnt, 1), Qt::DisplayRole).toString().compare(label) == 0 &&
|
||||
uatModel->data(uatModel->index(cnt, 2), Qt::DisplayRole).toString().compare(expression) == 0 )
|
||||
{
|
||||
rowIndex = uatModel->index(cnt, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rowIndex = uatModel->findRowForColumnContent(((QAction *)sender())->data(), 2);
|
||||
}
|
||||
|
||||
if ( rowIndex.isValid() )
|
||||
result = rowIndex.row();
|
||||
|
||||
delete uatModel;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean FilterExpressionToolBar::filter_expression_add_action(const void *key _U_, void *value, void *user_data)
|
||||
{
|
||||
filter_expression_t* fe = (filter_expression_t*)value;
|
||||
struct filter_expression_data* data = (filter_expression_data*)user_data;
|
||||
|
||||
if (!fe->enabled)
|
||||
return FALSE;
|
||||
|
||||
QAction *dfb_action = new QAction(fe->label, data->toolbar);
|
||||
if (strlen(fe->comment) > 0)
|
||||
{
|
||||
QString tooltip = QString("%1\n%2").arg(fe->comment).arg(fe->expression);
|
||||
dfb_action->setToolTip(tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
dfb_action->setToolTip(fe->expression);
|
||||
}
|
||||
dfb_action->setData(fe->expression);
|
||||
dfb_action->setProperty(dfe_property_, true);
|
||||
dfb_action->setProperty(dfe_property_label_, QString(fe->label));
|
||||
dfb_action->setProperty(dfe_property_expression_, QString(fe->expression));
|
||||
|
||||
if (data->actions_added) {
|
||||
QFrame *sep = new QFrame();
|
||||
sep->setEnabled(false);
|
||||
data->toolbar->addWidget(sep);
|
||||
}
|
||||
data->toolbar->addAction(dfb_action);
|
||||
connect(dfb_action, SIGNAL(triggered()), data->toolbar, SLOT(filterClicked()));
|
||||
data->actions_added = true;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void FilterExpressionToolBar::filterClicked()
|
||||
{
|
||||
bool prepare = false;
|
||||
QAction *dfb_action = qobject_cast<QAction*>(sender());
|
||||
|
||||
if (!dfb_action)
|
||||
return;
|
||||
|
||||
QString filterText = dfb_action->data().toString();
|
||||
prepare = (!(QApplication::keyboardModifiers() & Qt::ShiftModifier));
|
||||
|
||||
emit filterSelected(filterText, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
|
@ -0,0 +1,62 @@
|
|||
/* filter_expression_toolbar.h
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <ui/qt/widgets/drag_drop_toolbar.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#ifndef FILTER_EXPRESSION_TOOLBAR_H
|
||||
#define FILTER_EXPRESSION_TOOLBAR_H
|
||||
|
||||
class FilterExpressionToolBar : public DragDropToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FilterExpressionToolBar(QWidget * parent = Q_NULLPTR);
|
||||
|
||||
public slots:
|
||||
void filterExpressionsChanged();
|
||||
|
||||
signals:
|
||||
void filterSelected(QString, bool);
|
||||
void filterPreferences();
|
||||
void filterEdit(int uatIndex);
|
||||
|
||||
protected slots:
|
||||
void onCustomMenuHandler(const QPoint &pos);
|
||||
void onActionMoved(QAction * action, int oldPos, int newPos);
|
||||
void onFilterDropped(QString description, QString filter);
|
||||
|
||||
private slots:
|
||||
void removeFilter();
|
||||
void disableFilter();
|
||||
void editFilter();
|
||||
void filterClicked();
|
||||
void toolBarShowPreferences();
|
||||
|
||||
private:
|
||||
int uatRowIndexForFilter(QString label, QString expression);
|
||||
|
||||
static gboolean filter_expression_add_action(const void *key, void *value, void *user_data);
|
||||
};
|
||||
|
||||
#endif //FILTER_EXPRESSION_TOOLBAR_H
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
Loading…
Reference in New Issue