Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
tagging_rules_model.h
1/* tagging_rules_model.h
2 *
3 * Model for the Tagging Rules dialog
4 * Copyright 2026, Mark Stout <[email protected]>
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <[email protected]>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13#ifndef TAGGING_RULES_MODEL_H
14#define TAGGING_RULES_MODEL_H
15
16#include <config.h>
17
18#include <epan/tag_rules.h>
19
21
22#include <QList>
23#include <QAbstractItemModel>
24
28class TaggingRuleItem : public ModelHelperTreeItem<TaggingRuleItem>
29{
30public:
40 TaggingRuleItem(bool disabled, QString name, QString filter,
41 QString tag_content, QString tag_url, QString comment,
42 TaggingRuleItem *parent);
43
50
56
60 virtual ~TaggingRuleItem();
61
68
71
73 QString name_;
74
76 QString filter_;
77
79 QString tag_content_;
80
82 QString tag_url_;
83
85 QString comment_;
86};
87
91class TaggingRulesModel : public QAbstractItemModel
92{
93 Q_OBJECT
94
95public:
100 explicit TaggingRulesModel(QObject *parent);
101
105 virtual ~TaggingRulesModel();
106
118
123 TagContentRole = Qt::UserRole + 1,
124 TagUrlRole = Qt::UserRole + 2
125 };
126
130 void addRule(bool disabled, const QString &name, const QString &filter,
131 const QString &tag_content, const QString &tag_url,
132 const QString &comment);
133
141 void addRule(tag_rule_t *rule);
142
149 bool loadFromPath(const QString &path, QString &err);
150
158 bool writeToPath(const QString &path, const tag_prefs_t *prefs, QString &err);
159
166 bool importRules(const QString &path, QString &err);
167
174 bool exportRules(const QString &path, QString &err);
175
180 bool writeTags();
181
187 Qt::ItemFlags flags(const QModelIndex &index) const override;
188
195 QVariant data(const QModelIndex &index, int role) const override;
196
204 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
205
213 QVariant headerData(int section, Qt::Orientation orientation,
214 int role = Qt::DisplayRole) const override;
215
223 QModelIndex index(int row, int column,
224 const QModelIndex &parent = QModelIndex()) const override;
225
231 QModelIndex parent(const QModelIndex &indexItem) const override;
232
238 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
239
245 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
246
254 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
255
263 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
264
274 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
275 const QModelIndex &destinationParent, int destinationChild) override;
276
277 // Drag-and-drop functionality
278
283 Qt::DropActions supportedDropActions() const override;
284
289 QStringList mimeTypes() const override;
290
296 QMimeData *mimeData(const QModelIndexList &indexes) const override;
297
307 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
308 const QModelIndex &parent) override;
309
310private:
318 GSList *createTagRuleList();
319
321 TaggingRuleItem *root_;
322
324};
325
326#endif // TAGGING_RULES_MODEL_H
ModelHelperTreeItem(TaggingRuleItem *parent)
Definition tree_model_helpers.h:31
Represents a single tagging rule item in a tree model.
Definition tagging_rules_model.h:29
bool disabled_
Indicates if the rule is currently disabled.
Definition tagging_rules_model.h:70
TaggingRuleItem & operator=(TaggingRuleItem &rhs)
Assignment operator for TaggingRuleItem.
Definition tagging_rules_model.cpp:69
QString tag_url_
Optional URL opened when the COL_TAG cell is clicked.
Definition tagging_rules_model.h:82
virtual ~TaggingRuleItem()
Destroys the TaggingRuleItem.
Definition tagging_rules_model.cpp:65
QString filter_
The display filter expression associated with the rule.
Definition tagging_rules_model.h:76
QString name_
The display name of the rule (also used as frame.tag value).
Definition tagging_rules_model.h:73
TaggingRuleItem(bool disabled, QString name, QString filter, QString tag_content, QString tag_url, QString comment, TaggingRuleItem *parent)
Constructs a new TaggingRuleItem with explicit fields.
Definition tagging_rules_model.cpp:30
QString tag_content_
The visual content shown in the COL_TAG column (emoji / text).
Definition tagging_rules_model.h:79
QString comment_
Optional reference comment.
Definition tagging_rules_model.h:85
virtual ~TaggingRulesModel()
Destroys the TaggingRulesModel.
Definition tagging_rules_model.cpp:105
bool importRules(const QString &path, QString &err)
Imports tagging rules from a file, appending to the current model.
Definition tagging_rules_model.cpp:199
bool writeTags()
Applies the model rules as the active list and writes to the active profile's file.
Definition tagging_rules_model.cpp:233
void addRule(bool disabled, const QString &name, const QString &filter, const QString &tag_content, const QString &tag_url, const QString &comment)
Adds a new rule with specified properties.
Definition tagging_rules_model.cpp:144
QModelIndex parent(const QModelIndex &indexItem) const override
Retrieves the parent index of the specified index.
Definition tagging_rules_model.cpp:394
Qt::DropActions supportedDropActions() const override
Specifies the supported drag and drop actions.
Definition tagging_rules_model.cpp:491
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Sets data in the model for the given index and role.
Definition tagging_rules_model.cpp:299
bool writeToPath(const QString &path, const tag_prefs_t *prefs, QString &err)
Write current model rules to an arbitrary path.
Definition tagging_rules_model.cpp:188
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override
Moves rows from one location to another within the model.
Definition tagging_rules_model.cpp:461
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Handles dropped MIME data.
Definition tagging_rules_model.cpp:533
Qt::ItemFlags flags(const QModelIndex &index) const override
Retrieves the item flags for a given index.
Definition tagging_rules_model.cpp:244
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Retrieves header data for the given section, orientation, and role.
Definition tagging_rules_model.cpp:358
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Generates an index for the specified row and column.
Definition tagging_rules_model.cpp:374
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Removes rows from the model.
Definition tagging_rules_model.cpp:449
bool exportRules(const QString &path, QString &err)
Exports the current tagging rules to a file.
Definition tagging_rules_model.cpp:220
QStringList mimeTypes() const override
Retrieves the list of supported MIME types for drag and drop operations.
Definition tagging_rules_model.cpp:496
bool loadFromPath(const QString &path, QString &err)
Load rules from an arbitrary path into the model (replaces current contents).
Definition tagging_rules_model.cpp:167
QVariant data(const QModelIndex &index, int role) const override
Retrieves data from the model for the given index and role.
Definition tagging_rules_model.cpp:267
TaggingRulesColumn
Defines the columns used in the tagging rules model.
Definition tagging_rules_model.h:110
@ colCount
Definition tagging_rules_model.h:116
@ colComment
Definition tagging_rules_model.h:115
@ colTag
Definition tagging_rules_model.h:113
@ colLink
Definition tagging_rules_model.h:114
@ colName
Definition tagging_rules_model.h:111
@ colFilter
Definition tagging_rules_model.h:112
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Inserts rows into the model.
Definition tagging_rules_model.cpp:433
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns under the given parent.
Definition tagging_rules_model.cpp:428
QMimeData * mimeData(const QModelIndexList &indexes) const override
Generates MIME data for the specified list of indexes.
Definition tagging_rules_model.cpp:501
TaggingRulesRole
Custom data roles for TaggingRulesModel.
Definition tagging_rules_model.h:122
@ TagContentRole
Definition tagging_rules_model.h:123
@ TagUrlRole
Definition tagging_rules_model.h:124
TaggingRulesModel(QObject *parent)
Constructs a new TaggingRulesModel, cloning the current active rule list.
Definition tagging_rules_model.cpp:98
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
Definition tagging_rules_model.cpp:411
struct _tag_rule tag_rule_t
Data for a single tagging rule.
struct _tag_prefs tag_prefs_t
Display preferences for the tagging subsystem.