Multi diag tools
Public Member Functions | List of all members
Mdt::ItemModel::HeaderProxyModel Class Reference

HeaderProxyModel provides a simple way to set custom headers. More...

#include <HeaderProxyModel.h>

Inherits QIdentityProxyModel.

Public Member Functions

 HeaderProxyModel (QObject *parent=nullptr)
 Constructor.
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 Get header data. More...
 
QVariant horizontalHeaderData (int column, int role=Qt::DisplayRole) const
 Get horizontal header data. More...
 
void setHorizontalHeaderLabels (const QStringList &labels)
 Set horizontal header labels.
 

Detailed Description

HeaderProxyModel provides a simple way to set custom headers.

Common way to use Qt's item/view is to implement a item model, that let the user access relevant data. Such model also should implement header data access methodes. But, for some cases, it can be enouth to work with a existing model, such as VariantTableModel, that do not provide header data methods. In the latter case, HeaderProxyModel can be used.

Typical usage:

#include <Mdt/ItemModel/VariantTableModel.h>
#include <Mdt/ItemModel/HeaderProxyModel.h>
#include <QTableView>
using namespace Mdt::ItemModel;
// Setup model
model.populate(5, 2);
// Setup proxy model
HeaderProxyModel headerModel;
headerModel.setSourceModel(&model);
headerModel.setHorizontalHeaderLabels({"Id","Name"});
// Setup view
QTableView view;
view.setModel(&headerModel);
Note
When you have to deal with several proxy models, ProxyModelContainer can be helpful.

Definition at line 63 of file HeaderProxyModel.h.

Member Function Documentation

QVariant Mdt::ItemModel::HeaderProxyModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Get header data.

See also
horizontalHeaderData()

Definition at line 30 of file HeaderProxyModel.cpp.

QVariant Mdt::ItemModel::HeaderProxyModel::horizontalHeaderData ( int  column,
int  role = Qt::DisplayRole 
) const

Get horizontal header data.

If some horizontal header data has been set, and column is in that bound, these header data will be returned. Else, if a source model has allready been set, the header data from this model will be returned. Else, a null QVariant is returned.

See also
setHorizontalHeaderLabels()

Definition at line 38 of file HeaderProxyModel.cpp.


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