diff options
author | flow <flowlnlnln@gmail.com> | 2022-08-10 14:48:34 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-08-20 10:47:58 -0300 |
commit | 97a74d5c1f00a11d331a41b16690f7202fe102a3 (patch) | |
tree | e49ff4b05f4ac241a2df4920f3c6b4832bc0d252 /launcher/ui/pages/instance/ModFolderPage.cpp | |
parent | 256f8094f5fed85ff9136e8d0b9c9677d7b9e9db (diff) | |
download | PrismLauncher-97a74d5c1f00a11d331a41b16690f7202fe102a3.tar.gz PrismLauncher-97a74d5c1f00a11d331a41b16690f7202fe102a3.tar.bz2 PrismLauncher-97a74d5c1f00a11d331a41b16690f7202fe102a3.zip |
refactor: adapt rest of the codebase to the new resource model
In order to access the ModFolderModel from the ModFolderPage, i created
a new m_model for the correct type, shadowing the m_model of type
ResourceFolderModel. This creates two shared_ptr references to the same object,
but since they will have the same lifetime, it doesn't generate a memory
leak.
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/ui/pages/instance/ModFolderPage.cpp')
-rw-r--r-- | launcher/ui/pages/instance/ModFolderPage.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 45678db1..63897fb0 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -65,7 +65,7 @@ #include "ui/dialogs/ProgressDialog.h" ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> mods, QWidget* parent) - : ExternalResourcesPage(inst, mods, parent) + : ExternalResourcesPage(inst, mods, parent), m_model(mods) { // This is structured like that so that these changes // do not affect the Resource pack and Shader pack tabs @@ -110,6 +110,8 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning()); } + + connect(ui->treeView, &ModListView::activated, this, &ModFolderPage::itemActivated); } void ModFolderPage::runningStateChanged(bool running) @@ -124,6 +126,44 @@ bool ModFolderPage::shouldDisplay() const return true; } +void ModFolderPage::itemActivated(const QModelIndex&) +{ + if (!m_controlsEnabled) + return; + + auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()); + m_model->setModStatus(selection.indexes(), ModFolderModel::Toggle); +} + +void ModFolderPage::enableItem() +{ + if (!m_controlsEnabled) + return; + + auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()); + m_model->setModStatus(selection.indexes(), ModFolderModel::Enable); +} + +void ModFolderPage::disableItem() +{ + if (!m_controlsEnabled) + return; + + auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()); + m_model->setModStatus(selection.indexes(), ModFolderModel::Disable); +} + +bool ModFolderPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) +{ + auto sourceCurrent = m_filterModel->mapToSource(current); + int row = sourceCurrent.row(); + Mod const* m = m_model->at(row); + if (m) + ui->frame->updateWithMod(*m); + + return true; +} + void ModFolderPage::installMods() { if (!m_controlsEnabled) |