ModelDataBinding Class Reference

(Qtitan::ModelDataBinding)

The ModelDataBinding class - the class that enables QtitanDataGrid grid columns to interact with model data. More...

Inherits QObject.

Public Types

enum RelationMode { NoRelation, Relation, MasterDetailsRelation }

Public Functions

ModelDataBinding ( GridModelController * modelController, int column )
virtual ~ModelDataBinding ()
int column () const
QString columnName () const
QVariant defaultValue ( Qt::ItemDataRole role = Qt::EditRole ) const
Qt::ItemDataRole displayRole () const
Qt::ItemDataRole editRole () const
QModelIndex findRelationModelIndex ( const QVariant & foreignKeyValue ) const
int foreignKeyColumn () const
QString foreignKeyColumnName () const
Qt::ItemDataRole foreignKeyMasterRole () const
Qt::ItemDataRole foreignKeyRole () const
int getForeignColumnMapping ( Qt::ItemDataRole role ) const
QString getForeignColumnNameMapping ( Qt::ItemDataRole role ) const
Qt::ItemDataRole getForeignRoleMapping ( Qt::ItemDataRole role ) const
bool getValue ( GridRow * row, Qt::ItemDataRole role, QVariant & retval ) const
RelationMode relationMode () const
QAbstractItemModel * relationModel ()
const QModelIndex & relationParentIndex () const
void setColumn ( int column )
void setDefaultValue ( const QVariant & value, Qt::ItemDataRole role = Qt::EditRole )
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 ( RelationMode mode )
void setRelationModel ( QAbstractItemModel * model, QModelIndex parentIndex = QModelIndex() )
void setRoleMapping ( Qt::ItemDataRole role, const QString & foreignColumnName, Qt::ItemDataRole foreignRole = Qt::DisplayRole )
void setRoleMapping ( Qt::ItemDataRole role, int foreignColumn, Qt::ItemDataRole foreignRole = Qt::DisplayRole )
void setSummaryRole ( Qt::ItemDataRole role = Qt::DisplayRole )
void setSupportedSummaryTypes ( SummaryTypes types )
bool setValue ( GridRow * row, Qt::ItemDataRole role, const QVariant & value )
Qt::ItemDataRole summaryRole () const
SummaryTypes supportedSummaryTypes () const
  • 29 public functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 1 public variable inherited from QObject
  • 4 static public members inherited from QObject
  • 7 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The ModelDataBinding class - the class that enables QtitanDataGrid grid columns to interact with model data.

Member Type Documentation

enum ModelDataBinding::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
Qtitan::ModelDataBinding::NoRelation0The relation mode is not used.
Qtitan::ModelDataBinding::Relation1Relation mode. This mode allows the developer to create a mechanism used in the QSqlRelationalTableModel class in Qt.
Qtitan::ModelDataBinding::MasterDetailsRelation2A special mode that helps implement the relation of a master-detail in a grid cell.

Member Function Documentation

ModelDataBinding::ModelDataBinding ( GridModelController * modelController, int column )

ModelDataBinding::~ModelDataBinding () [virtual]

int ModelDataBinding::column () const

Returns a model column associated with the binding.

See also setColumn().

QString ModelDataBinding::columnName () const

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

QVariant ModelDataBinding::defaultValue ( Qt::ItemDataRole role = Qt::EditRole ) 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 ModelDataBinding::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 ModelDataBinding::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 ModelDataBinding::findRelationModelIndex ( const QVariant & foreignKeyValue ) const

Searches for a cell in the relation model of the foreignKeyValue key by its value using the settings set with the setForeignKey() method. If the key is not found in the external model, an invalid QModelIndex is returned.

int ModelDataBinding::foreignKeyColumn () const

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

QString ModelDataBinding::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 ModelDataBinding::foreignKeyMasterRole () const

Returns the role of the model that is used for obtaining the external key for the current model. For more information, see the setForeignKey() method.

Qt::ItemDataRole ModelDataBinding::foreignKeyRole () const

Returns the role of the relation model that is used for storing the external key. For more information, see the setForeignKey() method.

int ModelDataBinding::getForeignColumnMapping ( Qt::ItemDataRole role ) const

Returns the column of the external modeal that is mapped to the role of the current cell set by the role parameter.

QString ModelDataBinding::getForeignColumnNameMapping ( Qt::ItemDataRole role ) const

Returns the name of the column in the external model that is mapped to the role of the current cell defined by the role parameter.

Qt::ItemDataRole ModelDataBinding::getForeignRoleMapping ( Qt::ItemDataRole role ) const

Returns the role of the external model that is mapped to the role of the current cell set by the role parameter.

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

Gets the value of the role role from the model for the grid row defined by the row parameter. If successful, the value is saved as the retval parameter and the function returns "true".

RelationMode ModelDataBinding::relationMode () const

Returns the current relation mode used for this binding. By default, NoRelation is returned.

See also setRelationMode().

QAbstractItemModel * ModelDataBinding::relationModel ()

Returns a link to the external model.

See also setRelationModel().

const QModelIndex & ModelDataBinding::relationParentIndex () const

Returns the index of the parent of the relation model. It's used for access to the lower levels of the hierarchy of the relation model.

void ModelDataBinding::setColumn ( int column )

See also column().

void ModelDataBinding::setDefaultValue ( const QVariant & value, Qt::ItemDataRole role = Qt::EditRole )

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 ModelDataBinding::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 ModelDataBinding::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 ModelDataBinding::setForeignKey ( int foreignColumn, Qt::ItemDataRole foreignRole = Qt::DisplayRole, Qt::ItemDataRole masterRole = Qt::EditRole )

Defines the settings of the external key for the current relation mode. foreignColumn - The column of the model that is used for storing the external key in an external model. foreignRole - The role for obtaining the external key from an external model. masterRole - The role for obtaining the value of the external key of the current cell.

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

Defines the settings of the external key for the current relation mode. foreignColumnName - The name of the column of the model that is used for storing the external key in an external model. foreignRole - The role for obtaining the external key from an external model. masterRole - The role for obtaining the value of the external key of the current cell.

void ModelDataBinding::setRelationMode ( RelationMode mode )

Sets the Relation mode that should be used for the current binding. For more information about Relation modes, see Relation mode in QtitanDataGrid.

See also relationMode().

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

Defines the external model to be used in one of the Relation modes. The parentIndex parameter is used for gaining access to the lower levels of the hierarchy of the model set by the model parameter.

See also relationModel().

void ModelDataBinding::setRoleMapping ( Qt::ItemDataRole role, const QString & foreignColumnName, Qt::ItemDataRole foreignRole = Qt::DisplayRole )

Defines the mapping rule for obtaining the value of the current cell for the role set by the role parameter. The value will be taken from the column of the external model set by the foreignColumnName parameter and the role set by the foreignRole role. Once the method is called and the grid needs to obtain the value for the role role from the current cell, the grid will use an external key set by the setForeignKey() function to determine a row in the external modeal and obtain this value from the foreignColumnName column and the foreignRole role.

void ModelDataBinding::setRoleMapping ( Qt::ItemDataRole role, int foreignColumn, Qt::ItemDataRole foreignRole = Qt::DisplayRole )

Defines the mapping rule for obtaining the value of the current cell for the role set by the role parameter. The value will be taken from the column of the external model set by the foreignColumn parameter and the role set by the foreignRole role. Once the method is called and the grid needs to obtain the value for the role role from the current cell, the grid will use an external key set by the setForeignKey() function to determine a row in the external modeal and obtain this value from the foreignColumn column and the foreignRole role.

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

Defines the role for which summaries will be calculated if the user needs them.

See also summaryRole().

void ModelDataBinding::setSupportedSummaryTypes ( SummaryTypes types )

Defines acceptable summaries for binding.

See also supportedSummaryTypes().

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

Sets the value value of the role role of the model for the grid row defined by row parameter. If successful, the function returns "true".

Qt::ItemDataRole ModelDataBinding::summaryRole () const

Returns the role for which summaries will be calculated if the user needs them. By default, Qt::DisplayRole is used for calculating summaries.

See also setSummaryRole().

SummaryTypes ModelDataBinding::supportedSummaryTypes () const

Returns acceptable summaries for binding.

See also setSupportedSummaryTypes().