Wireshark  4.3.0
The Wireshark network protocol analyzer
enabled_protocols_model.h
Go to the documentation of this file.
1 
10 #ifndef ENABLED_PROTOCOLS_MODEL_H
11 #define ENABLED_PROTOCOLS_MODEL_H
12 
13 #include <config.h>
14 
16 
17 #include <epan/proto.h>
18 
19 #include <QAbstractItemModel>
20 #include <QSortFilterProxyModel>
21 
22 class EnabledProtocolItem : public ModelHelperTreeItem<EnabledProtocolItem>
23 {
24  Q_GADGET
25 public:
26  enum EnableProtocolType{
27  Any,
28  Standard,
29  Heuristic
30  };
31  Q_ENUM(EnableProtocolType)
32 
33  EnabledProtocolItem(QString name, QString description, bool enabled, EnabledProtocolItem* parent);
34  virtual ~EnabledProtocolItem();
35 
36  QString name() const {return name_;}
37  QString description() const {return description_;}
38  bool enabled() const {return enabled_;}
39  void setEnabled(bool enable) {enabled_ = enable;}
40 
41  EnableProtocolType type() const;
42 
43  bool applyValue();
44 
45 protected:
46  virtual void applyValuePrivate(bool value) = 0;
47 
48  QString name_;
49  QString description_;
50  bool enabled_;
51  bool enabledInit_; //value that model starts with to determine change
52  EnableProtocolType type_;
53 };
54 
55 class EnabledProtocolsModel : public QAbstractItemModel
56 {
57  Q_OBJECT
58 
59 public:
60  explicit EnabledProtocolsModel(QObject * parent = Q_NULLPTR);
61  virtual ~EnabledProtocolsModel();
62 
63  enum EnabledProtocolsColumn {
64  colProtocol = 0,
65  colDescription,
66  colLast
67  };
68 
69  enum EnableProtocolData {
70  DATA_ENABLE = Qt::UserRole,
71  DATA_PROTOCOL_TYPE
72  };
73 
74  QModelIndex index(int row, int column,
75  const QModelIndex & = QModelIndex()) const;
76  QModelIndex parent(const QModelIndex &) const;
77  Qt::ItemFlags flags(const QModelIndex &index) const;
78  QVariant data(const QModelIndex &index, int role) const;
79  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
80 
81  QVariant headerData(int section, Qt::Orientation orientation,
82  int role = Qt::DisplayRole) const;
83 
84  int rowCount(const QModelIndex &parent = QModelIndex()) const;
85  int columnCount(const QModelIndex &parent = QModelIndex()) const;
86 
87  void populate();
88 
89  void applyChanges(bool writeChanges = true);
90  static void disableProtocol(struct _protocol *protocol);
91 
92 protected:
93  static void saveChanges(bool writeChanges = true);
94 
95 private:
96  EnabledProtocolItem* root_;
97 };
98 
99 class EnabledProtocolsProxyModel : public QSortFilterProxyModel
100 {
101  Q_OBJECT
102 
103 public:
104  enum SearchType
105  {
106  EveryWhere,
107  OnlyProtocol,
108  OnlyDescription,
109  EnabledItems,
110  DisabledItems
111  };
112  Q_ENUM(SearchType)
113 
114  enum EnableType
115  {
116  Enable,
117  Disable,
118  Invert
119  };
120 
121  explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR);
122 
123  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
124  virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
125 
126  void setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type,
127  EnabledProtocolItem::EnableProtocolType protocolType);
128 
129  void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable, QModelIndex parent = QModelIndex());
130 
131 protected:
132  bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
133 
134 private:
135  EnabledProtocolsProxyModel::SearchType type_;
136  EnabledProtocolItem::EnableProtocolType protocolType_;
137  QString filter_;
138 
139  bool filterAcceptsSelf(int sourceRow, const QModelIndex &sourceParent) const;
140  bool filterAcceptsChild(int sourceRow, const QModelIndex &sourceParent) const;
141 };
142 
143 #endif // ENABLED_PROTOCOLS_MODEL_H
Definition: enabled_protocols_model.h:23
Definition: enabled_protocols_model.h:56
Definition: enabled_protocols_model.h:100
Definition: tree_model_helpers.h:23
Definition: proto.c:372