A model for hierarchical or flat database tables. More...
#include <bpstablemodel.h>
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 |
| BpsTableItem * | item (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. | |
| BpsTable * | slaveTable (const QString &aName) const |
| QStringList | slaveTables () const |
| BpsTable * | table () const |
Friends | |
| class | BpsTableItemPrivate |
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.
| 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.
| [in] | aTable | The master table definition. |
| [in] | aParent | The parent object |
| 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.
| [in] | aParent | The parent row. |
| [in] | aSignal | Emit itemsAdded(). |
| 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"));
| [in] | aMappingTable | The mapping table. |
| [in] | aMasterColumn | The mapping table column referencing c_key in the master table. |
| [in] | aAttribColumn | The mapping table column referencing c_key in the attribute table. |
| [in] | aAttribTable | The attribute table. |
| [in] | aNameColumn | The 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.
| [in] | aTable | The slave table definition. |
| [in] | aRefColumn | Name of the column referring to the master tables primary key. |
| QVariantList BpsTableModel::allKeys | ( | const QModelIndex & | aParent = QModelIndex() | ) | const |
Fetches all yet not fetched rows from database, and returns all record keys.
| [in] | aParent | The parent index. |
| bool BpsTableModel::canAdd | ( | ) | const |
| bool BpsTableModel::canDelete | ( | ) | const |
| bool BpsTableModel::canEdit | ( | ) | const |
| bool BpsTableModel::canPaste | ( | ) | const |
| void BpsTableModel::copy | ( | const QModelIndexList & | aIndexList | ) |
Copy items to clipboard.
| [in] | aIndexList | The 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.
| [in] | aIndex | The 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.
| [in] | aIndexList | This 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.
| [in] | aEnable | True to enable, false to disable. |
| QModelIndex BpsTableModel::firstIndex | ( | const QModelIndex & | aParent = QModelIndex() | ) |
Get index of first item.
| [in] | aParent | The parent index. |
| bool BpsTableModel::isModified | ( | ) | const |
| bool BpsTableModel::isReadOnly | ( | ) | const |
| bool BpsTableModel::isTree | ( | ) | const |
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.
| [in] | aIndex | Item 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.
| [in] | aIndexes | Indexes of the new items. |
| QVariant BpsTableModel::key | ( | const QModelIndex & | aIndex | ) | const |
| [in] | aIndex | This model index. |
| QModelIndex BpsTableModel::keyIndex | ( | const QVariant & | aKey | ) | const |
Get index from a key.
While searching, yet unloaded children of parent items get fetched.
| [in] | aKey | The key to find. |
| QString BpsTableModel::keyToolTipLabel | ( | ) | const |
| 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.
| [in] | aItem | The 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.
| [in] | aItem | The item to load options for. |
| void BpsTableModel::loadSlaveModels | ( | BpsTableItem * | aItem | ) |
Load slave models of the item, in case they were not yet loaded.
| [in] | aItem | The item to load slave models for. |
| void BpsTableModel::modified | ( | bool | aModified | ) | [signal] |
Emitted when the modification status of the model changes.
| [in] | aModified | True 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.
| [in] | aSrc | Index of the item to move. |
| [in] | aDstRow | The destination row. |
| [in] | aDstParent | Index of the destination parent. |
| QString BpsTableModel::optionsAttribTable | ( | const QString & | aMappingTable | ) | const |
Get the attribute table of a option mapping table.
| [in] | aMappingTable | The mapping table name. |
| QStringList BpsTableModel::optionsMappingTables | ( | ) | const |
| QString BpsTableModel::optionsNameColumn | ( | const QString & | aMappingTable | ) | const |
Get the name column in the attributes table of a option mapping table.
| [in] | aMappingTable | The mapping table name. |
| void BpsTableModel::paste | ( | const QModelIndex & | aParent = QModelIndex() | ) |
Paste clipboard data into new items.
| [in] | aParent | The 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.
| aMessage | Error message for the first failing row in case validation failed. |
| aIndexes | List 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. |
| aColumn | Name of the column failing. |
| BpsException | on datastore errors. |
| void BpsTableModel::setDropKeyboardModifiers | ( | Qt::KeyboardModifiers | aModifiers | ) | [slot] |
Views using to the model should report the drop keyboard modifiers with this slot.
| [in] | aModifiers | The 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.
| [in] | aLabel | The 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.
| [in] | aReadOnly | True to enable read-only mode. |
| BpsTable* BpsTableModel::slaveTable | ( | const QString & | aName | ) | const |
| [in] | aName | Name of the slave model table, without the prefix t_. |
| QStringList BpsTableModel::slaveTables | ( | ) | const |
| BpsTable* BpsTableModel::table | ( | ) | const |
| void BpsTableModel::unmodified | ( | bool | aUnmodified | ) | [signal] |
Emitted when the modification status of the model changes.
| [in] | aUnmodified | True if there the model is in a saved state, false otherwise. |