'Switch completion to a new model.
Called from on_update_completion().
Args:
model: The model to use.'

def set_model(self, model):

    if ((self.model() is not None) and (model is not self.model())):
        self.model().deleteLater()
        self.selectionModel().deleteLater()
    self.setModel(model)
    if (model is None):
        self._active = False
        self.hide()
        return
    model.setParent(self)
    self._active = True
    self._maybe_show()
    self._resize_columns()
    for i in range(model.rowCount()):
        self.expand(model.index(i, 0))
