aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/pref_models.h
blob: 09e8e14ac6681a7f3e1d22fea5c316960297ef27 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* pref_models.h
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef PREF_MODELS_H
#define PREF_MODELS_H

#include <config.h>

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

#include <epan/prefs.h>

#include <QSortFilterProxyModel>
#include <QTreeView>

class PrefsItem : public ModelHelperTreeItem<PrefsItem>
{
public:
    PrefsItem(module_t *module, pref_t *pref, PrefsItem* parent);
    PrefsItem(const QString name, PrefsItem* parent);
    virtual ~PrefsItem();

    QString getName() const {return name_;}
    pref_t* getPref() const {return pref_;}
    int getPrefType() const;
    int getPrefGUIType() const;
    bool isPrefDefault() const;
    QString getPrefTypeName() const;
    module_t* getModule() const {return module_;}
    QString getModuleName() const;
    QString getModuleTitle() const;
    void setChanged(bool changed = true);

private:
    pref_t *pref_;
    module_t *module_;
    QString name_;
    //set to true if changed during module manipulation
    //Used to determine proper "default" for comparison
    bool changed_;
};


class PrefsModel : public QAbstractItemModel
{
    Q_OBJECT

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

    //Names of special preferences handled by the GUI
    //Names used as keys to determine correct pan displayed
    static const char* ADVANCED_PREFERENCE_TREE_NAME;
    static const char* APPEARANCE_PREFERENCE_TREE_NAME;
    static const char* LAYOUT_PREFERENCE_TREE_NAME;
    static const char* COLUMNS_PREFERENCE_TREE_NAME;
    static const char* FONT_AND_COLORS_PREFERENCE_TREE_NAME;
    static const char* CAPTURE_PREFERENCE_TREE_NAME;
    static const char* EXPERT_PREFERENCE_TREE_NAME;
    static const char* FILTER_BUTTONS_PREFERENCE_TREE_NAME;

    enum PrefsModelColumn {
        colName = 0,
        colStatus,
        colType,
        colValue,
        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;

private:
    void populate();

    PrefsItem* root_;
};

class AdvancedPrefsModel : public QSortFilterProxyModel
{
    Q_OBJECT
public:

    explicit AdvancedPrefsModel(QObject * parent = Q_NULLPTR);

    enum AdvancedPrefsModelColumn {
        colName = 0,
        colStatus,
        colType,
        colValue,
        colLast
    };

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

    void setFilter(const QString& filter);

    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

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

    //Keep the internals of model hidden from tree
    void setFirstColumnSpanned(QTreeView* tree, const QModelIndex &index = QModelIndex());

protected:
    bool filterAcceptItem(PrefsItem& item) const;

private:

    QString filter_;
};

class ModulePrefsModel : public QSortFilterProxyModel
{
    Q_OBJECT
public:

    explicit ModulePrefsModel(QObject * parent = Q_NULLPTR);

    enum ModulePrefsModelColumn {
        colName = 0,
        colLast
    };

    enum ModulePrefsRoles {
        ModuleName = Qt::UserRole + 1
    };

    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

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

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

private:
    //cache of the translated "Advanced" preference name
    QString advancedPrefName_;
};

extern pref_t *prefFromPrefPtr(void *pref_ptr);

#endif // PREF_MODELS_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:
 */