'Add an item to the canvas.'

def addItem(self, citem):

    if (self.redirect is not None):
        name = self.redirect.addItem(citem)
        self.items.append(citem)
        return name
    if (not self.allowTransforms):
        citem.setMovable(False)
    citem.sigTransformChanged.connect(self.itemTransformChanged)
    citem.sigTransformChangeFinished.connect(self.itemTransformChangeFinished)
    citem.sigVisibilityChanged.connect(self.itemVisibilityChanged)
    name = citem.opts['name']
    if (name is None):
        name = 'item'
    newname = name
    insertLocation = 0
    parent = citem.parentItem()
    if (parent in (None, self.view.childGroup)):
        parent = self.itemList.invisibleRootItem()
    else:
        parent = parent.listItem
    siblings = [parent.child(i).canvasItem() for i in range(parent.childCount())]
    z = citem.zValue()
    if (z is None):
        zvals = [i.zValue() for i in siblings]
        if (parent is self.itemList.invisibleRootItem()):
            if (len(zvals) == 0):
                z = 0
            else:
                z = (max(zvals) + 10)
        elif (len(zvals) == 0):
            z = parent.canvasItem().zValue()
        else:
            z = (max(zvals) + 1)
        citem.setZValue(z)
    for i in range(parent.childCount()):
        ch = parent.child(i)
        zval = ch.canvasItem().graphicsItem().zValue()
        if (zval < z):
            insertLocation = i
            break
        else:
            insertLocation = (i + 1)
    node = QtGui.QTreeWidgetItem([name])
    flags = ((node.flags() | QtCore.Qt.ItemIsUserCheckable) | QtCore.Qt.ItemIsDragEnabled)
    if (not isinstance(citem, GroupCanvasItem)):
        flags = (flags & (~ QtCore.Qt.ItemIsDropEnabled))
    node.setFlags(flags)
    if citem.opts['visible']:
        node.setCheckState(0, QtCore.Qt.Checked)
    else:
        node.setCheckState(0, QtCore.Qt.Unchecked)
    node.name = name
    parent.insertChild(insertLocation, node)
    citem.name = name
    citem.listItem = node
    node.canvasItem = weakref.ref(citem)
    self.items.append(citem)
    ctrl = citem.ctrlWidget()
    ctrl.hide()
    self.ui.ctrlLayout.addWidget(ctrl)
    citem.setCanvas(self)
    if (len(self.items) == 2):
        self.autoRange()
    return citem
