'Initialize the grid from the model with rootIndex as the root.'

def __initFromModel(self, model, rootIndex):

    if (not rootIndex.isValid()):
        rootItem = model.invisibleRootItem()
    else:
        rootItem = model.itemFromIndex(rootIndex)
    self.__rootItem = rootItem
    for (i, item) in enumerate(iter_item(rootItem)):
        self.__insertItem(i, item)
