aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets/traffic_types_list.h
blob: fece2ef86a8a60ad0b659bbe02047261730f1150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @file
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef TRAFFIC_TYPES_LIST_H
#define TRAFFIC_TYPES_LIST_H

#include "config.h"

#include <QTreeView>
#include <QAbstractListModel>
#include <QMap>
#include <QString>

class TrafficTypesRowData
{

public:
    TrafficTypesRowData(int protocol, QString name);

    int protocol() const;
    QString name() const;
    bool checked() const;
    void setChecked(bool checked);

private:
    int _protocol;
    QString _name;
    bool _checked;
};

class TrafficTypesModel : public QAbstractListModel
{
    Q_OBJECT
public:

    enum {
        TRAFFIC_PROTOCOL = Qt::UserRole,
        TRAFFIC_IS_CHECKED,
    } eTrafficUserData;

    enum {
        COL_CHECKED,
        COL_NAME,
        COL_NUM,
        COL_PROTOCOL,
    } eTrafficColumnNames;

    TrafficTypesModel(GList ** recentList, QObject *parent = nullptr);

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    virtual QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
    virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    virtual bool setData(const QModelIndex &idx, const QVariant &value, int role) override;
    virtual Qt::ItemFlags flags (const QModelIndex & idx) const override;

    QList<int> protocols() const;

public slots:
    void selectProtocols(QList<int> protocols);

signals:
    void protocolsChanged(QList<int> protocols);

private:
    QList<TrafficTypesRowData> _allTaps;
    GList ** _recentList;

};

class TrafficTypesList : public QTreeView
{
    Q_OBJECT
public:

    TrafficTypesList(QWidget *parent = nullptr);

    void setProtocolInfo(QString name, GList ** recentList);
    QList<int> protocols() const;
    QList<int> selectedProtocols() const;

public slots:
    void selectProtocols(QList<int> protocols);

signals:
    void protocolsChanged(QList<int> protocols);

private:
    QString _name;
    TrafficTypesModel * _model;
};

#endif // TRAFFIC_TYPES_LIST_H