pollymc/launcher/ui/pages/modplatform/ModModel.h
flow 36571c5e22
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>
2023-01-13 16:23:07 -03:00

55 lines
1.8 KiB
C++

#pragma once
#include <QAbstractListModel>
#include "modplatform/ModIndex.h"
#include "modplatform/ResourceAPI.h"
#include "ui/pages/modplatform/ResourceModel.h"
#include "ui/widgets/ModFilterWidget.h"
class Version;
namespace ResourceDownload {
class ModPage;
class ModModel : public ResourceModel {
Q_OBJECT
public:
ModModel(const BaseInstance&, ResourceAPI* api);
/* Ask the API for more information */
void searchWithTerm(const QString& term, unsigned int sort, bool filter_changed);
virtual void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) = 0;
virtual void loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) = 0;
virtual void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) = 0;
void setFilter(std::shared_ptr<ModFilterWidget::Filter> filter) { m_filter = filter; }
public slots:
void searchRequestFinished(QJsonDocument& doc);
void infoRequestFinished(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index);
void versionRequestSucceeded(QJsonDocument doc, ModPlatform::IndexedPack& pack, const QModelIndex& index);
public slots:
ResourceAPI::SearchArgs createSearchArguments() override;
ResourceAPI::SearchCallbacks createSearchCallbacks() override;
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
ResourceAPI::VersionSearchCallbacks createVersionsCallbacks(QModelIndex&) override;
ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override;
ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(QModelIndex&) override;
protected:
virtual auto documentToArray(QJsonDocument& obj) const -> QJsonArray = 0;
protected:
std::shared_ptr<ModFilterWidget::Filter> m_filter = nullptr;
};
} // namespace ResourceDownload