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  void setShowChangedValues(bool show_changed_values);
112 
113  QVariant headerData(int section, Qt::Orientation orientation,
114  int role = Qt::DisplayRole) const;
115  QVariant data(const QModelIndex &index, int role) const;
116  Qt::ItemFlags flags(const QModelIndex &index) const;
117  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
118 
119  int columnCount(const QModelIndex &parent = QModelIndex()) const;
120 
121  //Keep the internals of model hidden from tree
122  void setFirstColumnSpanned(QTreeView* tree, const QModelIndex &index = QModelIndex());
123 
124 protected:
125  bool filterAcceptItem(PrefsItem& item) const;
126 
127 private:
128 
129  QString filter_;
130  bool show_changed_values_;
131  const QChar passwordChar_;
132 };
133 
134 class ModulePrefsModel : public QSortFilterProxyModel
135 {
136 public:
137 
138  explicit ModulePrefsModel(QObject * parent = Q_NULLPTR);
139 
140  enum ModulePrefsModelColumn {
141  colName = 0,
142  colLast
143  };
144 
145  enum ModulePrefsRoles {
146  ModuleName = Qt::UserRole + 1
147  };
148 
149  QVariant data(const QModelIndex &index, int role) const;
150  Qt::ItemFlags flags(const QModelIndex &index) const;
151  int columnCount(const QModelIndex &parent = QModelIndex()) const;
152 
153  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
154 
155 protected:
156  bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
157 
158 private:
159  //cache of the translated "Advanced" preference name
160  QString advancedPrefName_;
161 };
162 
163 extern pref_t *prefFromPrefPtr(void *pref_ptr);
164 
165 #endif // PREF_MODELS_H
Definition: pref_models.h:94
Definition: tree_model_helpers.h:23
Definition: pref_models.h:135
Definition: pref_models.h:23
Definition: pref_models.h:50
Definition: wslua.h:245
Definition: prefs-int.h:27
Definition: prefs.c:225