def index(self, row, column, parent=QModelIndex()): """Creates the index""" if parent.isValid() or \ row < 0 or row >= len(self.watchpoints) or \ column < 0 or column >= len(self.header): return QModelIndex() return self.createIndex(row, column, self.watchpoints[row])
def addBreakpoint(self, bpoint): """Adds a new breakpoint to the list""" cnt = len(self.breakpoints) self.beginInsertRows(QModelIndex(), cnt, cnt) self.breakpoints.append(bpoint) self.endInsertRows() self.sigBreakpoinsChanged.emit()
def deleteAll(self): """Deletes all breakpoints""" if self.breakpoints: self.beginRemoveRows(QModelIndex(), 0, len(self.breakpoints) - 1) self.breakpoints = [] self.endRemoveRows() self.sigBreakpoinsChanged.emit()
def deleteWatchPointByIndex(self, index): """Sets the values of a watch expression given by index""" if index.isValid(): row = index.row() self.beginRemoveRows(QModelIndex(), row, row) del self.watchpoints[row] self.endRemoveRows()
def addWatchPoint(self, cond, special, properties): """Adds a new watch expression to the list""" wpoint = [cond, special] + list(properties) cnt = len(self.watchpoints) self.beginInsertRows(QModelIndex(), cnt, cnt) self.watchpoints.append(wpoint) self.endInsertRows()
def selectionChanged(self, selected, deselected): """The slot is called when the selection has changed""" if selected.indexes(): self.sigSelectionChanged.emit(selected.indexes()[0]) else: self.sigSelectionChanged.emit(QModelIndex()) QTreeView.selectionChanged(self, selected, deselected)
def deleteBreakPointByIndex(self, index): """Deletes the breakpoint by its index""" if index.isValid(): row = index.row() self.beginRemoveRows(QModelIndex(), row, row) del self.breakpoints[row] self.endRemoveRows() self.sigBreakpoinsChanged.emit()
def getBreakPointIndex(self, fname, lineno): """Provides an index of a breakpoint""" for row in range(len(self.breakpoints)): bpoint = self.breakpoints[row] if bpoint.getAbsoluteFileName() == fname and \ bpoint.getLineNumber() == lineno: return self.createIndex(row, 0, self.breakpoints[row]) return QModelIndex()
def index(self, row, column, parent=None): """Creates an index""" if (parent and parent.isValid()) or \ row < 0 or row >= len(self.breakpoints) or \ column < 0 or column >= self.__columnCount: return QModelIndex() return self.createIndex(row, column, self.breakpoints[row])
def getWatchPointIndex(self, cond, special=""): """Provides the index of a watch expression given by expression""" for row in range(len(self.watchpoints)): wpoint = self.watchpoints[row] if wpoint[0] == cond: if special and wpoint[1] != special: continue return self.createIndex(row, 0, self.watchpoints[row]) return QModelIndex()
def deleteWatchPoints(self, idxList): """Deletes a list of watch expressions given by their indexes""" rows = [] for index in idxList: if index.isValid(): rows.append(index.row()) rows.sort(reverse=True) for row in rows: self.beginRemoveRows(QModelIndex(), row, row) del self.watchpoints[row] self.endRemoveRows()
def restoreBreakpoints(self): """Restores the breakpoints""" for _, bpoint in self.__breakpoints.items(): line = bpoint.getLineNumber() self.setBlockValue( self._qpart.document().findBlockByNumber(line - 1), 0) self.__breakpoints = {} self.__addBreakPoints( QModelIndex(), 0, self.__debugger.getBreakPointModel().rowCount() - 1) self.validateBreakpoints() self.update()
def deleteBreakPoints(self, idxList): """Deletes a list of breakpoints""" rows = [] for index in idxList: if index.isValid(): rows.append(index.row()) rows.sort(reverse=True) for row in rows: self.beginRemoveRows(QModelIndex(), row, row) del self.breakpoints[row] self.endRemoveRows() self.sigBreakpoinsChanged.emit()
def __findDuplicates(self, cond, special, showMessage=False, index=QModelIndex()): """Checks if an entry already exists""" idx = self.__model.getWatchPointIndex(cond, special) duplicate = idx.isValid( ) and idx.internalPointer() != index.internalPointer() # if showMessage and duplicate: # if not special: # msg = """<p>A watch expression '<b>%1</b>'""" # """ already exists.</p>""".arg(Utilities.html_encode(unicode(cond))) # else: # msg = self.trUtf8("""<p>A watch expression '<b>%1</b>'""" # """ for the variable <b>%2</b> already exists.</p>""")\ # .arg(special)\ # .arg(Utilities.html_encode(unicode(cond))) # KQMessageBox.warning(None, # "Watch expression already exists", msg) return duplicate
def __validateBreakpoints(self): """Checks all the breakpoints validity and deletes invalid""" # It is excepted that the method is called when all the files are # saved, e.g. when a new debugging session is started. for row in range(0, self.__breakpointModel.rowCount()): index = self.__breakpointModel.index(row, 0, QModelIndex()) bpoint = self.__breakpointModel.getBreakPointByIndex(index) fileName = bpoint.getAbsoluteFileName() line = bpoint.getLineNumber() if not os.path.exists(fileName): logging.warning("Breakpoint at " + fileName + ":" + str(line) + " is invalid (the file " "disappeared from the filesystem). " "The breakpoint is deleted.") self.__breakpointModel.deleteBreakPointByIndex(index) continue breakableLines = getBreakpointLines(fileName, None, True) if breakableLines is None: logging.warning("Breakpoint at " + fileName + ":" + str(line) + " does not point to a breakable " "line (the file could not be compiled). " "The breakpoint is deleted.") self.__breakpointModel.deleteBreakPointByIndex(index) continue if line not in breakableLines: logging.warning("Breakpoint at " + fileName + ":" + str(line) + " does not point to a breakable " "line (the file was modified). " "The breakpoint is deleted.") self.__breakpointModel.deleteBreakPointByIndex(index) continue # The breakpoint is OK, keep it return
def deleteAll(self): """Deletes all watch expressions""" if self.watchpoints: self.beginRemoveRows(QModelIndex(), 0, len(self.watchpoints) - 1) self.watchpoints = [] self.endRemoveRows()
def rowCount(self, parent=QModelIndex()): """Provides the current row count""" # we do not have a tree, parent should always be invalid if not parent.isValid(): return len(self.watchpoints) return 0
def columnCount(self, parent=QModelIndex()): """Provides the current column count""" return len(self.header) + 1
def hasChildren(self, parent=QModelIndex()): """True if has children""" if not parent.isValid(): return len(self.watchpoints) > 0 return False
def __sendBreakpoints(self): """Sends the breakpoints to the debugged program""" self.__validateBreakpoints() self.__addBreakPoints(QModelIndex(), 0, self.__breakpointModel.rowCount() - 1)
def parent(self, index): """Provides the parent index""" return QModelIndex()
def __breakPointDataAboutToBeChanged(self, startIndex, endIndex): """Handles the sigDataAboutToBeChanged signal of the bpoint model""" self.__deleteBreakPoints(QModelIndex(), startIndex.row(), endIndex.row())
def __changeBreakPoints(self, startIndex, endIndex): """Sets changed breakpoints""" self.__addBreakPoints(QModelIndex(), startIndex.row(), endIndex.row())