Public Slots | Public Member Functions

TableItemModel Class Reference

Item model populated with items from RDB tables. More...

#include <rdb/tableitemmodel.h>

List of all members.

Public Slots

Public Member Functions


Detailed Description

Item model populated with items from RDB tables.

This model implements QAbstractItemModel and connects one or more instances of AbstractTableModel to provide a list or tree of rows.

The top level items can be either all rows from a table or rows matching the given foreign key value. They can be additionally filtered using an AbstractRowFilter.

Child items are rows from another table whose foreign key match the primary key of their parent item. Child tables can be nested to any level.

The list of column used by the model can be set using the setColumns() method. This allows to map column indexes to logical identifiers passed to the table models.

Use the updateData() method to update the model and its views when data is chaged. The model automatically updates itself when table models emit update signal.


Constructor & Destructor Documentation

TableItemModel ( QObject *  parent  ) 

Constructor.

Parameters:
parent The parent object.
~TableItemModel (  ) 

Destructor.


Member Function Documentation

void setColumns ( const QList< int > &  columns  ) 

Set the list of columns for this model.

const QList<int>& columns (  )  const [inline]

Return the list of columns of this model.

void setRowFilter ( AbstractRowFilter filter  ) 

Set the filter for top level rows.

Parameters:
filter The row filter or NULL to disable filtering.
void setRootTableModel ( AbstractTableModel model,
const RDB::UniqueConstIndex< void > &  index 
)

Set the top level table model.

This method creates top level items using all rows of a table.

Parameters:
model The model for the top level table.
index The primary index of the table.
void setRootTableModel ( AbstractTableModel model,
const RDB::UniqueConstIndex< void > &  index,
const RDB::ForeignConstIndex< void > &  parentIndex,
int  parentId 
)

Set the top level table model.

This method creates top level items using table rows matching a given value of a foreign key.

Parameters:
model The model for the top level table.
index Index identifying rows in the table.
parentIndex Foreign index for matching with the given value.
parentId The value of the foreign key to match.
void setRootTableModel ( AbstractTableModel model,
const RDB::ForeignConstIndex< void > &  index,
const RDB::ForeignConstIndex< void > &  parentIndex,
int  parentId 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

AbstractTableModel * rootTableModel (  )  const

Return the top level table model.

void addChildTableModel ( AbstractTableModel model,
const RDB::UniqueConstIndex< void > &  index,
const RDB::ForeignConstIndex< void > &  parentIndex 
)

Add a nested child table model.

This method adds a new level of child items using rows from the given table whose foreign key match the primary key of their parent items.

Parameters:
model The model for the child table to add.
index Index identifying rows in the table.
parentIndex Foreign index for matching with parent table.
void addChildTableModel ( AbstractTableModel model,
const RDB::ForeignConstIndex< void > &  index,
const RDB::ForeignConstIndex< void > &  parentIndex 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

int totalCount (  )  const [inline]

Return the total number of top level rows.

The number of rows includes rows that were filtered out.

int sortColumn (  )  const [inline]

Return the column by which the data is sorted.

Qt::SortOrder sortOrder (  )  const [inline]

Return the sort order of the data.

QModelIndex findCell ( int  level,
int  id,
int  column 
)

Find the index of the specified cell.

Parameters:
level The nest level of the cell.
id The identifier of the row.
column The identifier of the column.
void updateData (  )  [slot]

Update the model and views connected to it.