GridModelDataBinding Class

GridModelDataBinding class contains the set of functions and methods for binding QtitanDataGrid columns to the data model. The class is constructed automatically by the grid column. You don't need to call the constructor directly. More...

Header: #include <GridModelDataBinding>
Inherits: QObject

Public Types

enum RelationMode { NoRelation, Relation, MasterDetailsRelation }

Public Functions

int column() const
QString columnName() const
GridModelController *controller() const
QVariant defaultValue(Qt::ItemDataRole role) const
Qt::ItemDataRole displayRole() const
Qt::ItemDataRole editRole() const
QModelIndex findRelationModelIndex(const QVariant &foreignKey, Qt::ItemDataRole masterRole, Qt::ItemDataRole &foreignRole) const
int foreignKeyColumn() const
QString foreignKeyColumnName() const
Qt::ItemDataRole foreignKeyMasterRole() const
Qt::ItemDataRole foreignKeyRole() const
int getColumnMapping(Qt::ItemDataRole masterRole) const
QString getColumnNameMapping(Qt::ItemDataRole masterRole) const
Qt::ItemDataRole getRoleMapping(Qt::ItemDataRole masterRole) const
bool getValue(const GridRow &row, Qt::ItemDataRole role, QVariant &retval) const
GridModelDataBinding::RelationMode relationMode() const
QAbstractItemModel *relationModel()
const QModelIndex &relationParentIndex() const
void setDefaultValue(const QVariant &value, Qt::ItemDataRole role)
void setDisplayRole(Qt::ItemDataRole role = Qt::DisplayRole)
void setEditRole(Qt::ItemDataRole role = Qt::EditRole)
void setForeignKey(int foreignColumn, Qt::ItemDataRole foreignRole = Qt::DisplayRole, Qt::ItemDataRole masterRole = Qt::EditRole)
void setForeignKey(const QString &foreignColumnName, Qt::ItemDataRole foreignRole = Qt::DisplayRole, Qt::ItemDataRole masterRole = Qt::EditRole)
void setRelationMode(GridModelDataBinding::RelationMode mode)
void setRelationModel(QAbstractItemModel *model, QModelIndex parentIndex = QModelIndex())
void setRoleMapping(Qt::ItemDataRole masterRole, const QString &columnName, Qt::ItemDataRole foreignRole = Qt::DisplayRole)
void setRoleMapping(Qt::ItemDataRole masterRole, int column, Qt::ItemDataRole foreignRole = Qt::DisplayRole)
void setSortRole(Qt::ItemDataRole role = Qt::DisplayRole)
void setSummaryRole(Qt::ItemDataRole role = Qt::DisplayRole)
void setSupportedSummaryTypes(GridSummary::SummaryTypes types)
bool setValue(const GridRow &row, Qt::ItemDataRole role, const QVariant &value)
Qt::ItemDataRole sortRole() const
Qt::ItemDataRole summaryRole() const
GridSummary::SummaryTypes supportedSummaryTypes() const

Detailed Description

Member Type Documentation

enum GridModelDataBinding::RelationMode

The enumerator of the relation modes used in QtitanDataGrid. More information about relation modes can be found in this thread Relation mode in QtitanDataGrid

ConstantValueDescription
GridModelDataBinding::NoRelation0The relation mode is not used.
GridModelDataBinding::Relation1Relation mode. This mode allows the developer to create a mechanism used in the QSqlRelationalTableModel class in Qt.
GridModelDataBinding::MasterDetailsRelation2Master-details relation. A special mode that helps to implement the relation of a master-detail in a grid cell.

Member Function Documentation

int GridModelDataBinding::column() const

Returns a model column associated with the binding.

QString GridModelDataBinding::columnName() const

Returns the name of the model column assosicated with the binding.

GridModelController *GridModelDataBinding::controller() const

Returns the model controller that owns the binding.

QVariant GridModelDataBinding::defaultValue(Qt::ItemDataRole role) const

Returns the default value of the grid column this relation (binding) is assocaited with. The value is not defined by default. The role parameter defines the role for which the default value should be obtained.

See also setDefaultValue().

Qt::ItemDataRole GridModelDataBinding::displayRole() const

Returns the role that should be used as the role for displaying the data of the Qt model. By default, Qt::DisplayRole is used.

See also setDisplayRole().

Qt::ItemDataRole GridModelDataBinding::editRole() const

Returns the role that will be used as the role for editing data in the Qt model. Qt::EditRole is used by default.

See also setEditRole().

QModelIndex GridModelDataBinding::findRelationModelIndex(const QVariant &foreignKey, Qt::ItemDataRole masterRole, Qt::ItemDataRole &foreignRole) const

Finds the QModelIndex in the relation model by the foreignKey for masterRole. foreignKey contains either foreign key value or relation model row index. Row index is used when foreignKeyColumn() is not specified. If QModelIndex is found then additionaly the foreignRole will contain Qt::ItemDataRole to query mapped value.

See also getRelationModelIndex().

int GridModelDataBinding::foreignKeyColumn() const

Returns the column in the relation(foreign) model that used to store the foreign keys.

QString GridModelDataBinding::foreignKeyColumnName() const

Returns the name of the relation column of the model that is used for storing the external key. For details, see the setForeignKey() method.

Qt::ItemDataRole GridModelDataBinding::foreignKeyMasterRole() const

Returns the Qt::ItemDataRole that will be used to query foreign key in the master model.

Qt::ItemDataRole GridModelDataBinding::foreignKeyRole() const

Returns the Qt::ItemDataRole in the relation(foreign) model that used to store the foreign keys.

int GridModelDataBinding::getColumnMapping(Qt::ItemDataRole masterRole) const

Returns the column in the relation model that is used to get the value associated with masterRole.

QString GridModelDataBinding::getColumnNameMapping(Qt::ItemDataRole masterRole) const

Returns the name of the column in the relation model that is used to get the value associated with masterRole.

Qt::ItemDataRole GridModelDataBinding::getRoleMapping(Qt::ItemDataRole masterRole) const

Returns the role that should be used to get the value from the relation model associated with masterRole.

bool GridModelDataBinding::getValue(const GridRow &row, Qt::ItemDataRole role, QVariant &retval) const

Returns the value for the role and row from the model. If successful, the value is saved as the retval parameter and the function returns true.

GridModelDataBinding::RelationMode GridModelDataBinding::relationMode() const

Returns the current relation mode that used to query the relation values. By default, GridModelDataBinding::NoRelation is returned.

See also setRelationMode().

QAbstractItemModel *GridModelDataBinding::relationModel()

Returns a reference to the relation model.

See also setRelationModel().

const QModelIndex &GridModelDataBinding::relationParentIndex() const

Returns QModelIndex that used as a parent to get an access to the lower levels of the hierarchy of the relation model.

void GridModelDataBinding::setDefaultValue(const QVariant &value, Qt::ItemDataRole role)

Defines the default value for the grid column this relation (binding) is associated with. When a new grid row is created, this value is used for cell initialization. The role parameter sets the role for which the default value needs to be obtained.

See also defaultValue().

void GridModelDataBinding::setDisplayRole(Qt::ItemDataRole role = Qt::DisplayRole)

Defines the role that should be used as the role for displaying the data of the Qt model.

See also displayRole().

void GridModelDataBinding::setEditRole(Qt::ItemDataRole role = Qt::EditRole)

Defines the role that should be used as the role for editing the data of the Qt model.

See also editRole().

void GridModelDataBinding::setForeignKey(int foreignColumn, Qt::ItemDataRole foreignRole = Qt::DisplayRole, Qt::ItemDataRole masterRole = Qt::EditRole)

Sets foreign key to make an access to the relation model. a foreignColumn and a foreignRole are the column and role in the relation model there the foreign key is stored. masterRole is a role that should be used to query the foreign key in the master model.

void GridModelDataBinding::setForeignKey(const QString &foreignColumnName, Qt::ItemDataRole foreignRole = Qt::DisplayRole, Qt::ItemDataRole masterRole = Qt::EditRole)

Sets foreign key to make an access to the relation model. a foreignColumnName and a foreignRole are the column name and role in the relation model there the foreign key is stored. masterRole is a role that should be used to get the foreign key in the master model.

void GridModelDataBinding::setRelationMode(GridModelDataBinding::RelationMode mode)

Sets the relation mode that should be used to query the relation values. For more information about relation modes, see Relation mechanism in QtitanDataGrid.

See also relationMode().

void GridModelDataBinding::setRelationModel(QAbstractItemModel *model, QModelIndex parentIndex = QModelIndex())

Defines the relation model that should be used to query the relation values. The parentIndex parameter is used for gaining access to the lower levels of the hierarchy of the model. Additionally, the method sets the relationMode to GridModelDataBinding::Relation.

See also relationModel().

void GridModelDataBinding::setRoleMapping(Qt::ItemDataRole masterRole, const QString &columnName, Qt::ItemDataRole foreignRole = Qt::DisplayRole)

Defines the foreign role foreignRole and columnName that should be used to get the value from the relation model associated with masterRole.

void GridModelDataBinding::setRoleMapping(Qt::ItemDataRole masterRole, int column, Qt::ItemDataRole foreignRole = Qt::DisplayRole)

Defines the foreign role foreignRole and column that should be used to get the value from the relation model associated with masterRole.

void GridModelDataBinding::setSortRole(Qt::ItemDataRole role = Qt::DisplayRole)

Defines the role that should be used to get the value for sorting.

See also sortRole().

void GridModelDataBinding::setSummaryRole(Qt::ItemDataRole role = Qt::DisplayRole)

Defines the role that should be used to get the value for summaries calculation.

See also summaryRole().

void GridModelDataBinding::setSupportedSummaryTypes(GridSummary::SummaryTypes types)

Defines acceptable summaries for binding.

See also supportedSummaryTypes().

bool GridModelDataBinding::setValue(const GridRow &row, Qt::ItemDataRole role, const QVariant &value)

Sets the value for the role and modelRowIndex to the model. If successful, the function returns true.

Qt::ItemDataRole GridModelDataBinding::sortRole() const

Returns the role that will be used to get the value for sorting. Qt::DisplayRole is used by default.

See also setSortRole().

Qt::ItemDataRole GridModelDataBinding::summaryRole() const

Returns the role that will be used to get the value for summaries calculation. Qt::DisplayRole is used by default.

See also setSummaryRole().

GridSummary::SummaryTypes GridModelDataBinding::supportedSummaryTypes() const

Returns acceptable summaries for binding.

See also setSupportedSummaryTypes().