chore(clang-tidy): modernize the code

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-05-11 23:16:39 +03:00
parent 18f04b1e29
commit 9c88eb9bc0
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
36 changed files with 713 additions and 632 deletions

View file

@ -69,12 +69,12 @@ ModFolderModel::ModFolderModel(const QDir& dir, BaseInstance* instance, bool isI
tr("Requires"), tr("Required By"), tr("File Name"), tr("Update") });
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, SortType::LOCK_UPDATE };
SortType::ReleaseType, SortType::Requires, SortType::RequiredBy, SortType::Filename, SortType::LockUpdate };
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, QHeaderView::Interactive };
m_columnsHideable = { false, true, false, true, true, true, true, true, true, true, true, true, true, true };
m_columnsHideable = { false, true, false, true, true, true, true, true, true, true, true, true, true, true, true };
connect(this, &ModFolderModel::parseFinished, this, &ModFolderModel::onParseFinished);
}
@ -137,13 +137,15 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
}
break;
case Qt::CheckStateRole:
if (column == ActiveColumn)
if (column == ActiveColumn) {
return at(row).enabled() ? Qt::Checked : Qt::Unchecked;
return QVariant();
}
return {};
case Qt::UserRole:
if (column == LockUpdateCoumn)
if (column == LockUpdateCoumn) {
return at(row).lockUpdate();
return QVariant();
}
return {};
default:
break;
}
@ -285,7 +287,7 @@ void ModFolderModel::onParseSucceeded(int ticket, const QString& resourceId)
namespace {
Mod* findById(QSet<Mod*> mods, const QString& resourceId)
{
auto found = std::ranges::find_if(mods, [resourceId](Mod* m) { return m->mod_id() == resourceId; });
auto found = std::ranges::find_if(mods, [resourceId](Mod* m) { return m->modId() == resourceId; });
return found != mods.end() ? *found : nullptr;
}
} // namespace
@ -303,17 +305,17 @@ void ModFolderModel::onParseFinished()
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 m->metadata() && m->metadata()->provider == provider && m->metadata()->projectId == modId;
});
return found != mods.end() ? *found : nullptr;
};
for (auto* mod : mods) {
auto id = mod->mod_id();
auto id = mod->modId();
for (const auto& dep : mod->dependencies()) {
auto* d = findById(mods, dep);
if (d) {
m_requires[id] << d;
m_requiredBy[d->mod_id()] << mod;
m_requiredBy[d->modId()] << mod;
}
}
if (mod->metadata()) {
@ -322,17 +324,17 @@ void ModFolderModel::onParseFinished()
auto* d = findByProjectID(dep.addonId, mod->metadata()->provider);
if (d) {
m_requires[id] << d;
m_requiredBy[d->mod_id()] << mod;
m_requiredBy[d->modId()] << mod;
}
}
}
}
}
for (auto* mod : mods) {
auto id = mod->mod_id();
auto id = mod->modId();
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());
mod->setRequiredByCount(static_cast<int>(m_requiredBy[id].count()));
mod->setRequiresCount(static_cast<int>(m_requires[id].count()));
int row = m_resourcesIndex[mod->internalId()];
emit dataChanged(index(row), index(row, columnCount(QModelIndex()) - 1));
}
@ -346,11 +348,11 @@ QSet<Mod*> collectMods(const QSet<Mod*>& mods, QHash<QString, QSet<Mod*>> relati
QSet<Mod*> affectedList = {};
QSet<Mod*> needToCheck = {};
for (auto* mod : mods) {
auto id = mod->mod_id();
auto id = mod->modId();
if (!seen.contains(id)) {
seen.insert(id);
for (auto* affected : relation[id]) {
auto affectedId = affected->mod_id();
auto affectedId = affected->modId();
if (findById(mods, affectedId) == nullptr && !seen.contains(affectedId)) {
seen.insert(affectedId);
@ -395,7 +397,7 @@ QModelIndexList ModFolderModel::getAffectedMods(const QModelIndexList& indexes,
}
}
for (auto* affected : affectedMods) {
auto affectedId = affected->mod_id();
auto affectedId = affected->modId();
auto row = m_resourcesIndex[affected->internalId()];
affectedList << index(row, 0);
}
@ -457,20 +459,20 @@ bool ModFolderModel::setResourceEnabled(const QModelIndexList& indexes, EnableAc
if (requiredToEnable.size() > 0 && requiredToDisable.size() > 0) {
title = tr("Confirm toggle");
message = tr("Toggling these mod(s) will cause changes to other mods.\n") +
tr("%n mod(s) will be enabled\n", "", requiredToEnable.size()) +
tr("%n mod(s) will be disabled\n", "", requiredToDisable.size()) +
tr("%n mod(s) will be enabled\n", "", static_cast<int>(requiredToEnable.size())) +
tr("%n mod(s) will be disabled\n", "", static_cast<int>(requiredToDisable.size())) +
tr("Do you want to automatically apply these related changes?\nIgnoring them may break the game.");
noButton = tr("Only Toggle Selected");
yesButton = tr("Toggle Required Mods");
} else if (requiredToEnable.size() > 0) {
title = tr("Confirm enable");
message = tr("The enabled mod(s) require %n mod(s).\n", "", requiredToEnable.size()) +
message = tr("The enabled mod(s) require %n mod(s).\n", "", static_cast<int>(requiredToEnable.size())) +
tr("Would you like to enable them as well?\nIgnoring them may break the game.");
noButton = tr("Only Enable Selected");
yesButton = tr("Enable Required");
} else {
title = tr("Confirm disable");
message = tr("The disabled mod(s) are required by %n mod(s).\n", "", requiredToDisable.size()) +
message = tr("The disabled mod(s) are required by %n mod(s).\n", "", static_cast<int>(requiredToDisable.size())) +
tr("Would you like to disable them as well?\nIgnoring them may break the game.");
noButton = tr("Only Disable Selected");
yesButton = tr("Disable Required");
@ -532,12 +534,12 @@ bool ModFolderModel::deleteResources(const QModelIndexList& indexes)
};
auto rsp = ResourceFolderModel::deleteResources(indexes);
for (auto* mod : allMods()) {
auto id = mod->mod_id();
auto id = mod->modId();
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());
mod->setRequiredByCount(static_cast<int>(m_requiredBy[id].count()));
mod->setRequiresCount(static_cast<int>(m_requires[id].count()));
int row = m_resourcesIndex[mod->internalId()];
emit dataChanged(index(row, RequiresColumn), index(row, RequiredByColumn));
}