Wireshark 4.7.0
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
 Returns the number of profile rows.
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of columns (always _LAST_ENTRY).
 
virtual QVariant data (const QModelIndex &idx, int role=Qt::DisplayRole) const
 Returns data for the given index and role.
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role)
 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
 Returns the header label for the given section.
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 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 ProfileItemgetCurrentProfile () const
 Returns the ProfileItem representing the profile that was active when the model was constructed.
 
const ProfileItemgetProfile (int index) const
 Returns the ProfileItem at the given flat list index.
 
const ProfileItemgetPersonalProfile (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
parentOptional 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
nameDisplay 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
nameDisplay name.
referenceOriginal/reference name for on-disk directory resolution.
isGlobaltrue for global profiles.
fromGlobaltrue if copied from a global profile.
isImporttrue 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
indexModel index of the profile to check.
isOriginalToDuplicatetrue 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
nameDisplay name to validate.
msgPopulated 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
virtual

Returns the number of columns (always _LAST_ENTRY).

Parameters
parentUnused.
Returns
Number of columns defined by the columns_ enum.

◆ data()

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

Returns data for the given index and role.

Parameters
idxModel index of the requested cell.
roleQt 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
idxModel index of the cell to query.
profilePathSet 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
idcsList 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
idxIndex of the profile to copy.
statusStatusType 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
nameName to match.
isGlobalIf true, restrict the search to global profiles.
searchReferenceIf 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
nameProfile name to search for.
Returns
Row index, or -1 if not found.

◆ flags()

Qt::ItemFlags ProfileModel::flags ( const QModelIndex &  index) const
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
indexModel 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
nameDisplay 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
indexZero-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
virtual

Returns the header label for the given section.

Parameters
sectionColumn (horizontal) or row (vertical) index.
orientationHeader orientation.
roleQt item data role.
Returns
QVariant with the header text, or an invalid QVariant for unsupported roles.

◆ illegalCharacters()

QString ProfileModel::illegalCharacters ( )
staticprotected

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
filenamePath to the source directory.
skippedCntSet to the number of profiles skipped due to conflicts.
importListPopulated with the names of successfully imported profiles.
fromZiptrue 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
errPopulated 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
idcsList of model indices to restore.
Returns
true if at least one entry was successfully restored.

◆ rowCount()

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

Returns the number of profile rows.

Parameters
parentUnused; 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 
)
virtual

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

Parameters
indexModel index of the cell to modify.
valueNew value to assign.
roleMust 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: