seriesmarker.gui.model.tree_series_model module¶
-
class
Column[source]¶ Bases:
enum.IntEnumConvenience enumeration of columns used by
TreeSeriesModel-
EPISODE= <Column.EPISODE: 1>¶
-
PROGRESS= <Column.PROGRESS: 2>¶
-
SERIES= <Column.SERIES: 0>¶
-
__new__(value)¶
-
_member_map_= OrderedDict([('SERIES', <Column.SERIES: 0>), ('EPISODE', <Column.EPISODE: 1>), ('PROGRESS', <Column.PROGRESS: 2>)])¶
-
_member_names_= ['SERIES', 'EPISODE', 'PROGRESS']¶
-
_value2member_map_= {0: <Column.SERIES: 0>, 1: <Column.EPISODE: 1>, 2: <Column.PROGRESS: 2>}¶
-
-
class
TreeSeriesModel(parent=None)[source]¶ Bases:
PySide.QtCore.QAbstractItemModelThis model is used to display series data (including seasons and episodes) in a
MainWindow.The model stores data in a tree structure, using
TreeNodeand derived classes as nodes in it. Those nodes contain items (series, seasons and episodes), which contain the actual data to display.-
__init__(parent=None)[source]¶ Initializes the model with a given parent.
Parameters: parent ( PySide.QtCore.QObject) – The parent of the model.
-
add_item(item, parent_index=<PySide.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0) ) >)[source]¶ Adds a given item to the model under the given parent.
The item is wrapped in a matching
TreeNode, depending on the item’s type, before it’s being added to the model.Seriesare being appended to the model’s root node,SeasonandEpisodeare inserted at the proper position in their parent’s children, so the display shows them in correct order (sorted by season respectively episode number).Parameters: - item (
object) – The item to add to the model. - parent_index (
QModelIndex) – The index of the node to add the item to.
- item (
-
columnCount(parent=<PySide.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0) ) >)[source]¶ Describes the number of columns the model is using.
Parameters: parent ( QModelIndex) – The parent to return the number of columns for.Returns: The number of columns. Overrides
QAbstractItemModel.columnCount()
-
data(index, role=PySide.QtCore.Qt.ItemDataRole.DisplayRole)[source]¶ Returns the data stored under the given role at a given index.
Parameters: - index (
QModelIndex) – Describes the node of the model to get data from. - role (
int) – Determines the kind of data to get from the node.
Returns: The string representation of the
TreeNodeat the given index forQt.DisplayRole.Returns: The node at the given index itself for
Qt.UserRole.Returns: The
decoration()of the node at the given index forQt.DecorationRole.Returns: The
Qt.CheckStaterepresenting thechecked()state of the node at the given index forQt.CheckedStateRole.Returns: The text alignment to use for the string representation of the node at the given index for
Qt.TextAlignmentRole.Returns: A monospace-family
PySide.QtGui.QFontfor column 1 and 2 forQt.FontRole.Returns: None for an invalid index or other roles.
Overrides
QAbstractItemModel.data()- index (
-
flags(index)[source]¶ Describes the item flags for a given index.
Item flags determine the behavior of an item in the GUI. By (de)activating different flags, the ‘look and feel’ of an item can be changed.
Parameters: index ( QModelIndex) – The index referring to the item to get flags for.Returns: The flags Qt.ItemIsUserCheckableandQt.ItemIsUserEnabledforTreeNodetypes that implementchecked().Returns: The flag Qt.ItemIsEnabledotherwise.Overrides
QAbstractItemModel.flags()
-
headerData(section, orientation, role)[source]¶ Defines the header data displayed in the GUI.
Parameters: Returns: The header caption for the given section as string for
Qt.DisplayRole.Returns: PySide.QtCore.Qt.AlignCenterforQt.TextAlignmentRole.Returns: None for orientations other than
Qt.Horizontal.Overrides
QAbstractItemModel.headerData()
-
index(row, column, parent=<PySide.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0) ) >)[source]¶ Returns the index of the item at the given row and column of the given parent.
Parameters: - row (
int) – The row of the item to get an index for. - column (
int) – The column of the item to get an index for. - parent (
QModelIndex) – The parent index of the item to get an index for.
Returns: The
QModelIndexof the item or an invalid index if no item exists at the given row or colum under the given parent.Overrides
QAbstractItemModel.index()- row (
-
index_of(item, parent=<PySide.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0) ) >)[source]¶ Looks up the index of the item’s node in the model.
The method checks the children of the parent, referred by the given index, if any of them contains the given item as data. If the search is successful, an index referring to the containing node is returned.
Parameters: - item (
object) – Data contained in aTreeNodeto look for. - parent (
QModelIndex) – The index referring to the parent node of the given item’s node.
Returns: A
QModelIndex, referring to the node which contains the given item if the search was successful, otherwise an invalid index.- item (
-
node_at(index)[source]¶ Returns the node at the given index of the model.
Parameters: index ( QModelIndex) – The index to get the associated node from.Returns: The TreeNodeif a node is associated with the given index, otherwise the model’s root node.
-
parent(child_index)[source]¶ Returns the index referring to the parent of the node referred by the given index.
Parameters: child_index ( QModelIndex) – The index of the item to get the parent index for.Returns: The QModelIndex, referring to the parent of the given index, or an invalid index if no parent exists.Overrides
QAbstractItemModel.parent()
Removes the series to which a given index is associated with from the model, regardless which part of the series the index describes (i.e. which part was selected in the GUI).
Parameters: index ( QModelIndex) – The index which describes the series to remove.Returns: The removed Seriesif successful, otherwise None.
-
removeRows(position, rows, parent=<PySide.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0) ) >)[source]¶ Removes a number of nodes from a given parent, beginning at a given position.
Parameters: - position (
int) – The index to start removing nodes from. - rows (
int) – The number of nodes to remove from the parent. - parent (
QModelIndex) – The parent to remove the rows from.
Returns: True if the nodes were successfully removed, otherwise False.
Overrides
QAbstractItemModel.removeRows()- position (
-
rowCount(parent=<PySide.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0) ) >)[source]¶ Returns the number of rows (nodes) under the given parent.
Parameters: parent ( QModelIndex) – The parent to return the number of rows for.Returns: The number of TreeNodeadded to the model as children of the given parent.Overrides
QAbstractItemModel.rowCount()
-
setData(index, value, role=PySide.QtCore.Qt.ItemDataRole.EditRole)[source]¶ Sets the given value of the given role at the given index.
This method is called whenever an episode is marked as (un)watched in the GUI. It then toggles the watched state of the corresponding
Episode.This method is also called whenever a banner was loaded to set a
PySide.QtGui.Pixmapas the node’s decoration and refresh the views afterwards.Parameters: - index (
QModelIndex) – The position to set the value at. - value (
object) – Value to be set at given index:Qt.CheckStateforQt.CheckStateRole,PySide.QtGui.PixmapforQt.DecorationRole. - role (
PySide.QtCore.Qt.ItemDataRole) – Determines the kind of data to set for the item.
Returns: True if successful, otherwise False.
Overrides
QAbstractItemModel.setData()Todo
Update of CheckState / progress kinda ugly, may be done in check(value), but needs reference to index and model - add reference to each node? Example:
for change in changes: self.dataChanged.emit(change.get_index())Todo
After upgrade to QT5, use SignalSpy in test case to check if only changes are emitted if there was really a change after checking.
- index (
-
staticMetaObject= <PySide.QtCore.QMetaObject object>¶
-