2012-01-04 22:13:01 +00:00
|
|
|
/* proto_tree.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2017-12-07 16:15:30 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-01-04 22:13:01 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-14 00:16:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
#include "proto_tree.h"
|
2017-12-07 16:15:30 +00:00
|
|
|
#include <ui/qt/models/proto_tree_model.h>
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-19 23:52:08 +00:00
|
|
|
#include <epan/ftypes/ftypes.h>
|
2012-01-04 22:13:01 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/variant_pointer.h>
|
2017-11-07 15:51:43 +00:00
|
|
|
#include <ui/qt/utils/wireshark_mime_data.h>
|
|
|
|
#include <ui/qt/widgets/drag_label.h>
|
2017-01-11 12:55:23 +00:00
|
|
|
|
2014-09-23 20:35:10 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QDesktopServices>
|
2012-01-04 22:13:01 +00:00
|
|
|
#include <QHeaderView>
|
2017-12-07 16:15:30 +00:00
|
|
|
#include <QItemSelectionModel>
|
2016-03-10 20:43:59 +00:00
|
|
|
#include <QScrollBar>
|
2017-12-07 16:15:30 +00:00
|
|
|
#include <QStack>
|
2012-08-19 23:52:08 +00:00
|
|
|
#include <QUrl>
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2017-11-07 15:51:43 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
#include <QWindow>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-07-23 19:53:45 +00:00
|
|
|
// To do:
|
|
|
|
// - Fix "apply as filter" behavior.
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
ProtoTree::ProtoTree(QWidget *parent) :
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView(parent),
|
|
|
|
proto_tree_model_(new ProtoTreeModel(this)),
|
2016-03-10 20:43:59 +00:00
|
|
|
decode_as_(NULL),
|
2017-11-09 17:39:55 +00:00
|
|
|
column_resize_timer_(0),
|
|
|
|
cap_file_(NULL)
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
2012-03-07 10:16:33 +00:00
|
|
|
setAccessibleName(tr("Packet details"));
|
2015-05-12 23:28:39 +00:00
|
|
|
// Leave the uniformRowHeights property as-is (false) since items might
|
|
|
|
// have multiple lines (e.g. packet comments). If this slows things down
|
|
|
|
// too much we should add a custom delegate which handles SizeHintRole
|
|
|
|
// similar to PacketListModel::data.
|
2015-02-11 23:00:27 +00:00
|
|
|
setHeaderHidden(true);
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
setModel(proto_tree_model_);
|
|
|
|
|
2015-02-11 23:00:27 +00:00
|
|
|
if (window()->findChild<QAction *>("actionViewExpandSubtrees")) {
|
|
|
|
// Assume we're a child of the main window.
|
|
|
|
// XXX We might want to reimplement setParent() and fill in the context
|
|
|
|
// menu there.
|
2015-07-29 23:24:39 +00:00
|
|
|
QMenu *main_menu_item, *submenu;
|
2015-07-23 19:53:45 +00:00
|
|
|
QAction *action;
|
|
|
|
|
2015-02-11 23:00:27 +00:00
|
|
|
ctx_menu_.addAction(window()->findChild<QAction *>("actionViewExpandSubtrees"));
|
|
|
|
ctx_menu_.addAction(window()->findChild<QAction *>("actionViewExpandAll"));
|
|
|
|
ctx_menu_.addAction(window()->findChild<QAction *>("actionViewCollapseAll"));
|
|
|
|
ctx_menu_.addSeparator();
|
2015-03-09 07:11:13 +00:00
|
|
|
|
|
|
|
action = window()->findChild<QAction *>("actionAnalyzeCreateAColumn");
|
|
|
|
ctx_menu_.addAction(action);
|
|
|
|
ctx_menu_.addSeparator();
|
|
|
|
|
2015-07-27 22:28:50 +00:00
|
|
|
main_menu_item = window()->findChild<QMenu *>("menuApplyAsFilter");
|
2017-09-17 21:48:12 +00:00
|
|
|
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
2015-07-23 19:53:45 +00:00
|
|
|
ctx_menu_.addMenu(submenu);
|
2015-02-11 23:00:27 +00:00
|
|
|
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"));
|
|
|
|
|
2015-07-27 22:28:50 +00:00
|
|
|
main_menu_item = window()->findChild<QMenu *>("menuPrepareAFilter");
|
2017-09-17 21:48:12 +00:00
|
|
|
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
2015-07-23 19:53:45 +00:00
|
|
|
ctx_menu_.addMenu(submenu);
|
2015-02-11 23:00:27 +00:00
|
|
|
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"));
|
2013-12-21 16:55:43 +00:00
|
|
|
|
2014-08-08 10:59:42 +00:00
|
|
|
QMenu *main_conv_menu = window()->findChild<QMenu *>("menuConversationFilter");
|
|
|
|
conv_menu_.setTitle(main_conv_menu->title());
|
|
|
|
ctx_menu_.addMenu(&conv_menu_);
|
|
|
|
|
2015-07-30 23:15:40 +00:00
|
|
|
colorize_menu_.setTitle(tr("Colorize with Filter"));
|
|
|
|
ctx_menu_.addMenu(&colorize_menu_);
|
2015-07-30 20:55:46 +00:00
|
|
|
|
|
|
|
main_menu_item = window()->findChild<QMenu *>("menuFollow");
|
2017-09-17 21:48:12 +00:00
|
|
|
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
2015-07-30 20:55:46 +00:00
|
|
|
ctx_menu_.addMenu(submenu);
|
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowTCPStream"));
|
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowUDPStream"));
|
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowSSLStream"));
|
2016-01-02 13:58:08 +00:00
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionAnalyzeFollowHTTPStream"));
|
2015-02-11 23:00:27 +00:00
|
|
|
ctx_menu_.addSeparator();
|
|
|
|
|
2015-07-29 23:24:39 +00:00
|
|
|
main_menu_item = window()->findChild<QMenu *>("menuEditCopy");
|
2017-09-17 21:48:12 +00:00
|
|
|
submenu = new QMenu(main_menu_item->title(), &ctx_menu_);
|
2015-07-24 01:39:30 +00:00
|
|
|
ctx_menu_.addMenu(submenu);
|
2015-03-23 11:04:36 +00:00
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionCopyAllVisibleItems"));
|
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionCopyAllVisibleSelectedTreeItems"));
|
2015-02-11 23:00:27 +00:00
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionEditCopyDescription"));
|
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionEditCopyFieldName"));
|
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionEditCopyValue"));
|
|
|
|
submenu->addSeparator();
|
|
|
|
|
2015-07-30 19:23:03 +00:00
|
|
|
submenu->addAction(window()->findChild<QAction *>("actionEditCopyAsFilter"));
|
2015-07-29 23:24:39 +00:00
|
|
|
submenu->addSeparator();
|
|
|
|
|
|
|
|
action = window()->findChild<QAction *>("actionContextCopyBytesHexTextDump");
|
|
|
|
submenu->addAction(action);
|
|
|
|
copy_actions_ << action;
|
|
|
|
action = window()->findChild<QAction *>("actionContextCopyBytesHexDump");
|
|
|
|
submenu->addAction(action);
|
|
|
|
copy_actions_ << action;
|
|
|
|
action = window()->findChild<QAction *>("actionContextCopyBytesPrintableText");
|
|
|
|
submenu->addAction(action);
|
|
|
|
copy_actions_ << action;
|
|
|
|
action = window()->findChild<QAction *>("actionContextCopyBytesHexStream");
|
|
|
|
submenu->addAction(action);
|
|
|
|
copy_actions_ << action;
|
|
|
|
action = window()->findChild<QAction *>("actionContextCopyBytesBinary");
|
|
|
|
submenu->addAction(action);
|
|
|
|
copy_actions_ << action;
|
2016-09-14 03:33:54 +00:00
|
|
|
action = window()->findChild<QAction *>("actionContextCopyBytesEscapedString");
|
|
|
|
submenu->addAction(action);
|
|
|
|
copy_actions_ << action;
|
2015-07-29 23:24:39 +00:00
|
|
|
|
2016-02-07 21:15:12 +00:00
|
|
|
action = window()->findChild<QAction *>("actionContextShowPacketBytes");
|
|
|
|
ctx_menu_.addAction(action);
|
2015-07-30 20:55:46 +00:00
|
|
|
action = window()->findChild<QAction *>("actionFileExportPacketBytes");
|
|
|
|
ctx_menu_.addAction(action);
|
|
|
|
|
|
|
|
ctx_menu_.addSeparator();
|
|
|
|
|
2015-07-31 23:52:37 +00:00
|
|
|
action = window()->findChild<QAction *>("actionContextWikiProtocolPage");
|
|
|
|
ctx_menu_.addAction(action);
|
|
|
|
action = window()->findChild<QAction *>("actionContextFilterFieldReference");
|
|
|
|
ctx_menu_.addAction(action);
|
2015-06-17 00:24:19 +00:00
|
|
|
ctx_menu_.addMenu(&proto_prefs_menu_);
|
|
|
|
ctx_menu_.addSeparator();
|
2015-02-11 23:00:27 +00:00
|
|
|
decode_as_ = window()->findChild<QAction *>("actionAnalyzeDecodeAs");
|
|
|
|
ctx_menu_.addAction(decode_as_);
|
2012-12-07 01:46:20 +00:00
|
|
|
// " <menuitem name='ResolveName' action='/ResolveName'/>\n"
|
2015-07-31 23:52:37 +00:00
|
|
|
ctx_menu_.addAction(window()->findChild<QAction *>("actionGoGoToLinkedPacket"));
|
|
|
|
ctx_menu_.addAction(window()->findChild<QAction *>("actionContextShowLinkedPacketInNewWindow"));
|
2015-02-11 23:00:27 +00:00
|
|
|
} else {
|
|
|
|
ctx_menu_.clear();
|
|
|
|
}
|
2012-12-07 01:46:20 +00:00
|
|
|
|
2012-08-19 20:47:11 +00:00
|
|
|
connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expand(QModelIndex)));
|
|
|
|
connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(collapse(QModelIndex)));
|
2017-12-07 16:15:30 +00:00
|
|
|
connect(this, SIGNAL(doubleClicked(QModelIndex)),
|
|
|
|
this, SLOT(itemDoubleClicked(QModelIndex)));
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
connect(&proto_prefs_menu_, SIGNAL(showProtocolPreferences(QString)),
|
|
|
|
this, SIGNAL(showProtocolPreferences(QString)));
|
2015-06-17 15:41:41 +00:00
|
|
|
connect(&proto_prefs_menu_, SIGNAL(editProtocolPreference(preference*,pref_module*)),
|
|
|
|
this, SIGNAL(editProtocolPreference(preference*,pref_module*)));
|
2016-03-10 20:43:59 +00:00
|
|
|
|
|
|
|
// resizeColumnToContents checks 1000 items by default. The user might
|
|
|
|
// have scrolled to an area with a different width at this point.
|
|
|
|
connect(verticalScrollBar(), SIGNAL(sliderReleased()),
|
|
|
|
this, SLOT(updateContentWidth()));
|
2017-11-07 15:51:43 +00:00
|
|
|
|
|
|
|
viewport()->installEventFilter(this);
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::clear() {
|
|
|
|
proto_tree_model_->setRootNode(NULL);
|
|
|
|
updateContentWidth();
|
|
|
|
}
|
|
|
|
|
2015-08-18 17:18:07 +00:00
|
|
|
void ProtoTree::closeContextMenu()
|
|
|
|
{
|
|
|
|
ctx_menu_.close();
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:46:20 +00:00
|
|
|
void ProtoTree::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
2015-02-11 23:00:27 +00:00
|
|
|
if (ctx_menu_.isEmpty()) return; // We're in a PacketDialog
|
|
|
|
|
2014-08-08 10:59:42 +00:00
|
|
|
QMenu *main_conv_menu = window()->findChild<QMenu *>("menuConversationFilter");
|
|
|
|
conv_menu_.clear();
|
|
|
|
foreach (QAction *action, main_conv_menu->actions()) {
|
|
|
|
conv_menu_.addAction(action);
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
QModelIndex index;
|
|
|
|
if (selectionModel()->hasSelection()) {
|
|
|
|
index = selectedIndexes().first();
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
|
|
|
|
proto_prefs_menu_.setModule(finfo.moduleName());
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2015-07-29 23:24:39 +00:00
|
|
|
foreach (QAction *action, copy_actions_) {
|
2017-10-30 12:58:28 +00:00
|
|
|
action->setProperty("idataprintable_",
|
2017-12-07 16:15:30 +00:00
|
|
|
VariantPointer<IDataPrintable>::asQVariant((IDataPrintable *)&finfo));
|
2015-07-29 23:24:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 21:07:26 +00:00
|
|
|
decode_as_->setData(qVariantFromValue(true));
|
2015-07-29 23:24:39 +00:00
|
|
|
|
|
|
|
// Set menu sensitivity and action data.
|
2017-12-07 16:15:30 +00:00
|
|
|
emit fieldSelected(&finfo);
|
2012-12-07 01:46:20 +00:00
|
|
|
ctx_menu_.exec(event->globalPos());
|
2013-12-10 21:07:26 +00:00
|
|
|
decode_as_->setData(QVariant());
|
2012-12-07 01:46:20 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 20:43:59 +00:00
|
|
|
void ProtoTree::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() == column_resize_timer_) {
|
|
|
|
killTimer(column_resize_timer_);
|
|
|
|
column_resize_timer_ = 0;
|
|
|
|
resizeColumnToContents(0);
|
2016-03-14 20:29:21 +00:00
|
|
|
} else {
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView::timerEvent(event);
|
2016-03-10 20:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// resizeColumnToContents checks 1000 items by default. The user might
|
|
|
|
// have scrolled to an area with a different width at this point.
|
|
|
|
void ProtoTree::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (event->isAutoRepeat()) return;
|
|
|
|
|
|
|
|
switch(event->key()) {
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_Down:
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
case Qt::Key_Home:
|
|
|
|
case Qt::Key_End:
|
|
|
|
updateContentWidth();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtoTree::updateContentWidth()
|
|
|
|
{
|
|
|
|
if (column_resize_timer_ == 0) {
|
|
|
|
column_resize_timer_ = startTimer(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 20:35:10 +00:00
|
|
|
void ProtoTree::setMonospaceFont(const QFont &mono_font)
|
|
|
|
{
|
|
|
|
mono_font_ = mono_font;
|
|
|
|
setFont(mono_font_);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::setRootNode(proto_node *root_node) {
|
2014-09-23 20:35:10 +00:00
|
|
|
setFont(mono_font_);
|
2017-12-07 16:15:30 +00:00
|
|
|
proto_tree_model_->setRootNode(root_node);
|
2016-03-10 20:43:59 +00:00
|
|
|
updateContentWidth();
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 01:56:14 +00:00
|
|
|
void ProtoTree::emitRelatedFrame(int related_frame, ft_framenum_type_t framenum_type)
|
2013-07-08 16:54:18 +00:00
|
|
|
{
|
2015-02-24 01:56:14 +00:00
|
|
|
emit relatedFrame(related_frame, framenum_type);
|
2013-07-08 16:54:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 22:22:20 +00:00
|
|
|
// XXX We select the first match, which might not be the desired item.
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::goToHfid(int hfid)
|
2015-03-11 22:22:20 +00:00
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
QModelIndex index = proto_tree_model_->findFirstHfid(hfid);
|
|
|
|
if (index.isValid()) {
|
|
|
|
scrollTo(index);
|
|
|
|
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
|
2015-03-11 22:22:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
2015-09-15 06:46:43 +00:00
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView::selectionChanged(selected, deselected);
|
|
|
|
if (selected.isEmpty()) return;
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
QModelIndex index = selected.indexes().first();
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
|
|
|
|
if (!finfo.isValid()) return;
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
// Find and highlight the protocol bytes
|
|
|
|
QModelIndex parent = index;
|
|
|
|
while (parent.isValid() && parent.parent().isValid()) {
|
|
|
|
parent = parent.parent();
|
|
|
|
}
|
|
|
|
if (parent.isValid()) {
|
|
|
|
FieldInformation parent_finfo(proto_tree_model_->protoNodeFromIndex(parent).protoNode());
|
|
|
|
finfo.setParentField(parent_finfo.fieldInfo());
|
|
|
|
}
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
if ( finfo.isValid() )
|
|
|
|
{
|
|
|
|
saveSelectedField(index);
|
|
|
|
emit fieldSelected(&finfo);
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
// else the GTK+ version pushes an empty string as described below.
|
|
|
|
/*
|
|
|
|
* Don't show anything if the field name is zero-length;
|
|
|
|
* the pseudo-field for text-only items is such
|
|
|
|
* a field, and we don't want "Text (text)" showing up
|
|
|
|
* on the status line if you've selected such a field.
|
|
|
|
*
|
|
|
|
* XXX - there are zero-length fields for which we *do*
|
|
|
|
* want to show the field name.
|
|
|
|
*
|
|
|
|
* XXX - perhaps the name and abbrev field should be null
|
|
|
|
* pointers rather than null strings for that pseudo-field,
|
|
|
|
* but we'd have to add checks for null pointers in some
|
|
|
|
* places if we did that.
|
|
|
|
*
|
|
|
|
* Or perhaps text-only items should have -1 as the field
|
|
|
|
* index, with no pseudo-field being used, but that might
|
|
|
|
* also require special checks for -1 to be added.
|
|
|
|
*/
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
2012-08-14 04:12:56 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::expand(const QModelIndex &index) {
|
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
|
|
|
|
if (!finfo.isValid()) return;
|
2012-08-19 20:47:11 +00:00
|
|
|
|
|
|
|
if(prefs.gui_auto_scroll_on_expand) {
|
|
|
|
ScrollHint scroll_hint = PositionAtTop;
|
|
|
|
if (prefs.gui_auto_scroll_percentage > 66) {
|
|
|
|
scroll_hint = PositionAtBottom;
|
|
|
|
} else if (prefs.gui_auto_scroll_percentage >= 33) {
|
|
|
|
scroll_hint = PositionAtCenter;
|
|
|
|
}
|
|
|
|
scrollTo(index, scroll_hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nodes with "finfo->tree_type" of -1 have no ett_ value, and
|
|
|
|
* are thus presumably leaf nodes and cannot be expanded.
|
|
|
|
*/
|
2017-12-07 16:15:30 +00:00
|
|
|
if (finfo.treeType() != -1) {
|
|
|
|
tree_expanded_set(finfo.treeType(), TRUE);
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
2016-01-13 19:27:11 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView::expand(index);
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::collapse(const QModelIndex &index) {
|
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
|
|
|
|
if (!finfo.isValid()) return;
|
2012-08-19 20:47:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nodes with "finfo->tree_type" of -1 have no ett_ value, and
|
|
|
|
* are thus presumably leaf nodes and cannot be collapsed.
|
|
|
|
*/
|
2017-12-07 16:15:30 +00:00
|
|
|
if (finfo.treeType() != -1) {
|
|
|
|
tree_expanded_set(finfo.treeType(), FALSE);
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView::collapse(index);
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
2012-08-14 04:12:56 +00:00
|
|
|
|
|
|
|
void ProtoTree::expandSubtrees()
|
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
if (!selectionModel()->hasSelection()) return;
|
|
|
|
|
|
|
|
QStack<QModelIndex> index_stack;
|
|
|
|
index_stack.push(selectionModel()->selectedIndexes().first());
|
|
|
|
|
|
|
|
while (!index_stack.isEmpty()) {
|
|
|
|
QModelIndex index = index_stack.pop();
|
|
|
|
expand(index);
|
|
|
|
int row_count = proto_tree_model_->rowCount(index);
|
|
|
|
for (int row = row_count - 1; row >= 0; row--) {
|
|
|
|
QModelIndex child = proto_tree_model_->index(row, 0, index);
|
|
|
|
if (proto_tree_model_->hasChildren(child)) {
|
|
|
|
index_stack.push(child);
|
|
|
|
}
|
2012-08-14 04:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
|
2016-03-10 20:43:59 +00:00
|
|
|
updateContentWidth();
|
2012-08-14 04:12:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-19 20:47:11 +00:00
|
|
|
void ProtoTree::expandAll()
|
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
for(int i = 0; i < num_tree_types; i++) {
|
2013-07-07 16:33:49 +00:00
|
|
|
tree_expanded_set(i, TRUE);
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView::expandAll();
|
2016-03-10 20:43:59 +00:00
|
|
|
updateContentWidth();
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtoTree::collapseAll()
|
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
for(int i = 0; i < num_tree_types; i++) {
|
2013-07-07 16:33:49 +00:00
|
|
|
tree_expanded_set(i, FALSE);
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
QTreeView::collapseAll();
|
2016-03-10 20:43:59 +00:00
|
|
|
updateContentWidth();
|
2012-08-19 20:47:11 +00:00
|
|
|
}
|
2012-08-19 23:52:08 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::itemDoubleClicked(const QModelIndex &index) {
|
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
|
|
|
|
if (!finfo.isValid()) return;
|
2012-08-19 23:52:08 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
if (finfo.headerInfo().type == FT_FRAMENUM) {
|
2015-02-13 16:36:53 +00:00
|
|
|
if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier) {
|
|
|
|
emit openPacketInNewWindow(true);
|
|
|
|
} else {
|
2017-12-07 16:15:30 +00:00
|
|
|
emit goToPacket(finfo.fieldInfo()->value.value.uinteger);
|
2015-02-13 16:36:53 +00:00
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
} else {
|
|
|
|
QString url = finfo.url();
|
|
|
|
if (!url.isEmpty()) {
|
2012-08-19 23:52:08 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 08:18:31 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::selectedFieldChanged(FieldInformation *finfo)
|
2016-02-23 08:30:48 +00:00
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
QModelIndex index = proto_tree_model_->findFieldInformation(finfo);
|
|
|
|
if (index.isValid()) {
|
|
|
|
scrollTo(index);
|
|
|
|
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
|
2016-02-23 08:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 22:47:12 +00:00
|
|
|
// Remember the currently focussed field based on:
|
|
|
|
// - current hf_id (obviously)
|
|
|
|
// - parent items (to avoid selecting a text item in a different tree)
|
2017-12-07 16:15:30 +00:00
|
|
|
// - the row of each item
|
|
|
|
void ProtoTree::saveSelectedField(QModelIndex &index)
|
2016-03-29 22:47:12 +00:00
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
selected_hfid_path_.clear();
|
|
|
|
while (index.isValid()) {
|
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode());
|
|
|
|
if (!finfo.isValid()) break;
|
|
|
|
selected_hfid_path_.prepend(QPair<int,int>(index.row(), finfo.headerInfo().id));
|
|
|
|
index = index.parent();
|
|
|
|
}
|
2016-03-29 22:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to focus a tree item which was previously also visible
|
|
|
|
void ProtoTree::restoreSelectedField()
|
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
if (selected_hfid_path_.isEmpty()) return;
|
|
|
|
|
|
|
|
QModelIndex cur_index = QModelIndex();
|
|
|
|
QPair<int,int> path_entry;
|
|
|
|
foreach (path_entry, selected_hfid_path_) {
|
|
|
|
int row = path_entry.first;
|
|
|
|
int hf_id = path_entry.second;
|
|
|
|
cur_index = proto_tree_model_->index(row, 0, cur_index);
|
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(cur_index).protoNode());
|
|
|
|
if (!finfo.isValid() || finfo.headerInfo().id != hf_id) {
|
|
|
|
cur_index = QModelIndex();
|
2016-03-29 22:47:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-12-07 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_index.isValid()) {
|
|
|
|
scrollTo(cur_index);
|
|
|
|
selectionModel()->select(cur_index, QItemSelectionModel::ClearAndSelect);
|
2016-03-29 22:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
const QString ProtoTree::toString(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
QModelIndex cur_idx = index.isValid() ? index : proto_tree_model_->index(0, 0);
|
|
|
|
QString tree_string;
|
|
|
|
int indent_level = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
tree_string.append(QString(" ").repeated(indent_level));
|
|
|
|
tree_string.append(cur_idx.data().toString());
|
|
|
|
tree_string.append("\n");
|
|
|
|
// Next child
|
|
|
|
if (isExpanded(cur_idx)) {
|
|
|
|
cur_idx = proto_tree_model_->index(0, 0, cur_idx);
|
|
|
|
indent_level++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Next sibling
|
|
|
|
QModelIndex sibling = proto_tree_model_->index(cur_idx.row() + 1, 0, cur_idx.parent());
|
|
|
|
if (sibling.isValid()) {
|
|
|
|
cur_idx = sibling;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Next parent
|
|
|
|
cur_idx = proto_tree_model_->index(cur_idx.parent().row() + 1, 0, cur_idx.parent().parent());
|
|
|
|
indent_level--;
|
|
|
|
} while (cur_idx.isValid() && cur_idx != index && indent_level >= 0);
|
|
|
|
|
|
|
|
return tree_string;
|
|
|
|
}
|
|
|
|
|
2017-11-07 15:51:43 +00:00
|
|
|
void ProtoTree::setCaptureFile(capture_file *cf)
|
|
|
|
{
|
|
|
|
cap_file_ = cf;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProtoTree::eventFilter(QObject * obj, QEvent * event)
|
|
|
|
{
|
|
|
|
if ( cap_file_ && event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseMove )
|
2017-12-07 16:15:30 +00:00
|
|
|
return QTreeView::eventFilter(obj, event);
|
2017-11-07 15:51:43 +00:00
|
|
|
|
2017-11-12 10:16:34 +00:00
|
|
|
/* Mouse was over scrollbar, ignoring */
|
|
|
|
if ( qobject_cast<QScrollBar *>(obj) )
|
2017-12-07 16:15:30 +00:00
|
|
|
return QTreeView::eventFilter(obj, event);
|
2017-11-12 10:16:34 +00:00
|
|
|
|
2017-11-07 15:51:43 +00:00
|
|
|
if ( event->type() == QEvent::MouseButtonPress )
|
|
|
|
{
|
2017-11-11 01:15:32 +00:00
|
|
|
QMouseEvent * ev = (QMouseEvent *)event;
|
|
|
|
|
2017-11-07 15:51:43 +00:00
|
|
|
if ( ev->buttons() & Qt::LeftButton )
|
2017-12-07 16:15:30 +00:00
|
|
|
drag_start_position_ = ev->pos();
|
2017-11-07 15:51:43 +00:00
|
|
|
}
|
|
|
|
else if ( event->type() == QEvent::MouseMove )
|
|
|
|
{
|
2017-11-11 01:15:32 +00:00
|
|
|
QMouseEvent * ev = (QMouseEvent *)event;
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
if ( ( ev->buttons() & Qt::LeftButton ) && (ev->pos() - drag_start_position_).manhattanLength()
|
2017-11-07 15:51:43 +00:00
|
|
|
> QApplication::startDragDistance())
|
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
QModelIndex idx = indexAt(drag_start_position_);
|
|
|
|
FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(idx).protoNode());
|
|
|
|
if ( finfo.isValid() )
|
2017-11-07 15:51:43 +00:00
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
/* Hack to prevent QItemSelection taking the item which has been dragged over at start
|
|
|
|
* of drag-drop operation. selectionModel()->blockSignals could have done the trick, but
|
|
|
|
* it does not take in a QTreeWidget (maybe View) */
|
|
|
|
emit fieldSelected(&finfo);
|
|
|
|
selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
|
|
|
QString filter = QString(proto_construct_match_selected_string(finfo.fieldInfo(), cap_file_->edt));
|
|
|
|
|
|
|
|
if ( filter.length() > 0 )
|
2017-11-07 15:51:43 +00:00
|
|
|
{
|
2017-12-07 16:15:30 +00:00
|
|
|
DisplayFilterMimeData * dfmd =
|
|
|
|
new DisplayFilterMimeData(QString(finfo.headerInfo().name), QString(finfo.headerInfo().abbreviation), filter);
|
|
|
|
QDrag * drag = new QDrag(this);
|
|
|
|
drag->setMimeData(dfmd);
|
|
|
|
|
|
|
|
DragLabel * content = new DragLabel(dfmd->labelText(), this);
|
|
|
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
qreal dpr = window()->windowHandle()->devicePixelRatio();
|
|
|
|
QPixmap pixmap(content->size() * dpr);
|
|
|
|
pixmap.setDevicePixelRatio(dpr);
|
|
|
|
#else
|
|
|
|
QPixmap pixmap(content->size());
|
|
|
|
#endif
|
|
|
|
content->render(&pixmap);
|
|
|
|
drag->setPixmap(pixmap);
|
|
|
|
|
|
|
|
drag->exec(Qt::CopyAction);
|
|
|
|
|
|
|
|
return true;
|
2017-11-07 15:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
return QTreeView::eventFilter(obj, event);
|
2017-11-07 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtoTree::rowsInserted(const QModelIndex &parent, int start, int end)
|
|
|
|
{
|
|
|
|
for (int row = start; row <= end; row++) {
|
|
|
|
QModelIndex index = proto_tree_model_->index(row, 0, parent);
|
|
|
|
if (proto_tree_model_->protoNodeFromIndex(index).isExpanded()) {
|
|
|
|
QTreeView::setExpanded(index, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-07 15:51:43 +00:00
|
|
|
|
2012-09-04 08:18:31 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|