def __init__(self, session, layer, feature): QUndoCommand.__init__(self, "Change geometry") self.session = session self.layer = layer self.subcentroids = self.session.model_layers.layer_by_name("subcentroids") self.sublinks = self.session.model_layers.layer_by_name("sublinks") self.feature = feature
def __init__(self, textedit2, pos): QUndoCommand.__init__(self) self.item2 = textedit2 self.newpos = self.item2.pos() # 移動後位置 print("init newpos", self.newpos) self.oldpos = pos # 原始位置 print("init oldpos", self.oldpos)
def __init__(self, obj, attrname, newvalue, name=None, parent=None): if name is None: name = "Set %r" % attrname QUndoCommand.__init__(self, name, parent) self.obj = obj self.attrname = attrname self.newvalue = newvalue self.oldvalue = getattr(obj, attrname)
def __init__(self, stack): QUndoCommand.__init__(self) self.stack = stack # Record the field that has changed. self.field = self.stack.edit self.store_cursor = self.field.textCursor() self.text_inserted = self.stack.last_edited self.setText(self.stack.edit_type) self.add_undo = self.stack.add_undo self.add_redo = self.stack.add_redo self.id = -1 self.child_count = 0 #self.corrected_qt_number_of_lines = self.field.corrected_qt_number_of_lines # todo self.text перевести на self.id print('new command') text12345 = self.text() if text12345 == 'symbol' or text12345 == 'enter' or text12345 == 'space': # остальные символы if text12345 == 'symbol': self.id = 1 self.give_position() self.pos3 = self.pos1 + 1 elif text12345 == 'backspace': self.text_inserted = '' #if not self.store_cursor.hasSelection():#no longer need it. i was forsed to not use default event ending # self.store_cursor.setPosition(self.store_cursor.position() - 1, 1) self.give_position() self.pos3 = self.pos1 elif text12345 == 'delete': self.text_inserted = '' #if not self.store_cursor.hasSelection():#the same as backspace. i'll move cursor in event # self.store_cursor.setPosition(self.store_cursor.position() + 1, 1) self.give_position() self.pos3 = self.pos1 elif text12345 == 'cut': # self.text_inserted = '' self.give_position() self.pos3 = self.pos1 elif text12345 == 'insert': self.give_position() self.pos3 = self.pos1 + len(self.text_inserted) elif text12345 == 'replace': self.give_position() self.pos3 = self.pos1 + len(self.text_inserted) elif text12345 == 'glue': print('emaaaa') #self.command_created_only = True print('self.childCount() = ', self.childCount()) return self.command_created_only = True #self.give_line_numbers() print(' self.pos1 = {}, self.pos2 = {}'.format(self.pos1, self.pos2)) self.text_deleted = self.store_cursor.selectedText() print(' selectedText', self.text_deleted) print(' last_edited', self.text_inserted)
def __init__(self, window, tinfo, start, end, first): QUndoCommand.__init__(self) self._tag = tinfo['obj'] self._start = start self._end = end self._x = tinfo['x'] self._y = tinfo['y'] self._window = window self._first = first self._name = tinfo['name']
def __init__(self, scheme, node, parent=None): QUndoCommand.__init__(self, "Remove %s" % node.title, parent) self.scheme = scheme self.node = node links = scheme.input_links(node) + \ scheme.output_links(node) for link in links: RemoveLinkCommand(scheme, link, parent=self)
def __init__(self, row, model, parent, add=True): QUndoCommand.__init__(self) self.row = row self.add = add self.model = model self._parent = parent if add: self.rowdata = [QVariant() for x in model._header] self.setText('Inserted Row %s' % (row + 1)) else: self.rowdata = [QVariant(x) for x in model.rows[row]] self.setText('Removed Row %s' % (row + 1))
def __init__(self, old, new, scene, msg=None, parent=None): QUndoCommand.__init__(self, parent) self.restored = True self.scene = scene self.data_old = old self.data_new = new self.diff = DictDiffer(old, new) self.setText(self.diff.output()) if msg is not None: self.setText(msg)
def __init__(self, row, column, value, model): QUndoCommand.__init__(self) self.old = model.rows[row][column] # to ensure we are working with a QVariant qvar = QVariant(value) self.new = qvar self.row = row self.column = column self.model = model label = str(qvar.value()) if "\n" in label or len(label) > 20: label = str(label).splitlines()[0].rstrip()[:18] + "..." self.setText('Row %s: Set %s = "%s"' % (row + 1, str(model._header[column].value()), label))
def __init__(self, editor, filename, text): QUndoCommand.__init__(self) ChangeFileCommand.fileVersionNumber += 1 self.editor = editor self.filename = filename self.setText(text) info = QFileInfo(filename) dir = info.dir().dirName() file = info.fileName() self.undoFilename = QDir.tempPath( ) + "/FlatSiteBuilder/" + dir + "/" + file + "." + str( ChangeFileCommand.fileVersionNumber) + ".undo" self.redoFilename = QDir.tempPath( ) + "/FlatSiteBuilder/" + dir + "/" + file + "." + str( ChangeFileCommand.fileVersionNumber) + ".redo"
def mouseReleaseEvent(self, event): if self.tmp_link_item: item = self.target_node_item_at(event.scenePos()) node = None stack = self.document.undoStack() self.macro = QUndoCommand(self.tr("Add link")) if item: # If the release was over a node item then connect them node = self.scene.node_for_item(item) else: # Release on an empty canvas part # Show a quick menu popup for a new widget creation. try: node = self.create_new(event) except Exception: log.error("Failed to create a new node, ending.", exc_info=True) node = None if node is not None: commands.AddNodeCommand(self.scheme, node, parent=self.macro) if node is not None: if self.direction == self.FROM_SOURCE: source_node = self.scene.node_for_item(self.source_item) sink_node = node else: source_node = node sink_node = self.scene.node_for_item(self.sink_item) self.connect_nodes(source_node, sink_node) if not self.isCanceled() or not self.isFinished() and \ self.macro is not None: # Push (commit) the add link/node action on the stack. stack.push(self.macro) self.end() else: self.end() return False
def __init__(self, scheme, annotation, old, new, parent=None): QUndoCommand.__init__(self, "Change text", parent) self.scheme = scheme self.annotation = annotation self.old = old self.new = new
def __init__(self, scheme, node, old_name, new_name, parent=None): QUndoCommand.__init__(self, "Rename", parent) self.scheme = scheme self.node = node self.old_name = old_name self.new_name = new_name
def __init__(self, scheme, item, new_line, parent=None): QUndoCommand.__init__(self, "Move arrow", parent) self.scheme = scheme self.item = item self.new_line = new_line self.old_line = (item.start_pos, item.end_pos)
def __init__(self, textedit): QUndoCommand.__init__(self) self.item1 = textedit print("storecommand", self.item1)
def __init__(self, scheme, link, parent=None): QUndoCommand.__init__(self, "Remove link", parent) self.scheme = scheme self.link = link
def __init__(self, item, name, use): QUndoCommand.__init__(self) self._name = name self._use = use self._item = item
def __init__(self, scheme, node, parent=None): QUndoCommand.__init__(self, "Add %s" % node.title, parent) self.scheme = scheme self.node = node
def __init__(self, window, tlist, llist, first): QUndoCommand.__init__(self) self._tlist = tlist self._llist = llist self._window = window self._first = first
def __init__(self, window, llist, first=False): QUndoCommand.__init__(self) self._window = window self._llist = llist self._first = first
def __init__(self, window, dlist, llist, first=False): QUndoCommand.__init__(self) self._dlist = dlist # tag list self._llist = llist # line list self._window = window self._first = first
def redo(self): # redo child commands QUndoCommand.redo(self) self.scheme.remove_node(self.node)
def addNet(self, newNet): # print("new net ({},{})->({},{})".format(newNet.pt1.x(), newNet.pt1.y(), newNet.pt2.x(), newNet.pt2.y())) # this algorithm normalizes the nets such that nets touch only at endpoints origin = newNet.pt1 newDir = newNet.pt2 - newNet.pt1 unitNewDir = QPointF(newDir) unitNewDir /= Geom.norm(unitNewDir) # nets to be deleted netsDel = set() netsAdd = set() # find any non-parallel nets that need to be split splitP1 = self._ctrl.doc.findObjsNear(newNet.pt1, objType=NetObj) splitP2 = self._ctrl.doc.findObjsNear(newNet.pt2, objType=NetObj) for net in splitP1: if (net.touchesPt(newNet.pt1) and not Geom.isParallel(newDir, net.pt2-net.pt1) and not net.connVtx(newNet)): netsDel.add(net) netsAdd.add(NetObj(newNet.pt1, net.pt1)) netsAdd.add(NetObj(newNet.pt1, net.pt2)) for net in splitP2: if (net.touchesPt(newNet.pt2) and not Geom.isParallel(newDir, net.pt2-net.pt1) and not net.connVtx(newNet)): netsDel.add(net) netsAdd.add(NetObj(newNet.pt2, net.pt1)) netsAdd.add(NetObj(newNet.pt2, net.pt2)) # find all intersecting nets xsnets = {net for net in self._ctrl.doc.findObjsInRect(newNet.bbox(), objType=NetObj) if newNet.intersectsNet(net)} # collinear nets (which need to be replaced) clnets = {net for net in xsnets if Geom.isParallel(newDir, net.pt2-net.pt1)} # print("collinear: " + str(clnets)) xsnets -= clnets # remove collinear nets from set of intersections # compute union of all nets to be replaced # coordinates of united nets (projected onto newDir); initialize with new net coords coords = {0, Geom.dotProd(unitNewDir, newNet.pt2-origin)} for net in clnets: if net.touchesPt(newNet.pt1) and net.touchesPt(newNet.pt2): # print("Not adding redundant net") return # new net is redundant because it is on top of an existing net coords.add(Geom.dotProd(unitNewDir, net.pt1-origin)) coords.add(Geom.dotProd(unitNewDir, net.pt2-origin)) netsDel |= clnets # find all intersection points minc = min(coords) maxc = max(coords) unitedNet = NetObj((origin+minc*unitNewDir).toPoint(), (origin+maxc*unitNewDir).toPoint()) # these nets touch the new net with an endpoint xsP1 = {net for net in xsnets if unitedNet.touchesPt(net.pt1) and not unitedNet.connVtx(net)} xsP2 = {net for net in xsnets if unitedNet.touchesPt(net.pt2) and not unitedNet.connVtx(net)} # print("touching: " + str(xsP1 | xsP2)) xscoords = {minc, maxc} for net in xsP1: xscoords.add(Geom.dotProd(unitNewDir, net.pt1-origin)) for net in xsP2: xscoords.add(Geom.dotProd(unitNewDir, net.pt2-origin)) xscoords = list(xscoords) xscoords.sort() # print(xscoords) p1 = xscoords.pop(0) while xscoords: p2 = xscoords.pop(0) netsAdd.add(NetObj((origin+p1*unitNewDir).toPoint(), (origin+p2*unitNewDir).toPoint())) p1 = p2 cmd = QUndoCommand() for obj in netsDel: # print("deleting {}".format(str(obj))) sch.document.ObjDelCmd(obj, doc=self._ctrl.doc, parent=cmd) for obj in netsAdd: # print("adding: {}".format(str(obj))) sch.document.ObjAddCmd(obj, doc=self._ctrl.doc, parent=cmd) self._ctrl.doc.doCommand(cmd)
def undo(self): self.scheme.add_node(self.node) # Undo child commands QUndoCommand.undo(self)
def __init__(self, scheme, item, new_geom, parent=None): QUndoCommand.__init__(self, "Resize", parent) self.scheme = scheme self.item = item self.new_geom = new_geom self.old_geom = item.rect
def __init__(self, scheme, annotation, parent=None): QUndoCommand.__init__(self, "Remove annotation", parent) self.scheme = scheme self.annotation = annotation
def __init__(self, window, newtag, selects, first): QUndoCommand.__init__(self) self._newtag = newtag self._selects = selects self._window = window self._first = first
def __init__(self, scheme, node, old, new, parent=None): QUndoCommand.__init__(self, "Move", parent) self.scheme = scheme self.node = node self.old = old self.new = new
def __init__(self, item, tag): QUndoCommand.__init__(self) self._name = tag._name self._use = tag._use self._item = item