Added categories filter
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
||||
Q_ASSERT(m_filter);
|
||||
|
||||
std::optional<std::list<Version>> versions{};
|
||||
std::optional<QStringList> categories{};
|
||||
auto loaders = profile->getSupportedModLoaders();
|
||||
|
||||
// Version filter
|
||||
@@ -32,11 +33,13 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
||||
versions = m_filter->versions;
|
||||
if (m_filter->loaders)
|
||||
loaders = m_filter->loaders;
|
||||
if (!m_filter->categoryIds.empty())
|
||||
categories = m_filter->categoryIds;
|
||||
auto side = m_filter->side;
|
||||
|
||||
auto sort = getCurrentSortingMethodByIndex();
|
||||
|
||||
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, loaders, versions, side };
|
||||
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, loaders, versions, side, categories };
|
||||
}
|
||||
|
||||
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
||||
|
||||
@@ -78,6 +78,7 @@ void ModPage::setFilterWidget(unique_qobject_ptr<ModFilterWidget>& widget)
|
||||
[&] { m_ui->searchButton->setStyleSheet("text-decoration: underline"); });
|
||||
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this,
|
||||
[&] { m_ui->searchButton->setStyleSheet("text-decoration: none"); });
|
||||
prepareProviderCategories();
|
||||
}
|
||||
|
||||
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
||||
|
||||
@@ -61,6 +61,8 @@ class ModPage : public ResourcePage {
|
||||
protected:
|
||||
ModPage(ModDownloadDialog* dialog, BaseInstance& instance);
|
||||
|
||||
virtual void prepareProviderCategories(){};
|
||||
|
||||
protected slots:
|
||||
virtual void filterMods();
|
||||
void triggerSearch() override;
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
*/
|
||||
|
||||
#include "FlameResourcePages.h"
|
||||
#include <QList>
|
||||
#include <memory>
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "modplatform/flame/FlameAPI.h"
|
||||
#include "ui_ResourcePage.h"
|
||||
|
||||
#include "FlameResourceModels.h"
|
||||
@@ -204,4 +208,14 @@ unique_qobject_ptr<ModFilterWidget> FlameModPage::createFilterWidget()
|
||||
return ModFilterWidget::create(&static_cast<MinecraftInstance&>(m_base_instance), false, this);
|
||||
}
|
||||
|
||||
void FlameModPage::prepareProviderCategories()
|
||||
{
|
||||
auto response = std::make_shared<QByteArray>();
|
||||
auto task = FlameAPI::getModCategories(response);
|
||||
QObject::connect(task.get(), &Task::succeeded, [this, response]() {
|
||||
auto categories = FlameAPI::loadModCategories(response);
|
||||
m_filter_widget->setCategories(categories);
|
||||
});
|
||||
task->start();
|
||||
};
|
||||
} // namespace ResourceDownload
|
||||
|
||||
@@ -96,6 +96,9 @@ class FlameModPage : public ModPage {
|
||||
|
||||
void openUrl(const QUrl& url) override;
|
||||
unique_qobject_ptr<ModFilterWidget> createFilterWidget() override;
|
||||
|
||||
protected:
|
||||
virtual void prepareProviderCategories() override;
|
||||
};
|
||||
|
||||
class FlameResourcePackPage : public ResourcePackResourcePage {
|
||||
|
||||
@@ -141,4 +141,15 @@ unique_qobject_ptr<ModFilterWidget> ModrinthModPage::createFilterWidget()
|
||||
{
|
||||
return ModFilterWidget::create(&static_cast<MinecraftInstance&>(m_base_instance), true, this);
|
||||
}
|
||||
|
||||
void ModrinthModPage::prepareProviderCategories()
|
||||
{
|
||||
auto response = std::make_shared<QByteArray>();
|
||||
auto task = ModrinthAPI::getModCategories(response);
|
||||
QObject::connect(task.get(), &Task::succeeded, [this, response]() {
|
||||
auto categories = ModrinthAPI::loadModCategories(response);
|
||||
m_filter_widget->setCategories(categories);
|
||||
});
|
||||
task->start();
|
||||
};
|
||||
} // namespace ResourceDownload
|
||||
|
||||
@@ -94,6 +94,9 @@ class ModrinthModPage : public ModPage {
|
||||
[[nodiscard]] inline auto helpPage() const -> QString override { return "Mod-platform"; }
|
||||
|
||||
unique_qobject_ptr<ModFilterWidget> createFilterWidget() override;
|
||||
|
||||
protected:
|
||||
virtual void prepareProviderCategories() override;
|
||||
};
|
||||
|
||||
class ModrinthResourcePackPage : public ResourcePackResourcePage {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "ModFilterWidget.h"
|
||||
#include <qcheckbox.h>
|
||||
#include <qcombobox.h>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QListWidget>
|
||||
#include <algorithm>
|
||||
#include "BaseVersionList.h"
|
||||
#include "meta/Index.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
@@ -76,6 +78,8 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extendedSuppo
|
||||
connect(ui->alphaCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
|
||||
connect(ui->unknownCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
|
||||
|
||||
connect(ui->categoriesList, &QListWidget::itemClicked, this, &ModFilterWidget::onCategoryClicked);
|
||||
|
||||
setHidden(true);
|
||||
loadVersionList();
|
||||
prepareBasicFilter();
|
||||
@@ -238,4 +242,33 @@ void ModFilterWidget::onVersionFilterTextChanged(QString version)
|
||||
emit filterChanged();
|
||||
}
|
||||
|
||||
#include "ModFilterWidget.moc"
|
||||
void ModFilterWidget::setCategories(QList<ModPlatform::Category> categories)
|
||||
{
|
||||
ui->categoriesList->clear();
|
||||
m_categories = categories;
|
||||
for (auto cat : categories) {
|
||||
auto item = new QListWidgetItem(cat.name, ui->categoriesList);
|
||||
item->setFlags(item->flags() & (~Qt::ItemIsUserCheckable));
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
ui->categoriesList->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void ModFilterWidget::onCategoryClicked(QListWidgetItem* item)
|
||||
{
|
||||
if (item)
|
||||
item->setCheckState(item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked);
|
||||
m_filter->categoryIds.clear();
|
||||
for (auto i = 0; i < ui->categoriesList->count(); i++) {
|
||||
auto item = ui->categoriesList->item(i);
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
auto c = std::find_if(m_categories.cbegin(), m_categories.cend(), [item](auto v) { return v.name == item->text(); });
|
||||
if (c != m_categories.cend())
|
||||
m_filter->categoryIds << c->id;
|
||||
}
|
||||
}
|
||||
m_filter_changed = true;
|
||||
emit filterChanged();
|
||||
};
|
||||
|
||||
#include "ModFilterWidget.moc"
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QButtonGroup>
|
||||
#include <QList>
|
||||
#include <QListWidgetItem>
|
||||
#include <QTabWidget>
|
||||
|
||||
#include "Version.h"
|
||||
@@ -26,11 +28,12 @@ class ModFilterWidget : public QTabWidget {
|
||||
ModPlatform::ModLoaderTypes loaders;
|
||||
QString side;
|
||||
bool hideInstalled;
|
||||
QStringList categoryIds;
|
||||
|
||||
bool operator==(const Filter& other) const
|
||||
{
|
||||
return hideInstalled == other.hideInstalled && side == other.side && loaders == other.loaders && versions == other.versions &&
|
||||
releases == other.releases;
|
||||
releases == other.releases && categoryIds == other.categoryIds;
|
||||
}
|
||||
bool operator!=(const Filter& other) const { return !(*this == other); }
|
||||
};
|
||||
@@ -45,6 +48,9 @@ class ModFilterWidget : public QTabWidget {
|
||||
void filterChanged();
|
||||
void filterUnchanged();
|
||||
|
||||
public slots:
|
||||
void setCategories(QList<ModPlatform::Category>);
|
||||
|
||||
private:
|
||||
ModFilterWidget(MinecraftInstance* instance, bool extendedSupport, QWidget* parent = nullptr);
|
||||
|
||||
@@ -59,6 +65,7 @@ class ModFilterWidget : public QTabWidget {
|
||||
void onSideFilterChanged();
|
||||
void onHideInstalledFilterChanged();
|
||||
void onIncludeSnapshotsChanged();
|
||||
void onCategoryClicked(QListWidgetItem* item);
|
||||
|
||||
private:
|
||||
Ui::ModFilterWidget* ui;
|
||||
@@ -69,4 +76,6 @@ class ModFilterWidget : public QTabWidget {
|
||||
|
||||
Meta::VersionList::Ptr m_version_list;
|
||||
VersionProxyModel* m_versions_proxy = nullptr;
|
||||
|
||||
QList<ModPlatform::Category> m_categories;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>460</width>
|
||||
<height>127</height>
|
||||
<height>132</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -145,6 +145,44 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="CategoryPage">
|
||||
<attribute name="title">
|
||||
<string>Categories</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QListWidget" name="categoriesList">
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerItem</enum>
|
||||
</property>
|
||||
<property name="flow">
|
||||
<enum>QListView::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="isWrapping" stdset="0">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::ListMode</enum>
|
||||
</property>
|
||||
<property name="modelColumn">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="ModPage">
|
||||
<attribute name="title">
|
||||
<string>Others</string>
|
||||
|
||||
Reference in New Issue
Block a user