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

This proxy model provides an extra row and column to handle user insertions. More...

Inheritance diagram for InsertProxyModel:

Public Types

enum  InsertDirection { NoInsert = 0x0 , InsertRow = 0x1 , InsertColumn = 0x2 }
 

Public Slots

virtual bool commitColumn ()
 
virtual bool commitRow ()
 

Signals

void dataForCornerChanged (const QVector< int > &roles)
 
void extraDataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
 
void insertDirectionChanged (InsertDirections direction)
 
void mergeDisplayEditChanged (bool separate)
 

Public Member Functions

 InsertProxyModel (QObject *parent=Q_NULLPTR)
 
 ~InsertProxyModel ()
 
QModelIndex buddy (const QModelIndex &index) const Q_DECL_OVERRIDE
 
int columnCount (const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
 
QVariant data (const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
 
virtual QVariant dataForCorner (int role=Qt::DisplayRole) const
 
Qt::ItemFlags flags (const QModelIndex &index) const Q_DECL_OVERRIDE
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 
InsertDirections insertDirection () const
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 
QMap< int, QVariant > itemData (const QModelIndex &index) const Q_DECL_OVERRIDE
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE
 
bool mergeDisplayEdit () const
 
bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild) Q_DECL_OVERRIDE
 
bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) Q_DECL_OVERRIDE
 
QModelIndex parent (const QModelIndex &index) const Q_DECL_OVERRIDE
 
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 
int rowCount (const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) Q_DECL_OVERRIDE
 
virtual void setDataForCorner (const QVariant &value, int role=Qt::EditRole)
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) Q_DECL_OVERRIDE
 
void setInsertDirection (const InsertDirections &direction)
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) Q_DECL_OVERRIDE
 
void setMergeDisplayEdit (bool val)
 
void setSourceModel (QAbstractItemModel *newSourceModel) Q_DECL_OVERRIDE
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) Q_DECL_OVERRIDE
 

Protected Member Functions

 InsertProxyModel (InsertProxyModelPrivate &dptr, QObject *parent)
 
virtual Qt::ItemFlags flagForExtra (bool isRow, int section) const
 flag function for the extra row or column More...
 
virtual bool validColumn () const
 Returns true if the extra column can be merged in the main model. More...
 
virtual bool validRow () const
 Returns true if the extra row can be merged in the main model. More...
 

Properties

InsertDirections insertDirection
 This property determines if the extra row, column or both are displayed. More...
 
bool mergeDisplayEdit
 This property determines if the Qt::DisplayRole and Qt::EditRole should be merged in the extra row/column. More...
 

Detailed Description

This proxy model provides an extra row and column to handle user insertions.

This proxy will add an extra row, column or both to allow users to insert new sections with a familiar interface.

You can use setInsertDirection to determine whether to show an extra row or column. By default, this model will behave as QIdentityProxyModel

You can either call commitRow/commitColumn or reimplement validRow/validColumn to decide when a row/column should be added to the main model.

Warning
Only flat models are supported. Branches of a tree will be hidden by the proxy

Member Enumeration Documentation

◆ InsertDirection

Direction of the Insertion

Enumerator
NoInsert 

No Insertion

InsertRow 

Insert new rows

InsertColumn 

Insert new columns

Constructor & Destructor Documentation

◆ InsertProxyModel()

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

Constructs a new proxy model with the given parent.

◆ ~InsertProxyModel()

InsertProxyModel::~InsertProxyModel ( )

Destructor

Member Function Documentation

◆ buddy()

QModelIndex InsertProxyModel::buddy ( const QModelIndex &  index) const

Reimplemented from base class

◆ columnCount()

int InsertProxyModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Reimplemented from base class

◆ commitColumn

bool InsertProxyModel::commitColumn ( )
virtualslot

Adds the extra column to the source model

◆ commitRow

bool InsertProxyModel::commitRow ( )
virtualslot

Adds the extra row to the source model

◆ data()

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

Reimplemented from base class

◆ dataForCorner()

QVariant InsertProxyModel::dataForCorner ( int  role = Qt::DisplayRole) const
virtual

Gets the data for the corner cell at the intersection between the extra row and extra column

◆ dataForCornerChanged

void InsertProxyModel::dataForCornerChanged ( const QVector< int > &  roles)
signal

This signal is emitted whenever the data for the corner at the intersection of the extra row and column is changed

◆ extraDataChanged

void InsertProxyModel::extraDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight,
const QVector< int > &  roles = QVector<int>() 
)
signal

Same as dataChanged but is emitted only for the extra row/column

◆ flagForExtra()

Qt::ItemFlags InsertProxyModel::flagForExtra ( bool  isRow,
int  section 
) const
protectedvirtual

flag function for the extra row or column

If isRow is true this method is referring to the extra row, otherwise it will be the extra column, section then determines the row or column this flag refers to

◆ flags()

Qt::ItemFlags InsertProxyModel::flags ( const QModelIndex &  index) const

Reimplemented from base class

◆ hasChildren()

bool InsertProxyModel::hasChildren ( const QModelIndex &  parent = QModelIndex()) const

Reimplemented from base class

◆ headerData()

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

Reimplemented from base class

◆ index()

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

Reimplemented from base class

◆ insertColumns()

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

Reimplemented from base class

◆ insertRows()

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

Reimplemented from base class

◆ mapFromSource()

QModelIndex InsertProxyModel::mapFromSource ( const QModelIndex &  sourceIndex) const

Reimplemented from base class

◆ mapToSource()

QModelIndex InsertProxyModel::mapToSource ( const QModelIndex &  proxyIndex) const

Reimplemented from base class

◆ moveColumns()

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

Reimplemented from base class

◆ moveRows()

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

Reimplemented from base class

◆ parent()

QModelIndex InsertProxyModel::parent ( const QModelIndex &  index) const

Reimplemented from base class

◆ removeColumns()

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

Reimplemented from base class

◆ removeRows()

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

Reimplemented from base class

◆ rowCount()

int InsertProxyModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Reimplemented from base class

◆ setData()

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

Reimplemented from base class

◆ setDataForCorner()

void InsertProxyModel::setDataForCorner ( const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Set the data for the corner cell at the intersection between the extra row and extra column

◆ setHeaderData()

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

Reimplemented from base class

◆ setItemData()

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

Reimplemented from base class

If the map contains both Qt::DisplayRole and Qt::EditRole and mergeDisplayEdit is set to true, the value of Qt::DisplayRole will prevail.

◆ setSourceModel()

void InsertProxyModel::setSourceModel ( QAbstractItemModel *  newSourceModel)

Reimplemented from base class

◆ sort()

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

Reimplemented from base class

◆ validColumn()

bool InsertProxyModel::validColumn ( ) const
protectedvirtual

Returns true if the extra column can be merged in the main model.

The default implementation never commits the column to the model.

If, for example, you want the row to be added to the source model as soon as there's any data in the Qt::DisplayRole of any cell you can repliement this method as:

if (!sourceModel()) return false; const int sourceCols = sourceModel()->columnCount(); const int sourceRows =
sourceModel()->rowCount(); for (int i = 0; i < sourceRows; ++i) { if (index(i, sourceCols).data().isValid()) return true;
}
return false;
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Definition: insertproxymodel.cpp:703
QVariant data(const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Definition: insertproxymodel.cpp:462

◆ validRow()

bool InsertProxyModel::validRow ( ) const
protectedvirtual

Returns true if the extra row can be merged in the main model.

The default implementation never commits the row to the model.

If, for example, you want the row to be added to the source model as soon as there's any data in the Qt::DisplayRole of any cell you can repliement this method as:

if (!sourceModel())
return false;
const int sourceCols = sourceModel()->columnCount();
const int sourceRows = sourceModel()->rowCount();
for (int i = 0; i < sourceCols; ++i) {
if (index(sourceRows,i).data().isValid())
return true;
}
return false;

Property Documentation

◆ insertDirection

InsertProxyModel::insertDirection
readwrite

This property determines if the extra row, column or both are displayed.

Access functions: insertDirection(), setInsertDirection()
Notifier signal: insertDirectionChanged()

◆ mergeDisplayEdit

InsertProxyModel::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 false it will be duplicated for both roles. If there is data both in Qt::DisplayRole and Qt::EditRole when you set this property to true Qt::DisplayRole will prevail. This property only affects the extra row/column. Data in the source model is not affected.