Servus  1.5.1
C++ network oriented utilities including a zeroconf implementation
servus::qt::ItemModel Class Reference

An item model on top of a Servus service, to be used in a Qt item view. More...

#include <itemModel.h>

+ Inheritance diagram for servus::qt::ItemModel:
+ Collaboration diagram for servus::qt::ItemModel:

Public Member Functions

SERVUSQT_API ItemModel (Servus &service, QObject *parent=nullptr)
 Construct a new model by filling it with the current discovered instances and put the service into browsing state. More...
 
virtual SERVUSQT_API ~ItemModel ()
 Destruct the model and reset the service back to non-browsing state. More...
 
SERVUSQT_API QModelIndex index (int row, int colum, const QModelIndex &parent=QModelIndex()) const override
 Mandatory override of QAbstractItemModel::index. More...
 
SERVUSQT_API QModelIndex parent (const QModelIndex &index) const override
 Mandatory override of QAbstractItemModel::parent. More...
 
SERVUSQT_API int rowCount (const QModelIndex &index=QModelIndex()) const override
 Mandatory override of QAbstractItemModel::rowCount. More...
 
SERVUSQT_API int columnCount (const QModelIndex &index=QModelIndex()) const override
 Mandatory override of QAbstractItemModel::columnCount. More...
 
SERVUSQT_API QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 Mandatory override of QAbstractItemModel::data. More...
 
SERVUSQT_API QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 Optional override of QAbstractItemModel::headerData. More...
 

Detailed Description

An item model on top of a Servus service, to be used in a Qt item view.

The model is represented as a hierarchy with two levels where the first level containts one row per discovered instance of the service, and the second level contains one row per announced key-value pair.

The model itself sets the given Servus instance into the browsing state and asynchronously browses for new and/or deleted instances every 100ms.

Version
1.2

Definition at line 45 of file itemModel.h.

Constructor & Destructor Documentation

SERVUSQT_API servus::qt::ItemModel::ItemModel ( Servus service,
QObject *  parent = nullptr 
)

Construct a new model by filling it with the current discovered instances and put the service into browsing state.

Parameters
servicethe mutable service instance that the model represents
parentoptional parent for memory ownership
Version
1.2
virtual SERVUSQT_API servus::qt::ItemModel::~ItemModel ( )
virtual

Destruct the model and reset the service back to non-browsing state.

Member Function Documentation

SERVUSQT_API int servus::qt::ItemModel::columnCount ( const QModelIndex &  index = QModelIndex()) const
override

Mandatory override of QAbstractItemModel::columnCount.

Independent of index, the column count will always be 1.

SERVUSQT_API QVariant servus::qt::ItemModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Mandatory override of QAbstractItemModel::data.

If index points to an instance item, the returned data for Qt::DisplayRole will be the instance name, and for Qt::ToolTipRole and Qt::UserRole the data will be the hostname. If index points to a key-value item, the returned data for Qt::DisplayRole will be a string in the format "key = value". For any other index and/or role, the returned data will be QVariant().

SERVUSQT_API QVariant servus::qt::ItemModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override

Optional override of QAbstractItemModel::headerData.

If orientation is Qt::Horizontal and role is Qt::DisplayRole, the returned data will be a string in the format "Instances for <service-name>". For any other input, the returned data will be QVariant().

SERVUSQT_API QModelIndex servus::qt::ItemModel::index ( int  row,
int  colum,
const QModelIndex &  parent = QModelIndex() 
) const
override

Mandatory override of QAbstractItemModel::index.

SERVUSQT_API QModelIndex servus::qt::ItemModel::parent ( const QModelIndex &  index) const
override

Mandatory override of QAbstractItemModel::parent.

If index points to a key-value item, the parent will be the corresponding instance. If index points to an instance, the parent will be QModelIndex().

SERVUSQT_API int servus::qt::ItemModel::rowCount ( const QModelIndex &  index = QModelIndex()) const
override

Mandatory override of QAbstractItemModel::rowCount.

If index points is QModelIndex(), the row count will be the number of discovered instances. If index points to an instance item, the row count will be the number of announced key-value items. If index points to a key-value item, the row count will always be 0.


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