easymodel.treemodel.ItemData

class easymodel.treemodel.ItemData[source]

Bases: object

An abstract class that holds data and is used as an interface for TreeItems

When subclassing implement ItemData.data() and ItemData.column_count(). It is advised to reimplement ItemData.internal_data() too. For editable models, check ItemData.set_data().

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

column_count() Return the number of columns that can be queried for data
data(column, role) Return the data for the specified column and role
flags(column) Return the item flags for the item
internal_data() Return the internal data of the ItemData
set_data(column, value, role) Set the data for the given column to value
to_item(*args, **kwargs) Create and return a new TreeItem out of this instance.
data(column, role)[source]

Return the data for the specified column and role

The column addresses one attribute of the data. When used in a root item, the data should return the horizontal header data. When returning None, the section Number is used (starting at 1) by the treemodel. So if you want an empty header, return an empty string!

Parameters:
  • column (int) – the data column
  • role (QtCore.Qt.ItemDataRole) – the data role
Returns:

data depending on the role

Return type:

Raises:

None

set_data(column, value, role)[source]

Set the data for the given column to value

The default implementation returns False

Parameters:
  • column (int) – the column to set
  • value – the value to set
  • role (QtCore.Qt.ItemDataRole) – the role, usually EditRole
Returns:

True, if editing was successfull

Return type:

bool

Raises:

None

column_count()[source]

Return the number of columns that can be queried for data

Returns:the number of columns
Return type:int
Raises:None
internal_data()[source]

Return the internal data of the ItemData

E.g. a ListItemData could return the list it uses, a ProjectItemData could return the Project etc.

Returns:the data the itemdata uses as information
Return type:None|arbitrary data
Raises:None
flags(column)[source]

Return the item flags for the item

Default is QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable

Parameters:column (int) – the column to query
Returns:the item flags
Return type:QtCore.Qt.ItemFlags
Raises:None
to_item(*args, **kwargs)[source]

Create and return a new TreeItem out of this instance.

All arguments and keyword arguments passed to this function are used in TreeItem.__init__(). The first argument will always be this instance (self).

Parameters:
  • args – the positional arguments for the TreeItem, the itemdata instance (self) will always be the prepended
  • kwargs – Keyword arguments. Do not use data because it is already used by this function.
Returns:

the created item

Return type:

TreeItem

Raises:

None