Merge pull request #6715 from lemondrops/manager-reload

Manager: Reload VMs after changing the system directory
This commit is contained in:
Miran Grča
2026-01-15 03:33:00 +01:00
committed by GitHub
33 changed files with 213 additions and 14 deletions

View File

@@ -451,6 +451,56 @@ VMManagerMain::~VMManagerMain()
delete vm_model;
}
void
VMManagerMain::reload()
{
// Disconnect and save the old selection mdoel to be deleted later
QItemSelectionModel *old_selection_model = ui->listView->selectionModel();
disconnect(old_selection_model, &QItemSelectionModel::currentChanged, this, &VMManagerMain::currentSelectionChanged);
// Disconnect and delete the model and proxy model
disconnect(vm_model, &VMManagerModel::systemDataChanged, this, &VMManagerMain::modelDataChange);
disconnect(vm_model, &VMManagerModel::globalConfigurationChanged, this, nullptr);
delete proxy_model;
delete vm_model;
// Reset the details view and toolbar to initial state
selected_sysconfig = new VMManagerSystem();
vm_details->reset();
emit selectionOrStateChanged(nullptr);
// Create the new model and proxy model
vm_model = new VMManagerModel;
proxy_model = new StringListProxyModel(this);
proxy_model->setSourceModel(vm_model);
ui->listView->setModel(proxy_model);
// Delete the old selection model
delete old_selection_model;
// Set up the new models
proxy_model->setSortCaseSensitivity(Qt::CaseInsensitive);
ui->listView->model()->sort(0, Qt::AscendingOrder);
connect(vm_model, &VMManagerModel::systemDataChanged, this, &VMManagerMain::modelDataChange);
connect(vm_model, &VMManagerModel::globalConfigurationChanged, this, []() {
vmm_main_window->updateSettings();
});
const QItemSelectionModel *selection_model = ui->listView->selectionModel();
connect(selection_model, &QItemSelectionModel::currentChanged, this, &VMManagerMain::currentSelectionChanged);
// Update the search completer
auto *completerModel = new QStringListModel(getSearchCompletionList(), ui->searchBar->completer());
ui->searchBar->completer()->setModel(completerModel);
// If machines are found, set the selection to the first one
if (proxy_model->rowCount(QModelIndex()) > 0) {
const QModelIndex first_index = proxy_model->index(0, 0);
ui->listView->setCurrentIndex(first_index);
emit selectionOrStateChanged(selected_sysconfig);
}
// Notify the status bar
emit updateStatusRight(machineCountString());
}
void
VMManagerMain::updateGlobalSettings()
{
@@ -734,12 +784,9 @@ VMManagerMain::deleteSystem(VMManagerSystem *sysconfig)
delete sysconfig;
if (vm_model->rowCount(QModelIndex()) <= 0) {
selected_sysconfig = new VMManagerSystem();
/* no machines left - get rid of the last machine's leftovers */
ui->detailsArea->layout()->removeWidget(vm_details);
delete vm_details;
vm_details = new VMManagerDetails();
ui->detailsArea->layout()->addWidget(vm_details);
selected_sysconfig = new VMManagerSystem();
vm_details->reset();
/* tell the mainwindow to disable the toolbar buttons */
emit selectionOrStateChanged(nullptr);
}