Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
DistributionModel Class Reference

Table model of the distinct value combinations of the counted fields. More...

#include <distribution_model.h>

Inheritance diagram for DistributionModel:

Public Types

enum  { SortRole = Qt::UserRole + 1 }
 Item data role holding the typed sort key of a cell.
using SortKind = DistributionField::SortKind
 The sort kind of a field, see DistributionField::SortKind.

Signals

void summaryChanged ()
 Emitted when the summary values or hasResult() changed.

Public Member Functions

 DistributionModel (QObject *parent=nullptr)
 Constructs an empty model without fields.
void setFields (const QList< DistributionField > &fields)
 Sets the counted fields and removes all rows.
void clear ()
 Removes all rows and counts, keeps the fields.
bool addPacket (proto_tree *tree)
 Counts the field values of one packet.
void publish ()
 Makes the rows and counts added since the last call visible.
void setResolveValues (bool resolve)
 Shows resolved labels instead of the raw values.
bool hasFields () const
 Tells whether fields were set.
bool hasResult () const
 Tells whether there is a result to describe.
int countColumn () const
 Returns the column of the counts.
int percentColumn () const
 Returns the column of the percentages.
QString filterExpression (int row) const
 Returns the display filter matching a row.
QList< QVariant > rowData (int row) const
 Returns the data of a row for copying and saving.
quint64 count (int row) const
 Returns the count of a row.
QList< int > topRows (int n) const
 Returns the rows with the highest counts.
QString rowLabel (int row) const
 Returns a short name of a row.
QStringList fieldNames () const
 Returns the names of the counted fields.
int distinctValues () const
 Returns the number of published distinct value combinations.
quint64 packets () const
 Returns the number of counted packets at the last publish().
quint64 observations () const
 Returns the number of observations at the last publish().
double entropy () const
 Returns the normalized Shannon entropy at the last publish().
int rowCount (const QModelIndex &parent=QModelIndex()) const override
int columnCount (const QModelIndex &parent=QModelIndex()) const override
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override

Static Public Member Functions

static bool supportsField (const header_field_info *hfinfo)
 Tells whether the values of a field can be counted.
static SortKind sortKind (enum ftenum type)
 Returns how the values of a field type sort.
static QString parseFields (const QStringList &names, QList< DistributionField > &fields)
 Resolves field names into counted fields.

Static Public Attributes

static constexpr int maxFields = 4
 The maximum number of fields that can be counted together.

Detailed Description

Table model of the distinct value combinations of the counted fields.

Rows are appended while packets are added and become visible only when publish() is called, so a view keeps its selection, scroll position and sort while the counts update. Columns are one per field, then Count and Percent. Without fields the model has the three columns Value, Count and Percent and no rows.

Constructor & Destructor Documentation

◆ DistributionModel()

DistributionModel::DistributionModel ( QObject * parent = nullptr)
explicit

Constructs an empty model without fields.

Parameters
parentThe parent object.

Member Function Documentation

◆ addPacket()

bool DistributionModel::addPacket ( proto_tree * tree)

Counts the field values of one packet.

Every combination of the distinct values of the fields is one observation. New rows are not visible before publish().

Parameters
treeThe protocol tree of the packet.
Returns
True when the packet contains every field, false when it was skipped.

◆ count()

quint64 DistributionModel::count ( int row) const

Returns the count of a row.

Parameters
rowThe row.
Returns
The number of observations of the row, 0 for a row that is not published.

◆ countColumn()

int DistributionModel::countColumn ( ) const

Returns the column of the counts.

Returns
The Count column.

◆ distinctValues()

int DistributionModel::distinctValues ( ) const
inline

Returns the number of published distinct value combinations.

Returns
The number of rows.

◆ entropy()

double DistributionModel::entropy ( ) const
inline

Returns the normalized Shannon entropy at the last publish().

Returns
The entropy between 0 and 1.

◆ fieldNames()

QStringList DistributionModel::fieldNames ( ) const

Returns the names of the counted fields.

Returns
The field abbreviations.

◆ filterExpression()

QString DistributionModel::filterExpression ( int row) const

Returns the display filter matching a row.

Parameters
rowThe row.
Returns
The filter, one comparison per field joined by "&&".

◆ hasFields()

bool DistributionModel::hasFields ( ) const
inline

Tells whether fields were set.

Returns
True when setFields() was called with at least one field.

◆ hasResult()

bool DistributionModel::hasResult ( ) const
inline

Tells whether there is a result to describe.

Returns
True after publish() since the last setFields() or clear().

◆ observations()

quint64 DistributionModel::observations ( ) const
inline

Returns the number of observations at the last publish().

Returns
The observation count.

◆ packets()

quint64 DistributionModel::packets ( ) const
inline

Returns the number of counted packets at the last publish().

Returns
The packet count.

◆ parseFields()

QString DistributionModel::parseFields ( const QStringList & names,
QList< DistributionField > & fields )
static

Resolves field names into counted fields.

The names are expected to have passed the field list checks of FieldFilterEdit (known names or aliases, none empty, at most maxFields). This only checks what is specific to counting. An alias is stored under the abbreviation of its field.

Parameters
namesThe field names.
fieldsReceives the resolved fields.
Returns
An empty string on success, else a message for the first field that cannot be counted.

◆ percentColumn()

int DistributionModel::percentColumn ( ) const

Returns the column of the percentages.

Returns
The Percent column.

◆ publish()

void DistributionModel::publish ( )

Makes the rows and counts added since the last call visible.

Always emits summaryChanged(), also when nothing changed.

◆ rowData()

QList< QVariant > DistributionModel::rowData ( int row) const

Returns the data of a row for copying and saving.

Parameters
rowThe row.
Returns
The shown field texts, the count as qulonglong and the percentage as double.

◆ rowLabel()

QString DistributionModel::rowLabel ( int row) const

Returns a short name of a row.

Parameters
rowThe row.
Returns
The shown field texts joined by ", ".

◆ setFields()

void DistributionModel::setFields ( const QList< DistributionField > & fields)

Sets the counted fields and removes all rows.

Parameters
fieldsThe fields, as returned by parseFields().

◆ setResolveValues()

void DistributionModel::setResolveValues ( bool resolve)

Shows resolved labels instead of the raw values.

Parameters
resolveTrue to show the resolved labels.

◆ sortKind()

DistributionModel::SortKind DistributionModel::sortKind ( enum ftenum type)
static

Returns how the values of a field type sort.

Parameters
typeThe field type.
Returns
The sort kind of that type.

◆ supportsField()

bool DistributionModel::supportsField ( const header_field_info * hfinfo)
static

Tells whether the values of a field can be counted.

Parameters
hfinfoThe field.
Returns
True unless the field is a protocol or a label without value.

◆ topRows()

QList< int > DistributionModel::topRows ( int n) const

Returns the rows with the highest counts.

Parameters
nThe maximum number of rows.
Returns
The published rows, by decreasing count.

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