aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/dissector_tables_model.h
blob: c36648cc6a7c1deae3642f66792613d57e9c3619 (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
101
102
/* dissector_tables_model.h
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef DISSECTOR_TABLES_MODEL_H
#define DISSECTOR_TABLES_MODEL_H

#include <config.h>

#include <ui/qt/models/tree_model_helpers.h>

#include <QSortFilterProxyModel>

class DissectorTablesItem : public ModelHelperTreeItem<DissectorTablesItem>
{
public:
    DissectorTablesItem(QString tableName, QString shortName, DissectorTablesItem* parent);
    virtual ~DissectorTablesItem();

    QString tableName() const {return tableName_;}
    QString shortName() const {return shortName_;}

    virtual bool lessThan(DissectorTablesItem &right) const;

protected:
    QString tableName_;
    QString shortName_;
};

class DissectorTablesModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    explicit DissectorTablesModel(QObject * parent = Q_NULLPTR);
    virtual ~DissectorTablesModel();

    enum DissectorTablesColumn {
        colTableName = 0,
        colShortName,
        colLast
    };

    QModelIndex index(int row, int column,
                      const QModelIndex & = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &) const;
    QVariant data(const QModelIndex &index, int role) const;

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    void populate();

private:
    DissectorTablesItem* root_;
};

class DissectorTablesProxyModel : public QSortFilterProxyModel
{
    Q_OBJECT
public:

    explicit DissectorTablesProxyModel(QObject * parent = Q_NULLPTR);

    virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;

    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;

    void adjustHeader(const QModelIndex &currentIndex);
    void setFilter(const QString& filter);

protected:
    bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
    bool filterAcceptItem(DissectorTablesItem& item) const;

private:

    QString tableName_;
    QString shortName_;
    QString filter_;
};

#endif // DISSECTOR_TABLES_MODEL_H

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */