Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
RoleMaskProxyModel Class Reference

This proxy will act as a mask on top of the source model to intercept data. More...

Inheritance diagram for RoleMaskProxyModel:

Signals

void maskedDataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
 
void maskedRolesChanged ()
 
void maskHeaderDataChanged (bool val)
 
void mergeDisplayEditChanged (bool val)
 
void transparentIfEmptyChanged (bool val)
 

Public Member Functions

 RoleMaskProxyModel (QObject *parent=Q_NULLPTR)
 
 ~RoleMaskProxyModel ()
 
void addMaskedRole (int role)
 
bool clearItemData (const QModelIndex &index) override
 
void clearMaskedData (const QModelIndex &index)
 
void clearMaskedFlags (const QModelIndex &index)
 
void clearMaskedRoles ()
 
QVariant data (const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QMap< int, QVariant > itemData (const QModelIndex &index) const override
 
const Qt::ItemFlags * maskedFlags (const QModelIndex &index) const
 
QMap< int, QVariant > maskedItemData (const QModelIndex &index) const
 
QVariant maskedRoleDefaultValue (int role) const
 
QList< int > maskedRoles () const
 
bool maskHeaderData () const
 
bool mergeDisplayEdit () const
 
void multiData (const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override
 
void removeMaskedRole (int role)
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) override
 
bool setMaskedFlags (const QModelIndex &index, Qt::ItemFlags flags)
 
bool setMaskedRoleDefaultValue (int role, const QVariant &value)
 
void setMaskedRoles (const QList< int > &roles)
 
void setMaskHeaderData (bool val)
 
void setMergeDisplayEdit (bool val)
 
void setSourceModel (QAbstractItemModel *sourceModel) override
 
void setTransparentIfEmpty (bool val)
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 
bool transparentIfEmpty () const
 

Protected Member Functions

 RoleMaskProxyModel (RoleMaskProxyModelPrivate &dptr, QObject *parent)
 
const QSet< int > & maskedRolesSets () const
 

Properties

QList< int > maskedRoles
 Returns the list of roles managed by the proxy model. More...
 
bool maskHeaderData
 This property determines if the role mask should apply to the headers too. More...
 
bool mergeDisplayEdit
 This property determines if the Qt::DisplayRole and Qt::EditRole should be merged in the extra row/column. More...
 
bool transparentIfEmpty
 This property determines if a mapped role containing no data should be transparent. More...
 

Detailed Description

This proxy will act as a mask on top of the source model to intercept data.

This proxy model can be used to manage data in roles not supported by the source model. The user can select what roles should be managed by the proxy model and the rest will be left to the source model.

Constructor & Destructor Documentation

◆ RoleMaskProxyModel() [1/2]

RoleMaskProxyModel::RoleMaskProxyModel ( QObject *  parent = Q_NULLPTR)
explicit

Constructs a new proxy model with the given parent.

◆ ~RoleMaskProxyModel()

RoleMaskProxyModel::~RoleMaskProxyModel ( )

Destructor

◆ RoleMaskProxyModel() [2/2]

RoleMaskProxyModel::RoleMaskProxyModel ( RoleMaskProxyModelPrivate &  dptr,
QObject *  parent 
)
protected

Constructor used only while subclassing the private class. Not part of the public API

Member Function Documentation

◆ addMaskedRole()

void RoleMaskProxyModel::addMaskedRole ( int  role)

Adds role to the list of roles managed by the proxy model

◆ clearItemData()

bool RoleMaskProxyModel::clearItemData ( const QModelIndex &  index)
override

Reimplemented from base class

Due to limitations in the architecture, the model might emit 2 separate dataChanged signals, one for the roles that were masked and one for the roles that are managed by the sorce model

◆ clearMaskedData()

void RoleMaskProxyModel::clearMaskedData ( const QModelIndex &  index)

Removes all the data managed by the proxy model for a certain index.

◆ clearMaskedFlags()

void RoleMaskProxyModel::clearMaskedFlags ( const QModelIndex &  index)

Removes all the flags managed by the proxy model for a certain index.

◆ clearMaskedRoles()

void RoleMaskProxyModel::clearMaskedRoles ( )

Removes all roles managed by the proxy model

◆ data()

QVariant RoleMaskProxyModel::data ( const QModelIndex &  proxyIndex,
int  role = Qt::DisplayRole 
) const
override

Reimplemented from base class

◆ flags()

Qt::ItemFlags RoleMaskProxyModel::flags ( const QModelIndex &  index) const
override

Reimplemented from base class

◆ headerData()

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

Reimplemented from base class

◆ itemData()

QMap< int, QVariant > RoleMaskProxyModel::itemData ( const QModelIndex &  index) const
override

Reimplemented from base class

◆ maskedDataChanged

RoleMaskProxyModel::maskedDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight,
const QVector< int > &  roles 
)
signal

This signal is emitted whenever a dataChanged() signal is emitted for a role managed by the proxy

◆ maskedFlags()

const Qt::ItemFlags * RoleMaskProxyModel::maskedFlags ( const QModelIndex &  index) const

Returns the flags managed by the proxy model for a certain index or nullptr if no flag is stored in the proxy model

◆ maskedItemData()

QMap< int, QVariant > RoleMaskProxyModel::maskedItemData ( const QModelIndex &  index) const

Returns all the data managed by the proxy model for a certain index. The key of the map is the corresponding role

◆ maskedRoleDefaultValue()

QVariant RoleMaskProxyModel::maskedRoleDefaultValue ( int  role) const

Returns the default value for the role when the proxy is not transparent

See also
transparentIfEmpty

◆ maskedRolesChanged

RoleMaskProxyModel::maskedRolesChanged ( )
signal

This signal is emitted whenever the list of roles managed by the proxy changes

◆ maskedRolesSets()

const QSet< int > & RoleMaskProxyModel::maskedRolesSets ( ) const
protected

Same as maskedRoles but returns it in the way it is stored internally rather than converting it to QList

◆ multiData()

void RoleMaskProxyModel::multiData ( const QModelIndex &  index,
QModelRoleDataSpan  roleDataSpan 
) const
override

Reimplemented from base class

◆ removeMaskedRole()

void RoleMaskProxyModel::removeMaskedRole ( int  role)

Removes role from the list of roles managed by the proxy model

◆ setData()

bool RoleMaskProxyModel::setData ( const QModelIndex &  proxyIndex,
const QVariant &  value,
int  role = Qt::EditRole 
)
override

Reimplemented from base class

◆ setHeaderData()

bool RoleMaskProxyModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant &  value,
int  role = Qt::EditRole 
)
override

Reimplemented from base class

◆ setItemData()

bool RoleMaskProxyModel::setItemData ( const QModelIndex &  index,
const QMap< int, QVariant > &  roles 
)
override

Reimplemented from base class

Due to limitations in the architecture, the model might emit 2 separate dataChanged signals, one for the roles that were masked and one for the roles that are managed by the sorce model

◆ setMaskedFlags()

bool RoleMaskProxyModel::setMaskedFlags ( const QModelIndex &  index,
Qt::ItemFlags  flags 
)

Sets custom flags for the index that override the ones from the source model

◆ setMaskedRoles()

void RoleMaskProxyModel::setMaskedRoles ( const QList< int > &  newRoles)

Set the list of roles managed by the proxy model

◆ setSourceModel()

void RoleMaskProxyModel::setSourceModel ( QAbstractItemModel *  sourceMdl)
override

Reimplemented from base class

◆ sort()

void RoleMaskProxyModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
override

Reimplemented from base class

This method will do nothing.

If you want to sort based on the marked data use a QSortFilterProxyModel on top of this proxy.

Property Documentation

◆ maskedRoles

RoleMaskProxyModel::maskedRoles
readwrite

Returns the list of roles managed by the proxy model.

Access functions: maskedRoles()

◆ maskHeaderData

RoleMaskProxyModel::maskHeaderData
readwrite

This property determines if the role mask should apply to the headers too.

Access functions: maskHeaderData(), setMaskHeaderData()
Notifier signal: maskHeaderDataChanged()

By default this property is set to false

◆ mergeDisplayEdit

RoleMaskProxyModel::mergeDisplayEdit
readwrite

This property determines if the Qt::DisplayRole and Qt::EditRole should be merged in the extra row/column.

Access functions: mergeDisplayEdit(), setMergeDisplayEdit()
Notifier signal: mergeDisplayEditChanged()

By default the two roles are one and the same you can use this property to separate them. If there's any data in the role when you set this property to true it will be duplicated for both roles. If there is data both in Qt::DisplayRole and Qt::EditRole when you set this property to false Qt::DisplayRole will prevail. This property only has effect if Qt::DisplayRole and/or Qt::EditRole are masked by the proxy. Data in the source model is not affected.

◆ transparentIfEmpty

RoleMaskProxyModel::transparentIfEmpty
readwrite

This property determines if a mapped role containing no data should be transparent.

Access functions: transparentIfEmpty(), setTransparentIfEmpty()
Notifier signal: transparentIfEmptyChanged()

If this property is set to true, roles managed by the proxy will show the source model data unless it gets ovewritten in the proxy