1 /* proto_tree.h 2 * 3 * Wireshark - Network traffic analyzer 4 * By Gerald Combs <gerald@wireshark.org> 5 * Copyright 1998 Gerald Combs 6 * 7 * SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #ifndef PROTO_TREE_H 11 #define PROTO_TREE_H 12 13 #include <config.h> 14 15 #include <epan/proto.h> 16 17 #include "cfile.h" 18 19 #include "protocol_preferences_menu.h" 20 21 #include <ui/qt/utils/field_information.h> 22 #include <QTreeView> 23 #include <QMenu> 24 25 class ProtoTreeModel; 26 class ProtoNode; 27 28 class ProtoTree : public QTreeView 29 { 30 Q_OBJECT 31 public: 32 explicit ProtoTree(QWidget *parent = 0, epan_dissect_t *edt_fixed = 0); colorizeMenu()33 QMenu *colorizeMenu() { return &colorize_menu_; } 34 void setRootNode(proto_node *root_node); 35 void emitRelatedFrame(int related_frame, ft_framenum_type_t framenum_type = FT_FRAMENUM_NONE); 36 void autoScrollTo(const QModelIndex &index); 37 void goToHfid(int hfid); 38 void clear(); 39 void restoreSelectedField(); 40 QString toString(const QModelIndex &start_idx = QModelIndex()) const; 41 42 protected: 43 44 enum { 45 Name = 0, 46 Description, 47 Value 48 }; 49 50 virtual void contextMenuEvent(QContextMenuEvent *event); 51 virtual void timerEvent(QTimerEvent *event); 52 virtual void keyReleaseEvent(QKeyEvent *event); 53 virtual bool eventFilter(QObject * obj, QEvent * ev); 54 virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); 55 56 QString traverseTree(const QModelIndex & rootNode, int identLevel = 0) const; 57 58 private: 59 ProtoTreeModel *proto_tree_model_; 60 QMenu conv_menu_; 61 QMenu colorize_menu_; 62 ProtocolPreferencesMenu proto_prefs_menu_; 63 QList<QAction *> copy_actions_; 64 int column_resize_timer_; 65 QList<QPair<int,int> > selected_hfid_path_; // row, hfinfo 66 67 QPoint drag_start_position_; 68 69 capture_file *cap_file_; 70 epan_dissect_t *edt_; 71 72 void saveSelectedField(QModelIndex &index); 73 static void foreachTreeNode(proto_node *node, gpointer proto_tree_ptr); 74 75 signals: 76 void fieldSelected(FieldInformation *); 77 void openPacketInNewWindow(bool); 78 void goToPacket(int); 79 void relatedFrame(int, ft_framenum_type_t); 80 void showProtocolPreferences(const QString module_name); 81 void editProtocolPreference(struct preference *pref, struct pref_module *module); 82 83 public slots: 84 85 /* Set the capture file */ 86 void setCaptureFile(capture_file *cf); 87 void setMonospaceFont(const QFont &mono_font); 88 void syncExpanded(const QModelIndex & index); 89 void syncCollapsed(const QModelIndex & index); 90 void expandSubtrees(); 91 void collapseSubtrees(); 92 void expandAll(); 93 void collapseAll(); 94 void itemClicked(const QModelIndex & index); 95 void itemDoubleClicked(const QModelIndex & index); 96 void selectedFieldChanged(FieldInformation *); 97 void selectedFrameChanged(QList<int>); 98 99 protected slots: 100 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 101 #if 0 102 void ctxShowPacketBytes(); 103 void ctxExportPacketBytes(); 104 #endif 105 void ctxCopyVisibleItems(); 106 void ctxCopyAsFilter(); 107 void ctxCopySelectedInfo(); 108 void ctxOpenUrlWiki(); 109 110 private slots: 111 void updateContentWidth(); 112 void connectToMainWindow(); 113 }; 114 115 #endif // PROTO_TREE_H 116