1 /* decode_as_delegate.h
2  * Delegates for editing various field types in a Decode As record.
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef DECODE_AS_DELEGATE_H
12 #define DECODE_AS_DELEGATE_H
13 
14 #include <config.h>
15 #include <glib.h>
16 
17 #include "cfile.h"
18 
19 #include <QStyledItemDelegate>
20 #include <QSet>
21 #include <QList>
22 #include <ui/qt/models/decode_as_model.h>
23 
24 typedef struct _packet_proto_data_t {
25     const gchar* proto_name;
26     const gchar* table_ui_name;
27     guint8       curr_layer_num;
28 } packet_proto_data_t;
29 
30 class DecodeAsDelegate : public QStyledItemDelegate
31 {
32 public:
33     DecodeAsDelegate(QObject *parent = 0, capture_file *cf = NULL);
34 
35     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
36                           const QModelIndex &index) const;
37     void setEditorData(QWidget *editor, const QModelIndex &index) const;
38     void setModelData(QWidget *editor, QAbstractItemModel *model,
39                       const QModelIndex &index) const;
40 
41 #if 0
42     void updateEditorGeometry(QWidget *editor,
43             const QStyleOptionViewItem &option, const QModelIndex &index) const;
44 #endif
45 
46 private:
47     DecodeAsItem *indexToField(const QModelIndex &index) const;
48     void collectDAProtocols(QSet<QString>& all_protocols, QList<QString>& current_list) const;
49     void cachePacketProtocols();
50     bool isSelectorCombo(DecodeAsItem* item) const;
51 
52     static void decodeAddProtocol(const gchar *table_name, const gchar *proto_name, gpointer value, gpointer user_data);
53 
54     capture_file *cap_file_;
55     QList<packet_proto_data_t> packet_proto_list_;
56 };
57 #endif // DECODE_AS_DELEGATE_H
58