refactor(RD): add helper in ResourceModel to find current sorting
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
563fe8d515
commit
c3f0139f76
@ -21,20 +21,13 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
|||||||
Q_ASSERT(m_filter);
|
Q_ASSERT(m_filter);
|
||||||
|
|
||||||
std::optional<std::list<Version>> versions{};
|
std::optional<std::list<Version>> versions{};
|
||||||
std::optional<ResourceAPI::SortingMethod> sort{};
|
|
||||||
|
|
||||||
{ // Version filter
|
{ // Version filter
|
||||||
if (!m_filter->versions.empty())
|
if (!m_filter->versions.empty())
|
||||||
versions = m_filter->versions;
|
versions = m_filter->versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Sorting method
|
auto sort = getCurrentSortingMethodByIndex();
|
||||||
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 };
|
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getModLoaders(), versions };
|
||||||
}
|
}
|
||||||
|
@ -222,6 +222,21 @@ void ResourceModel::runInfoJob(Task::Ptr ptr)
|
|||||||
m_current_info_job.run();
|
m_current_info_job.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<ResourceAPI::SortingMethod> ResourceModel::getCurrentSortingMethodByIndex() const
|
||||||
|
{
|
||||||
|
std::optional<ResourceAPI::SortingMethod> sort{};
|
||||||
|
|
||||||
|
{ // Find sorting method by ID
|
||||||
|
auto sorting_methods = getSortingMethods();
|
||||||
|
auto method = std::find_if(sorting_methods.constBegin(), sorting_methods.constEnd(),
|
||||||
|
[this](auto const& e) { return m_current_sort_index == e.index; });
|
||||||
|
if (method != sorting_methods.constEnd())
|
||||||
|
sort = *method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sort;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
|
std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
|
||||||
{
|
{
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
|
@ -84,6 +84,8 @@ class ResourceModel : public QAbstractListModel {
|
|||||||
void runSearchJob(NetJob::Ptr);
|
void runSearchJob(NetJob::Ptr);
|
||||||
void runInfoJob(Task::Ptr);
|
void runInfoJob(Task::Ptr);
|
||||||
|
|
||||||
|
[[nodiscard]] auto getCurrentSortingMethodByIndex() const -> std::optional<ResourceAPI::SortingMethod>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const BaseInstance& m_base_instance;
|
const BaseInstance& m_base_instance;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user