code: def insertItem(self, childItem, position=None, parentIndex=None):
          
          if parentIndex is None:
              parentIndex=QtCore.QModelIndex()
  
          parentItem = self.getItem(parentIndex, altItem=self.invisibleRootItem)
  
          nChildren = parentItem.nChildren()
          if position is None:
              position = nChildren
  
          assert 0 <= position <= nChildren, \
              "position should be 0 < {} <= {}".format(position, nChildren)
  
          self.beginInsertRows(parentIndex, position, position)
          try:
              parentItem.insertChild(childItem, position)
          finally:
              self.endInsertRows()
  
          childIndex = self.index(position, 0, parentIndex)
          assert childIndex.isValid(), "Sanity check failed: childIndex not valid"
          return childIndex
docs: Inserts a childItem before row 'position' under the parent index.
  
              If position is None the child will be appended as the last child of the parent.
              Returns the index of the new inserted child.