<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_root(self, index):
 """Set the given index as root index of list :param index: the new root index :type index: QtCore.QModelIndex :returns: None :rtype: None :raises: None """

        if not index.isValid():
            self.setModel(None) # so we will not see toplevel stuff
            self.setCurrentIndex(QtCore.QModelIndex())
            self.new_root.emit(QtCore.QModelIndex())
            return
        if self.model() != index.model():
            self.setModel(index.model())
        self.setRootIndex(index)
        if self.model().hasChildren(index):
            self.setCurrentIndex(self.model().index(0, 0, index))
            self.new_root.emit(self.model().index(0, 0, index))
        else:
            self.new_root.emit(QtCore.QModelIndex())