mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
chore(clang-tidy): fix clang tidy warnings
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
4c9081a934
commit
bac959bc6f
23 changed files with 650 additions and 546 deletions
|
|
@ -52,28 +52,27 @@
|
|||
#include <QUuid>
|
||||
#include <algorithm>
|
||||
|
||||
#include "minecraft/Component.h"
|
||||
#include "minecraft/mod/Resource.h"
|
||||
#include "minecraft/mod/ResourceFolderModel.h"
|
||||
#include "minecraft/mod/tasks/LocalModParseTask.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
|
||||
ModFolderModel::ModFolderModel(const QDir& dir, BaseInstance* instance, bool is_indexed, bool create_dir, QObject* parent)
|
||||
: ResourceFolderModel(QDir(dir), instance, is_indexed, create_dir, parent)
|
||||
ModFolderModel::ModFolderModel(const QDir& dir, BaseInstance* instance, bool isIndexed, bool createDir, QObject* parent)
|
||||
: ResourceFolderModel(QDir(dir), instance, isIndexed, createDir, parent)
|
||||
{
|
||||
m_column_names = QStringList({ "Enable", "Image", "Name", "Version", "Last Modified", "Provider", "Size", "Side", "Loaders",
|
||||
"Minecraft Versions", "Release Type", "Requires", "Required By", "File Name" });
|
||||
m_column_names_translated =
|
||||
m_columnNames = QStringList({ "Enable", "Image", "Name", "Version", "Last Modified", "Provider", "Size", "Side", "Loaders",
|
||||
"Minecraft Versions", "Release Type", "Requires", "Required By", "File Name" });
|
||||
m_columnNamesTranslated =
|
||||
QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Version"), tr("Last Modified"), tr("Provider"), tr("Size"), tr("Side"),
|
||||
tr("Loaders"), tr("Minecraft Versions"), tr("Release Type"), tr("Requires"), tr("Required By"), tr("File Name") });
|
||||
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::VERSION, SortType::DATE,
|
||||
SortType::PROVIDER, SortType::SIZE, SortType::SIDE, SortType::LOADERS, SortType::MC_VERSIONS,
|
||||
SortType::RELEASE_TYPE, SortType::REQUIRES, SortType::REQUIRED_BY, SortType::FILENAME };
|
||||
m_column_resize_modes = { QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Stretch, QHeaderView::Interactive,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive };
|
||||
tr("Loaders"), tr("Minecraft Versions"), tr("Release Type"), tr("Requires"), tr("Required By"), tr("File Name") });
|
||||
m_columnSortKeys = { SortType::Enabled, SortType::Name, SortType::Name, SortType::Version, SortType::Date,
|
||||
SortType::Provider, SortType::Size, SortType::Side, SortType::Loaders, SortType::McVersions,
|
||||
SortType::ReleaseType, SortType::Requires, SortType::RequiredBy, SortType::Filename };
|
||||
m_columnResizeModes = { QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Stretch, QHeaderView::Interactive,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive };
|
||||
m_columnsHideable = { false, true, false, true, true, true, true, true, true, true, true, true, true, true };
|
||||
|
||||
connect(this, &ModFolderModel::parseFinished, this, &ModFolderModel::onParseFinished);
|
||||
|
|
@ -81,8 +80,9 @@ ModFolderModel::ModFolderModel(const QDir& dir, BaseInstance* instance, bool is_
|
|||
|
||||
QVariant ModFolderModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!validateIndex(index))
|
||||
if (!validateIndex(index)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
|
|
@ -120,6 +120,8 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
|
|||
case RequiresColumn: {
|
||||
return at(row).requiresCount();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole: {
|
||||
|
|
@ -158,6 +160,8 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
|
|||
case FileNameColumn:
|
||||
mappedIndex = index.siblingAtColumn(ResourceFolderModel::FileNameColumn);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (mappedIndex.isValid()) {
|
||||
|
|
@ -229,12 +233,12 @@ QVariant ModFolderModel::headerData(int section, [[maybe_unused]] Qt::Orientatio
|
|||
|
||||
int ModFolderModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : NUM_COLUMNS;
|
||||
return parent.isValid() ? 0 : NumColumns;
|
||||
}
|
||||
|
||||
Task* ModFolderModel::createParseTask(Resource& resource)
|
||||
{
|
||||
return new LocalModParseTask(m_next_resolution_ticket, resource.type(), resource.fileinfo());
|
||||
return new LocalModParseTask(m_nextResolutionTicket, resource.type(), resource.fileinfo());
|
||||
}
|
||||
|
||||
bool ModFolderModel::isValid()
|
||||
|
|
@ -242,35 +246,37 @@ bool ModFolderModel::isValid()
|
|||
return m_dir.exists() && m_dir.isReadable();
|
||||
}
|
||||
|
||||
void ModFolderModel::onParseSucceeded(int ticket, QString mod_id)
|
||||
void ModFolderModel::onParseSucceeded(int ticket, const QString& resourceId)
|
||||
{
|
||||
auto iter = m_active_parse_tasks.constFind(ticket);
|
||||
if (iter == m_active_parse_tasks.constEnd())
|
||||
auto iter = m_activeParseTasks.constFind(ticket);
|
||||
if (iter == m_activeParseTasks.constEnd()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = m_resources_index[mod_id];
|
||||
int row = m_resourcesIndex[resourceId];
|
||||
|
||||
auto parse_task = *iter;
|
||||
auto cast_task = static_cast<LocalModParseTask*>(parse_task.get());
|
||||
const auto& parseTask = *iter;
|
||||
auto* castTask = static_cast<LocalModParseTask*>(parseTask.get());
|
||||
|
||||
Q_ASSERT(cast_task->token() == ticket);
|
||||
Q_ASSERT(castTask->token() == ticket);
|
||||
|
||||
auto resource = find(mod_id);
|
||||
auto resource = find(resourceId);
|
||||
|
||||
auto result = cast_task->result();
|
||||
auto result = castTask->result();
|
||||
if (result && resource) {
|
||||
auto* mod = static_cast<Mod*>(resource.get());
|
||||
mod->finishResolvingWithDetails(std::move(result->details));
|
||||
|
||||
}
|
||||
emit dataChanged(index(row, RequiresColumn), index(row, RequiredByColumn));
|
||||
}
|
||||
|
||||
Mod* findById(QSet<Mod*> mods, QString modId)
|
||||
namespace {
|
||||
Mod* findById(QSet<Mod*> mods, const QString& resourceId)
|
||||
{
|
||||
auto found = std::find_if(mods.begin(), mods.end(), [modId](Mod* m) { return m->mod_id() == modId; });
|
||||
auto found = std::ranges::find_if(mods, [resourceId](Mod* m) { return m->mod_id() == resourceId; });
|
||||
return found != mods.end() ? *found : nullptr;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ModFolderModel::onParseFinished()
|
||||
{
|
||||
|
|
@ -283,25 +289,25 @@ void ModFolderModel::onParseFinished()
|
|||
m_requires.clear();
|
||||
m_requiredBy.clear();
|
||||
|
||||
auto findByProjectID = [mods](QVariant modId, ModPlatform::ResourceProvider provider) -> Mod* {
|
||||
auto found = std::find_if(mods.begin(), mods.end(), [modId, provider](Mod* m) {
|
||||
auto findByProjectID = [mods](const QVariant& modId, ModPlatform::ResourceProvider provider) -> Mod* {
|
||||
auto found = std::ranges::find_if(mods, [modId, provider](Mod* m) {
|
||||
return m->metadata() && m->metadata()->provider == provider && m->metadata()->project_id == modId;
|
||||
});
|
||||
return found != mods.end() ? *found : nullptr;
|
||||
};
|
||||
for (auto mod : mods) {
|
||||
for (auto* mod : mods) {
|
||||
auto id = mod->mod_id();
|
||||
for (auto dep : mod->dependencies()) {
|
||||
auto d = findById(mods, dep);
|
||||
for (const auto& dep : mod->dependencies()) {
|
||||
auto* d = findById(mods, dep);
|
||||
if (d) {
|
||||
m_requires[id] << d;
|
||||
m_requiredBy[d->mod_id()] << mod;
|
||||
}
|
||||
}
|
||||
if (mod->metadata()) {
|
||||
for (auto dep : mod->metadata()->dependencies) {
|
||||
for (const auto& dep : mod->metadata()->dependencies) {
|
||||
if (dep.type == ModPlatform::DependencyType::REQUIRED) {
|
||||
auto d = findByProjectID(dep.addonId, mod->metadata()->provider);
|
||||
auto* d = findByProjectID(dep.addonId, mod->metadata()->provider);
|
||||
if (d) {
|
||||
m_requires[id] << d;
|
||||
m_requiredBy[d->mod_id()] << mod;
|
||||
|
|
@ -310,29 +316,31 @@ void ModFolderModel::onParseFinished()
|
|||
}
|
||||
}
|
||||
}
|
||||
for (auto mod : mods) {
|
||||
for (auto* mod : mods) {
|
||||
auto id = mod->mod_id();
|
||||
if (mod->requiredByCount() != m_requiredBy[id].count() || mod->requiresCount() != m_requires[id].count()) {
|
||||
mod->setRequiredByCount(m_requiredBy[id].count());
|
||||
mod->setRequiresCount(m_requires[id].count());
|
||||
int row = m_resources_index[mod->internal_id()];
|
||||
int row = m_resourcesIndex[mod->internalId()];
|
||||
emit dataChanged(index(row), index(row, columnCount(QModelIndex()) - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QSet<Mod*> collectMods(QSet<Mod*> mods, QHash<QString, QSet<Mod*>> relation, std::set<QString>& seen, bool shouldBeEnabled)
|
||||
namespace {
|
||||
|
||||
QSet<Mod*> collectMods(const QSet<Mod*>& mods, QHash<QString, QSet<Mod*>> relation, std::set<QString>& seen, bool shouldBeEnabled)
|
||||
{
|
||||
QSet<Mod*> affectedList = {};
|
||||
QSet<Mod*> needToCheck = {};
|
||||
for (auto mod : mods) {
|
||||
for (auto* mod : mods) {
|
||||
auto id = mod->mod_id();
|
||||
if (seen.count(id) == 0) {
|
||||
if (!seen.contains(id)) {
|
||||
seen.insert(id);
|
||||
for (auto affected : relation[id]) {
|
||||
for (auto* affected : relation[id]) {
|
||||
auto affectedId = affected->mod_id();
|
||||
|
||||
if (findById(mods, affectedId) == nullptr && seen.count(affectedId) == 0) {
|
||||
if (findById(mods, affectedId) == nullptr && !seen.contains(affectedId)) {
|
||||
seen.insert(affectedId);
|
||||
if (shouldBeEnabled != affected->enabled()) {
|
||||
affectedList << affected;
|
||||
|
|
@ -348,11 +356,13 @@ QSet<Mod*> collectMods(QSet<Mod*> mods, QHash<QString, QSet<Mod*>> relation, std
|
|||
}
|
||||
return affectedList;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
QModelIndexList ModFolderModel::getAffectedMods(const QModelIndexList& indexes, EnableAction action)
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
if (indexes.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QModelIndexList affectedList = {};
|
||||
auto affectedModsList = selectedMods(indexes);
|
||||
|
|
@ -372,9 +382,9 @@ QModelIndexList ModFolderModel::getAffectedMods(const QModelIndexList& indexes,
|
|||
return {}; // this function should not be called with TOGGLE
|
||||
}
|
||||
}
|
||||
for (auto affected : affectedMods) {
|
||||
for (auto* affected : affectedMods) {
|
||||
auto affectedId = affected->mod_id();
|
||||
auto row = m_resources_index[affected->internal_id()];
|
||||
auto row = m_resourcesIndex[affected->internalId()];
|
||||
affectedList << index(row, 0);
|
||||
}
|
||||
return affectedList;
|
||||
|
|
@ -382,8 +392,9 @@ QModelIndexList ModFolderModel::getAffectedMods(const QModelIndexList& indexes,
|
|||
|
||||
bool ModFolderModel::setResourceEnabled(const QModelIndexList& indexes, EnableAction action)
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
if (indexes.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto indexedModsList = selectedMods(indexes);
|
||||
auto indexedMods = QSet(indexedModsList.begin(), indexedModsList.end());
|
||||
|
|
@ -402,7 +413,7 @@ bool ModFolderModel::setResourceEnabled(const QModelIndexList& indexes, EnableAc
|
|||
break;
|
||||
}
|
||||
case EnableAction::TOGGLE: {
|
||||
for (auto mod : indexedMods) {
|
||||
for (auto* mod : indexedMods) {
|
||||
if (mod->enabled()) {
|
||||
toDisable << mod;
|
||||
} else {
|
||||
|
|
@ -417,10 +428,10 @@ bool ModFolderModel::setResourceEnabled(const QModelIndexList& indexes, EnableAc
|
|||
auto requiredToDisable = collectMods(toDisable, m_requiredBy, seen, false);
|
||||
|
||||
toDisable.removeIf([toEnable](Mod* m) { return toEnable.contains(m); });
|
||||
auto toList = [this](QSet<Mod*> mods) {
|
||||
auto toList = [this](const QSet<Mod*>& mods) {
|
||||
QModelIndexList list;
|
||||
for (auto mod : mods) {
|
||||
auto row = m_resources_index[mod->internal_id()];
|
||||
for (auto* mod : mods) {
|
||||
auto row = m_resourcesIndex[mod->internalId()];
|
||||
list << index(row, 0);
|
||||
}
|
||||
return list;
|
||||
|
|
@ -453,8 +464,8 @@ bool ModFolderModel::setResourceEnabled(const QModelIndexList& indexes, EnableAc
|
|||
yesButton = tr("Disable Required");
|
||||
}
|
||||
|
||||
auto box = CustomMessageBox::selectable(nullptr, title, message, QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No);
|
||||
auto* box = CustomMessageBox::selectable(nullptr, title, message, QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No);
|
||||
box->button(QMessageBox::No)->setText(noButton);
|
||||
box->button(QMessageBox::Yes)->setText(yesButton);
|
||||
auto response = box->exec();
|
||||
|
|
@ -472,21 +483,23 @@ bool ModFolderModel::setResourceEnabled(const QModelIndexList& indexes, EnableAc
|
|||
return disableStatus && enableStatus;
|
||||
}
|
||||
|
||||
QStringList reqToList(QSet<Mod*> l)
|
||||
namespace {
|
||||
QStringList reqToList(const QSet<Mod*>& l)
|
||||
{
|
||||
QStringList req;
|
||||
for (auto m : l) {
|
||||
for (auto* m : l) {
|
||||
req << m->name();
|
||||
}
|
||||
return req;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
QStringList ModFolderModel::requiresList(QString id)
|
||||
QStringList ModFolderModel::requiresList(const QString& id)
|
||||
{
|
||||
return reqToList(m_requires[id]);
|
||||
}
|
||||
|
||||
QStringList ModFolderModel::requiredByList(QString id)
|
||||
QStringList ModFolderModel::requiredByList(const QString& id)
|
||||
{
|
||||
return reqToList(m_requiredBy[id]);
|
||||
}
|
||||
|
|
@ -495,7 +508,7 @@ bool ModFolderModel::deleteResources(const QModelIndexList& indexes)
|
|||
{
|
||||
auto deleteInvalid = [](QSet<Mod*>& mods) {
|
||||
for (auto it = mods.begin(); it != mods.end();) {
|
||||
auto mod = *it;
|
||||
auto* mod = *it;
|
||||
// the QFileInfo::exists is used instead of mod->fileinfo().exists
|
||||
// because the later somehow caches that the file exists
|
||||
if (!mod || !QFileInfo::exists(mod->fileinfo().absoluteFilePath())) {
|
||||
|
|
@ -506,14 +519,14 @@ bool ModFolderModel::deleteResources(const QModelIndexList& indexes)
|
|||
}
|
||||
};
|
||||
auto rsp = ResourceFolderModel::deleteResources(indexes);
|
||||
for (auto mod : allMods()) {
|
||||
for (auto* mod : allMods()) {
|
||||
auto id = mod->mod_id();
|
||||
deleteInvalid(m_requiredBy[id]);
|
||||
deleteInvalid(m_requires[id]);
|
||||
if (mod->requiredByCount() != m_requiredBy[id].count() || mod->requiresCount() != m_requires[id].count()) {
|
||||
mod->setRequiredByCount(m_requiredBy[id].count());
|
||||
mod->setRequiresCount(m_requires[id].count());
|
||||
int row = m_resources_index[mod->internal_id()];
|
||||
int row = m_resourcesIndex[mod->internalId()];
|
||||
emit dataChanged(index(row, RequiresColumn), index(row, RequiredByColumn));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue