Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
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
22class PrefsItem;
23
27class PrefsModel : public QAbstractItemModel
28{
29 Q_OBJECT
30
31public:
36 explicit PrefsModel(QObject *parent = Q_NULLPTR);
37
39 virtual ~PrefsModel();
40
57
68
76 QModelIndex index(int row, int column,
77 const QModelIndex &parent = QModelIndex()) const;
78
85 QModelIndex parent(const QModelIndex &index) const;
86
93 QVariant data(const QModelIndex &index, int role) const;
94
100 int rowCount(const QModelIndex &parent = QModelIndex()) const;
101
107 int columnCount(const QModelIndex &parent = QModelIndex()) const;
108
114 static QString typeToString(PrefsModelType type);
115
121 static QString typeToHelp(PrefsModelType type);
122
123private:
127 void populate();
128
129 PrefsItem *root_;
130};
131
135class PrefsItem : public ModelHelperTreeItem<PrefsItem>
136{
137public:
144 PrefsItem(module_t *module, pref_t *pref, PrefsItem *parent);
145
151 PrefsItem(const QString name, PrefsItem *parent);
152
159
161 virtual ~PrefsItem();
162
167 QString getName() const { return name_; }
168
173 pref_t *getPref() const { return pref_; }
174
179 int getPrefType() const;
180
185 bool isPrefDefault() const;
186
191 QString getPrefTypeName() const;
192
197 module_t *getModule() const { return module_; }
198
203 QString getModuleName() const;
204
209 QString getModuleTitle() const;
210
215 QString getModuleHelp() const;
216
221 void setChanged(bool changed = true);
222
223private:
224 pref_t *pref_;
225 module_t *module_;
226 QString name_;
227 QString help_;
230 bool changed_;
231};
232
236class AdvancedPrefsModel : public QSortFilterProxyModel
237{
238 Q_OBJECT
239
240public:
245 explicit AdvancedPrefsModel(QObject *parent = Q_NULLPTR);
246
257
268 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
269
278 void setFilter(const QString &filter);
279
285 void setShowChangedValues(bool show_changed_values);
286
294 QVariant headerData(int section, Qt::Orientation orientation,
295 int role = Qt::DisplayRole) const;
296
304 QVariant data(const QModelIndex &index, int role) const;
305
314 Qt::ItemFlags flags(const QModelIndex &index) const;
315
324 bool setData(const QModelIndex &index, const QVariant &value,
325 int role = Qt::EditRole);
326
332 int columnCount(const QModelIndex &parent = QModelIndex()) const;
333
343 void setFirstColumnSpanned(QTreeView *tree, const QModelIndex &index = QModelIndex());
344
345protected:
351 bool filterAcceptItem(PrefsItem &item) const;
352
353private:
354 QString filter_;
355 bool show_changed_values_;
356 const QChar passwordChar_;
357};
358
363class ModulePrefsModel : public QSortFilterProxyModel
364{
365public:
370 explicit ModulePrefsModel(QObject *parent = Q_NULLPTR);
371
379
384 ModuleName = Qt::UserRole + 1,
385 ModuleHelp = Qt::UserRole + 2
386 };
387
395 QVariant data(const QModelIndex &index, int role) const;
396
403 Qt::ItemFlags flags(const QModelIndex &index) const;
404
410 int columnCount(const QModelIndex &parent = QModelIndex()) const;
411
419 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
420
421protected:
429 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
430
431private:
434 QString advancedPrefName_;
435};
436
443extern pref_t *prefFromPrefPtr(void *pref_ptr);
444
445#endif // PREF_MODELS_H
Sort/filter proxy model for the Advanced Preferences pane.
Definition pref_models.h:237
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Determine whether a source row should be included in the view.
Definition pref_models.cpp:722
void setFirstColumnSpanned(QTreeView *tree, const QModelIndex &index=QModelIndex())
Mark module-level rows as spanning all columns in tree.
Definition pref_models.cpp:653
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Write value to the preference at index.
Definition pref_models.cpp:527
AdvancedPrefsModelColumn
Column indices for the Advanced preferences view.
Definition pref_models.h:250
@ colStatus
Definition pref_models.h:252
@ colType
Definition pref_models.h:253
@ colName
Definition pref_models.h:251
@ colLast
Definition pref_models.h:255
@ colValue
Definition pref_models.h:254
void setShowChangedValues(bool show_changed_values)
Restrict the view to preferences that differ from their defaults.
Definition pref_models.cpp:752
bool filterAcceptItem(PrefsItem &item) const
Test whether a single PrefsItem passes the current filters.
Definition pref_models.cpp:677
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Return the column header label.
Definition pref_models.cpp:408
void setFilter(const QString &filter)
Set the text filter applied to preference names and values.
Definition pref_models.cpp:739
int columnCount(const QModelIndex &parent=QModelIndex()) const
Return the number of columns in this model.
Definition pref_models.cpp:647
Base class to inherit basic tree item from.
Definition tree_model_helpers.h:25
Sort/filter proxy model for the module (left-hand) pane of the Preferences dialog.
Definition pref_models.h:364
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
Define the sort order for module rows.
Definition pref_models.cpp:845
int columnCount(const QModelIndex &parent=QModelIndex()) const
Return the number of columns in this model.
Definition pref_models.cpp:840
ModulePrefsModelColumn
Column indices for the module pane.
Definition pref_models.h:375
@ colName
Definition pref_models.h:376
@ colLast
Definition pref_models.h:377
ModulePrefsRoles
Custom data roles for module items.
Definition pref_models.h:383
@ ModuleHelp
Definition pref_models.h:385
@ ModuleName
Definition pref_models.h:384
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Determine whether a source row should appear in the module pane.
Definition pref_models.cpp:875
A single node in the PrefsModel tree.
Definition pref_models.h:136
QString getModuleHelp() const
Return the help text for the associated module.
Definition pref_models.cpp:125
void setChanged(bool changed=true)
Mark this preference as having been changed during this session.
Definition pref_models.cpp:139
QString getName() const
Return the display name of this item.
Definition pref_models.h:167
bool isPrefDefault() const
Return whether the preference currently holds its default value.
Definition pref_models.cpp:90
QString getPrefTypeName() const
Return a human-readable string for the preference type.
Definition pref_models.cpp:101
QString getModuleName() const
Return the internal (short) name of the associated module.
Definition pref_models.cpp:109
int getPrefType() const
Return the numeric type of the underlying preference.
Definition pref_models.cpp:82
QString getModuleTitle() const
Return the display title of the associated module.
Definition pref_models.cpp:117
pref_t * getPref() const
Return the pref_t this item represents.
Definition pref_models.h:173
module_t * getModule() const
Return the preference module associated with this item.
Definition pref_models.h:197
virtual ~PrefsItem()
Destroy this PrefsItem and all of its children.
Definition pref_models.cpp:78
Tree model backing the Preferences dialog.
Definition pref_models.h:28
static QString typeToString(PrefsModelType type)
Return the display name for a built-in preference page type.
Definition pref_models.cpp:334
int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of child rows under parent.
Definition pref_models.cpp:156
virtual ~PrefsModel()
Destroy the model and its PrefsItem tree.
Definition pref_models.cpp:151
QModelIndex parent(const QModelIndex &index) const
Return the parent model index of index.
Definition pref_models.cpp:179
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Return the model index for the item at (row, column) under parent.
Definition pref_models.cpp:198
static QString typeToHelp(PrefsModelType type)
Return the help text for a built-in preference page type.
Definition pref_models.cpp:356
PrefsModelType
Top-level preference page type identifiers.
Definition pref_models.h:44
@ Appearance
Definition pref_models.h:46
@ Capture
Definition pref_models.h:51
@ Expert
Definition pref_models.h:52
@ Advanced
Definition pref_models.h:45
@ FontAndColors
Definition pref_models.h:49
@ Layout
Definition pref_models.h:47
@ FilterButtons
Definition pref_models.h:53
@ WelcomePage
Definition pref_models.h:50
@ RSAKeys
Definition pref_models.h:54
@ Columns
Definition pref_models.h:48
@ Aggregation
Definition pref_models.h:55
PrefsModelColumn
Column indices for the raw PrefsModel tree.
Definition pref_models.h:61
@ colStatus
Definition pref_models.h:63
@ colLast
Definition pref_models.h:66
@ colValue
Definition pref_models.h:65
@ colName
Definition pref_models.h:62
@ colType
Definition pref_models.h:64
int columnCount(const QModelIndex &parent=QModelIndex()) const
Return the number of columns.
Definition pref_models.cpp:173
pref_t * prefFromPrefPtr(void *pref_ptr)
Retrieves the preference structure associated with a given preference pointer.
Definition pref_models.cpp:27
Represents a preference module grouping related preferences under a named, hierarchical entry in the ...
Definition prefs-int.h:27
Definition prefs.c:207