BPS C++ API  2.24.4
BpsTableModel Class Reference

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

#include <bpstablemodel.h>

+ Inheritance diagram for BpsTableModel:

Public Slots

void refresh ()
 Refresh the model immediately. More...
 
void setEmpty ()
 Clears the model and inhibits loading any records from database, independent from filter. More...
 

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. More...
 
void modified (bool aModified)
 Emitted when the modification status of the model changes. More...
 
void unmodified (bool aUnmodified)
 Emitted when the modification status of the model changes. More...
 

Public Member Functions

QModelIndex addItem (const QModelIndex &aParent=QModelIndex(), bool aSignal=true)
 Creates a new row in the model. More...
 
void addOptions (const QString &aMappingTable, const QString &aMasterColumn, const QString &aAttribColumn, const QString &aAttribTable, const QString &aNameColumn)
 Add a slave options definition. More...
 
void addSlaveTable (BpsTable *aTable, const QString &aRefColumn)
 Add a slave table. More...
 
QVariantList allKeys (const QModelIndex &aParent=QModelIndex()) const
 Fetches all yet not fetched rows from database, and returns all record keys. More...
 
 BpsTableModel (BpsTable *aTable, QObject *aParent)
 Create a master table model. More...
 
bool canAdd () const
 
bool canDelete () const
 
bool canEdit () const
 
bool canMove () const
 
bool canPaste () const
 
void copy (const QModelIndexList &aIndexList)
 Copy items to clipboard. More...
 
void deleteItem (const QModelIndex &aIndex)
 Delete a single row from the model. More...
 
void deleteItems (const QModelIndexList &aIndexList)
 Delete a number of rows from the model. More...
 
void enableTree (bool aEnable)
 Enables or disables tree mode. More...
 
QModelIndex firstIndex (const QModelIndex &aParent=QModelIndex())
 Get index of first item. More...
 
bool isModified () const
 
bool isReadOnly () const
 
bool isTree () const
 
BpsTableItemitem (const QModelIndex &aIndex) const
 Get the table item of a certain index. More...
 
QVariant key (const QModelIndex &aIndex) const
 
QModelIndex keyIndex (const QVariant &aKey) const
 Get index from a key. More...
 
QString keyToolTipLabel () const
 
void loadAdditionalFields (BpsTableItem *aItem)
 Load additional fields of the record, in case they were not yet loaded. More...
 
void loadOptions (BpsTableItem *aItem)
 Load options of the record from the mapping tables, in case they were not yet loaded. More...
 
void loadSlaveModels (BpsTableItem *aItem)
 Load slave models of the item, in case they were not yet loaded. More...
 
void moveItem (const QModelIndex &aSrc, int aDstRow, const QModelIndex &aDstParent=QModelIndex())
 Moves the source item to the target. More...
 
QString optionsAttribTable (const QString &aMappingTable) const
 Get the attribute table of a option mapping table. More...
 
QStringList optionsMappingTables () const
 
QString optionsNameColumn (const QString &aMappingTable) const
 Get the name column in the attributes table of a option mapping table. More...
 
void paste (const QModelIndex &aParent=QModelIndex())
 Paste clipboard data into new items. More...
 
bool save (QString &aMessage, QModelIndexList &aIndexes, QString &aColumn)
 Save pending changes to the datastore. More...
 
void setKeyToolTipLabel (const QString &aLabel)
 Set label to display the record key as tool tip. More...
 
void setReadOnly (bool aReadOnly)
 Enable or disable read-only mode. More...
 
BpsTableslaveTable (const QString &aName) const
 
QStringList slaveTables () const
 
BpsTabletable () const
 
- Public Member Functions inherited from QAbstractItemModel
virtual QModelIndex buddy (const QModelIndex &index) const const
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const const
 
virtual bool canFetchMore (const QModelIndex &parent) const const
 
bool checkIndex (const QModelIndex &index, QAbstractItemModel::CheckIndexOptions options) const const
 
virtual int columnCount (const QModelIndex &parent) const const=0
 
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
virtual QVariant data (const QModelIndex &index, int role) const const=0
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 
virtual void fetchMore (const QModelIndex &parent)
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const const
 
virtual bool hasChildren (const QModelIndex &parent) const const
 
bool hasIndex (int row, int column, const QModelIndex &parent) const const
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role) const const
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent) const const=0
 
bool insertColumn (int column, const QModelIndex &parent)
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent)
 
bool insertRow (int row, const QModelIndex &parent)
 
virtual bool insertRows (int row, int count, const QModelIndex &parent)
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const const
 
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
 
void layoutChanged (const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const const
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const const
 
virtual QStringList mimeTypes () const const
 
void modelAboutToBeReset ()
 
void modelReset ()
 
bool moveColumn (const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
 
bool moveRow (const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
 
virtual QModelIndex parent (const QModelIndex &index) const const=0
 
 QAbstractItemModel (QObject *parent)
 
bool removeColumn (int column, const QModelIndex &parent)
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent)
 
bool removeRow (int row, const QModelIndex &parent)
 
virtual bool removeRows (int row, int count, const QModelIndex &parent)
 
virtual void revert ()
 
virtual QHash< int, QByteArrayroleNames () const const
 
virtual int rowCount (const QModelIndex &parent) const const=0
 
void rowsAboutToBeInserted (const QModelIndex &parent, int start, int end)
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role)
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role)
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 
void setSupportedDragActions (Qt::DropActions actions)
 
virtual QModelIndex sibling (int row, int column, const QModelIndex &index) const const
 
virtual void sort (int column, Qt::SortOrder order)
 
virtual QSize span (const QModelIndex &index) const const
 
virtual bool submit ()
 
virtual Qt::DropActions supportedDragActions () const const
 
virtual Qt::DropActions supportedDropActions () const const
 
- Public Member Functions inherited from QObject
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
 QObject (QObject *parent)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Member Functions

 BpsTableModel (BpsTable *aTable, const QString &aRefColumn, BpsTableItem *aMasterItem)
 Constructor for slave table models. More...
 
virtual BpsTableModelcreateSlaveModel (BpsTable *aTable, const QString &aRefColumn, BpsTableItem *aMasterItem)
 Create a slave table model. More...
 
virtual void deleteTableItem (BpsTable *aTable, BpsTableItem *aItem)
 Delete a existing item from the database. More...
 
virtual void insertTableItem (BpsTable *aTable, BpsTableItem *aItem)
 Inserts a new item into the database. More...
 
virtual void loadTableItem (BpsTable *aTable, BpsTableItem *aItem, bool aAdditionalFields)
 Overload this method to process items immediately after loading from the database. More...
 
virtual void loadTableOptions (BpsTable *aTable, BpsTableItem *aItem, const QString &aMappingTable)
 Overload this method to process options immediately after loading from the database. More...
 
virtual void updateTableItem (BpsTable *aTable, BpsTableItem *aItem)
 Update a existing item into the database. More...
 
- Protected Member Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 
void beginResetModel ()
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndex createIndex (int row, int column, quintptr id) const const
 
QModelIndex createIndex (int row, int column, void *ptr) const const
 
void endInsertColumns ()
 
void endInsertRows ()
 
void endMoveColumns ()
 
void endMoveRows ()
 
void endRemoveColumns ()
 
void endRemoveRows ()
 
void endResetModel ()
 
QModelIndexList persistentIndexList () const const
 
void reset ()
 
void resetInternalData ()
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Friends

class BpsTableItemPrivate
 

Additional Inherited Members

- Public Types inherited from QAbstractItemModel
enum  CheckIndexOption
 
enum  LayoutChangeHint
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QAbstractItemModel
typedef CheckIndexOptions
 
 DoNotUseParent
 
 HorizontalSortHint
 
 IndexIsValid
 
 NoLayoutChangeHint
 
 NoOption
 
 ParentIsInvalid
 
 VerticalSortHint
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Properties inherited from QObject
 objectName
 

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() [1/2]

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
aTableThe master table definition.
aParentThe parent object

◆ BpsTableModel() [2/2]

BpsTableModel::BpsTableModel ( BpsTable aTable,
const QString aRefColumn,
BpsTableItem aMasterItem 
)
protected

Constructor for slave table models.

Parameters
aTableThe slave table definition.
aRefColumnThe column referencing the master table.
aMasterItemThe master table item.

Member Function Documentation

◆ addItem()

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
aParentThe parent row.
aSignalEmit itemsAdded().
Returns
The index of the new item.

◆ addOptions()

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"));
#define bStr(aStr)
Encapsulation for string literals.
Definition: bpsglobals.h:125
Parameters
aMappingTableThe mapping table.
aMasterColumnThe mapping table column referencing c_key in the master table.
aAttribColumnThe mapping table column referencing c_key in the attribute table.
aAttribTableThe attribute table.
aNameColumnThe attribute tables name column (may also be a function call).

◆ addSlaveTable()

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
aTableThe slave table definition.
aRefColumnName of the column referring to the master tables primary key.
Returns
Pointer to the slave model.

◆ allKeys()

QVariantList BpsTableModel::allKeys ( const QModelIndex aParent = QModelIndex()) const

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

Parameters
aParentThe parent index.
Returns
All keys of the records in order.

◆ canAdd()

bool BpsTableModel::canAdd ( ) const
Returns
True if the current user has add permission on the table.

◆ canDelete()

bool BpsTableModel::canDelete ( ) const
Returns
True if the current user has delete permission on the table.

◆ canEdit()

bool BpsTableModel::canEdit ( ) const
Returns
True if the current user has edit permission on the table.

◆ canMove()

bool BpsTableModel::canMove ( ) const
Returns
True if the model is a tree and supports moving items.

◆ canPaste()

bool BpsTableModel::canPaste ( ) const
Returns
True if the clipboard contains data that can be pasted into the model.

◆ copy()

void BpsTableModel::copy ( const QModelIndexList &  aIndexList)

Copy items to clipboard.

Parameters
aIndexListThe item list to copy.

◆ createSlaveModel()

virtual BpsTableModel* BpsTableModel::createSlaveModel ( BpsTable aTable,
const QString aRefColumn,
BpsTableItem aMasterItem 
)
protectedvirtual

Create a slave table model.

Overload this method to create the slave models as custom overloaded class.

The default implementation is:

return new BpsTableModel(aTable, aRefColumn, aMasterItem);
BpsTableModel(BpsTable *aTable, QObject *aParent)
Create a master table model.
Parameters
aTableThe slave table definition.
aRefColumnThe column referencing the master table.
aMasterItemThe master table item.

◆ deleteItem()

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
aIndexThe index of the row to delete.

◆ deleteItems()

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
aIndexListThis list of row indexes to delete.

◆ deleteTableItem()

virtual void BpsTableModel::deleteTableItem ( BpsTable aTable,
BpsTableItem aItem 
)
protectedvirtual

Delete a existing item from the database.

Overload this method to do any pre- or post-processing, or to do any alternate actions.

The default implementation is:

BpsQuery q(aTable->datastore());
q.prepare(bStr("delete from %1 where c_key=?").arg(aTable->name()));
q.bind(aItem->key());
q.execute();
BPS query class.
Definition: bpsquery.h:23
Parameters
aTableThe table object.
aItemThe table item object.
Exceptions
BpsExceptionthrown on errors.

◆ enableTree()

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
aEnableTrue to enable, false to disable.

◆ firstIndex()

QModelIndex BpsTableModel::firstIndex ( const QModelIndex aParent = QModelIndex())

Get index of first item.

Parameters
aParentThe parent index.
Returns
The index if any first row, or QModelIndex() if no such record.

◆ insertTableItem()

virtual void BpsTableModel::insertTableItem ( BpsTable aTable,
BpsTableItem aItem 
)
protectedvirtual

Inserts a new item into the database.

Overload this method to do any pre- or post-processing, or to do any alternate actions.

The default implementation is:

aItem->setValue(bStr("c_key"), aTable->datastore()->nextKey(aTable->rawname()));
BpsSqlValues vals(aItem->values());
BpsQuery q(aTable->datastore());
q.prepare(
bStr("insert into %1 (%2) values (%3)")
.arg(aTable->name())
.arg(vals.columns())
.arg(vals.tags())
);
q.execute(vals.values());
Convenience class to help composing select, insert and update statements.
Definition: bpssqlvalues.h:54
Parameters
aTableThe table object.
aItemThe table item object.
Exceptions
BpsExceptionthrown on errors.

◆ isModified()

bool BpsTableModel::isModified ( ) const
Returns
True if the model is modified, and needs save.

◆ isReadOnly()

bool BpsTableModel::isReadOnly ( ) const
Returns
True if in read-only mode.

◆ isTree()

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.

◆ item()

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
aIndexItem index.
Returns
The item at this index.

◆ itemsAdded

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
aIndexesIndexes of the new items.

◆ key()

QVariant BpsTableModel::key ( const QModelIndex aIndex) const
Parameters
aIndexThis model index.
Returns
The key value of the row.

◆ keyIndex()

QModelIndex BpsTableModel::keyIndex ( const QVariant aKey) const

Get index from a key.

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

Parameters
aKeyThe key to find.
Returns
The valid model index if found, or QModelIndex() if no record with this key is found.

◆ keyToolTipLabel()

QString BpsTableModel::keyToolTipLabel ( ) const
Returns
The label to display the key tool tip. Default is empty (do not display key tool tip).

◆ loadAdditionalFields()

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
aItemThe item to load additional fields for.

◆ loadOptions()

void BpsTableModel::loadOptions ( BpsTableItem aItem)

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

Parameters
aItemThe item to load options for.

◆ loadSlaveModels()

void BpsTableModel::loadSlaveModels ( BpsTableItem aItem)

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

Parameters
aItemThe item to load slave models for.

◆ loadTableItem()

virtual void BpsTableModel::loadTableItem ( BpsTable aTable,
BpsTableItem aItem,
bool  aAdditionalFields 
)
protectedvirtual

Overload this method to process items immediately after loading from the database.

The default implementation does nothing, leaving the item unchanged.

Parameters
aTableThe table object.
aItemThe table item object.
aAdditionalFieldsFalse when regular fields got loaded, true when additional fields got loaded.
Exceptions
BpsExceptionthrown on errors.

◆ loadTableOptions()

virtual void BpsTableModel::loadTableOptions ( BpsTable aTable,
BpsTableItem aItem,
const QString aMappingTable 
)
protectedvirtual

Overload this method to process options immediately after loading from the database.

The default implementation does nothing, leaving the options unchanged.

Parameters
aTableThe table object.
aItemThe table item object.
aMappingTableName of the options mapping table.
Exceptions
BpsExceptionthrown on errors.

◆ modified

void BpsTableModel::modified ( bool  aModified)
signal

Emitted when the modification status of the model changes.

Parameters
aModifiedTrue if there are unsaved changes, false otherwise.

◆ moveItem()

void BpsTableModel::moveItem ( const QModelIndex aSrc,
int  aDstRow,
const QModelIndex aDstParent = QModelIndex() 
)

Moves the source item to the target.

Parameters
aSrcIndex of the item to move.
aDstRowThe destination row.
aDstParentIndex of the destination parent.

◆ optionsAttribTable()

QString BpsTableModel::optionsAttribTable ( const QString aMappingTable) const

Get the attribute table of a option mapping table.

Parameters
aMappingTableThe mapping table name.
Returns
Name of the attribute table, or empty string if not found.

◆ optionsMappingTables()

QStringList BpsTableModel::optionsMappingTables ( ) const
Returns
A list of all option mapping tables added to this master model.

◆ optionsNameColumn()

QString BpsTableModel::optionsNameColumn ( const QString aMappingTable) const

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

Parameters
aMappingTableThe mapping table name.
Returns
Name of the column, or empty string if not found.

◆ paste()

void BpsTableModel::paste ( const QModelIndex aParent = QModelIndex())

Paste clipboard data into new items.

Parameters
aParentThe parent row to create new items under.

◆ refresh

void BpsTableModel::refresh ( )
slot

Refresh the model immediately.

Unsaved changes are lost.

◆ save()

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.

◆ setEmpty

void BpsTableModel::setEmpty ( )
slot

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

Unsaved changes are lost.

◆ setKeyToolTipLabel()

void BpsTableModel::setKeyToolTipLabel ( const QString aLabel)

Set label to display the record key as tool tip.

Parameters
aLabelThe text to display as label

◆ setReadOnly()

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
aReadOnlyTrue to enable read-only mode.

◆ slaveTable()

BpsTable* BpsTableModel::slaveTable ( const QString aName) const
Parameters
aNameName of the slave model table, without the prefix t_.
Returns
The table record, or 0 if no such slave model.

◆ slaveTables()

QStringList BpsTableModel::slaveTables ( ) const
Returns
A list of all slave tables added to this master model.

◆ table()

BpsTable* BpsTableModel::table ( ) const
Returns
The table definition.

◆ unmodified

void BpsTableModel::unmodified ( bool  aUnmodified)
signal

Emitted when the modification status of the model changes.

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

◆ updateTableItem()

virtual void BpsTableModel::updateTableItem ( BpsTable aTable,
BpsTableItem aItem 
)
protectedvirtual

Update a existing item into the database.

Overload this method to do any pre- or post-processing, or to do any alternate actions.

The default implementation is:

// collect modified values
BpsSqlValues vals(aItem->changedValues());
if (!vals.isEmpty()) {
BpsQuery q(aTable->datastore());
q.prepare(
bStr("update %1 set %2 where c_key=?")
.arg(aTable->name())
.arg(vals.pairs())
);
q.execute(vals.values() << aItem->key());
} // if
Parameters
aTableThe table object.
aItemThe table item object.
Exceptions
BpsExceptionthrown on errors.

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