Documents > BPS V2 C++ API
BpsTableModel Class Reference

A model for hierarchical or flat database tables. More...

#include <bpstablemodel.h>

List of all members.

Public Slots

void refresh ()
 Refresh the model immediately.
void setDropKeyboardModifiers (Qt::KeyboardModifiers aModifiers)
 Views using to the model should report the drop keyboard modifiers with this slot.
void setEmpty ()
 Clears the model and inhibits loading any records from database, independent from filter.

Signals

void itemsAdded (const QModelIndexList &aIndexes)
 This signal is emitted after one or more new rows is/are added either by calling addItem, or by executing drag/drop with ctrl pressed to copy records.
void modified (bool aModified)
 Emitted when the modification status of the model changes.
void unmodified (bool aUnmodified)
 Emitted when the modification status of the model changes.

Public Member Functions

QModelIndex addItem (const QModelIndex &aParent=QModelIndex(), bool aSignal=true)
 Creates a new row in the model.
void addOptions (const QString &aMappingTable, const QString &aMasterColumn, const QString &aAttribColumn, const QString &aAttribTable, const QString &aNameColumn)
 Add a slave options definition.
void addSlaveTable (BpsTable *aTable, const QString &aRefColumn)
 Add a slave table.
QVariantList allKeys (const QModelIndex &aParent=QModelIndex()) const
 Fetches all yet not fetched rows from database, and returns all record keys.
 BpsTableModel (BpsTable *aTable, QObject *aParent)
 Create a master table model.
bool canAdd () const
bool canDelete () const
bool canEdit () const
bool canPaste () const
void copy (const QModelIndexList &aIndexList)
 Copy items to clipboard.
void deleteItem (const QModelIndex &aIndex)
 Delete a single row from the model.
void deleteItems (const QModelIndexList &aIndexList)
 Delete a number of rows from the model.
void enableTree (bool aEnable)
 Enables or disables tree mode.
QModelIndex firstIndex (const QModelIndex &aParent=QModelIndex())
 Get index of first item.
bool isModified () const
bool isReadOnly () const
bool isTree () const
BpsTableItemitem (const QModelIndex &aIndex) const
 Get the table item of a certain index.
QVariant key (const QModelIndex &aIndex) const
QModelIndex keyIndex (const QVariant &aKey) const
 Get index from a key.
QString keyToolTipLabel () const
void loadAdditionalFields (BpsTableItem *aItem)
 Load additional fields of the record, in case they were not yet loaded.
void loadOptions (BpsTableItem *aItem)
 Load options of the record from the mapping tables, in case they were not yet loaded.
void loadSlaveModels (BpsTableItem *aItem)
 Load slave models of the item, in case they were not yet loaded.
void moveItem (const QModelIndex &aSrc, int aDstRow, const QModelIndex &aDstParent=QModelIndex())
 Moves the source item to the target.
QString optionsAttribTable (const QString &aMappingTable) const
 Get the attribute table of a option mapping table.
QStringList optionsMappingTables () const
QString optionsNameColumn (const QString &aMappingTable) const
 Get the name column in the attributes table of a option mapping table.
void paste (const QModelIndex &aParent=QModelIndex())
 Paste clipboard data into new items.
bool save (QString &aMessage, QModelIndexList &aIndexes, QString &aColumn)
 Save pending changes to the datastore.
void setKeyToolTipLabel (const QString &aLabel)
 Set label to display the record key as tool tip.
void setReadOnly (bool aReadOnly)
 Enable or disable read-only mode.
BpsTableslaveTable (const QString &aName) const
QStringList slaveTables () const
BpsTabletable () const

Friends

class BpsTableItemPrivate

Detailed Description

A model for hierarchical or flat database tables.

The model also supports slave table models: tables without a own synthetic key but where part of the primary key references to the master table.


Constructor & Destructor Documentation

BpsTableModel::BpsTableModel ( BpsTable aTable,
QObject *  aParent 
)

Create a master table model.

The table must have a synthetic primary key c_key, and optionally a key c_parent if the table is hierarchical. Also, there must exist a sequence s_tablename to create new primary keys. Neither c_key nor c_parent should appear aFields.

Parameters:
[in]aTableThe master table definition.
[in]aParentThe parent object

Member Function Documentation

QModelIndex BpsTableModel::addItem ( const QModelIndex &  aParent = QModelIndex(),
bool  aSignal = true 
)

Creates a new row in the model.

On save the model will do an insert query for the new row. After creation the signal itemAdded will be emitted.

Parameters:
[in]aParentThe parent row.
[in]aSignalEmit itemsAdded().
Returns:
The index of the new item.
void BpsTableModel::addOptions ( const QString &  aMappingTable,
const QString &  aMasterColumn,
const QString &  aAttribColumn,
const QString &  aAttribTable,
const QString &  aNameColumn 
)

Add a slave options definition.

Options are mapping tables with one reference column to the master table and one column to an attribute table. Table editors typically display the options as a list of checkable items.

 model->addOptions(
    bStr("t_partnerattributes"), 
    bStr("c_partner"), 
    bStr("c_pnrattribute"), 
    bStr("t_pnrattributes"), 
    bStr("c_name"));
Parameters:
[in]aMappingTableThe mapping table.
[in]aMasterColumnThe mapping table column referencing c_key in the master table.
[in]aAttribColumnThe mapping table column referencing c_key in the attribute table.
[in]aAttribTableThe attribute table.
[in]aNameColumnThe attribute tables name column (may also be a function call).
void BpsTableModel::addSlaveTable ( BpsTable aTable,
const QString &  aRefColumn 
)

Add a slave table.

The slave table must have the column aRef referring to the primary key of the master table. The column aRef must not appear in aFields.

Like master tables, the slave table must also have a synthetic primary key c_key, and optionally a key c_parent if the table is hierarchical. Also, there must exist a sequence s_tablename to create new primary keys. Neither c_key nor c_parent should appear aFields.

Parameters:
[in]aTableThe slave table definition.
[in]aRefColumnName of the column referring to the master tables primary key.
Returns:
Pointer to the slave model.
QVariantList BpsTableModel::allKeys ( const QModelIndex &  aParent = QModelIndex()) const

Fetches all yet not fetched rows from database, and returns all record keys.

Parameters:
[in]aParentThe parent index.
Returns:
All keys of the records in order.
bool BpsTableModel::canAdd ( ) const
Returns:
True if the current user has add permission on the table.
bool BpsTableModel::canDelete ( ) const
Returns:
True if the current user has delete permission on the table.
bool BpsTableModel::canEdit ( ) const
Returns:
True if the current user has edit permission on the table.
bool BpsTableModel::canPaste ( ) const
Returns:
True if the clipboard contains data that can be pasted into the model.
void BpsTableModel::copy ( const QModelIndexList &  aIndexList)

Copy items to clipboard.

Parameters:
[in]aIndexListThe item list to copy.
void BpsTableModel::deleteItem ( const QModelIndex &  aIndex)

Delete a single row from the model.

If the row was created but not yet saved to the datastore, it will get removed from the model immediately. Otherwise when it is a row existing already in the datastore, the row will be marked for deletion and the delete query will get run at save.

Parameters:
[in]aIndexThe index of the row to delete.
void BpsTableModel::deleteItems ( const QModelIndexList &  aIndexList)

Delete a number of rows from the model.

Rows created but not yet saved to the datastore will get removed from the model immediately. Rows existing already in the datastore will be marked for deletion and delete queries will get run at save.

Parameters:
[in]aIndexListThis list of row indexes to delete.
void BpsTableModel::enableTree ( bool  aEnable)

Enables or disables tree mode.

Enabling only works if the table has a column c_parent, otherwise it is ignored.

Parameters:
[in]aEnableTrue to enable, false to disable.
QModelIndex BpsTableModel::firstIndex ( const QModelIndex &  aParent = QModelIndex())

Get index of first item.

Parameters:
[in]aParentThe parent index.
Returns:
The index if any first row, or QModelIndex() if no such record.
bool BpsTableModel::isModified ( ) const
Returns:
True if the model is modified, and needs save.
bool BpsTableModel::isReadOnly ( ) const
Returns:
True if in read-only mode.
bool BpsTableModel::isTree ( ) const
Returns:
True if the model is for a hierarchical table. The default is true if the table has a column c_parent, and false otherwise.
BpsTableItem* BpsTableModel::item ( const QModelIndex &  aIndex) const

Get the table item of a certain index.

This is basically the same as static_cast<BpsTableItem*>(aIndex.internalPointer()). However it will return the root item for invalid indexes.

Parameters:
[in]aIndexItem index.
Returns:
The item at this index.
void BpsTableModel::itemsAdded ( const QModelIndexList &  aIndexes) [signal]

This signal is emitted after one or more new rows is/are added either by calling addItem, or by executing drag/drop with ctrl pressed to copy records.

Parameters:
[in]aIndexesIndexes of the new items.
QVariant BpsTableModel::key ( const QModelIndex &  aIndex) const
Parameters:
[in]aIndexThis model index.
Returns:
The key value of the row.
QModelIndex BpsTableModel::keyIndex ( const QVariant &  aKey) const

Get index from a key.

While searching, yet unloaded children of parent items get fetched.

Parameters:
[in]aKeyThe key to find.
Returns:
The valid model index if found, or QModelIndex() if no record with this key is found.
QString BpsTableModel::keyToolTipLabel ( ) const
Returns:
The label to display the key tool tip. Default is empty (do not display key tool tip).
void BpsTableModel::loadAdditionalFields ( BpsTableItem aItem)

Load additional fields of the record, in case they were not yet loaded.

AdditionalFields are fields having isRegular() false and not displayed by the models view, but handled by an editor instead.

Parameters:
[in]aItemThe item to load additional fields for.
void BpsTableModel::loadOptions ( BpsTableItem aItem)

Load options of the record from the mapping tables, in case they were not yet loaded.

Parameters:
[in]aItemThe item to load options for.
void BpsTableModel::loadSlaveModels ( BpsTableItem aItem)

Load slave models of the item, in case they were not yet loaded.

Parameters:
[in]aItemThe item to load slave models for.
void BpsTableModel::modified ( bool  aModified) [signal]

Emitted when the modification status of the model changes.

Parameters:
[in]aModifiedTrue if there are unsaved changes, false otherwise.
void BpsTableModel::moveItem ( const QModelIndex &  aSrc,
int  aDstRow,
const QModelIndex &  aDstParent = QModelIndex() 
)

Moves the source item to the target.

Parameters:
[in]aSrcIndex of the item to move.
[in]aDstRowThe destination row.
[in]aDstParentIndex of the destination parent.
QString BpsTableModel::optionsAttribTable ( const QString &  aMappingTable) const

Get the attribute table of a option mapping table.

Parameters:
[in]aMappingTableThe mapping table name.
Returns:
Name of the attribute table, or empty string if not found.
QStringList BpsTableModel::optionsMappingTables ( ) const
Returns:
A list of all option mapping tables added to this master model.
QString BpsTableModel::optionsNameColumn ( const QString &  aMappingTable) const

Get the name column in the attributes table of a option mapping table.

Parameters:
[in]aMappingTableThe mapping table name.
Returns:
Name of the column, or empty string if not found.
void BpsTableModel::paste ( const QModelIndex &  aParent = QModelIndex())

Paste clipboard data into new items.

Parameters:
[in]aParentThe parent row to create new items under.
void BpsTableModel::refresh ( ) [slot]

Refresh the model immediately.

Unsaved changes are lost.

bool BpsTableModel::save ( QString &  aMessage,
QModelIndexList &  aIndexes,
QString &  aColumn 
)

Save pending changes to the datastore.

Existing table validators are run before inserts, updates and deletes, and in case of a failure the message and index are set. In case validation failed for a row marked for deletion, that row will get reset to the original state so a subsequent error action can open the failing field for information.

Parameters:
aMessageError message for the first failing row in case validation failed.
aIndexesList of failing indexes, starting with the master model. The last index in the list is the failing item. In case the failure was in a 2nd level slave, the list would contain 3 indexes (master, 1st level slave, 2nd level slave). In case the failure was in the master, the list would only contain 1 index.
aColumnName of the column failing.
Returns:
True if save was successful, false if save failed.
Exceptions:
BpsExceptionon datastore errors.
void BpsTableModel::setDropKeyboardModifiers ( Qt::KeyboardModifiers  aModifiers) [slot]

Views using to the model should report the drop keyboard modifiers with this slot.

Parameters:
[in]aModifiersThe keyboard modifiers.
void BpsTableModel::setEmpty ( ) [slot]

Clears the model and inhibits loading any records from database, independent from filter.

Unsaved changes are lost.

void BpsTableModel::setKeyToolTipLabel ( const QString &  aLabel)

Set label to display the record key as tool tip.

Parameters:
[in]aLabelThe text to display as label
void BpsTableModel::setReadOnly ( bool  aReadOnly)

Enable or disable read-only mode.

In read-only mode, direct editing by the view is disabled. Read-only is disabled by default, allowing direct editing by attached views.

Parameters:
[in]aReadOnlyTrue to enable read-only mode.
BpsTable* BpsTableModel::slaveTable ( const QString &  aName) const
Parameters:
[in]aNameName of the slave model table, without the prefix t_.
Returns:
The table record, or 0 if no such slave model.
QStringList BpsTableModel::slaveTables ( ) const
Returns:
A list of all slave tables added to this master model.
BpsTable* BpsTableModel::table ( ) const
Returns:
The table definition.
void BpsTableModel::unmodified ( bool  aUnmodified) [signal]

Emitted when the modification status of the model changes.

Parameters:
[in]aUnmodifiedTrue if there the model is in a saved state, false otherwise.

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