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
GenericModel Class Reference

This is a full implementation for generic use of the QAbstractItemModel interface. More...

Inheritance diagram for GenericModel:

Signals

void mergeDisplayEditChanged (bool val)
 
void sortRoleChanged (int val)
 

Public Member Functions

 GenericModel (QObject *parent=Q_NULLPTR)
 
 ~GenericModel ()
 
bool clearItemData (const QModelIndex &index) override
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex()) override
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 
QMap< int, QVariant > itemData (const QModelIndex &index) const override
 
bool mergeDisplayEdit () const
 
QMimeData * mimeData (const QModelIndexList &indexes) const override
 
QStringList mimeTypes () const override
 
bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild) override
 
bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override
 
void multiData (const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override
 
QModelIndex parent (const QModelIndex &index) const override
 
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex()) override
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 
QHash< int, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
virtual bool setFlags (const QModelIndex &index, Qt::ItemFlags flags)
 
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
 
void setMergeDisplayEdit (bool val)
 
void setRoleNames (const QHash< int, QByteArray > &rNames)
 Sets the role names. More...
 
void setSortRole (int role)
 
bool setSpan (const QModelIndex &index, const QSize &size)
 Set the amount of rows and columns an item should occupy. More...
 
void sort (int column, const QModelIndex &parent, Qt::SortOrder order=Qt::AscendingOrder, bool recursive=true)
 Sorts all children of parent by column in the given order. More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 
int sortRole () const
 
QSize span (const QModelIndex &index) const override
 
Qt::DropActions supportedDragActions () const override
 
Qt::DropActions supportedDropActions () const override
 

Protected Member Functions

 GenericModel (GenericModelPrivate &dptr, QObject *parent)
 
virtual bool mimeForValue (QMimeData *data, const QVariant &value) const
 Stores the /a value in the appropriate mime type of /a data. More...
 

Properties

bool mergeDisplayEdit
 This property determines if the Qt::DisplayRole and Qt::EditRole should be merged in the extra row/column. More...
 
int sortRole
 the item role that is used to query the source model's data when sorting items More...
 

Detailed Description

This is a full implementation for generic use of the QAbstractItemModel interface.

The model can replace QStandardItemModel depending only on Qt Core.

Constructor & Destructor Documentation

◆ GenericModel()

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

Constructs a new model with the given parent.

◆ ~GenericModel()

GenericModel::~GenericModel ( )

Destructor

Member Function Documentation

◆ clearItemData()

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

Reimplemented from base class

◆ columnCount()

int GenericModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Reimplemented from base class

◆ data()

QVariant GenericModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Reimplemented from base class

◆ dropMimeData()

bool GenericModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
override

Reimplemented from base class

◆ flags()

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

Reimplemented from base class

◆ hasChildren()

bool GenericModel::hasChildren ( const QModelIndex &  parent = QModelIndex()) const
override

Reimplemented from base class

◆ headerData()

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

Reimplemented from base class

◆ index()

QModelIndex GenericModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

Reimplemented from base class

◆ insertColumns()

bool GenericModel::insertColumns ( int  column,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Reimplemented from base class

◆ insertRows()

bool GenericModel::insertRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Reimplemented from base class

◆ itemData()

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

Reimplemented from base class

◆ mimeData()

QMimeData * GenericModel::mimeData ( const QModelIndexList &  indexes) const
override

Reimplemented from base class

◆ mimeForValue()

bool GenericModel::mimeForValue ( QMimeData *  data,
const QVariant &  value 
) const
protectedvirtual

Stores the /a value in the appropriate mime type of /a data.

Returns true if the data has been stored. Reimplement to support custom types.

◆ mimeTypes()

QStringList GenericModel::mimeTypes ( ) const
override

Reimplemented from base class

◆ moveColumns()

bool GenericModel::moveColumns ( const QModelIndex &  sourceParent,
int  sourceColumn,
int  count,
const QModelIndex &  destinationParent,
int  destinationChild 
)
override

Reimplemented from base class

◆ moveRows()

bool GenericModel::moveRows ( const QModelIndex &  sourceParent,
int  sourceRow,
int  count,
const QModelIndex &  destinationParent,
int  destinationChild 
)
override

Reimplemented from base class

◆ multiData()

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

Reimplemented from base class

◆ parent()

QModelIndex GenericModel::parent ( const QModelIndex &  index) const
override

Reimplemented from base class

◆ removeColumns()

bool GenericModel::removeColumns ( int  column,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Reimplemented from base class

◆ removeRows()

bool GenericModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Reimplemented from base class

◆ roleNames()

QHash< int, QByteArray > GenericModel::roleNames ( ) const
override

Reimplemented from base class

◆ rowCount()

int GenericModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Reimplemented from base class

◆ setData()

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

Reimplemented from base class

◆ setFlags()

bool GenericModel::setFlags ( const QModelIndex &  index,
Qt::ItemFlags  flags 
)
virtual

Set the item flags for a specific index

◆ setHeaderData()

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

Reimplemented from base class

◆ setItemData()

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

Reimplemented from base class

If mergeDisplayEdit is true (the default) and roles contains valuer for both Qt::EditRole and Qt::DisplayRole the latter will prevail

◆ setRoleNames()

void GenericModel::setRoleNames ( const QHash< int, QByteArray > &  rNames)

Sets the role names.

This method is a setter for roleNames() allowing you to customise the role names without subclassing the model.

Pass an empty rNames to revert to the default role names

◆ setSpan()

bool GenericModel::setSpan ( const QModelIndex &  index,
const QSize &  size 
)

Set the amount of rows and columns an item should occupy.

At the moment no view provided by Qt supports this

◆ sort() [1/2]

void GenericModel::sort ( int  column,
const QModelIndex &  parent,
Qt::SortOrder  order = Qt::AscendingOrder,
bool  recursive = true 
)

Sorts all children of parent by column in the given order.

The role used for the sorting is determined by sortRole. If recursive is set to true the sorting will propagate down the hierarchy of the model

◆ sort() [2/2]

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

Reimplemented from base class

◆ span()

QSize GenericModel::span ( const QModelIndex &  index) const
override

Reimplemented from base class

At the moment no view provided by Qt supports this

◆ supportedDragActions()

Qt::DropActions GenericModel::supportedDragActions ( ) const
override

Reimplemented from base class

◆ supportedDropActions()

Qt::DropActions GenericModel::supportedDropActions ( ) const
override

Reimplemented from base class

Property Documentation

◆ mergeDisplayEdit

GenericModel::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.

◆ sortRole

GenericModel::sortRole
readwrite

the item role that is used to query the source model's data when sorting items

Access functions: sortRole(), setSortRole()
Notifier signal: sortRoleChanged()

The default value is Qt::DisplayRole.