Wireshark 5.1.0
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 group, QString description, bool enabled, EnabledProtocolItem * parent);
47
51 virtual ~EnabledProtocolItem();
52
57 QString name() const {return name_;}
58
59 QString group() const { return group_; }
60
65 QString description() const {return description_;}
66
71 bool enabled() const {return enabled_;}
72
77 void setEnabled(bool enable) {enabled_ = enable;}
78
84
89 bool applyValue();
90
91protected:
96 virtual void applyValuePrivate(bool value) = 0;
97
99 QString name_;
100
102 QString group_;
103
106
109
111 bool enabledInit_; //value that model starts with to determine change
112
115};
116
120class EnabledProtocolsModel : public QAbstractItemModel
121{
122 Q_OBJECT
123
124public:
129 explicit EnabledProtocolsModel(QObject * parent = Q_NULLPTR);
130
134 virtual ~EnabledProtocolsModel();
135
145
153
161 QModelIndex index(int row, int column,
162 const QModelIndex &parent = QModelIndex()) const override;
163
169 QModelIndex parent(const QModelIndex &index) const override;
170
176 Qt::ItemFlags flags(const QModelIndex &index) const override;
177
184 QVariant data(const QModelIndex &index, int role) const override;
185
193 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
194
202 QVariant headerData(int section, Qt::Orientation orientation,
203 int role = Qt::DisplayRole) const override;
204
210 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
211
217 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
218
222 void populate();
223
228 void applyChanges(bool writeChanges = true);
229
234 static void disableProtocol(struct _protocol *protocol);
235
236protected:
241 static void saveChanges(bool writeChanges = true);
242
243private:
245 EnabledProtocolItem* root_;
246};
247
251class EnabledProtocolsProxyModel : public QSortFilterProxyModel
252{
253 Q_OBJECT
254
255public:
267 Q_ENUM(SearchType)
268 Q_DECLARE_FLAGS(SearchTypes, SearchType)
269
270
279
284 explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR);
285
292 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
293
299 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
300
307 void setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchTypes type,
309
315 void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable, QModelIndex parent = QModelIndex());
316
317protected:
324 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
325
326private:
328 EnabledProtocolsProxyModel::SearchTypes type_;
329
332
334 QString filter_;
335
342 bool filterAcceptsSelf(int sourceRow, const QModelIndex &sourceParent) const;
343
350 bool filterAcceptsChild(int sourceRow, const QModelIndex &sourceParent) const;
351};
352
353Q_DECLARE_OPERATORS_FOR_FLAGS(EnabledProtocolsProxyModel::SearchTypes)
354
355#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:105
QString description() const
Retrieves the description of the protocol.
Definition enabled_protocols_model.h:65
bool enabledInit_
Definition enabled_protocols_model.h:111
bool applyValue()
Applies the current enabled value to the underlying core structures.
Definition enabled_protocols_model.cpp:91
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:82
bool enabled_
Definition enabled_protocols_model.h:108
EnableProtocolType type_
Definition enabled_protocols_model.h:114
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:86
QString name_
Definition enabled_protocols_model.h:99
EnabledProtocolItem(QString name, QString group, QString description, bool enabled, EnabledProtocolItem *parent)
Constructs a new EnabledProtocolItem.
Definition enabled_protocols_model.cpp:71
QString group_
Definition enabled_protocols_model.h:102
void setEnabled(bool enable)
Sets the enabled state of the protocol.
Definition enabled_protocols_model.h:77
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:71
static void disableProtocol(struct _protocol *protocol)
Disables a specific protocol directly in the core.
Definition enabled_protocols_model.cpp:331
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:256
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:174
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns under a given parent.
Definition enabled_protocols_model.cpp:132
EnabledProtocolsModel(QObject *parent=Q_NULLPTR)
Constructs a new EnabledProtocolsModel.
Definition enabled_protocols_model.cpp:104
Qt::ItemFlags flags(const QModelIndex &index) const override
Retrieves the item flags for a given index.
Definition enabled_protocols_model.cpp:196
void applyChanges(bool writeChanges=true)
Applies pending changes to the core protocol definitions.
Definition enabled_protocols_model.cpp:313
virtual ~EnabledProtocolsModel()
Destroys the EnabledProtocolsModel.
Definition enabled_protocols_model.cpp:110
static void saveChanges(bool writeChanges=true)
Triggers the core mechanism to save protocol changes.
Definition enabled_protocols_model.cpp:340
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under a given parent.
Definition enabled_protocols_model.cpp:115
EnableProtocolData
Enumerates the custom data roles for the enabled protocols model.
Definition enabled_protocols_model.h:149
@ DATA_PROTOCOL_TYPE
Definition enabled_protocols_model.h:151
@ DATA_ENABLE
Definition enabled_protocols_model.h:150
void populate()
Populates the model with protocols from the core engine.
Definition enabled_protocols_model.cpp:288
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:214
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:137
QModelIndex parent(const QModelIndex &index) const override
Retrieves the parent of a given index.
Definition enabled_protocols_model.cpp:155
EnabledProtocolsColumn
Enumerates the columns for the enabled protocols model.
Definition enabled_protocols_model.h:139
@ colLast
Definition enabled_protocols_model.h:143
@ colProtocol
Definition enabled_protocols_model.h:140
@ colDescription
Definition enabled_protocols_model.h:142
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:397
EnabledProtocolsProxyModel(QObject *parent=Q_NULLPTR)
Constructs a new EnabledProtocolsProxyModel.
Definition enabled_protocols_model.cpp:349
EnableType
Defines the action type when batch enabling/disabling items.
Definition enabled_protocols_model.h:274
@ Invert
Definition enabled_protocols_model.h:277
@ Enable
Definition enabled_protocols_model.h:275
@ Disable
Definition enabled_protocols_model.h:276
void setFilter(const QString &filter, EnabledProtocolsProxyModel::SearchTypes type, EnabledProtocolItem::EnableProtocolType protocolType)
Sets the active filter criteria.
Definition enabled_protocols_model.cpp:478
SearchType
Defines the search filtering scope.
Definition enabled_protocols_model.h:260
@ EveryWhere
Definition enabled_protocols_model.h:261
@ OnlyProtocol
Definition enabled_protocols_model.h:262
@ OnlyDescription
Definition enabled_protocols_model.h:263
@ DisabledItems
Definition enabled_protocols_model.h:265
@ EnabledItems
Definition enabled_protocols_model.h:264
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Retrieves item flags, taking into account any proxy state modifications.
Definition enabled_protocols_model.cpp:380
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:495
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:356
ModelHelperTreeItem(EnabledProtocolItem *parent)
Definition tree_model_helpers.h:31
Definition proto.c:400