Wireshark  4.3.0
The Wireshark network protocol analyzer
pref_models.h
Go to the documentation of this file.
1 
10 #ifndef PREF_MODELS_H
11 #define PREF_MODELS_H
12 
13 #include <config.h>
14 
16 
17 #include <epan/prefs.h>
18 
19 #include <QSortFilterProxyModel>
20 #include <QTreeView>
21 
22 class PrefsItem : public ModelHelperTreeItem<PrefsItem>
23 {
24 public:
25  PrefsItem(module_t *module, pref_t *pref, PrefsItem* parent);
26  PrefsItem(const QString name, PrefsItem* parent);
27  virtual ~PrefsItem();
28 
29  QString getName() const {return name_;}
30  pref_t* getPref() const {return pref_;}
31  int getPrefType() const;
32  bool isPrefDefault() const;
33  QString getPrefTypeName() const;
34  module_t* getModule() const {return module_;}
35  QString getModuleName() const;
36  QString getModuleTitle() const;
37  void setChanged(bool changed = true);
38 
39 private:
40  pref_t *pref_;
41  module_t *module_;
42  QString name_;
43  //set to true if changed during module manipulation
44  //Used to determine proper "default" for comparison
45  bool changed_;
46 };
47 
48 
49 class PrefsModel : public QAbstractItemModel
50 {
51  Q_OBJECT
52 
53 public:
54  explicit PrefsModel(QObject * parent = Q_NULLPTR);
55  virtual ~PrefsModel();
56 
57  enum PrefsModelType {
58  Advanced = Qt::UserRole,
59  Appearance,
60  Layout,
61  Columns,
62  FontAndColors,
63  Capture,
64  Expert,
65  FilterButtons,
66  RSAKeys
67  };
68 
69  enum PrefsModelColumn {
70  colName = 0,
71  colStatus,
72  colType,
73  colValue,
74  colLast
75  };
76 
77  QModelIndex index(int row, int column,
78  const QModelIndex & = QModelIndex()) const;
79  QModelIndex parent(const QModelIndex &) const;
80  QVariant data(const QModelIndex &index, int role) const;
81 
82  int rowCount(const QModelIndex &parent = QModelIndex()) const;
83  int columnCount(const QModelIndex &parent = QModelIndex()) const;
84 
85  static QString typeToString(int type);
86 
87 private:
88  void populate();
89 
90  PrefsItem* root_;
91 };
92 
93 class AdvancedPrefsModel : public QSortFilterProxyModel
94 {
95  Q_OBJECT
96 
97 public:
98  explicit AdvancedPrefsModel(QObject * parent = Q_NULLPTR);
99 
100  enum AdvancedPrefsModelColumn {
101  colName = 0,
102  colStatus,
103  colType,
104  colValue,
105  colLast
106  };
107 
108  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
109 
110  void setFilter(const QString& filter);
111 
112  QVariant headerData(int section, Qt::Orientation orientation,
113  int role = Qt::DisplayRole) const;
114  QVariant data(const QModelIndex &index, int role) const;
115  Qt::ItemFlags flags(const QModelIndex &index) const;
116  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
117 
118  int columnCount(const QModelIndex &parent = QModelIndex()) const;
119 
120  //Keep the internals of model hidden from tree
121  void setFirstColumnSpanned(QTreeView* tree, const QModelIndex &index = QModelIndex());
122 
123 protected:
124  bool filterAcceptItem(PrefsItem& item) const;
125 
126 private:
127 
128  QString filter_;
129  const QChar passwordChar_;
130 };
131 
132 class ModulePrefsModel : public QSortFilterProxyModel
133 {
134 public:
135 
136  explicit ModulePrefsModel(QObject * parent = Q_NULLPTR);
137 
138  enum ModulePrefsModelColumn {
139  colName = 0,
140  colLast
141  };
142 
143  enum ModulePrefsRoles {
144  ModuleName = Qt::UserRole + 1
145  };
146 
147  QVariant data(const QModelIndex &index, int role) const;
148  Qt::ItemFlags flags(const QModelIndex &index) const;
149  int columnCount(const QModelIndex &parent = QModelIndex()) const;
150 
151  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
152 
153 protected:
154  bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
155 
156 private:
157  //cache of the translated "Advanced" preference name
158  QString advancedPrefName_;
159 };
160 
161 extern pref_t *prefFromPrefPtr(void *pref_ptr);
162 
163 #endif // PREF_MODELS_H
Definition: pref_models.h:94
Definition: tree_model_helpers.h:23
Definition: pref_models.h:133
Definition: pref_models.h:23
Definition: pref_models.h:50
Definition: wslua.h:205
Definition: prefs-int.h:27
Definition: prefs.c:200