seriesmarker.gui.model.tree_node module

class TreeNode(data, parent=None)[source]

Bases: seriesmarker.gui.model.decorated_node.DecoratedNode

Base class to store series data in a PySide.QtCore.QAbstractItemModel.

__init__(data, parent=None)[source]

Initializes the node.

Parameters:
  • model – The model the node has been added to.
  • data (object) – The data the node contains.
  • parent (TreeNode) – The node’s parent in the tree.
_adjust_caches(delta_leaves, delta_checks)[source]

Adjusts cached values according to given deltas.

Note

By calling this method, the caches of all parents of the node (including parent’s parents) are also being adjusted.

Parameters:
  • delta_leaves (int) – Amount to adjust cached leaf counts by.
  • delta_checks (int) – Amount to adjust cached check counts by.

See also

leaf_count() checked_count()

append(node)[source]

Adds a node to the current one’s children.

Parameters:node (TreeNode) – The node to add.
check(state, origin=None)[source]

Sets the checked state of the node.

The checked state indicates whether or not an episode has been watched. When the state is set, the tree of the node is traversed upwards to its root, and the cached count of watched episodes in its branch is updated accordingly.

Parameters:
  • state (bool) – The checked state to set.
  • origin – The node which initiated the check call. Used to determine when to traverse the tree upward.
Type:

TreeNode

Returns:

A (immutable) tuple of all changed nodes.

See also

checked()

checked()[source]

Gets the checked state of the node.

Note

Derived classes have to define whatever the checked state describes and how it is determined.

Returns:The boolean value of the checked state, or None if the state is undefined.
checked_count

Returns the number of checked nodes in the branch of the node.

The branch is traversed, beginning from the node to the leaf-level. All checked nodes are counted, including the starting node.

Note

Once counted, the number of checked nodes is cached for further usage.

Returns:The count of checked nodes in the node’s branch.
child(index)[source]

Returns the node’s child at the given index.

Parameters:index (int) – The index of the child to return.
Returns:The child TreeNode with the given index.
child_count()[source]

Returns the number of the node’s children.

Returns:The children’s count.
child_index()[source]

Returns the index of the node in it’s parent’s children.

Returns:The (integer) index of the node.
children

Returns an immutable representation of the node’s children.

Returns:The children of the node in a tuple of TreeNode.
insert(index, node)[source]

Inserts a node to the current one’s children at a given position.

Parameters:
  • index (int) – The index where to insert the node.
  • node (TreeNode) – The node to insert.
leaf_count

Returns the number of leaves in the branch of the node.

Note

Once counted, the number of leaves is cached for further usage.

Returns:The count of nodes without children in the node’s branch.
name()[source]

Returns a string representation of the node’s data.

Note

Derived classes should override this method to return an appropriate value.

Returns:The string representation of the node’s data.
remove(index)[source]

Removes a child at a given index from the node’s children.

Parameters:index (int) – The position of the child to remove.