refactor(RD): decouple ResourceModels from ResourcePages
This makes it so that we don't need a reference to the parent page in the model. It will be useful once we change the page from a widget-based one to a QML page. It also makes tasks be created in the dialog instead of the page, so that the dialog can also have the necessary information to mark versions as selected / deselected easily. It also makes the task pointers into smart pointers. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -18,8 +18,6 @@
|
||||
|
||||
#include "ModrinthResourceModels.h"
|
||||
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
|
||||
|
||||
#include "modplatform/modrinth/ModrinthAPI.h"
|
||||
#include "modplatform/modrinth/ModrinthPackIndex.h"
|
||||
|
||||
@ -28,7 +26,7 @@ namespace ResourceDownload {
|
||||
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
|
||||
const char* ModrinthModModel::sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
|
||||
|
||||
ModrinthModModel::ModrinthModModel(ModrinthModPage* parent) : ModModel(parent, new ModrinthAPI){};
|
||||
ModrinthModModel::ModrinthModModel(BaseInstance const& base) : ModModel(base, new ModrinthAPI){};
|
||||
|
||||
void ModrinthModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
|
||||
{
|
||||
@ -42,7 +40,7 @@ void ModrinthModModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObjec
|
||||
|
||||
void ModrinthModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
|
||||
{
|
||||
::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_associated_page->m_base_instance);
|
||||
::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
|
||||
}
|
||||
|
||||
auto ModrinthModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
|
||||
|
@ -19,6 +19,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui/pages/modplatform/ModModel.h"
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
@ -28,10 +29,13 @@ class ModrinthModModel : public ModModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ModrinthModModel(ModrinthModPage* parent);
|
||||
ModrinthModModel(const BaseInstance&);
|
||||
~ModrinthModModel() override = default;
|
||||
|
||||
private:
|
||||
[[nodiscard]] QString debugName() const override { return Modrinth::debugName() + " (Model)"; }
|
||||
[[nodiscard]] QString metaEntryBase() const override { return Modrinth::metaEntryBase(); }
|
||||
|
||||
void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
|
||||
void loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
|
||||
void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
|
||||
|
@ -47,7 +47,7 @@ namespace ResourceDownload {
|
||||
ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instance)
|
||||
: ModPage(dialog, instance)
|
||||
{
|
||||
m_model = new ModrinthModModel(this);
|
||||
m_model = new ModrinthModModel(instance);
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
// index is used to set the sorting with the modrinth api
|
||||
|
Reference in New Issue
Block a user