1 /* supported_protocols_model.h 2 * 3 * Wireshark - Network traffic analyzer 4 * By Gerald Combs <gerald@wireshark.org> 5 * Copyright 1998 Gerald Combs 6 * 7 * SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #ifndef SUPPORTED_PROTOCOLS_MODEL_H 11 #define SUPPORTED_PROTOCOLS_MODEL_H 12 13 #include <config.h> 14 15 #include <ui/qt/models/tree_model_helpers.h> 16 17 #include <epan/proto.h> 18 19 #include <QSortFilterProxyModel> 20 21 class SupportedProtocolsItem : public ModelHelperTreeItem<SupportedProtocolsItem> 22 { 23 public: 24 SupportedProtocolsItem(protocol_t* proto, const char *name, const char* filter, ftenum_t ftype, const char* descr, SupportedProtocolsItem* parent); 25 virtual ~SupportedProtocolsItem(); 26 protocol()27 protocol_t* protocol() const {return proto_; } name()28 QString name() const { return name_; } type()29 ftenum_t type() const {return ftype_; } filter()30 QString filter() const { return filter_; } description()31 QString description() const { return descr_; } 32 33 private: 34 protocol_t* proto_; 35 QString name_; 36 QString filter_; 37 ftenum_t ftype_; 38 QString descr_; 39 }; 40 41 42 class SupportedProtocolsModel : public QAbstractItemModel 43 { 44 Q_OBJECT 45 46 public: 47 explicit SupportedProtocolsModel(QObject * parent = Q_NULLPTR); 48 virtual ~SupportedProtocolsModel(); 49 50 enum SupportedProtocolsColumn { 51 colName = 0, 52 colFilter, 53 colType, 54 colDescription, 55 colLast 56 }; 57 fieldCount()58 int fieldCount() {return field_count_;} 59 60 QModelIndex index(int row, int column, 61 const QModelIndex & = QModelIndex()) const; 62 QModelIndex parent(const QModelIndex &) const; 63 QVariant data(const QModelIndex &index, int role) const; 64 65 QVariant headerData(int section, Qt::Orientation orientation, 66 int role = Qt::DisplayRole) const; 67 68 int rowCount(const QModelIndex &parent = QModelIndex()) const; 69 int columnCount(const QModelIndex &parent = QModelIndex()) const; 70 71 void populate(); 72 73 private: 74 SupportedProtocolsItem* root_; 75 int field_count_; 76 }; 77 78 class SupportedProtocolsProxyModel : public QSortFilterProxyModel 79 { 80 public: 81 82 explicit SupportedProtocolsProxyModel(QObject * parent = Q_NULLPTR); 83 84 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; 85 86 void setFilter(const QString& filter); 87 88 protected: 89 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; 90 bool filterAcceptItem(SupportedProtocolsItem& item) const; 91 92 private: 93 94 QString filter_; 95 }; 96 97 #endif // SUPPORTED_PROTOCOLS_MODEL_H 98