Пример #1
0
    def setModelData(self, editor, styleOption, modelIndex):
        """Update the model with the results from an editor.

        Sets the cell error flag if the format doesn't match.
        Arguments:
            editor -- the editor widget
            styleOption -- the data for styles and geometry
            modelIndex -- the index of the cell to be painted
        """
        cell = self.parent().item(modelIndex.row(), modelIndex.column())
        if isinstance(cell, DataEditCell):
            if editor.modified:
                newText = editor.contents()
                numLines = newText.count('\n')
                skipUndoAvail = numLines == self.prevNumLines
                self.prevNumLines = numLines
                treeStructure = globalref.mainControl.activeControl.structure
                undo.DataUndo(treeStructure.undoList, cell.node, False, False,
                              skipUndoAvail, cell.field.name)
                try:
                    cell.node.setData(cell.field, newText)
                except ValueError:
                    editor.setErrorFlag()
                self.parent().nodeModified.emit(cell.node)
                cell.titleCellRef.setText(cell.node.title(cell.spot))
                cell.typeCellRef.setText(cell.node.formatRef.name)
                editor.modified = False
        else:
            super().setModelData(editor, styleOption, modelIndex)
Пример #2
0
    def changeNode(self, newTextLine):
        """Replace the current text line in the current node.

        Arguments:
            newTextLine -- the new text to use
        """
        node = self.currentSpot.nodeRef
        undo.DataUndo(self.controlRef.structure.undoList, node)
        textLines = node.data.get(self.currentField, '').split('\n')
        textLines[self.lineNum] = newTextLine
        node.data[self.currentField] = '\n'.join(textLines)
        self.controlRef.updateTreeNode(node)
Пример #3
0
    def changeNode(self, newTextLine):
        """Replace the current text line in the current node.

        Arguments:
            newTextLine -- the new text to use
        """
        undo.DataUndo(self.currentNode.modelRef.undoList, self.currentNode)
        textLines = (self.currentNode.data.get(self.currentField,
                                               '').split('\n'))
        textLines[self.lineNum] = newTextLine
        self.currentNode.data[self.currentField] = '\n'.join(textLines)
        self.controlRef.updateTreeNode(self.currentNode)
Пример #4
0
 def readChange(self):
     """Update nodes after edited by user.
     """
     textList = [
         ' '.join(text.split()) for text in self.toPlainText().split('\n')
         if text.strip()
     ]
     selSpots = self.treeView.selectionModel().selectedSpots()
     treeStructure = globalref.mainControl.activeControl.structure
     if self.isChildView:
         if not selSpots:
             selSpots = [treeStructure.structSpot()]
         parentSpot = selSpots[0]
         parent = parentSpot.nodeRef
         selSpots = parentSpot.childSpots()
     if len(selSpots) == len(textList):
         # collect changes first to skip false clone changes
         changes = [(spot.nodeRef, text)
                    for spot, text in zip(selSpots, textList)
                    if spot.nodeRef.title(spot) != text]
         for node, text in changes:
             undoObj = undo.DataUndo(treeStructure.undoList,
                                     node,
                                     skipSame=True)
             if node.setTitle(text):
                 self.nodeModified.emit(node)
             else:
                 treeStructure.undoList.removeLastUndo(undoObj)
     elif self.isChildView and (textList or parent != treeStructure):
         undo.ChildDataUndo(treeStructure.undoList, parent)
         # clear hover to avoid crash if deleted child item was hovered over
         self.treeView.clearHover()
         isDeleting = len(selSpots) > len(textList)
         control = globalref.mainControl.activeControl
         if isDeleting and len(control.windowList) > 1:
             # clear other window selections that are about to be deleted
             for window in control.windowList:
                 if window != control.activeWindow:
                     selectModel = window.treeView.selectionModel()
                     ancestors = set()
                     for spot in selectModel.selectedBranchSpots():
                         ancestors.update(set(spot.spotChain()))
                     if ancestors & set(selSpots):
                         selectModel.selectSpots([], False)
         expandState = self.treeView.savedExpandState(selSpots)
         parent.replaceChildren(textList, treeStructure)
         self.treeView.restoreExpandState(expandState)
         if self.treeView.selectionModel().selectedSpots():
             self.treeView.expandSpot(parentSpot)
         self.treeModified.emit()
     else:
         self.updateContents()  # remove illegal changes
Пример #5
0
    def setData(self, index, value, role=Qt.EditRole):
        """Set node title after edit operation.

        Return True on success.
        Arguments:
            index -- the node's model index
            value -- the string result of the editing
            role -- the edit role of the data
        """
        if role != Qt.EditRole:
            return super().setData(index, value, role)
        node = index.internalPointer().nodeRef
        dataUndo = undo.DataUndo(self.treeStructure.undoList, node)
        if node.setTitle(value):
            self.dataChanged.emit(index, index)
            self.treeModified.emit(True)
            return True
        self.treeStructure.undoList.removeLastUndo(dataUndo)
        return False
Пример #6
0
 def readChange(self):
     """Update nodes after edited by user.
     """
     textList = [' '.join(text.split()) for text in self.toPlainText().
                 split('\n') if text.strip()]
     selNodes = self.selectModel.selectedNodes()
     if self.isChildView:
         parent = selNodes[0]
         selNodes = parent.childList
     if len(selNodes) == len(textList):
         for node, text in zip(selNodes, textList):
             if node.title() != text:
                 undoObj = undo.DataUndo(node.modelRef.undoList, node, True)
                 if node.setTitle(text):
                     self.nodeModified.emit(node)
                 else:
                     node.modelRef.undoList.removeLastUndo(undoObj)
     elif self.isChildView:
         undo.BranchUndo(parent.modelRef.undoList, parent)
         parent.replaceChildren(textList)
         self.treeModified.emit()
     else:
         self.updateContents()  # remove illegal changes
Пример #7
0
    def setModelData(self, editor, styleOption, modelIndex):
        """Update the model with the results from an editor.

        Sets the cell error flag if the format doesn't match.
        Arguments:
            editor -- the editor widget
            styleOption -- the data for styles and geometry
            modelIndex -- the index of the cell to be painted
        """
        cell = self.parent().item(modelIndex.row(), modelIndex.column())
        if isinstance(cell, DataEditCell):
            if editor.modified:
                newText = editor.contents()
                numLines = newText.count('\n')
                skipUndoAvail = numLines == self.prevNumLines
                self.prevNumLines = numLines
                undo.DataUndo(cell.node.modelRef.undoList, cell.node,
                              skipUndoAvail, cell.field.name)
                try:
                    cell.node.setData(cell.field, newText)
                except ValueError:
                    editor.setErrorFlag()
                self.parent().nodeModified.emit(cell.node)
                cell.titleCellRef.setText(cell.node.title())
                cell.typeCellRef.setText(cell.node.formatName)
                linkRefCollect = cell.node.modelRef.linkRefCollect
                if (hasattr(editor, 'addedIntLinkFlag') and
                    (editor.addedIntLinkFlag or
                     linkRefCollect.linkCount(cell.node, cell.field.name))):
                    linkRefCollect.searchForLinks(cell.node, cell.field.name)
                    editor.addedIntLinkFlag = False
                if cell.idCellRef:
                    cell.idCellRef.setText(cell.node.uniqueId)
                editor.modified = False
        else:
            super().setModelData(editor, styleOption, modelIndex)