refactor(RD): clear up sorting methods
This refactors the sorting methods to join every bit of it into a single list, easing maintanance. It also removes the weird index contraint on the list of methods by adding an index field to the DS that holds the method. Lastly, it puts the available methods on their respective API, so other resources on the same API can re-use them later on. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
c8eca4fb85
commit
36571c5e22
17 changed files with 93 additions and 61 deletions
|
@ -20,12 +20,23 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
|||
Q_ASSERT(profile);
|
||||
Q_ASSERT(m_filter);
|
||||
|
||||
std::optional<std::list<Version>> versions {};
|
||||
if (!m_filter->versions.empty())
|
||||
versions = m_filter->versions;
|
||||
std::optional<std::list<Version>> versions{};
|
||||
std::optional<ResourceAPI::SortingMethod> sort{};
|
||||
|
||||
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term,
|
||||
getSorts()[currentSort], profile->getModLoaders(), versions };
|
||||
{ // Version filter
|
||||
if (!m_filter->versions.empty())
|
||||
versions = m_filter->versions;
|
||||
}
|
||||
|
||||
{ // Sorting method
|
||||
auto sorting_methods = getSortingMethods();
|
||||
auto method = std::find_if(sorting_methods.begin(), sorting_methods.end(),
|
||||
[this](auto const& e) { return m_current_sort_index == e.index; });
|
||||
if (method != sorting_methods.end())
|
||||
sort = *method;
|
||||
}
|
||||
|
||||
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getModLoaders(), versions };
|
||||
}
|
||||
ResourceAPI::SearchCallbacks ModModel::createSearchCallbacks()
|
||||
{
|
||||
|
@ -44,8 +55,8 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& en
|
|||
Q_ASSERT(profile);
|
||||
Q_ASSERT(m_filter);
|
||||
|
||||
std::optional<std::list<Version>> versions {};
|
||||
if (!m_filter->versions.empty())
|
||||
std::optional<std::list<Version>> versions{};
|
||||
if (!m_filter->versions.empty())
|
||||
versions = m_filter->versions;
|
||||
|
||||
return { pack, versions, profile->getModLoaders() };
|
||||
|
@ -73,14 +84,14 @@ ResourceAPI::ProjectInfoCallbacks ModModel::createInfoCallbacks(QModelIndex& ent
|
|||
} };
|
||||
}
|
||||
|
||||
void ModModel::searchWithTerm(const QString& term, const int sort, const bool filter_changed)
|
||||
void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filter_changed)
|
||||
{
|
||||
if (m_search_term == term && m_search_term.isNull() == term.isNull() && currentSort == sort && !filter_changed) {
|
||||
if (m_search_term == term && m_search_term.isNull() == term.isNull() && m_current_sort_index == sort && !filter_changed) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSearchTerm(term);
|
||||
currentSort = sort;
|
||||
m_current_sort_index = sort;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
@ -142,7 +153,7 @@ void ModModel::infoRequestFinished(QJsonDocument& doc, ModPlatform::IndexedPack&
|
|||
qWarning() << "Failed to cache mod info!";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
emit projectInfoUpdated();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue