(self, index, text)
Insert line to the document
Insert line to the document
Insert line to the document
def insert(self, index, text):
        """Insert line to the document
        """
        if index < 0 or index > self._doc.blockCount():
            raise IndexError('Invalid block index', index)

        if index == 0:  # first
            cursor = QTextCursor(self._doc.firstBlock())
            cursor.insertText(text)
            cursor.insertBlock()
        elif index != self._doc.blockCount():  # not the last
            cursor = QTextCursor(self._doc.findBlockByNumber(index).previous())
            cursor.movePosition(QTextCursor.EndOfBlock)
            cursor.insertBlock()
            cursor.insertText(text)
        else:  # last append to the end
            self.append(text)
def insert ( self , index , text ) : if index < 0 or index > self . _doc . blockCount ( ) : raise IndexError ( 'Invalid block index' , index ) if index == 0 : # first cursor = QTextCursor ( self . _doc . firstBlock ( ) ) cursor . insertText ( text ) cursor . insertBlock ( ) elif index != self . _doc . blockCount ( ) : # not the last cursor = QTextCursor ( self . _doc . findBlockByNumber ( index ) . previous ( ) ) cursor . movePosition ( QTextCursor . EndOfBlock ) cursor . insertBlock ( ) cursor . insertText ( text ) else : # last append to the end self . append ( text )