NOISSUE make FTB pack selection fancier

This commit is contained in:
Petr Mrázek 2018-04-06 21:59:04 +02:00
parent 6323aae56f
commit 15926b2b4a
2 changed files with 56 additions and 39 deletions

View File

@ -115,41 +115,52 @@ void FTBPage::ftbPackDataDownloadFailed(QString reason)
//TODO: Display the error //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<FtbModpack>();
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<FtbModpack>();
onPackSelectionChanged(&selectedPack);
} }
void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model) void FTBPage::onPackSelectionChanged(FtbModpack* pack)
{ {
ui->packVersionSelection->clear(); ui->packVersionSelection->clear();
FtbModpack selectedPack = model->data(now, Qt::UserRole).value<FtbModpack>(); if(pack)
{
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>" ui->modpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>"
"<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>"); "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
bool currentAdded = false; bool currentAdded = false;
for(int i = 0; i < selectedPack.oldVersions.size(); i++) for(int i = 0; i < pack->oldVersions.size(); i++)
{ {
if(selectedPack.currentVersion == selectedPack.oldVersions.at(i)) if(pack->currentVersion == pack->oldVersions.at(i))
{ {
currentAdded = true; currentAdded = true;
} }
ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i)); ui->packVersionSelection->addItem(pack->oldVersions.at(i));
} }
if(!currentAdded) if(!currentAdded)
{ {
ui->packVersionSelection->addItem(selectedPack.currentVersion); ui->packVersionSelection->addItem(pack->currentVersion);
}
selected = *pack;
} }
selected = selectedPack;
suggestCurrent(); suggestCurrent();
} }
@ -164,16 +175,6 @@ void FTBPage::onVersionSelectionItemChanged(QString data)
selectedVersion = data; selectedVersion = data;
} }
FtbModpack FTBPage::getSelectedModpack()
{
return selected;
}
QString FTBPage::getSelectedVersion()
{
return selectedVersion;
}
void FTBPage::onSortingSelectionChanged(QString data) void FTBPage::onSortingSelectionChanged(QString data)
{ {
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data); FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
@ -183,6 +184,26 @@ void FTBPage::onSortingSelectionChanged(QString data)
void FTBPage::onTabChanged(int tab) void FTBPage::onTabChanged(int tab)
{ {
ui->publicPackList->selectionModel()->reset(); FtbFilterModel* currentModel = nullptr;
ui->thirdPartyPackList->selectionModel()->reset(); 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<FtbModpack>();
onPackSelectionChanged(&pack);
}
else
{
onPackSelectionChanged();
}
} }

View File

@ -58,12 +58,9 @@ public:
bool shouldDisplay() const override; bool shouldDisplay() const override;
void openedImpl() override; void openedImpl() override;
FtbModpack getSelectedModpack();
QString getSelectedVersion();
private: private:
void suggestCurrent(); void suggestCurrent();
void onPackSelectionChanged(QModelIndex first, QModelIndex second, FtbFilterModel *model); void onPackSelectionChanged(FtbModpack *pack = nullptr);
private slots: private slots:
void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks); void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
@ -79,7 +76,6 @@ private slots:
private: private:
bool initialized = false; bool initialized = false;
FtbModpack selectedPack;
FtbModpack selected; FtbModpack selected;
QString selectedVersion; QString selectedVersion;