TTkAbstractTableModel๐ŸŒถ๏ธ

class TTkAbstractTableModel[source]๐ŸŒถ๏ธ

Bases: object

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() and columnCount() functions return the dimensions of the table.

Subclassing

When subclassing TTkAbstractTableModel, you must implement rowCount(), columnCount(), and data(). Well behaved models will also implement headerData().

Editable models need to implement setData().

Built-In Implementation

TTkTableModelList basic subclass implementing a 2d list as data structure

TTkTableModelCSV subclass of TTkTableModelList including the api to import csv data

TTkTableModelSQLite3 subclass of TTkTableModelList including support for sqlite3 databases

Signals๐ŸŒถ๏ธ

dataChanged

This signal is emitted whenever the data in an existing item changes.

Members๐ŸŒถ๏ธ

dataChanged: pyTTkSignal๐ŸŒถ๏ธ

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

Methods๐ŸŒถ๏ธ

columnCount() int[source]๐ŸŒถ๏ธ

Returns the number of columns of the current moodel.

Returns:

int

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:

TTkConstant.ItemFlag

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.

Parameters:
  • pos (int) โ€“ the position (col or row) of the header

  • orientation (TTkConstant.Direction) โ€“ the orienttin of the header to be retrieved

Returns:

TTkString

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:

TTkModelIndex

rowCount() int[source]๐ŸŒถ๏ธ

Returns the number of rows of the current model.

Returns:

int

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

sort(column: int, order: SortOrder) None[source]๐ŸŒถ๏ธ

Sorts the model by column in the given order.

Parameters:
  • column (int) โ€“ The column index to be sorted, if -1 is provided the original unsorted order is used.

  • order (TTkConstant.SortOrder) โ€“ the sorting order

ttkStringData(row: int, col: int) TTkString[source]๐ŸŒถ๏ธ

Returns the TTkString reprsents the ddata stored in the row/column.

Parameters:
  • row (int) โ€“ the row position of the data

  • col (int) โ€“ the column position of the data

Returns:

TTkString