3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef ENABLED_PROTOCOLS_MODEL_H
11 #define ENABLED_PROTOCOLS_MODEL_H
15 #include <ui/qt/models/tree_model_helpers.h>
17 #include <epan/proto.h>
19 #include <QAbstractItemModel>
20 #include <QSortFilterProxyModel>
22 class EnabledProtocolItem
: public ModelHelperTreeItem
<EnabledProtocolItem
>
26 enum EnableProtocolType
{
31 Q_ENUM(EnableProtocolType
)
33 EnabledProtocolItem(QString name
, QString description
, bool enabled
, EnabledProtocolItem
* parent
);
34 virtual ~EnabledProtocolItem();
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
;}
41 EnableProtocolType
type() const;
46 virtual void applyValuePrivate(bool value
) = 0;
51 bool enabledInit_
; //value that model starts with to determine change
52 EnableProtocolType type_
;
55 class EnabledProtocolsModel
: public QAbstractItemModel
60 explicit EnabledProtocolsModel(QObject
* parent
= Q_NULLPTR
);
61 virtual ~EnabledProtocolsModel();
63 enum EnabledProtocolsColumn
{
69 enum EnableProtocolData
{
70 DATA_ENABLE
= Qt::UserRole
,
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
);
81 QVariant
headerData(int section
, Qt::Orientation orientation
,
82 int role
= Qt::DisplayRole
) const;
84 int rowCount(const QModelIndex
&parent
= QModelIndex()) const;
85 int columnCount(const QModelIndex
&parent
= QModelIndex()) const;
89 void applyChanges(bool writeChanges
= true);
90 static void disableProtocol(struct _protocol
*protocol
);
93 static void saveChanges(bool writeChanges
= true);
96 EnabledProtocolItem
* root_
;
99 class EnabledProtocolsProxyModel
: public QSortFilterProxyModel
121 explicit EnabledProtocolsProxyModel(QObject
* parent
= Q_NULLPTR
);
123 virtual bool filterAcceptsRow(int sourceRow
, const QModelIndex
&sourceParent
) const override
;
124 virtual Qt::ItemFlags
flags(const QModelIndex
&index
) const override
;
126 void setFilter(const QString
& filter
, EnabledProtocolsProxyModel::SearchType type
,
127 EnabledProtocolItem::EnableProtocolType protocolType
);
129 void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable
, QModelIndex parent
= QModelIndex());
132 bool lessThan(const QModelIndex
&source_left
, const QModelIndex
&source_right
) const override
;
135 EnabledProtocolsProxyModel::SearchType type_
;
136 EnabledProtocolItem::EnableProtocolType protocolType_
;
139 bool filterAcceptsSelf(int sourceRow
, const QModelIndex
&sourceParent
) const;
140 bool filterAcceptsChild(int sourceRow
, const QModelIndex
&sourceParent
) const;
143 #endif // ENABLED_PROTOCOLS_MODEL_H