Wireshark 4.7.3
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
enabled_protocols_model.h
Go to the documentation of this file.
1
9
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
25class EnabledProtocolItem : public ModelHelperTreeItem<EnabledProtocolItem>
26{
27 Q_GADGET
28public:
37 Q_ENUM(EnableProtocolType)
38
39
46 EnabledProtocolItem(QString name, QString description, bool enabled, EnabledProtocolItem* parent);
47
51 virtual ~EnabledProtocolItem();
52
57 QString name() const {return name_;}
58
63 QString description() const {return description_;}
64
69 bool enabled() const {return enabled_;}
70
75 void setEnabled(bool enable) {enabled_ = enable;}
76
82
87 bool applyValue();
88
89protected:
94 virtual void applyValuePrivate(bool value) = 0;
95
97 QString name_;
98
101
104
106 bool enabledInit_; //value that model starts with to determine change
107
110};
111
115class EnabledProtocolsModel : public QAbstractItemModel
116{
117 Q_OBJECT
118
119public:
124 explicit EnabledProtocolsModel(QObject * parent = Q_NULLPTR);
125
129 virtual ~EnabledProtocolsModel();
130
139
147
155 QModelIndex index(int row, int column,
156 const QModelIndex &parent = QModelIndex()) const override;
157
163 QModelIndex parent(const QModelIndex &index) const override;
164
170 Qt::ItemFlags flags(const QModelIndex &index) const override;
171
178 QVariant data(const QModelIndex &index, int role) const override;
179
187 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
188
196 QVariant headerData(int section, Qt::Orientation orientation,
197 int role = Qt::DisplayRole) const override;
198
204 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
205
211 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
212
216 void populate();
217
222 void applyChanges(bool writeChanges = true);
223
228 static void disableProtocol(struct _protocol *protocol);
229
230protected:
235 static void saveChanges(bool writeChanges = true);
236
237private:
239 EnabledProtocolItem* root_;
240};
241
245class EnabledProtocolsProxyModel : public QSortFilterProxyModel
246{
247 Q_OBJECT
248
249public:
261 Q_ENUM(SearchType)
262 Q_DECLARE_FLAGS(SearchTypes, SearchType)
263
264
273
278 explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR);
279
286 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
287
293 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
294
301 void setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchTypes type,
303
309 void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable, QModelIndex parent = QModelIndex());
310
311protected:
318 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
319
320private:
322 EnabledProtocolsProxyModel::SearchTypes type_;
323
326
328 QString filter_;
329
336 bool filterAcceptsSelf(int sourceRow, const QModelIndex &sourceParent) const;
337
344 bool filterAcceptsChild(int sourceRow, const QModelIndex &sourceParent) const;
345};
346
347Q_DECLARE_OPERATORS_FOR_FLAGS(EnabledProtocolsProxyModel::SearchTypes)
348
349#endif // ENABLED_PROTOCOLS_MODEL_H
Represents a protocol item that can be enabled or disabled in a tree model.
Definition enabled_protocols_model.h:26
QString description_
Definition enabled_protocols_model.h:100
QString description() const
Retrieves the description of the protocol.
Definition enabled_protocols_model.h:63
bool enabledInit_
Definition enabled_protocols_model.h:106
bool applyValue()
Applies the current enabled value to the underlying core structures.
Definition enabled_protocols_model.cpp:89
EnabledProtocolItem(QString name, QString description, bool enabled, EnabledProtocolItem *parent)
Constructs a new EnabledProtocolItem.
Definition enabled_protocols_model.cpp:70
QString name() const
Retrieves the name of the protocol.
Definition enabled_protocols_model.h:57
virtual ~EnabledProtocolItem()
Destroys the EnabledProtocolItem.
Definition enabled_protocols_model.cpp:80
bool enabled_
Definition enabled_protocols_model.h:103
EnableProtocolType type_
Definition enabled_protocols_model.h:109
virtual void applyValuePrivate(bool value)=0
Implements the specific logic to apply the value change to the core.
EnableProtocolType type() const
Retrieves the type of the protocol item.
Definition enabled_protocols_model.cpp:84
QString name_
Definition enabled_protocols_model.h:97
void setEnabled(bool enable)
Sets the enabled state of the protocol.
Definition enabled_protocols_model.h:75
EnableProtocolType
Defines the type of enabled protocol.
Definition enabled_protocols_model.h:32
@ Heuristic
Definition enabled_protocols_model.h:35
@ Any
Definition enabled_protocols_model.h:33
@ Standard
Definition enabled_protocols_model.h:34
bool enabled() const
Checks if the protocol is currently marked as enabled.
Definition enabled_protocols_model.h:69
static void disableProtocol(struct _protocol *protocol)
Disables a specific protocol directly in the core.
Definition enabled_protocols_model.cpp:325
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Sets data in the model for a given index and role.
Definition enabled_protocols_model.cpp:250
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Generates an index for the given row and column.
Definition enabled_protocols_model.cpp:170
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns under a given parent.
Definition enabled_protocols_model.cpp:130
EnabledProtocolsModel(QObject *parent=Q_NULLPTR)
Constructs a new EnabledProtocolsModel.
Definition enabled_protocols_model.cpp:102
Qt::ItemFlags flags(const QModelIndex &index) const override
Retrieves the item flags for a given index.
Definition enabled_protocols_model.cpp:192
void applyChanges(bool writeChanges=true)
Applies pending changes to the core protocol definitions.
Definition enabled_protocols_model.cpp:307
virtual ~EnabledProtocolsModel()
Destroys the EnabledProtocolsModel.
Definition enabled_protocols_model.cpp:108
static void saveChanges(bool writeChanges=true)
Triggers the core mechanism to save protocol changes.
Definition enabled_protocols_model.cpp:334
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under a given parent.
Definition enabled_protocols_model.cpp:113
EnableProtocolData
Enumerates the custom data roles for the enabled protocols model.
Definition enabled_protocols_model.h:143
@ DATA_PROTOCOL_TYPE
Definition enabled_protocols_model.h:145
@ DATA_ENABLE
Definition enabled_protocols_model.h:144
void populate()
Populates the model with protocols from the core engine.
Definition enabled_protocols_model.cpp:282
QVariant data(const QModelIndex &index, int role) const override
Retrieves data from the model for a given index and role.
Definition enabled_protocols_model.cpp:210
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Retrieves the header data for a specific section and role.
Definition enabled_protocols_model.cpp:135
QModelIndex parent(const QModelIndex &index) const override
Retrieves the parent of a given index.
Definition enabled_protocols_model.cpp:151
EnabledProtocolsColumn
Enumerates the columns for the enabled protocols model.
Definition enabled_protocols_model.h:134
@ colLast
Definition enabled_protocols_model.h:137
@ colProtocol
Definition enabled_protocols_model.h:135
@ colDescription
Definition enabled_protocols_model.h:136
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Determines whether a row from the source model should be displayed.
Definition enabled_protocols_model.cpp:389
EnabledProtocolsProxyModel(QObject *parent=Q_NULLPTR)
Constructs a new EnabledProtocolsProxyModel.
Definition enabled_protocols_model.cpp:343
EnableType
Defines the action type when batch enabling/disabling items.
Definition enabled_protocols_model.h:268
@ Invert
Definition enabled_protocols_model.h:271
@ Enable
Definition enabled_protocols_model.h:269
@ Disable
Definition enabled_protocols_model.h:270
void setFilter(const QString &filter, EnabledProtocolsProxyModel::SearchTypes type, EnabledProtocolItem::EnableProtocolType protocolType)
Sets the active filter criteria.
Definition enabled_protocols_model.cpp:470
SearchType
Defines the search filtering scope.
Definition enabled_protocols_model.h:254
@ EveryWhere
Definition enabled_protocols_model.h:255
@ OnlyProtocol
Definition enabled_protocols_model.h:256
@ OnlyDescription
Definition enabled_protocols_model.h:257
@ DisabledItems
Definition enabled_protocols_model.h:259
@ EnabledItems
Definition enabled_protocols_model.h:258
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Retrieves item flags, taking into account any proxy state modifications.
Definition enabled_protocols_model.cpp:372
void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable, QModelIndex parent=QModelIndex())
Applies an enable/disable action to a parent item and all its children.
Definition enabled_protocols_model.cpp:487
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
Compares two source indices to determine their sort order.
Definition enabled_protocols_model.cpp:350
ModelHelperTreeItem(EnabledProtocolItem *parent)
Definition tree_model_helpers.h:31
Definition proto.c:394