From 010a5d80d6d5302de6c512d3ffd66d0db1785716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 21 Feb 2021 11:12:16 +0100 Subject: [PATCH] Switch back to invalidating filter when receiving mod updates. --- src/mainwindow.cpp | 38 ++++++++++++++++++-------------------- src/mainwindow.h | 11 +++++++++-- src/modlistview.cpp | 5 +++++ src/modlistview.h | 4 ++++ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0fabd0dce..9f1ae7b69 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2819,41 +2819,37 @@ void MainWindow::nxmUpdateInfoAvailable(QString gameName, QVariant userData, QVa } QVariantList resultList = resultData.toList(); - QFutureWatcher>>> *watcher = new QFutureWatcher>>>(); - QObject::connect(watcher, &QFutureWatcher>>::finished, this, &MainWindow::finishUpdateInfo); - QFuture>>> future = QtConcurrent::run([=]() -> std::pair>> { - return std::make_pair(gameNameReal, ModInfo::filteredMods(gameNameReal, resultList, userData.toBool(), true)); + auto* watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, watcher]() { + finishUpdateInfo(watcher->result()); + watcher->deleteLater(); + }); + auto future = QtConcurrent::run([=]() { + return NxmUpdateInfoData{ gameNameReal, ModInfo::filteredMods(gameNameReal, resultList, userData.toBool(), true) }; }); watcher->setFuture(future); + ui->modList->invalidateFilter(); } -void MainWindow::finishUpdateInfo() +void MainWindow::finishUpdateInfo(const NxmUpdateInfoData& data) { - QFutureWatcher>>> *watcher = static_cast>>> *>(sender()); - - QString game = watcher->result().first; - auto finalMods = watcher->result().second; - - if (finalMods.empty()) { - log::info("{}", tr("None of your %1 mods appear to have had recent file updates.").arg(game)); + if (data.finalMods.empty()) { + log::info("{}", tr("None of your %1 mods appear to have had recent file updates.").arg(data.game)); } std::set> organizedGames; - for (auto mod : finalMods) { + for (auto& mod : data.finalMods) { if (mod->canBeUpdated()) { organizedGames.insert(std::make_pair(mod->gameName().toLower(), mod->nexusId())); } - m_OrganizerCore.modList()->notifyChange(ModInfo::getIndex(mod->name())); } - if (!finalMods.empty() && organizedGames.empty()) + if (!data.finalMods.empty() && organizedGames.empty()) log::warn("{}", tr("All of your mods have been checked recently. We restrict update checks to help preserve your available API requests.")); - for (auto game : organizedGames) + for (const auto& game : organizedGames) { NexusInterface::instance().requestUpdates(game.second, this, QVariant(), game.first, QString()); - - disconnect(sender()); - delete sender(); + } } void MainWindow::nxmUpdatesAvailable(QString gameName, int modID, QVariant userData, QVariant resultData, int requestID) @@ -2928,13 +2924,15 @@ void MainWindow::nxmUpdatesAvailable(QString gameName, int modID, QVariant userD if (foundUpdate) { // Just get the standard data updates for endorsements and descriptions mod->setLastNexusUpdate(QDateTime::currentDateTimeUtc()); - m_OrganizerCore.modList()->notifyChange(ModInfo::getIndex(mod->name())); } else { // Scrape mod data here so we can use the mod version if no file update was located requiresInfo = true; } } + // invalidate the filter to display mods with an update + ui->modList->invalidateFilter(); + if (requiresInfo) NexusInterface::instance().requestModInfo(gameNameReal, modID, this, QVariant(), QString()); } diff --git a/src/mainwindow.h b/src/mainwindow.h index f9cf541c9..4f7a09625 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -224,6 +224,13 @@ private slots: void toggleMO2EndorseState(); void toggleUpdateAction(); + // update info + struct NxmUpdateInfoData { + QString game; + std::set finalMods; + }; + void finishUpdateInfo(const NxmUpdateInfoData& data); + private: static const char *PATTERN_BACKUP_GLOB; @@ -331,10 +338,10 @@ private slots: void modInstalled(const QString &modName); - void finishUpdateInfo(); + // update info + void nxmUpdateInfoAvailable(QString gameName, QVariant userData, QVariant resultData, int requestID); void nxmEndorsementsAvailable(QVariant userData, QVariant resultData, int); - void nxmUpdateInfoAvailable(QString gameName, QVariant userData, QVariant resultData, int requestID); void nxmUpdatesAvailable(QString gameName, int modID, QVariant userData, QVariant resultData, int requestID); void nxmModInfoAvailable(QString gameName, int modID, QVariant userData, QVariant resultData, int requestID); void nxmEndorsementToggled(QString, int, QVariant, QVariant resultData, int); diff --git a/src/modlistview.cpp b/src/modlistview.cpp index cb4cb2fba..47fc880dc 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -299,6 +299,11 @@ std::optional ModListView::prevMod(unsigned int modIndex) const return {}; } +void ModListView::invalidateFilter() +{ + m_sortProxy->invalidate(); +} + void ModListView::setFilterCriteria(const std::vector& criteria) { m_sortProxy->setCriteria(criteria); diff --git a/src/modlistview.h b/src/modlistview.h index 408bc900f..a306c955a 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -112,6 +112,10 @@ class ModListView : public QTreeView public slots: + // invalidate (refresh) the filter (similar to a layout changed event) + // + void invalidateFilter(); + // set the filter criteria/options for mods // void setFilterCriteria(const std::vector& criteria);