refactor: adapt rest of the codebase to the new resource model

In order to access the ModFolderModel from the ModFolderPage, i created
a new m_model for the correct type, shadowing the m_model of type
ResourceFolderModel. This creates two shared_ptr references to the same object,
but since they will have the same lifetime, it doesn't generate a memory
leak.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2022-08-10 14:48:34 -03:00
parent 256f8094f5
commit 97a74d5c1f
27 changed files with 235 additions and 263 deletions

View File

@ -50,7 +50,8 @@ public:
Mod() = default;
Mod(const QFileInfo &file);
explicit Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata);
Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata);
Mod(QString file_path) : Mod(QFileInfo(file_path)) {}
auto enabled() const -> bool { return m_enabled; }

View File

@ -49,7 +49,7 @@
#include "minecraft/mod/tasks/LocalModParseTask.h"
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(dir), m_is_indexed(is_indexed)
ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed)
{
FS::ensureFolderPathExists(m_dir.absolutePath());
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE };

View File

@ -34,6 +34,8 @@ class Resource : public QObject {
Resource(QObject* parent = nullptr);
Resource(QFileInfo file_info);
Resource(QString file_path) : Resource(QFileInfo(file_path)) {}
~Resource() override = default;
void setFile(QFileInfo file_info);

View File

@ -261,6 +261,9 @@ void ResourceFolderModel::applyUpdates(QSet<QString>& current_set, QSet<QString>
std::sort(removed_rows.begin(), removed_rows.end());
for (int i = 0; i < removed_rows.size(); i++)
removed_rows[i] -= i;
for (auto& removed_index : removed_rows) {
beginRemoveRows(QModelIndex(), removed_index, removed_index);

View File

@ -0,0 +1,13 @@
#pragma once
#include "Resource.h"
class ResourcePack : public Resource {
Q_OBJECT
public:
using Ptr = shared_qobject_ptr<Resource>;
ResourcePack(QObject* parent = nullptr) : Resource(parent) {}
ResourcePack(QFileInfo file_info) : Resource(file_info) {}
};

View File

@ -35,5 +35,4 @@
#include "ResourcePackFolderModel.h"
ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ResourceFolderModel(dir) {
}
ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}

View File

@ -2,9 +2,13 @@
#include "ResourceFolderModel.h"
#include "ResourcePack.h"
class ResourcePackFolderModel : public ResourceFolderModel
{
Q_OBJECT
public:
explicit ResourcePackFolderModel(const QString &dir);
RESOURCE_HELPERS(ResourcePack)
};

View File

@ -0,0 +1,10 @@
#pragma once
#include "ResourceFolderModel.h"
class ShaderPackFolderModel : public ResourceFolderModel {
Q_OBJECT
public:
explicit ShaderPackFolderModel(const QString& dir) : ResourceFolderModel(QDir(dir)) {}
};

View File

@ -35,24 +35,4 @@
#include "TexturePackFolderModel.h"
TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ModFolderModel(dir) {
}
QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::ToolTipRole) {
switch (section) {
case ActiveColumn:
return tr("Is the texture pack enabled?");
case NameColumn:
return tr("The name of the texture pack.");
case VersionColumn:
return tr("The version of the texture pack.");
case DateColumn:
return tr("The date and time this texture pack was last changed (or added).");
default:
return QVariant();
}
}
return ModFolderModel::headerData(section, orientation, role);
}
TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}

View File

@ -1,13 +1,11 @@
#pragma once
#include "ModFolderModel.h"
#include "ResourceFolderModel.h"
class TexturePackFolderModel : public ModFolderModel
class TexturePackFolderModel : public ResourceFolderModel
{
Q_OBJECT
public:
explicit TexturePackFolderModel(const QString &dir);
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
};