refactor!!!: migrate from shared pointers

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2026-01-07 19:16:54 +05:00
parent c64d871a28
commit 549405ab2f
No known key found for this signature in database
GPG key ID: B77C34313AEE1FFF
199 changed files with 742 additions and 709 deletions

View file

@ -322,14 +322,14 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(view, &InstanceView::droppedURLs, this, &MainWindow::processURLs, Qt::QueuedConnection);
proxymodel = new InstanceProxyModel(this);
proxymodel->setSourceModel(APPLICATION->instances().get());
proxymodel->setSourceModel(APPLICATION->instances());
proxymodel->sort(0);
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
view->setModel(proxymodel);
view->setSourceOfGroupCollapseStatus(
[](const QString& groupName) -> bool { return APPLICATION->instances()->isGroupCollapsed(groupName); });
connect(view, &InstanceView::groupStateChanged, APPLICATION->instances().get(), &InstanceList::on_GroupStateChanged);
connect(view, &InstanceView::groupStateChanged, APPLICATION->instances(), &InstanceList::on_GroupStateChanged);
ui->horizontalLayout->addWidget(view);
}
// The cat background
@ -365,13 +365,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(view->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::instanceChanged);
// track icon changes and update the toolbar!
connect(APPLICATION->icons().get(), &IconList::iconUpdated, this, &MainWindow::iconUpdated);
connect(APPLICATION->icons(), &IconList::iconUpdated, this, &MainWindow::iconUpdated);
// model reset -> selection is invalid. All the instance pointers are wrong.
connect(APPLICATION->instances().get(), &InstanceList::dataIsInvalid, this, &MainWindow::selectionBad);
connect(APPLICATION->instances(), &InstanceList::dataIsInvalid, this, &MainWindow::selectionBad);
// handle newly added instances
connect(APPLICATION->instances().get(), &InstanceList::instanceSelectRequest, this, &MainWindow::instanceSelectRequest);
connect(APPLICATION->instances(), &InstanceList::instanceSelectRequest, this, &MainWindow::instanceSelectRequest);
// When the global settings page closes, we want to know about it and update our state
connect(APPLICATION, &Application::globalSettingsApplied, this, &MainWindow::globalSettingsClosed);
@ -394,8 +394,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
// Update the menu when the active account changes.
// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit.
// Template hell sucks...
connect(APPLICATION->accounts().get(), &AccountList::defaultAccountChanged, [this] { defaultAccountChanged(); });
connect(APPLICATION->accounts().get(), &AccountList::listChanged, [this] { defaultAccountChanged(); });
connect(APPLICATION->accounts(), &AccountList::defaultAccountChanged, [this] { defaultAccountChanged(); });
connect(APPLICATION->accounts(), &AccountList::listChanged, [this] { defaultAccountChanged(); });
// Show initial account
defaultAccountChanged();
@ -419,7 +419,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
auto updater = APPLICATION->updater();
if (updater) {
connect(updater.get(), &ExternalUpdater::canCheckForUpdatesChanged, this, &MainWindow::updatesAllowedChanged);
connect(updater, &ExternalUpdater::canCheckForUpdatesChanged, this, &MainWindow::updatesAllowedChanged);
}
}
@ -960,7 +960,7 @@ void MainWindow::processURLs(QList<QUrl> urls)
auto array = std::make_shared<QByteArray>();
auto api = FlameAPI();
auto job = api.getFile(addonId, fileId, array);
auto job = api.getFile(addonId, fileId, array.get());
connect(job.get(), &Task::failed, this,
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
@ -1062,7 +1062,7 @@ void MainWindow::processURLs(QList<QUrl> urls)
qDebug() << "Adding resource" << localFileName << "to" << dlg.selectedInstanceKey;
auto inst = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey);
auto minecraftInst = std::dynamic_pointer_cast<MinecraftInstance>(inst);
auto minecraftInst = dynamic_cast<MinecraftInstance*>(inst);
switch (type) {
case ModPlatform::ResourceType::ResourcePack:
@ -1442,7 +1442,7 @@ void MainWindow::on_actionExportInstanceZip_triggered()
void MainWindow::on_actionExportInstanceMrPack_triggered()
{
if (m_selectedInstance) {
auto instance = std::dynamic_pointer_cast<MinecraftInstance>(m_selectedInstance);
auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance);
if (instance != nullptr) {
ExportPackDialog dlg(instance, this);
dlg.exec();
@ -1453,7 +1453,7 @@ void MainWindow::on_actionExportInstanceMrPack_triggered()
void MainWindow::on_actionExportInstanceFlamePack_triggered()
{
if (m_selectedInstance) {
auto instance = std::dynamic_pointer_cast<MinecraftInstance>(m_selectedInstance);
auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance);
if (instance) {
if (auto cmp = instance->getPackProfile()->getComponent("net.minecraft");
cmp && cmp->getVersionFile() && cmp->getVersionFile()->type == "snapshot") {
@ -1506,7 +1506,7 @@ void MainWindow::instanceActivated(QModelIndex index)
if (!index.isValid())
return;
QString id = index.data(InstanceList::InstanceIDRole).toString();
InstancePtr inst = APPLICATION->instances()->getInstanceById(id);
BaseInstance* inst = APPLICATION->instances()->getInstanceById(id);
if (!inst)
return;
@ -1520,7 +1520,7 @@ void MainWindow::on_actionLaunchInstance_triggered()
}
}
void MainWindow::activateInstance(InstancePtr instance)
void MainWindow::activateInstance(BaseInstance* instance)
{
APPLICATION->launch(instance);
}
@ -1567,8 +1567,8 @@ void MainWindow::instanceChanged(const QModelIndex& current, [[maybe_unused]] co
return;
}
if (m_selectedInstance) {
disconnect(m_selectedInstance.get(), &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
disconnect(m_selectedInstance.get(), &BaseInstance::profilerChanged, this, &MainWindow::refreshCurrentInstance);
disconnect(m_selectedInstance, &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
disconnect(m_selectedInstance, &BaseInstance::profilerChanged, this, &MainWindow::refreshCurrentInstance);
}
QString id = current.data(InstanceList::InstanceIDRole).toString();
m_selectedInstance = APPLICATION->instances()->getInstanceById(id);
@ -1588,8 +1588,8 @@ void MainWindow::instanceChanged(const QModelIndex& current, [[maybe_unused]] co
APPLICATION->settings()->set("SelectedInstance", m_selectedInstance->id());
connect(m_selectedInstance.get(), &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
connect(m_selectedInstance.get(), &BaseInstance::profilerChanged, this, &MainWindow::refreshCurrentInstance);
connect(m_selectedInstance, &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
connect(m_selectedInstance, &BaseInstance::profilerChanged, this, &MainWindow::refreshCurrentInstance);
} else {
APPLICATION->settings()->set("SelectedInstance", QString());
selectionBad();