TimeLaneModel

class caqtus.gui.condetrol.timelanes_editor.TimeLaneModel(
name: str,
lane: L,
parent: QObject | None = None,
)

Bases: QAbstractListModel, Generic

An abstract list model to represent a time lane.

This class inherits from PySide6.QtCore.QAbstractListModel and can be used to represent a lane in the timelanes editor.

It is meant to be subclassed for each lane type that needs to be represented in the timelanes editor. Some common methods are implemented here, but subclasses will need to implement at least the abstract methods: data(), setData(), insertRow(). In addition, subclasses may want to override flags() to change the item flags for the cells in the lane. The get_cell_context_actions() method can be overridden to add context menu actions to the cells in the lane.

Warning

All user edits to the data model should be done through the undo stack of the model.

set_undo_stack(undo_stack: QUndoStack) None

Set the undo stack for the model.

name() str

Return the name of the lane represented by this model.

get_lane() L

Return a copy of the lane represented by this model.

set_lane(lane: L_contra) None

Set the lane represented by this model.

This method does not push changes to the undo stack.

rowCount(
parent: QModelIndex | QPersistentModelIndex = _DEFAULT_INDEX,
) int

Return the number of steps in the lane.

abstractmethod data(
index: QModelIndex | QPersistentModelIndex,
role: int = Qt.ItemDataRole.DisplayRole,
) Any

Return the data to be shown to the user for the given index and role.

See PySide6.QtCore.QAbstractItemModel.data() for more information on the roles that can be used.

This method must be implemented by subclasses, typically by calling the lane_value() method and returning the appropriate value for the given role.

lane_value(step: int) T

Return the value of the underlying lane at the given step.

abstractmethod setData(
index,
value,
role: int = Qt.ItemDataRole.EditRole,
) bool

Set the data for the given index and role.

See PySide6.QtCore.QAbstractItemModel.setData() for more information on the roles that can be used.

This method must be implemented by subclasses, typically by calling the set_lane_value() method with an adequate value.

set_lane_value(step: int, value: T) bool

Set the value of the underlying lane at the given step.

The value of the whole block the step is part of is set to the new value.

The change is pushed to the undo stack.

Returns:

True if the value was set successfully, False otherwise.

class SetValueCommand(
*,
model: TimeLaneModel,
step: int,
previous_value: Any,
new_value: Any,
)

Bases: QUndoCommand

An undo/redo command to set the value of a step in a time lane model.

headerData(
section: int,
orientation: Orientation,
role: int = Qt.ItemDataRole.DisplayRole,
) Any

Return the data for the model header.

flags(index) ItemFlag

Return the flags for the given index.

By default, the flags are set to ItemIsEnabled, ItemIsEditable, and ItemIsSelectable.

abstractmethod insertRow(
row: int,
parent: QModelIndex | QPersistentModelIndex = _DEFAULT_INDEX,
) bool

Insert a row at the given row index.

This method must be implemented by subclasses, typically by calling the insert_lane_value() method with an adequate value.

insert_lane_value(step: int, value: T) bool

Insert a value at the given row index.

The action is pushed to the undo stack.

class InsertValueCommand(
model: TimeLaneModel,
step: int,
new_value: Any,
)

Bases: QUndoCommand

removeRow(
row,
parent: QModelIndex | QPersistentModelIndex = _DEFAULT_INDEX,
) bool

Remove a row at the given row index.

The action is pushed to the undo stack.

class RemoveStepCommand(
model: TimeLaneModel,
step: int,
value: Any,
start: int,
stop: int,
)

Bases: QUndoCommand

span(index) QSize

Return the span of the cell at the given index.

break_span(index: QModelIndex) bool

Break the block of the cell at the given index.

The action is pushed to the undo stack.

class BreakSpanCommand(
model: TimeLaneModel,
step: int,
start: int,
stop: int,
lane: TimeLane,
)

Bases: QUndoCommand

expand_step(step: int, start: int, stop: int) bool

Expand the step at the given index to the given range.

The action is pushed to the undo stack.

class ExpandStepCommand(
model: TimeLaneModel,
step: int,
start: int,
stop: int,
lane: TimeLane,
)

Bases: QUndoCommand

get_header_context_actions() list[QAction | QMenu]

Return a list of context menu actions for the lane header.

simplify() None

Simplify the lane by merging contiguous blocks of the same value.

The action is pushed to the undo stack.

class SimplifyCommand(model: TimeLaneModel, lane: TimeLane)

Bases: QUndoCommand