TermTk.TTkAbstract.abstracttablemodel
TTkModelIndex
- class TTkModelIndex[source]
This class is used as an index into item models derived from
TTkAbstractTableModel
. The index is used by item views, delegates, and selection models to locate an item in the model.New
TTkModelIndex
objects are created by the model using theTTkAbstractTableModel
->index()
function. An invalid model index can be constructed with theTTkModelIndex
constructor.Model indexes refer to items in models, and contain all the information required to specify their locations in those models. Each index is located in a given row and column; use
row()
,column()
, anddata()
to obtain this information.To obtain a model index that refers to an existing item in a model, call
TTkAbstractTableModel
->index()
with the required row and column values.
TTkAbstractTableModel
- class TTkAbstractTableModel[source]
TTkAbstractTableModel
provides a standard interface for models that represent their data as a two-dimensional array of items. It is not used directly, but must be subclassed.Since the model provides a more specialized interface than
TTkAbstractItemModel
, it is not suitable for use with tree views.The
rowCount()
andcolumnCount()
functions return the dimensions of the table.Subclassing
When subclassing
TTkAbstractTableModel
, you must implementrowCount()
,columnCount()
, anddata()
. Well behaved models will also implementheaderData()
.Editable models need to implement
setData()
.Built-In Implementation
TTkTableModelList
basic subclass implementing a 2d list as data structureTTkTableModelCSV
subclass ofTTkTableModelList
including the api to import csv data- signal dataChanged(pos, size)
This signal is emitted whenever the data in an existing item changes.
If more items are affected, the pos/size definne the minimum area including all of those changes.
When reimplementing the
setData()
function, this signal must be emitted explicitly.- Parameters
pos (tuple(int,int)) – the topLeft margin of the modified area
size (tuple(int,int)) – the size of the modified area
- data(row: int, col: int) object [source]
Returns the data stored for the item referred to by the row/column.
Note: If you do not have a value to return, return None instead of returning 0.
- Parameters
row (int) – the row position of the data
col (int) – the column position of the data
- Returns
object
- flags(row: int, col: int) ItemFlag [source]
Returns the item flags for the given row,column.
The base class implementation returns a combination of flags that enables the item (
ItemIsEnabled
) and allows it to be selected (ItemIsSelectable
).- Parameters
row (int) – the row position od the data
col (int) – the column position of the data
- Returns
- headerData(pos: int, orientation: Direction) TTkString [source]
Returns the data for the given role and section in the header with the specified orientation.
For horizontal headers, the section number corresponds to the column number. Similarly, for vertical headers, the section number corresponds to the row number.
- index(row: int, col: int) TTkModelIndex [source]
Returns the index of the item in the model specified by the given row, column.
- Parameters
row (int) – the row position of the index
col (int) – the column position of the index
- Returns
- setData(row: int, col: int, data: object) bool [source]
Returns true if successful; otherwise returns false.
The
dataChanged()
signal should be emitted if the data was successfully set.The base class implementation returns false. This function and
data()
must be reimplemented for editable models.- Parameters
row (int) – the row position of the data
col (int) – the column position of the data
data (object) – the data to be set in the (row,col) position of the table
- Returns
bool