| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
ProfileModel Class Reference

Table model that manages the full set of configuration profiles, supporting creation, duplication, deletion, import, and export. More...

`#include <profile_model.h>`

Inheritance diagram for ProfileModel:

## Public Types
enum | { COL_NAME = 0 , COL_TYPE , COL_AUTO_SWITCH_FILTER , _LAST_ENTRY }
| Column index constants for the profile table. More...
enum | { DATA_IS_DEFAULT = Qt::UserRole , DATA_IS_GLOBAL }
| Custom Qt::UserRole data keys returned by data(). More...

## Public Member Functions
| ProfileModel (QObject *parent=Q_NULLPTR)
| Constructs a ProfileModel and populates it from the current profile directories.
virtual | ~ProfileModel ()
| Destroys the model and frees all ProfileItem instances.
void | fillTable ()
| (Re-)populates the model from the on-disk profile directories.
virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const override
| Returns the number of profile rows.
virtual int | columnCount (const QModelIndex &parent=QModelIndex()) const override
| Returns the number of columns (always `_LAST_ENTRY`).
virtual QVariant | data (const QModelIndex &idx, int role=Qt::DisplayRole) const override
| Returns data for the given index and role.
virtual bool | setData (const QModelIndex &index, const QVariant &value, int role) override
| Sets data for an editable cell (profile name or auto-switch filter).
virtual QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
| Returns the header label for the given section.
virtual Qt::ItemFlags | flags (const QModelIndex &index) const override
| Returns the item flags for the given index.
void | deleteEntries (QModelIndexList idcs)
| Marks the profiles at the given indices for deletion.
bool | restoreEntries (QModelIndexList idcs)
| Clears the deletion flag on the profiles at the given indices.
int | findByName (const QString &name)
| Returns the row index of the first profile whose name matches exactly.
QModelIndex | addNewProfile (QString name)
| Adds a new empty personal profile with the given name.
QModelIndex | duplicateEntry (QModelIndex idx, ProfileItem::StatusType status=ProfileItem::StatusType::Copy)
| Creates a duplicate of the profile at `idx`.
QModelIndex | activeProfile () const
| Returns the model index of the currently active (in-use) profile row.
bool | userProfilesExist () const
| Returns whether any editable (non-global, non-default) profiles exist.
bool | isDataValid (QString &err)
| Validates all pending profile changes for conflicts and illegal names.
void | importProfilesFromDir (QString filename, int &skippedCnt, QStringList &importList, bool fromZip=false)
| Imports profiles from a directory (or an extracted ZIP staging area).
QList< int > | findAllByNameAndVisibility (const QString &name, bool isGlobal=false, bool searchReference=false) const
| Finds all profiles matching the given name and global-scope flag.
bool | checkDuplicate (const QModelIndex &index, bool isOriginalToDuplicate=false) const
| Checks whether the profile at `index` has a name collision with another entry.
void | applyChanges ()
| Applies all pending changes (additions, renames, copies, deletions) to the on-disk profile directories and updates libwireshark's profile list.
const ProfileItem * | getCurrentProfile () const
| Returns the ProfileItem representing the profile that was active when the model was constructed.
const ProfileItem * | getProfile (int index) const
| Returns the ProfileItem at the given flat list index.
const ProfileItem * | getPersonalProfile (const QString &name)
| Finds a personal (non-global) profile by name.
QVariant | dataPath (const QModelIndex &idx, QString &profilePath) const
| Returns display data for a cell together with the profile's filesystem path.

## Static Public Member Functions
static bool | checkNameValidity (QString name, QString &msg)
| Validates a candidate profile name for illegal characters and reserved names.

## Public Attributes
enum ProfileModel:: { ... } | columns_
| Column index constants for the profile table.
enum ProfileModel:: { ... } | data_values_
| Custom Qt::UserRole data keys returned by data().

## Protected Member Functions
QModelIndex | addNewProfile (QString name, QString reference, bool isGlobal=false, bool fromGlobal=false, bool isImport=false)
| Internal helper that inserts a new ProfileItem with explicit field values.

## Static Protected Member Functions
static QString | illegalCharacters ()
| Returns the set of characters that are not permitted in profile names.

## Detailed Description

Table model that manages the full set of configuration profiles, supporting creation, duplication, deletion, import, and export.

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum

Column index constants for the profile table.

Enumerator
COL_NAME | Profile name column.
COL_TYPE | Profile type (Personal / Global) column.
COL_AUTO_SWITCH_FILTER | Auto-switch display-filter expression column.
_LAST_ENTRY | Sentinel: total number of columns.

## ◆ anonymous enum

anonymous enum

Custom Qt::UserRole data keys returned by data().

Enumerator
DATA_IS_DEFAULT | bool — `true` if the item represents the default profile.
DATA_IS_GLOBAL | bool — `true` if the item represents a global profile.

## Constructor & Destructor Documentation

## ◆ ProfileModel()

ProfileModel::ProfileModel | ( | QObject * | parent = Q_NULLPTR | ) |
| explicit

Constructs a ProfileModel and populates it from the current profile directories.

Parameters

  parent | Optional parent QObject.

## Member Function Documentation

## ◆ activeProfile()

QModelIndex ProfileModel::activeProfile | ( |  | ) | const

Returns the model index of the currently active (in-use) profile row.

Returns
  Valid model index, or an invalid index if the active profile is not found.

## ◆ addNewProfile() [1/2]

QModelIndex ProfileModel::addNewProfile | ( | QString | name | ) |

Adds a new empty personal profile with the given name.

Parameters

  name | Display name for the new profile.

Returns
  Model index of the newly inserted row.

## ◆ addNewProfile() [2/2]

QModelIndex ProfileModel::addNewProfile | ( | QString | name,
|  | QString | reference,
|  | bool | isGlobal = false,
|  | bool | fromGlobal = false,
|  | bool | isImport = false )
| protected

Internal helper that inserts a new ProfileItem with explicit field values.

Parameters

  name | Display name.
  reference | Original/reference name for on-disk directory resolution.
  isGlobal | `true` for global profiles.
  fromGlobal | `true` if copied from a global profile.
  isImport | `true` if imported from an external source.

Returns
  Model index of the newly inserted row.

## ◆ checkDuplicate()

bool ProfileModel::checkDuplicate | ( | const QModelIndex & | index,
|  | bool | isOriginalToDuplicate = false ) const

Checks whether the profile at `index` has a name collision with another entry.

Parameters

  index | Model index of the profile to check.
  isOriginalToDuplicate | `true` when checking whether the source of a pending duplication would cause a conflict.

Returns
  `true` if a duplicate name exists.

## ◆ checkNameValidity()

bool ProfileModel::checkNameValidity | ( | QString | name,
|  | QString & | msg )
| static

Validates a candidate profile name for illegal characters and reserved names.

Parameters

  name | Display name to validate.
  msg | Populated with a human-readable reason if the name is invalid.

Returns
  `true` if the name is acceptable.

## ◆ columnCount()

int ProfileModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const
| override virtual

Returns the number of columns (always `_LAST_ENTRY`).

Parameters

  parent | Unused.

Returns
  Number of columns defined by the `columns_` enum.

## ◆ data()

QVariant ProfileModel::data | ( | const QModelIndex & | idx,
|  | int | role = Qt::DisplayRole ) const
| override virtual

Returns data for the given index and role.

Parameters

  idx | Model index of the requested cell.
  role | Qt item data role.

Returns
  QVariant with the requested data, or an invalid QVariant if unavailable.

## ◆ dataPath()

QVariant ProfileModel::dataPath | ( | const QModelIndex & | idx,
|  | QString & | profilePath ) const

Returns display data for a cell together with the profile's filesystem path.

Parameters

  idx | Model index of the cell to query.
  profilePath | Set to the filesystem path of the profile at `idx`.

Returns
  QVariant with the display value for the cell.

## ◆ deleteEntries()

void ProfileModel::deleteEntries | ( | QModelIndexList | idcs | ) |

Marks the profiles at the given indices for deletion.

Parameters

  idcs | List of model indices to delete.

## ◆ duplicateEntry()

QModelIndex ProfileModel::duplicateEntry | ( | QModelIndex | idx,
|  | ProfileItem::StatusType | status = ProfileItem::StatusType::Copy )

Creates a duplicate of the profile at `idx`.

Parameters

  idx | Index of the profile to copy.
  status | StatusType to assign to the duplicate (default: Copy).

Returns
  Model index of the newly inserted duplicate row.

## ◆ fillTable()

void ProfileModel::fillTable | ( |  | ) |

(Re-)populates the model from the on-disk profile directories.

Clears all existing items, then walks both the personal and global profile directories and adds a ProfileItem for each discovered profile.

## ◆ findAllByNameAndVisibility()

QList< int > ProfileModel::findAllByNameAndVisibility | ( | const QString & | name,
|  | bool | isGlobal = false,
|  | bool | searchReference = false ) const

Finds all profiles matching the given name and global-scope flag.

Parameters

  name | Name to match.
  isGlobal | If `true`, restrict the search to global profiles.
  searchReference | If `true`, also match against the reference (original) name.

Returns
  List of row indices for all matching profiles.

## ◆ findByName()

int ProfileModel::findByName | ( | const QString & | name | ) |

Returns the row index of the first profile whose name matches exactly.

Parameters

  name | Profile name to search for.

Returns
  Row index, or `-1` if not found.

## ◆ flags()

Qt::ItemFlags ProfileModel::flags | ( | const QModelIndex & | index | ) | const
| override virtual

Returns the item flags for the given index.

Global and default profiles are not editable; personal profiles support Qt::ItemIsEditable in the name and auto-switch-filter columns.

Parameters

  index | Model index to query.

Returns
  Combination of Qt::ItemFlag values.

## ◆ getCurrentProfile()

const ProfileItem * ProfileModel::getCurrentProfile | ( |  | ) | const
| inline

Returns the ProfileItem representing the profile that was active when the model was constructed.

Returns
  Pointer to the current profile item, or `nullptr` if unknown.

## ◆ getPersonalProfile()

const ProfileItem * ProfileModel::getPersonalProfile | ( | const QString & | name | ) |

Finds a personal (non-global) profile by name.

Parameters

  name | Display name to search for.

Returns
  Pointer to the matching ProfileItem, or `nullptr` if not found.

## ◆ getProfile()

const ProfileItem * ProfileModel::getProfile | ( | int | index | ) | const
| inline

Returns the ProfileItem at the given flat list index.

Parameters

  index | Zero-based index into the internal profile list.

Returns
  Pointer to the corresponding ProfileItem.

## ◆ headerData()

QVariant ProfileModel::headerData | ( | int | section,
|  | Qt::Orientation | orientation,
|  | int | role = Qt::DisplayRole ) const
| override virtual

Returns the header label for the given section.

Parameters

  section | Column (horizontal) or row (vertical) index.
  orientation | Header orientation.
  role | Qt item data role.

Returns
  QVariant with the header text, or an invalid QVariant for unsupported roles.

## ◆ illegalCharacters()

QString ProfileModel::illegalCharacters | ( |  | ) |
| static protected

Returns the set of characters that are not permitted in profile names.

Returns
  String of illegal characters.

## ◆ importProfilesFromDir()

void ProfileModel::importProfilesFromDir | ( | QString | filename,
|  | int & | skippedCnt,
|  | QStringList & | importList,
|  | bool | fromZip = false )

Imports profiles from a directory (or an extracted ZIP staging area).

Parameters

  filename | Path to the source directory.
  skippedCnt | Set to the number of profiles skipped due to conflicts.
  importList | Populated with the names of successfully imported profiles.
  fromZip | `true` when the directory is a temporary ZIP extraction; affects name sanitisation.

## ◆ isDataValid()

bool ProfileModel::isDataValid | ( | QString & | err | ) |

Validates all pending profile changes for conflicts and illegal names.

Parameters

  err | Populated with a human-readable error message on failure.

Returns
  `true` if all data is valid and changes can be applied.

## ◆ restoreEntries()

bool ProfileModel::restoreEntries | ( | QModelIndexList | idcs | ) |

Clears the deletion flag on the profiles at the given indices.

Parameters

  idcs | List of model indices to restore.

Returns
  `true` if at least one entry was successfully restored.

## ◆ rowCount()

int ProfileModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const
| override virtual

Returns the number of profile rows.

Parameters

  parent | Unused; pass a default QModelIndex for table models.

Returns
  Number of ProfileItem entries in the model.

## ◆ setData()

bool ProfileModel::setData | ( | const QModelIndex & | index,
|  | const QVariant & | value,
|  | int | role )
| override virtual

Sets data for an editable cell (profile name or auto-switch filter).

Parameters

  index | Model index of the cell to modify.
  value | New value to assign.
  role | Must be Qt::EditRole.

Returns
  `true` if the value was successfully applied.

## ◆ userProfilesExist()

bool ProfileModel::userProfilesExist | ( |  | ) | const

Returns whether any editable (non-global, non-default) profiles exist.

Returns
  `true` if at least one personal profile is present.

The documentation for this class was generated from the following files:

- /builds/wireshark/wireshark/ui/qt/models/profile_model.h
- /builds/wireshark/wireshark/ui/qt/models/profile_model.cpp