Qt: Move Packetlist Header Context Menu to subclass
This is a cleanup patch to remove unused or unnecessary code from packet list and put it in its respective header class for better code maintenance Change-Id: Ib7d7f34ab9cdd802199b3f279499855c80f8f0c5 Reviewed-on: https://code.wireshark.org/review/33587 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
0bb8563f05
commit
e39f2bb517
|
@ -2586,7 +2586,7 @@ void MainWindow::matchFieldFilter(FilterAction::Action action, FilterAction::Act
|
|||
{
|
||||
QString field_filter;
|
||||
|
||||
if (packet_list_->contextMenuActive() || packet_list_->hasFocus()) {
|
||||
if (packet_list_->hasFocus()) {
|
||||
field_filter = packet_list_->getFilterFromRowAndColumn();
|
||||
} else if (capture_file_.capFile() && capture_file_.capFile()->finfo_selected) {
|
||||
char *tmp_field = proto_construct_match_selected_string(capture_file_.capFile()->finfo_selected,
|
||||
|
@ -2596,9 +2596,7 @@ void MainWindow::matchFieldFilter(FilterAction::Action action, FilterAction::Act
|
|||
}
|
||||
|
||||
if (field_filter.isEmpty()) {
|
||||
QString err = tr("No filter available. Try another ");
|
||||
err.append(packet_list_->contextMenuActive() ? "column" : "item");
|
||||
err.append(".");
|
||||
QString err = tr("No filter available. Try another item").append(".");
|
||||
main_ui_->statusBar->pushTemporaryStatus(err);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -212,8 +212,6 @@ packet_list_recent_write_all(FILE *rf) {
|
|||
|
||||
#define MIN_COL_WIDTH_STR "MMMMMM"
|
||||
|
||||
Q_DECLARE_METATYPE(PacketList::ColumnActions)
|
||||
|
||||
enum copy_summary_type {
|
||||
copy_summary_text_,
|
||||
copy_summary_csv_,
|
||||
|
@ -244,7 +242,13 @@ PacketList::PacketList(QWidget *parent) :
|
|||
setUniformRowHeights(true);
|
||||
setAccessibleName("Packet list");
|
||||
|
||||
setHeader(new PacketListHeader(header()->orientation()));
|
||||
packet_list_header_ = new PacketListHeader(header()->orientation(), cap_file_);
|
||||
connect(packet_list_header_, &PacketListHeader::resetColumnWidth, this, &PacketList::setRecentColumnWidth);
|
||||
connect(packet_list_header_, &PacketListHeader::updatePackets, this, &PacketList::updatePackets);
|
||||
connect(packet_list_header_, &PacketListHeader::showColumnPreferences, this, &PacketList::showProtocolPreferences);
|
||||
connect(packet_list_header_, &PacketListHeader::editColumn, this, &PacketList::editColumn);
|
||||
connect(packet_list_header_, &PacketListHeader::columnsChanged, this, &PacketList::columnsChanged);
|
||||
setHeader(packet_list_header_);
|
||||
|
||||
// Shrink down to a small but nonzero size in the main splitter.
|
||||
int one_em = fontMetrics().height();
|
||||
|
@ -257,8 +261,6 @@ PacketList::PacketList(QWidget *parent) :
|
|||
setModel(packet_list_model_);
|
||||
sortByColumn(-1, Qt::AscendingOrder);
|
||||
|
||||
initHeaderContextMenu();
|
||||
|
||||
g_assert(gbl_cur_packet_list == NULL);
|
||||
gbl_cur_packet_list = this;
|
||||
|
||||
|
@ -267,9 +269,6 @@ PacketList::PacketList(QWidget *parent) :
|
|||
connect(wsApp, SIGNAL(addressResolutionChanged()), this, SLOT(redrawVisiblePacketsDontSelectCurrent()));
|
||||
connect(wsApp, SIGNAL(columnDataChanged()), this, SLOT(redrawVisiblePacketsDontSelectCurrent()));
|
||||
|
||||
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(header(), SIGNAL(customContextMenuRequested(QPoint)),
|
||||
this, SLOT(showHeaderMenu(QPoint)));
|
||||
connect(header(), SIGNAL(sectionResized(int,int,int)),
|
||||
this, SLOT(sectionResized(int,int,int)));
|
||||
connect(header(), SIGNAL(sectionMoved(int,int,int)),
|
||||
|
@ -468,146 +467,6 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS
|
|||
}
|
||||
}
|
||||
|
||||
void PacketList::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
const char *module_name = NULL;
|
||||
if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) {
|
||||
GPtrArray *finfo_array = proto_all_finfos(cap_file_->edt->tree);
|
||||
|
||||
for (guint i = finfo_array->len - 1; i > 0 ; i --) {
|
||||
field_info *fi = (field_info *)g_ptr_array_index (finfo_array, i);
|
||||
header_field_info *hfinfo = fi->hfinfo;
|
||||
|
||||
if (!g_str_has_prefix(hfinfo->abbrev, "text") &&
|
||||
!g_str_has_prefix(hfinfo->abbrev, "_ws.expert") &&
|
||||
!g_str_has_prefix(hfinfo->abbrev, "_ws.lua") &&
|
||||
!g_str_has_prefix(hfinfo->abbrev, "_ws.malformed")) {
|
||||
|
||||
if (hfinfo->parent == -1) {
|
||||
module_name = hfinfo->abbrev;
|
||||
} else {
|
||||
module_name = proto_registrar_get_abbrev(hfinfo->parent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_ptr_array_free(finfo_array, TRUE);
|
||||
}
|
||||
proto_prefs_menu_.setModule(module_name);
|
||||
|
||||
QModelIndex ctxIndex = indexAt(event->pos());
|
||||
// frameData will be owned by one of the submenus, see below.
|
||||
FrameInformation * frameData =
|
||||
new FrameInformation(new CaptureFile(this, cap_file_), packet_list_model_->getRowFdata(ctxIndex.row()));
|
||||
|
||||
ctx_menu_.clear();
|
||||
// XXX We might want to reimplement setParent() and fill in the context
|
||||
// menu there.
|
||||
ctx_menu_.addAction(window()->findChild<QAction *>("actionEditMarkPacket"));
|
||||
ctx_menu_.addAction(window()->findChild<QAction *>("actionEditIgnorePacket"));
|
||||
ctx_menu_.addAction(window()->findChild<QAction *>("actionEditSetTimeReference"));
|
||||
ctx_menu_.addAction(window()->findChild<QAction *>("actionEditTimeShift"));
|
||||
ctx_menu_.addAction(window()->findChild<QAction *>("actionEditPacketComment"));
|
||||
|
||||
ctx_menu_.addSeparator();
|
||||
|
||||
ctx_menu_.addAction(window()->findChild<QAction *>("actionViewEditResolvedName"));
|
||||
ctx_menu_.addSeparator();
|
||||
|
||||
QMenu *main_menu_item = window()->findChild<QMenu *>("menuApplyAsFilter");
|
||||
QMenu *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"));
|
||||
|
||||
const char *conv_menu_name = "menuConversationFilter";
|
||||
main_menu_item = window()->findChild<QMenu *>(conv_menu_name);
|
||||
conv_menu_.setTitle(main_menu_item->title());
|
||||
conv_menu_.setObjectName(conv_menu_name);
|
||||
ctx_menu_.addMenu(&conv_menu_);
|
||||
|
||||
const char *colorize_menu_name = "menuColorizeConversation";
|
||||
main_menu_item = window()->findChild<QMenu *>(colorize_menu_name);
|
||||
colorize_menu_.setTitle(main_menu_item->title());
|
||||
colorize_menu_.setObjectName(colorize_menu_name);
|
||||
ctx_menu_.addMenu(&colorize_menu_);
|
||||
|
||||
main_menu_item = window()->findChild<QMenu *>("menuSCTP");
|
||||
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
||||
ctx_menu_.addMenu(submenu);
|
||||
submenu->addAction(window()->findChild<QAction *>("actionSCTPAnalyseThisAssociation"));
|
||||
submenu->addAction(window()->findChild<QAction *>("actionSCTPShowAllAssociations"));
|
||||
submenu->addAction(window()->findChild<QAction *>("actionSCTPFilterThisAssociation"));
|
||||
|
||||
main_menu_item = window()->findChild<QMenu *>("menuFollow");
|
||||
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
||||
ctx_menu_.addMenu(submenu);
|
||||
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowTCPStream"));
|
||||
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowUDPStream"));
|
||||
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowTLSStream"));
|
||||
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowHTTPStream"));
|
||||
|
||||
ctx_menu_.addSeparator();
|
||||
|
||||
main_menu_item = window()->findChild<QMenu *>("menuEditCopy");
|
||||
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
||||
ctx_menu_.addMenu(submenu);
|
||||
|
||||
QAction * action = submenu->addAction(tr("Summary as Text"));
|
||||
action->setData(copy_summary_text_);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(copySummary()));
|
||||
action = submenu->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as CSV"));
|
||||
action->setData(copy_summary_csv_);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(copySummary()));
|
||||
action = submenu->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as YAML"));
|
||||
action->setData(copy_summary_yaml_);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(copySummary()));
|
||||
submenu->addSeparator();
|
||||
|
||||
submenu->addAction(window()->findChild<QAction *>("actionEditCopyAsFilter"));
|
||||
submenu->addSeparator();
|
||||
|
||||
QActionGroup * copyEntries = DataPrinter::copyActions(this, frameData);
|
||||
submenu->addActions(copyEntries->actions());
|
||||
copyEntries->setParent(submenu);
|
||||
frameData->setParent(submenu);
|
||||
|
||||
ctx_menu_.addSeparator();
|
||||
ctx_menu_.addMenu(&proto_prefs_menu_);
|
||||
decode_as_ = window()->findChild<QAction *>("actionAnalyzeDecodeAs");
|
||||
ctx_menu_.addAction(decode_as_);
|
||||
// "Print" not ported intentionally
|
||||
action = window()->findChild<QAction *>("actionViewShowPacketInNewWindow");
|
||||
ctx_menu_.addAction(action);
|
||||
|
||||
decode_as_->setData(QVariant::fromValue(true));
|
||||
ctx_column_ = columnAt(event->x());
|
||||
|
||||
// Set menu sensitivity for the current column and set action data.
|
||||
if ( frameData )
|
||||
emit frameSelected(frameData->frameNum());
|
||||
else
|
||||
emit frameSelected(-1);
|
||||
|
||||
ctx_menu_.exec(event->globalPos());
|
||||
ctx_column_ = -1;
|
||||
decode_as_->setData(QVariant());
|
||||
}
|
||||
|
||||
// Auto scroll if:
|
||||
// - We're not at the end
|
||||
// - We are capturing
|
||||
|
@ -706,42 +565,6 @@ void PacketList::setRecentColumnWidth(int col)
|
|||
setColumnWidth(col, col_width);
|
||||
}
|
||||
|
||||
void PacketList::initHeaderContextMenu()
|
||||
{
|
||||
header_ctx_menu_.clear();
|
||||
header_actions_.clear();
|
||||
|
||||
// Leave these out for now since Qt doesn't have a "no sort" option
|
||||
// and the user can sort by left-clicking on the header.
|
||||
// header_actions_[] = header_ctx_menu_.addAction(tr("Sort Ascending"));
|
||||
// header_actions_[] = header_ctx_menu_.addAction(tr("Sort Descending"));
|
||||
// header_actions_[] = header_ctx_menu_.addAction(tr("Do Not Sort"));
|
||||
// header_ctx_menu_.addSeparator();
|
||||
header_actions_[caAlignLeft] = header_ctx_menu_.addAction(tr("Align Left"));
|
||||
header_actions_[caAlignCenter] = header_ctx_menu_.addAction(tr("Align Center"));
|
||||
header_actions_[caAlignRight] = header_ctx_menu_.addAction(tr("Align Right"));
|
||||
header_ctx_menu_.addSeparator();
|
||||
header_actions_[caColumnPreferences] = header_ctx_menu_.addAction(tr("Column Preferences" UTF8_HORIZONTAL_ELLIPSIS));
|
||||
header_actions_[caEditColumn] = header_ctx_menu_.addAction(tr("Edit Column")); // XXX Create frame instead of dialog
|
||||
header_actions_[caResizeToContents] = header_ctx_menu_.addAction(tr("Resize To Contents"));
|
||||
header_actions_[caResolveNames] = header_ctx_menu_.addAction(tr("Resolve Names"));
|
||||
header_ctx_menu_.addSeparator();
|
||||
// header_actions_[caDisplayedColumns] = header_ctx_menu_.addAction(tr("Displayed Columns"));
|
||||
show_hide_separator_ = header_ctx_menu_.addSeparator();
|
||||
// header_actions_[caHideColumn] = header_ctx_menu_.addAction(tr("Hide This Column"));
|
||||
header_actions_[caRemoveColumn] = header_ctx_menu_.addAction(tr("Remove This Column"));
|
||||
|
||||
foreach (ColumnActions ca, header_actions_.keys()) {
|
||||
header_actions_[ca]->setData(QVariant::fromValue(ca));
|
||||
connect(header_actions_[ca], SIGNAL(triggered()), this, SLOT(headerMenuTriggered()));
|
||||
}
|
||||
|
||||
checkable_actions_ = QList<ColumnActions>() << caAlignLeft << caAlignCenter << caAlignRight << caResolveNames;
|
||||
foreach (ColumnActions ca, checkable_actions_) {
|
||||
header_actions_[ca]->setCheckable(true);
|
||||
}
|
||||
}
|
||||
|
||||
void PacketList::drawCurrentPacket()
|
||||
{
|
||||
QModelIndex current_index = currentIndex();
|
||||
|
@ -1015,11 +838,6 @@ void PacketList::writeRecent(FILE *rf) {
|
|||
fprintf (rf, "\n");
|
||||
}
|
||||
|
||||
bool PacketList::contextMenuActive()
|
||||
{
|
||||
return ctx_column_ >= 0 ? true : false;
|
||||
}
|
||||
|
||||
QString PacketList::getFilterFromRowAndColumn()
|
||||
{
|
||||
frame_data *fdata;
|
||||
|
@ -1212,6 +1030,7 @@ void PacketList::setCaptureFile(capture_file *cf)
|
|||
}
|
||||
}
|
||||
packet_list_model_->setCaptureFile(cf);
|
||||
packet_list_header_->setCaptureFile(cf);
|
||||
create_near_overlay_ = true;
|
||||
sortByColumn(-1, Qt::AscendingOrder);
|
||||
}
|
||||
|
@ -1377,105 +1196,8 @@ void PacketList::applyTimeShift()
|
|||
// XXX emit packetDissectionChanged(); ?
|
||||
}
|
||||
|
||||
void PacketList::showHeaderMenu(QPoint pos)
|
||||
void PacketList::updatePackets(bool redraw)
|
||||
{
|
||||
header_ctx_column_ = header()->logicalIndexAt(pos);
|
||||
foreach (ColumnActions ca, checkable_actions_) {
|
||||
header_actions_[ca]->setChecked(false);
|
||||
}
|
||||
|
||||
switch (recent_get_column_xalign(header_ctx_column_)) {
|
||||
case COLUMN_XALIGN_LEFT:
|
||||
header_actions_[caAlignLeft]->setChecked(true);
|
||||
break;
|
||||
case COLUMN_XALIGN_CENTER:
|
||||
header_actions_[caAlignCenter]->setChecked(true);
|
||||
break;
|
||||
case COLUMN_XALIGN_RIGHT:
|
||||
header_actions_[caAlignRight]->setChecked(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bool can_resolve = resolve_column(header_ctx_column_, cap_file_);
|
||||
header_actions_[caResolveNames]->setChecked(can_resolve && get_column_resolved(header_ctx_column_));
|
||||
header_actions_[caResolveNames]->setEnabled(can_resolve);
|
||||
|
||||
header_actions_[caRemoveColumn]->setEnabled(header_ctx_column_ >= 0 && header()->count() > 2);
|
||||
|
||||
foreach (QAction *action, show_hide_actions_) {
|
||||
header_ctx_menu_.removeAction(action);
|
||||
delete action;
|
||||
}
|
||||
show_hide_actions_.clear();
|
||||
for (int i = 0; i < prefs.num_cols; i++) {
|
||||
QAction *action = new QAction(get_column_title(i), &header_ctx_menu_);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(get_column_visible(i));
|
||||
action->setData(QVariant::fromValue(i));
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(columnVisibilityTriggered()));
|
||||
header_ctx_menu_.insertAction(show_hide_separator_, action);
|
||||
show_hide_actions_ << action;
|
||||
}
|
||||
|
||||
header_ctx_menu_.popup(header()->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void PacketList::headerMenuTriggered()
|
||||
{
|
||||
QAction *ha = qobject_cast<QAction*>(sender());
|
||||
if (!ha) return;
|
||||
|
||||
bool checked = ha->isChecked();
|
||||
bool redraw = false;
|
||||
|
||||
switch(ha->data().value<ColumnActions>()) {
|
||||
case caAlignLeft:
|
||||
recent_set_column_xalign(header_ctx_column_, checked ? COLUMN_XALIGN_LEFT : COLUMN_XALIGN_DEFAULT);
|
||||
break;
|
||||
case caAlignCenter:
|
||||
recent_set_column_xalign(header_ctx_column_, checked ? COLUMN_XALIGN_CENTER : COLUMN_XALIGN_DEFAULT);
|
||||
break;
|
||||
case caAlignRight:
|
||||
recent_set_column_xalign(header_ctx_column_, checked ? COLUMN_XALIGN_RIGHT : COLUMN_XALIGN_DEFAULT);
|
||||
break;
|
||||
case caColumnPreferences:
|
||||
emit showColumnPreferences(PrefsModel::COLUMNS_PREFERENCE_TREE_NAME);
|
||||
break;
|
||||
case caEditColumn:
|
||||
emit editColumn(header_ctx_column_);
|
||||
break;
|
||||
case caResolveNames:
|
||||
set_column_resolved(header_ctx_column_, checked);
|
||||
packet_list_model_->resetColumns();
|
||||
prefs_main_write();
|
||||
redraw = true;
|
||||
break;
|
||||
case caResizeToContents:
|
||||
resizeColumnToContents(header_ctx_column_);
|
||||
break;
|
||||
case caDisplayedColumns:
|
||||
// No-op
|
||||
break;
|
||||
case caHideColumn:
|
||||
set_column_visible(header_ctx_column_, FALSE);
|
||||
hideColumn(header_ctx_column_);
|
||||
prefs_main_write();
|
||||
break;
|
||||
case caRemoveColumn:
|
||||
{
|
||||
if (header()->count() > 2) {
|
||||
column_prefs_remove_nth(header_ctx_column_);
|
||||
columnsChanged();
|
||||
prefs_main_write();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (redraw) {
|
||||
redrawVisiblePackets();
|
||||
} else {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QTreeView>
|
||||
#include <QPainter>
|
||||
|
||||
class PacketListHeader;
|
||||
class OverlayScrollBar;
|
||||
|
||||
class QAction;
|
||||
|
@ -31,18 +32,6 @@ class PacketList : public QTreeView
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ColumnActions {
|
||||
caAlignLeft,
|
||||
caAlignCenter,
|
||||
caAlignRight,
|
||||
caColumnPreferences,
|
||||
caEditColumn,
|
||||
caResolveNames,
|
||||
caResizeToContents,
|
||||
caDisplayedColumns,
|
||||
caHideColumn,
|
||||
caRemoveColumn
|
||||
};
|
||||
explicit PacketList(QWidget *parent = 0);
|
||||
PacketListModel *packetListModel() const;
|
||||
QMenu *conversationMenu() { return &conv_menu_; }
|
||||
|
@ -65,7 +54,6 @@ public:
|
|||
void thaw(bool restore_selection = false);
|
||||
void clear();
|
||||
void writeRecent(FILE *rf);
|
||||
bool contextMenuActive();
|
||||
QString getFilterFromRowAndColumn();
|
||||
void resetColorized();
|
||||
QString packetComment();
|
||||
|
@ -81,7 +69,6 @@ public:
|
|||
|
||||
protected:
|
||||
void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void timerEvent(QTimerEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
virtual void mousePressEvent (QMouseEvent *event);
|
||||
|
@ -93,6 +80,7 @@ protected slots:
|
|||
|
||||
private:
|
||||
PacketListModel *packet_list_model_;
|
||||
PacketListHeader * packet_list_header_;
|
||||
ProtoTree *proto_tree_;
|
||||
capture_file *cap_file_;
|
||||
QMenu ctx_menu_;
|
||||
|
@ -109,10 +97,6 @@ private:
|
|||
QVector<QRgb> overlay_colors_;
|
||||
|
||||
RelatedPacketDelegate related_packet_delegate_;
|
||||
QMenu header_ctx_menu_;
|
||||
QMap<ColumnActions, QAction*> header_actions_;
|
||||
QList<ColumnActions> checkable_actions_;
|
||||
int header_ctx_column_;
|
||||
QAction *show_hide_separator_;
|
||||
QList<QAction *>show_hide_actions_;
|
||||
bool capture_in_progress_;
|
||||
|
@ -130,7 +114,6 @@ private:
|
|||
void setColumnVisibility();
|
||||
int sizeHintForColumn(int column) const;
|
||||
void setRecentColumnWidth(int column);
|
||||
void initHeaderContextMenu();
|
||||
void drawCurrentPacket();
|
||||
void applyRecentColumnWidths();
|
||||
void scrollViewChanged(bool at_end);
|
||||
|
@ -173,8 +156,6 @@ public slots:
|
|||
void preferencesChanged();
|
||||
|
||||
private slots:
|
||||
void showHeaderMenu(QPoint pos);
|
||||
void headerMenuTriggered();
|
||||
void columnVisibilityTriggered();
|
||||
void sectionResized(int col, int, int new_width);
|
||||
void sectionMoved(int, int, int);
|
||||
|
@ -183,6 +164,7 @@ private slots:
|
|||
void vScrollBarActionTriggered(int);
|
||||
void drawFarOverlay();
|
||||
void drawNearOverlay();
|
||||
void updatePackets(bool redraw);
|
||||
};
|
||||
|
||||
#endif // PACKET_LIST_H
|
||||
|
|
|
@ -10,15 +10,23 @@
|
|||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
#include <QToolTip>
|
||||
#include <QAction>
|
||||
#include <packet_list.h>
|
||||
|
||||
#include <wireshark_application.h>
|
||||
#include <epan/column.h>
|
||||
#include <ui/recent.h>
|
||||
#include <ui/preference_utils.h>
|
||||
#include <ui/packet_list_utils.h>
|
||||
#include <ui/qt/main_window.h>
|
||||
|
||||
#include <models/packet_list_model.h>
|
||||
#include <ui/qt/utils/wireshark_mime_data.h>
|
||||
#include <ui/qt/widgets/packet_list_header.h>
|
||||
|
||||
PacketListHeader::PacketListHeader(Qt::Orientation orientation, QWidget *parent) :
|
||||
QHeaderView(orientation, parent)
|
||||
PacketListHeader::PacketListHeader(Qt::Orientation orientation, capture_file * cap_file, QWidget *parent) :
|
||||
QHeaderView(orientation, parent),
|
||||
cap_file_(cap_file)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
setSectionsMovable(true);
|
||||
|
@ -133,6 +141,175 @@ void PacketListHeader::mouseMoveEvent(QMouseEvent *e)
|
|||
QHeaderView::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
void PacketListHeader::setCaptureFile(capture_file *cap_file)
|
||||
{
|
||||
this->cap_file_ = cap_file;
|
||||
}
|
||||
|
||||
void PacketListHeader::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
int sectionIdx = logicalIndexAt(event->pos());
|
||||
QAction * action = Q_NULLPTR;
|
||||
QMenu * contextMenu = new QMenu(this);
|
||||
contextMenu->setProperty("column", qVariantFromValue(sectionIdx));
|
||||
|
||||
QActionGroup * alignmentActions = new QActionGroup(contextMenu);
|
||||
alignmentActions->setExclusive(true);
|
||||
alignmentActions->setProperty("column", qVariantFromValue(sectionIdx));
|
||||
action = alignmentActions->addAction(tr("Align Left"));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(false);
|
||||
if ( recent_get_column_xalign(sectionIdx) == COLUMN_XALIGN_LEFT || recent_get_column_xalign(sectionIdx) == COLUMN_XALIGN_DEFAULT )
|
||||
action->setChecked(true);
|
||||
action->setData(qVariantFromValue(COLUMN_XALIGN_LEFT));
|
||||
action = alignmentActions->addAction(tr("Align Center"));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(recent_get_column_xalign(sectionIdx) == COLUMN_XALIGN_CENTER ? true : false);
|
||||
action->setData(qVariantFromValue(COLUMN_XALIGN_CENTER));
|
||||
action = alignmentActions->addAction(tr("Align Right"));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(recent_get_column_xalign(sectionIdx) == COLUMN_XALIGN_RIGHT ? true : false);
|
||||
action->setData(qVariantFromValue(COLUMN_XALIGN_RIGHT));
|
||||
connect(alignmentActions, &QActionGroup::triggered, this, &PacketListHeader::setAlignment);
|
||||
|
||||
contextMenu->addActions(alignmentActions->actions());
|
||||
contextMenu->addSeparator();
|
||||
|
||||
action = contextMenu->addAction(tr("Column Preferences" UTF8_HORIZONTAL_ELLIPSIS));
|
||||
connect(action, &QAction::triggered, this, &PacketListHeader::showColumnPrefs);
|
||||
action = contextMenu->addAction(tr("Edit Column"));
|
||||
connect(action, &QAction::triggered, this, &PacketListHeader::doEditColumn);
|
||||
action = contextMenu->addAction(tr("Resize to Contents"));
|
||||
connect(action, &QAction::triggered, this, &PacketListHeader::resizeToContent);
|
||||
|
||||
action = contextMenu->addAction(tr("Resolve Names"));
|
||||
bool canResolve = resolve_column(sectionIdx, cap_file_);
|
||||
action->setEnabled(canResolve);
|
||||
action->setChecked(canResolve && get_column_resolved(sectionIdx));
|
||||
connect(action, &QAction::triggered, this, &PacketListHeader::doResolveNames);
|
||||
|
||||
contextMenu->addSeparator();
|
||||
|
||||
for (int cnt = 0; cnt < prefs.num_cols; cnt++) {
|
||||
QAction *action = new QAction(get_column_title(cnt));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(get_column_visible(cnt));
|
||||
action->setData(QVariant::fromValue(cnt));
|
||||
connect(action, &QAction::triggered, this, &PacketListHeader::columnVisibilityTriggered);
|
||||
contextMenu->addAction(action);
|
||||
}
|
||||
|
||||
contextMenu->addSeparator();
|
||||
|
||||
action = contextMenu->addAction(tr("Remove this Column"));
|
||||
action->setEnabled(sectionIdx >= 0 && count() > 2);
|
||||
connect(action, &QAction::triggered, this, &PacketListHeader::removeColumn);
|
||||
|
||||
contextMenu->popup(viewport()->mapToGlobal(event->pos()));
|
||||
}
|
||||
|
||||
void PacketListHeader::setSectionVisibility()
|
||||
{
|
||||
for (int cnt = 0; cnt < prefs.num_cols; cnt++)
|
||||
setSectionHidden(cnt, get_column_visible(cnt) ? false : true);
|
||||
}
|
||||
|
||||
void PacketListHeader::columnVisibilityTriggered()
|
||||
{
|
||||
QAction *ha = qobject_cast<QAction*>(sender());
|
||||
if (!ha) return;
|
||||
|
||||
int col = ha->data().toInt();
|
||||
set_column_visible(col, ha->isChecked());
|
||||
setSectionVisibility();
|
||||
if (ha->isChecked())
|
||||
emit resetColumnWidth(col);
|
||||
|
||||
prefs_main_write();
|
||||
}
|
||||
|
||||
void PacketListHeader::setAlignment(QAction *action)
|
||||
{
|
||||
if (!action)
|
||||
return;
|
||||
|
||||
QActionGroup * group = action->actionGroup();
|
||||
if (! group)
|
||||
return;
|
||||
|
||||
int section = group->property("column").toInt();
|
||||
if ( section >= 0 )
|
||||
{
|
||||
QChar data = action->data().toChar();
|
||||
recent_set_column_xalign(section, action->isChecked() ? data.toLatin1() : COLUMN_XALIGN_DEFAULT);
|
||||
emit updatePackets(false);
|
||||
}
|
||||
}
|
||||
|
||||
void PacketListHeader::showColumnPrefs()
|
||||
{
|
||||
emit showColumnPreferences(PrefsModel::COLUMNS_PREFERENCE_TREE_NAME);
|
||||
}
|
||||
|
||||
void PacketListHeader::doEditColumn()
|
||||
{
|
||||
QAction * action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
return;
|
||||
|
||||
QMenu * menu = qobject_cast<QMenu *>(action->parent());
|
||||
if (! menu)
|
||||
return;
|
||||
|
||||
int section = menu->property("column").toInt();
|
||||
emit editColumn(section);
|
||||
}
|
||||
|
||||
void PacketListHeader::doResolveNames()
|
||||
{
|
||||
QAction * action = qobject_cast<QAction *>(sender());
|
||||
QMenu * menu = qobject_cast<QMenu *>(action->parent());
|
||||
PacketListModel * plmModel = qobject_cast<PacketListModel *>(model());
|
||||
if ( ! action || ! menu || ! plmModel )
|
||||
return;
|
||||
|
||||
int section = menu->property("column").toInt();
|
||||
|
||||
set_column_resolved(section, action->isChecked());
|
||||
plmModel->resetColumns();
|
||||
prefs_main_write();
|
||||
emit updatePackets(true);
|
||||
}
|
||||
|
||||
void PacketListHeader::resizeToContent()
|
||||
{
|
||||
QAction * action = qobject_cast<QAction *>(sender());
|
||||
QMenu * menu = qobject_cast<QMenu *>(action->parent());
|
||||
if (! action || ! menu)
|
||||
return;
|
||||
|
||||
int section = menu->property("column").toInt();
|
||||
PacketList * packetList = qobject_cast<PacketList *>(parent());
|
||||
if ( packetList )
|
||||
packetList->resizeColumnToContents(section);
|
||||
}
|
||||
|
||||
void PacketListHeader::removeColumn()
|
||||
{
|
||||
QAction * action = qobject_cast<QAction *>(sender());
|
||||
QMenu * menu = qobject_cast<QMenu *>(action->parent());
|
||||
if (! action || ! menu)
|
||||
return;
|
||||
|
||||
int section = menu->property("column").toInt();
|
||||
|
||||
if (count() > 2) {
|
||||
column_prefs_remove_nth(section);
|
||||
emit columnsChanged();
|
||||
prefs_main_write();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
|
|
|
@ -10,14 +10,22 @@
|
|||
#ifndef UI_QT_WIDGETS_PACKET_LIST_HEADER_H_
|
||||
#define UI_QT_WIDGETS_PACKET_LIST_HEADER_H_
|
||||
|
||||
#include <cfile.h>
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QDrag>
|
||||
#include <QMenu>
|
||||
|
||||
class QEvent;
|
||||
|
||||
class PacketListHeader : public QHeaderView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PacketListHeader(Qt::Orientation orientation, QWidget *parent = nullptr);
|
||||
PacketListHeader(Qt::Orientation orientation, capture_file * cap_file, QWidget *parent = nullptr);
|
||||
|
||||
void setCaptureFile(capture_file * cap_file);
|
||||
|
||||
protected:
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
@ -27,11 +35,34 @@ protected:
|
|||
virtual void mouseMoveEvent(QMouseEvent *e) override;
|
||||
virtual void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
virtual void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
|
||||
protected slots:
|
||||
void columnVisibilityTriggered();
|
||||
|
||||
void setAlignment(QAction *);
|
||||
|
||||
void showColumnPrefs();
|
||||
void doEditColumn();
|
||||
void doResolveNames();
|
||||
void resizeToContent();
|
||||
void removeColumn();
|
||||
|
||||
signals:
|
||||
void resetColumnWidth(int col);
|
||||
void updatePackets(bool redraw);
|
||||
void showColumnPreferences(QString pane_name);
|
||||
void editColumn(int column);
|
||||
|
||||
void columnsChanged();
|
||||
|
||||
private:
|
||||
|
||||
capture_file * cap_file_;
|
||||
int sectionIdx;
|
||||
int lastSize;
|
||||
|
||||
void setSectionVisibility();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue