diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp index bdfd1d8e..70e3ebd4 100644 --- a/application/pages/modplatform/FTBPage.cpp +++ b/application/pages/modplatform/FTBPage.cpp @@ -115,41 +115,52 @@ void FTBPage::ftbPackDataDownloadFailed(QString reason) //TODO: Display the error } -void FTBPage::onPublicPackSelectionChanged(QModelIndex first, QModelIndex second) +void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev) { - onPackSelectionChanged(first, second, publicFilterModel); + if(!now.isValid()) + { + onPackSelectionChanged(); + return; + } + FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value(); + onPackSelectionChanged(&selectedPack); } -void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second) +void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev) { - onPackSelectionChanged(first, second, thirdPartyFilterModel); + if(!now.isValid()) + { + onPackSelectionChanged(); + return; + } + FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value(); + onPackSelectionChanged(&selectedPack); } -void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model) +void FTBPage::onPackSelectionChanged(FtbModpack* pack) { ui->packVersionSelection->clear(); - FtbModpack selectedPack = model->data(now, Qt::UserRole).value(); - - ui->modpackInfo->setHtml("Pack by " + selectedPack.author + "" + "
Minecraft " + selectedPack.mcVersion + "
" - "
" + selectedPack.description + "
  • " + selectedPack.mods.replace(";", "
  • ") + "
"); - - bool currentAdded = false; - - for(int i = 0; i < selectedPack.oldVersions.size(); i++) + if(pack) { - if(selectedPack.currentVersion == selectedPack.oldVersions.at(i)) + ui->modpackInfo->setHtml("Pack by " + pack->author + "" + "
Minecraft " + pack->mcVersion + "
" + "
" + pack->description + "
  • " + pack->mods.replace(";", "
  • ") + "
"); + bool currentAdded = false; + + for(int i = 0; i < pack->oldVersions.size(); i++) { - currentAdded = true; + if(pack->currentVersion == pack->oldVersions.at(i)) + { + currentAdded = true; + } + ui->packVersionSelection->addItem(pack->oldVersions.at(i)); } - ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i)); - } - if(!currentAdded) - { - ui->packVersionSelection->addItem(selectedPack.currentVersion); + if(!currentAdded) + { + ui->packVersionSelection->addItem(pack->currentVersion); + } + selected = *pack; } - - selected = selectedPack; suggestCurrent(); } @@ -164,16 +175,6 @@ void FTBPage::onVersionSelectionItemChanged(QString data) selectedVersion = data; } -FtbModpack FTBPage::getSelectedModpack() -{ - return selected; -} - -QString FTBPage::getSelectedVersion() -{ - return selectedVersion; -} - void FTBPage::onSortingSelectionChanged(QString data) { FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data); @@ -183,6 +184,26 @@ void FTBPage::onSortingSelectionChanged(QString data) void FTBPage::onTabChanged(int tab) { - ui->publicPackList->selectionModel()->reset(); - ui->thirdPartyPackList->selectionModel()->reset(); + FtbFilterModel* currentModel = nullptr; + QTreeView* currentList = nullptr; + if (tab == 0) + { + currentModel = publicFilterModel; + currentList = ui->publicPackList; + } + else + { + currentModel = thirdPartyFilterModel; + currentList = ui->thirdPartyPackList; + } + QModelIndex idx = currentList->currentIndex(); + if(idx.isValid()) + { + auto pack = currentModel->data(idx, Qt::UserRole).value(); + onPackSelectionChanged(&pack); + } + else + { + onPackSelectionChanged(); + } } diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h index a5327d31..00c5e9c5 100644 --- a/application/pages/modplatform/FTBPage.h +++ b/application/pages/modplatform/FTBPage.h @@ -58,12 +58,9 @@ public: bool shouldDisplay() const override; void openedImpl() override; - FtbModpack getSelectedModpack(); - QString getSelectedVersion(); - private: void suggestCurrent(); - void onPackSelectionChanged(QModelIndex first, QModelIndex second, FtbFilterModel *model); + void onPackSelectionChanged(FtbModpack *pack = nullptr); private slots: void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks); @@ -79,7 +76,6 @@ private slots: private: bool initialized = false; - FtbModpack selectedPack; FtbModpack selected; QString selectedVersion;