def data(self, index: Qt.QModelIndex, role: int = Qt.Qt.UserRole) -> Any: if not index.isValid(): return None row = index.row() if row >= len(self.items): return None column = index.column() if column >= self.COLUMN_COUNT: return None if role in (Qt.Qt.DisplayRole, Qt.Qt.EditRole): if column == self.START_FRAME_COLUMN: return str(self.items[row].start) if column == self.END_FRAME_COLUMN: if self.items[row].end != self.items[row].start: return str(self.items[row].end) else: return '' if column == self.START_TIME_COLUMN: return str(Time(self.items[row].start)) if column == self.END_TIME_COLUMN: if self.items[row].end != self.items[row].start: return str(Time(self.items[row].end)) else: return '' if column == self.LABEL_COLUMN: return str(self.items[row].label) if role == Qt.Qt.UserRole: if column == self.START_FRAME_COLUMN: return self.items[row].start if column == self.END_FRAME_COLUMN: return self.items[row].end if column == self.START_TIME_COLUMN: return Time(self.items[row].start) if column == self.END_TIME_COLUMN: return Time(self.items[row].end) if column == self.LABEL_COLUMN: return self.items[row].label return None
def handle_slider_released(self, first_index: QModelIndex, last_index: QModelIndex): self.dragging = False self.thumbnails.load_thumbnails(first_index.row() - 50, last_index.row() + 50)
def setData(self, index: Qt.QModelIndex, value: Any, role: int = Qt.Qt.EditRole) -> bool: from copy import deepcopy if not index.isValid(): return False if role not in (Qt.Qt.EditRole, Qt.Qt.UserRole): return False row = index.row() column = index.column() scene = deepcopy(self.items[row]) if column == self.START_FRAME_COLUMN: if not isinstance(value, Frame): raise TypeError if scene.start != scene.end: if value > scene.end: return False scene.start = value else: scene.start = value scene.end = value proper_update = True elif column == self.END_FRAME_COLUMN: if not isinstance(value, Frame): raise TypeError if scene.start != scene.end: if value < scene.start: return False scene.end = value else: scene.start = value scene.end = value proper_update = True elif column == self.START_TIME_COLUMN: if not isinstance(value, Time): raise TypeError frame = Frame(value) if scene.start != scene.end: if frame > scene.end: return False scene.start = frame else: scene.start = frame scene.end = frame proper_update = True elif column == self.END_TIME_COLUMN: if not isinstance(value, Time): raise TypeError frame = Frame(value) if scene.start != scene.end: if frame < scene.start: return False scene.end = frame else: scene.start = frame scene.end = frame proper_update = True elif column == self.LABEL_COLUMN: if not isinstance(value, str): raise TypeError scene.label = value proper_update = False if proper_update is True: i = bisect_right(self.items, scene) if i > row: i -= 1 if i != row: self.beginMoveRows(self.createIndex(row, 0), row, row, self.createIndex(i, 0), i) del self.items[row] self.items.insert(i, scene) self.endMoveRows() else: self.items[index.row()] = scene self.dataChanged.emit(index, index) else: self.items[index.row()] = scene self.dataChanged.emit(index, index) return True
def _is_index_valid(self, index: QModelIndex) -> bool: if index.row() < 0 or index.row() >= self.rowCount( ) or not index.isValid(): return False return True