Beispiel #1
0
    def setShots(self, shots):
        self.beginResetModel()

        self._root = Node()

        for shot in shots:
            shotNode = Node(str(shot), defaultVal='')
            self._root.addChild(shotNode)

            stages = sorted(shot.getStages(),
                            key=lambda c: Stage.STAGES.index(c.stage))

            for stg in stages:
                shotNode.addChild(StageNode(stg))

        self.endResetModel()
Beispiel #2
0
class ElementPickerModel(QAbstractItemModel):
    HEADERS = [
        'Name', 'Type', 'Version', 'Container', 'Author', 'Created',
        'Published Version'
    ]

    def __init__(self, elements, parent=None):
        super(ElementPickerModel, self).__init__(parent)

        self.setElements(elements)

    def setElements(self, elements):
        self.beginResetModel()

        self._root = Node()

        for el in elements:
            self._root.addChild(ElementNode(el))

        self.endResetModel()

    def columnCount(self, index):
        if index.isValid():
            return index.internalPointer().columnCount()

        return self._root.columnCount()

    def rowCount(self, index=QModelIndex()):
        if index.isValid():
            return index.internalPointer().childCount()

        return self._root.childCount()

    def headerData(self, section, orientation, role=Qt.DisplayRole):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            if section >= 0 and section < len(ElementPickerModel.HEADERS):
                return ElementPickerModel.HEADERS[section]
        elif orientation == Qt.Vertical:
            return None

        return super(ElementPickerModel, self).headerData(section,
                                                          orientation,
                                                          role=role)

    def data(self, index, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        node = index.internalPointer()

        if node and role == Qt.DisplayRole:
            return str(node.data(index.column()))

        return None

    def supportedDropActions(self):
        return Qt.CopyAction

    def mimeData(self, indexes):
        if len(indexes) == 0:
            return None

        data = QMimeData()
        for idx in indexes:
            el = idx.internalPointer()._element
            lastPub = el.getLatestPublishedFile()

            if lastPub and lastPub.versionless_path:
                fs = FrameSequence(lastPub.versionless_path)

                if fs.isValid():
                    data.setText('{} {}-{}'.format(lastPub.versionless_path,
                                                   fs.first(), fs.last()))
                else:
                    data.setText(lastPub.versionless_path)

        return data

    def flags(self, index):
        default = super(ElementPickerModel, self).flags(index)
        return Qt.ItemIsDragEnabled | default

    def addChild(self, node, parent):
        if not parent or not parent.isValid():
            parent = self._root
        else:
            parent = parent.internalPointer()
        parent.addChild(node)

    def index(self, row, col, parent=QModelIndex()):
        if not self.hasIndex(row, col, parent):
            return QModelIndex()

        if not parent or not parent.isValid():
            parent = self._root
        else:
            parent = parent.internalPointer()

        child = parent.child(row)

        if child:
            return self.createIndex(row, col, child)
        else:
            return QModelIndex()

    def parent(self, index):
        if index.isValid():
            p = index.internalPointer().parent()

            if p:
                if p == self._root:
                    return QModelIndex()
                else:
                    return QAbstractItemModel.createIndex(self, p.row(), 0, p)

        return QModelIndex()
Beispiel #3
0
class FixesSidebarTreeModel(QAbstractItemModel):
	def __init__(self, fixes, parent=None):
		super(FixesSidebarTreeModel, self).__init__(parent)

		self.setFixes(fixes)

	def setFixes(self, fixes):
		self.beginResetModel()

		self._root = Node()
		self.all = SidebarNode('All Fixes')
		self.all.num = len(fixes)

		self._root.addChild(self.all)

		nodes = {}

		for f in fixes:
			self.addFixTargetToTree(f.target, nodes)

		self.endResetModel()

	def addFixTargetToTree(self, target, nodes, childToAdd=None):
		if isinstance(target, Show):
			node = nodes.get(target.id)
			if node is None:
				existed = False
				node = SidebarNode(target)
				nodes[target.id] = node
				self.all.addChild(node)

			node.incrementNum()

			if childToAdd is not None:
				node.addChild(childToAdd)

			return
		else:
			parent = target.parent
			node = nodes.get(target.id)
			existed = True
			if node is None:
				existed = False
				node = SidebarNode(target)
				nodes[target.id] = node

			node.incrementNum()

			if childToAdd is not None:
				node.addChild(childToAdd)

			self.addFixTargetToTree(parent, nodes, childToAdd=node if not existed else None)

	def columnCount(self, index):
		if index.isValid():
			return index.internalPointer().columnCount()

		return self._root.columnCount()

	def rowCount(self, index):
		if index.isValid():
			return index.internalPointer().childCount()

		return self._root.childCount()

	def data(self, index, role=Qt.DisplayRole):
		if not index.isValid():
			return QVariant()

		node = index.internalPointer()

		if node and role == Qt.DisplayRole:
			return str(node.data(index.column()))

		return QVariant()

	def addChild(self, node, parent):
		if not parent or not parent.isValid():
			parent = self._root
		else:
			parent = parent.internalPointer()
		parent.addChild(node)

	def index(self, row, col, parent=QModelIndex()):
		if not self.hasIndex(row, col, parent):
			return QModelIndex()

		if not parent or not parent.isValid():
			parent = self._root
		else:
			parent = parent.internalPointer()

		child = parent.child(row)

		if child:
			return self.createIndex(row, col, child)
		else:
			return QModelIndex()

	def parent(self, index):
		if index.isValid():
			p = index.internalPointer().parent()

			if p:
				if p == self._root:
					return QModelIndex()
				else:
					return QAbstractItemModel.createIndex(self, p.row(), 0, p)

		return QModelIndex()
Beispiel #4
0
class FixViewerModel(QAbstractItemModel):
	HEADERS = ['Number', 'Type', 'Priority', 'Show', 'Requested', 'From', 'Assigned To', 'Assigned', 'Department', 'Target', 'Status', 'Due', 'Days Left', 'Bid', 'Subject']

	def __init__(self, fixes, parent=None):
		super(FixViewerModel, self).__init__(parent)

		self.setFixes(fixes)

	def setFixes(self, fixes):
		self.beginResetModel()

		self._root = Node()

		for fix in fixes:
			self._root.addChild(FixNode(fix))

		self.endResetModel()

	def columnCount(self, index):
		if index.isValid():
			return index.internalPointer().columnCount()

		return self._root.columnCount()

	def rowCount(self, index):
		if index.isValid():
			return index.internalPointer().childCount()

		return self._root.childCount()

	def headerData(self, section, orientation, role=Qt.DisplayRole):
		if orientation == Qt.Horizontal and role == Qt.DisplayRole:
			if section >= 0 and section < len(FixViewerModel.HEADERS):
				return FixViewerModel.HEADERS[section]
		elif orientation == Qt.Vertical:
			return QVariant()

		return super(FixViewerModel, self).headerData(section, orientation, role=role)

	def data(self, index, role=Qt.DisplayRole):
		if not index.isValid():
			return QVariant()

		node = index.internalPointer()

		if node and role == Qt.DisplayRole:
			return str(node.data(index.column()))

		return QVariant()

	def addChild(self, node, parent):
		if not parent or not parent.isValid():
			parent = self._root
		else:
			parent = parent.internalPointer()
		parent.addChild(node)

	def index(self, row, col, parent=QModelIndex()):
		if not self.hasIndex(row, col, parent):
			return QModelIndex()

		if not parent or not parent.isValid():
			parent = self._root
		else:
			parent = parent.internalPointer()

		child = parent.child(row)

		if child:
			return self.createIndex(row, col, child)
		else:
			return QModelIndex()

	def parent(self, index):
		if index.isValid():
			p = index.internalPointer().parent()

			if p:
				if p == self._root:
					return QModelIndex()
				else:
					return QAbstractItemModel.createIndex(self, p.row(), 0, p)

		return QModelIndex()
Beispiel #5
0
class StageStatusModel(QAbstractItemModel):
    HEADERS = ['', 'Status', 'Assignee', 'Started', 'Completed']

    def __init__(self, shots, parent=None):
        super(StageStatusModel, self).__init__(parent)

        self.setShots(shots)

    def setShots(self, shots):
        self.beginResetModel()

        self._root = Node()

        for shot in shots:
            shotNode = Node(str(shot), defaultVal='')
            self._root.addChild(shotNode)

            stages = sorted(shot.getStages(),
                            key=lambda c: Stage.STAGES.index(c.stage))

            for stg in stages:
                shotNode.addChild(StageNode(stg))

        self.endResetModel()

    def headerData(self, section, orientation, role=Qt.DisplayRole):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            if section >= 0 and section < len(StageStatusModel.HEADERS):
                return StageStatusModel.HEADERS[section]
        elif orientation == Qt.Vertical:
            return QVariant()

        return super(StageStatusModel, self).headerData(section,
                                                        orientation,
                                                        role=role)

    def columnCount(self, index):
        if index.isValid():
            return index.internalPointer().columnCount()

        return len(StageNode.MAPPING)

    def rowCount(self, index):
        if index.isValid():
            return index.internalPointer().childCount()

        return self._root.childCount()

    def data(self, index, role=Qt.DisplayRole):
        if not index.isValid():
            return QVariant()

        node = index.internalPointer()

        if node and role == Qt.DisplayRole:
            return str(node.data(index.column()))

        return QVariant()

    def addChild(self, node, parent):
        if not parent or not parent.isValid():
            parent = self._root
        else:
            parent = parent.internalPointer()
        parent.addChild(node)

    def index(self, row, col, parent=QModelIndex()):
        if not self.hasIndex(row, col, parent):
            return QModelIndex()

        if not parent or not parent.isValid():
            parent = self._root
        else:
            parent = parent.internalPointer()

        child = parent.child(row)

        if child:
            return self.createIndex(row, col, child)
        else:
            return QModelIndex()

    def parent(self, index):
        if index.isValid():
            p = index.internalPointer().parent()

            if p:
                if p == self._root:
                    return QModelIndex()
                else:
                    return QAbstractItemModel.createIndex(self, p.row(), 0, p)

        return QModelIndex()