示例#1
0
    def parent(self, index):
        if not index.isValid():
            return QtCore.QModelIndex()

        thisStep = self.stepForIndex(index)
        parentStep = thisStep.parent if thisStep else None
        if not parentStep or parentStep == self._blueprint.rootStep:
            return QtCore.QModelIndex()

        return self.createIndex(parentStep.indexInParent(), 0, parentStep)
示例#2
0
    def parent(self, index):  # override
        if not index.isValid():
            return QtCore.QModelIndex()

        childItem = index.internalPointer()
        parentItem = childItem.parent()

        if parentItem == self.rootItem:
            return QtCore.QModelIndex()

        return self.createIndex(parentItem.row(), 0, parentItem)
示例#3
0
    def index(self, row, column, parent):  # override
        if not self.hasIndex(row, column, parent):
            return QtCore.QModelIndex()

        parentItem = self.getItem(parent)

        childItem = parentItem.child(row)
        if childItem:
            return self.createIndex(row, column, childItem)
        else:
            return QtCore.QModelIndex()
示例#4
0
    def index(self, row, column, parent=QtCore.QModelIndex()):
        """
        Create a QModelIndex for a row, column, and parent index
        """
        if parent.isValid() and column != 0:
            return QtCore.QModelIndex()

        parentStep = self.stepForIndex(parent)
        if parentStep and parentStep.canHaveChildren:
            step = parentStep.getChildAt(row)
            return self.createIndex(row, column, step)

        return QtCore.QModelIndex()
示例#5
0
    def parent(self, index):
        if not index.isValid():
            return QtCore.QModelIndex()

        childStep = self.stepForIndex(index)
        if childStep:
            parentStep = childStep.parent
        else:
            return QtCore.QModelIndex()

        if parentStep is None or parentStep == self._blueprint.rootStep:
            return QtCore.QModelIndex()

        return self.createIndex(parentStep.indexInParent(), 0, parentStep)
示例#6
0
 def insertRows(self, row, count, parent=QtCore.QModelIndex()):
     self.beginInsertRows(parent, row, row + count - 1)
     step = self.stepForIndex(parent)
     for _ in range(count):
         step.insertChild(row, BuildStep())
     self.endInsertRows()
     return True
示例#7
0
    def createStepsForSelection(self):
        """
        Create new BuildSteps in the hierarchy at the
        current selection and return the new model indexes.
        """
        if self.blueprintModel.isReadOnly():
            return

        selIndexes = self.selectionModel.selectedIndexes()
        if not selIndexes:
            selIndexes = [QtCore.QModelIndex()]

        model = self.selectionModel.model()

        def getParentAndInsertIndex(index):
            step = model.stepForIndex(index)
            print('step', step)
            if step.canHaveChildren:
                print('inserting at num children')
                return index, step.numChildren()
            else:
                print('inserting at selected + 1')
                return model.parent(index), index.row() + 1

        newIndexes = []
        for index in selIndexes:
            parentIndex, insertIndex = getParentAndInsertIndex(index)
            if self.model.insertRows(insertIndex, 1, parentIndex):
                newIndex = self.model.index(insertIndex, 0, parentIndex)
                newIndexes.append(newIndex)

        return newIndexes
示例#8
0
    def removeRows(self, position, rows, parent=QtCore.QModelIndex()):
        parentItem = self.getItem(parent)

        self.beginRemoveRows(parent, position, position + rows - 1)
        success = parentItem.removeChildren(position, rows)
        self.endRemoveRows()

        return success
示例#9
0
 def indexByStepPath(self, path):
     """
     Return a QModelIndex for a step by path
     """
     if self._blueprint:
         step = self._blueprint.getStepByPath(path)
         return self.indexByStep(step)
     return QtCore.QModelIndex()
示例#10
0
    def dropMimeData(self, data, action, row, column, parentIndex):
        if not self.canDropMimeData(data, action, row, column, parentIndex):
            return False

        if action == QtCore.Qt.IgnoreAction:
            return True

        try:
            stepDataList = meta.decodeMetaData(str(data.data('text/plain')))
        except Exception as e:
            LOG.error(e)
            return False

        print('dropData', stepDataList, data, action, row, column, parentIndex)

        beginRow = 0
        parentPath = None

        if parentIndex.isValid():
            parentStep = self.stepForIndex(parentIndex)
            if parentStep:
                if parentStep.canHaveChildren:
                    # drop into step group
                    beginRow = parentStep.numChildren()
                    parentPath = parentStep.getFullPath()
                else:
                    # drop next to step
                    beginRow = parentIndex.row()
                    parentPath = os.path.dirname(parentStep.getFullPath())

        if not parentPath:
            parentPath = ''
            beginRow = self.rowCount(QtCore.QModelIndex())
        if row != -1:
            beginRow = row

        cmds.undoInfo(openChunk=True, chunkName='Drag Pulse Actions')
        self.isMoveActionOpen = True
        cmds.evalDeferred(self._deferredMoveUndoClose)

        # create dropped steps
        count = len(stepDataList)
        for i in range(count):
            stepDataStr = serializeAttrValue(stepDataList[i])
            newStepPath = cmds.pulseCreateStep(
                parentPath, beginRow + i, stepDataStr)
            if newStepPath:
                newStepPath = newStepPath[0]

                if action == QtCore.Qt.MoveAction:
                    # create queue of renames to perform after source
                    # steps have been removed
                    targetName = stepDataList[i].get('name', '')
                    self.dragRenameQueue.append((newStepPath, targetName))

        return True
示例#11
0
    def insertBuildItems(self,
                         position,
                         childBuildItems,
                         parent=QtCore.QModelIndex()):
        parentItem = self.getItem(parent)

        self.beginInsertRows(parent, position,
                             position + len(childBuildItems) - 1)
        success = parentItem.insertChildren(position, childBuildItems)
        self.endInsertRows()

        return success
示例#12
0
    def createStepsForSelection(self, stepData=None):
        """
        Create new BuildSteps in the hierarchy at the
        current selection and return the new step paths.

        Args:
            stepData (str): A string representation of serialized
                BuildStep data used to create the new steps
        """
        if self.blueprintModel.isReadOnly():
            return

        selIndexes = self.selectionModel.selectedIndexes()
        if not selIndexes:
            selIndexes = [QtCore.QModelIndex()]

        model = self.selectionModel.model()

        def getParentAndInsertIndex(index):
            step = model.stepForIndex(index)
            print('step', step)
            if step.canHaveChildren:
                print('inserting at num children')
                return step, step.numChildren()
            else:
                print('inserting at selected + 1')
                return step.parent, index.row() + 1

        newPaths = []
        for index in selIndexes:
            parentStep, insertIndex = getParentAndInsertIndex(index)
            parentPath = parentStep.getFullPath() if parentStep else None
            if not parentPath:
                parentPath = ''
            if not stepData:
                stepData = ''
            newStepPath = cmds.pulseCreateStep(parentPath, insertIndex,
                                               stepData)
            if newStepPath:
                # TODO: remove this if/when plugin command only returns single string
                newStepPath = newStepPath[0]
                newPaths.append(newStepPath)
            # if self.model.insertRows(insertIndex, 1, parentIndex):
            #     newIndex = self.model.index(insertIndex, 0, parentIndex)
            #     newPaths.append(newIndex)

        return newPaths
示例#13
0
 def indexByStepPath(self, path):
     """
     Return a QModelIndex for a step by path
     """
     # TODO: debug, this is not working
     if self._blueprint:
         step = self._blueprint.getStepByPath(path)
         if step:
             childIndeces = []
             while step.parent:
                 childIndeces.append(step.indexInParent())
                 step = step.parent
             # print(childIndeces)
             parentIndex = QtCore.QModelIndex()
             for childIndex in childIndeces:
                 index = self.index(childIndex, 0, parentIndex)
                 parentIndex = index
             return index
示例#14
0
 def rowCount(self, parent=QtCore.QModelIndex()):
     step = self.stepForIndex(parent)
     return step.numChildren() if step else 0
示例#15
0
 def columnCount(self, parent=QtCore.QModelIndex()):
     return 1
示例#16
0
 def rowCount(self, parent=QtCore.QModelIndex()):  # override
     return self.getItem(parent).childCount()
示例#17
0
 def step(self, row, column, parent=QtCore.QModelIndex()):
     """
     Return the BuildStep for a row, column, and parent index.
     """
     return self.stepForIndex(self.index(row, column, parent))
示例#18
0
 def insertRows(self, position, rows, parent=QtCore.QModelIndex()):
     raise RuntimeError(
         "Cannot insert rows without data, use insertBuildItems instead")
示例#19
0
 def removeRows(self, row, count, parent=QtCore.QModelIndex()):
     self.beginRemoveRows(parent, row, row + count - 1)
     step = self.stepForIndex(parent)
     step.removeChildren(row, count)
     self.endRemoveRows()
     return True
示例#20
0
 def indexByStep(self, step):
     if step and step != self._blueprint.rootStep:
         return self.createIndex(step.indexInParent(), 0, step)
     return QtCore.QModelIndex()