QAdvanced Item View  0.4
The QAIV (Qt Advanced Item Views) library provides GUI and utility classes extending the capabilities of the Qt item views.
 All Classes Functions Variables Enumerations Enumerator Properties Groups Pages
Public Types | Public Member Functions | Properties | List of all members
QConditionalDecorationProxyModel Class Reference

The QConditionalDecorationProxyModel class implements a proxy model for conditional decorations. More...

#include <qconditionaldecorationproxymodel.h>

Inheritance diagram for QConditionalDecorationProxyModel:

Public Types

enum  ItemDataRole { ConditionalDecorationRole = Qt::UserRole + 421, IconSetsRole }
 

Public Member Functions

 QConditionalDecorationProxyModel (QObject *parent=0)
 
 ~QConditionalDecorationProxyModel ()
 
void addDecoration (int column, QAbstractItemModelDecoration *decoration)
 
void addIcon (const QString &set, const QString &name, const QString &resource)
 
void addIconSet (const QString &name, const QVariantMap icons)
 
virtual QVariant data (const QModelIndex &index, int role) const
 
QIcon icon (const QString &set, const QString &name) const
 
QSize iconSize () const
 
int iconSpacing () const
 
QMap< QString, QVariant > iconSets () const
 
bool restoreState (const QByteArray &state)
 
QByteArray stateState () const
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role)
 
void setIconSize (const QSize &size)
 
void setIconSpacing (int spacing)
 

Properties

QSize iconSize
 
int iconSpacing
 

Detailed Description

The QConditionalDecorationProxyModel class implements a proxy model for conditional decorations.

Lets assume we want to decorate colum 'Maturity Level' in the source model show below:

qconditionaldecorationproxymodel01.png
Source Model

The code to set up the model and the view would look like this:

QTableView* tableView = new QTableView(this);
QStandardItemModel* model = new QStandardItemModel();
...
QConditionalDecorationProxyModel* proxy = new QConditionalDecorationProxyModel(this);
proxy->setSourceModel(model);
view->setModel(proxy);

To add a decoration, we need to create a QConditionalDecoration and add condition defining the match conditions and values:

decoration->addCondition(QConditionalDecoration::IsEqual, "Active", "leds", "green (on)");
decoration->addCondition(QConditionalDecoration::IsEqual, "Deprecated", "leds", "red (on)");
decoration->addCondition(QConditionalDecoration::IsEqual, "Done", "leds", "yellow (on)");
decoration->addCondition(QConditionalDecoration::IsEqual, "Maintained", "leds", "orange (on)");

For all items matching none of the previously defined conditions, we set a default decoration:

decoration->setDefaultDecoration("leds", "white (on)");

Finally we add the decoration to the proxy model:

proxy->addDecoration(3, decoration);

After adding the decoration the view is updated and shows the decorations.

qconditionaldecorationproxymodel02.png
Decorated Model

Default Icon Sets

Icon SetIcon NameIcon
emoticonshappy
emoticon_smile.ico
neutral
emoticon_neutral.ico
unhappy
emoticon_unhappy.ico
flagsred (on)
flag_red.ico
yellow
flag_yellow.ico
green
flag_green.ico
blue
flag_blue.ico
orange
flag_orange.ico
pink
flag_pink.ico
purple
flag_purple.ico
ledsred (on)
red-on.ico
yellow (on)
yellow-on.ico
green (on)
green-on.ico
blue (on)
blue-on.ico
orange (on)
amber-on.ico
white (on)
white-on.ico
tagsred (on)
tag_red.ico
yellow
tag_yellow.ico
green
tag_green.ico
blue
tag_blue.ico
orange
tag_orange.ico
pink
tag_pink.ico
purple
tag_purple.ico
Remarks
Thanks to FatCow (www.fatcow.com) for providing the icons under CC Attribution 3.0 United States.

Constructor & Destructor Documentation

QConditionalDecorationProxyModel::QConditionalDecorationProxyModel ( QObject *  parent = 0)
explicit

Constructs a QConditionalDecorationProxyModel with the given parent.

QConditionalDecorationProxyModel::~QConditionalDecorationProxyModel ( )

Destroys the QConditionalDecorationProxyModel object.

Member Function Documentation

void QConditionalDecorationProxyModel::addDecoration ( int  column,
QAbstractItemModelDecoration decoration 
)

Adds a decoration for the specified column.

void QConditionalDecorationProxyModel::addIconSet ( const QString &  name,
const QVariantMap  icons 
)

Adds the icon set name with the given icons to the proxy model.

QMap<QString,QIcon> icons;
icons["Custom1"] = QIcon(":/custom1");
icons["Custom2"] = QIcon(":/custom2");
proxy->addIconSet("Custom", icons);
See also
addIcon()
QVariant QConditionalDecorationProxyModel::data ( const QModelIndex &  index,
int  role 
) const
virtual

QSortFilterProxyModel::data()

QIcon QConditionalDecorationProxyModel::icon ( const QString &  set,
const QString &  name 
) const

Returns the icon specified by the given set and name. An invalid QIcon is returned if the iconset set or the icon name cannot be retrieved.

QMap< QString, QVariant > QConditionalDecorationProxyModel::iconSets ( ) const

Returns a map of icon sets defined for this proxy.

QSize QConditionalDecorationProxyModel::iconSize ( ) const

Returns the size of the icons.

See also
setIconSize()
int QConditionalDecorationProxyModel::iconSpacing ( ) const

Returns the spacing between the icons of an item.

bool QConditionalDecorationProxyModel::restoreState ( const QByteArray &  state)

Restores the proxy model's state and decoratrions.

bool QConditionalDecorationProxyModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
virtual

QSortFilterProxyModel::setData()

void QConditionalDecorationProxyModel::setIconSize ( const QSize &  size)

Sets the icon size to size.

See also
iconSize()
void QConditionalDecorationProxyModel::setIconSpacing ( int  spacing)

Sets the spacing between the icons of an item to spacing.

QByteArray QConditionalDecorationProxyModel::stateState ( ) const

Saves the proxy model's state and decorations.

Property Documentation

QSize QConditionalDecorationProxyModel::iconSize
readwrite

This property holds the size of item's icons.

Remarks
The default is QSize(16, 16)
int QConditionalDecorationProxyModel::iconSpacing
readwrite

This property holds the spacing between the icons of an item.

Remarks
The default is 3.

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