chore:fixed some codeql warnings

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-10-04 13:51:25 +03:00
parent 024c474658
commit 3b51c58743
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
46 changed files with 191 additions and 251 deletions

View File

@ -18,7 +18,7 @@ DataMigrationTask::DataMigrationTask(QObject* parent,
const IPathMatcher::Ptr pathMatcher)
: Task(parent), m_sourcePath(sourcePath), m_targetPath(targetPath), m_pathMatcher(pathMatcher), m_copy(sourcePath, targetPath)
{
m_copy.matcher(m_pathMatcher.get()).whitelist(true);
m_copy.matcher(m_pathMatcher).whitelist(true);
}
void DataMigrationTask::executeTask()

View File

@ -99,7 +99,7 @@ class copy : public QObject {
m_followSymlinks = follow;
return *this;
}
copy& matcher(const IPathMatcher* filter)
copy& matcher(IPathMatcher::Ptr filter)
{
m_matcher = filter;
return *this;
@ -126,7 +126,7 @@ class copy : public QObject {
private:
bool m_followSymlinks = true;
const IPathMatcher* m_matcher = nullptr;
IPathMatcher::Ptr m_matcher = nullptr;
bool m_whitelist = false;
QDir m_src;
QDir m_dst;
@ -187,7 +187,7 @@ class create_link : public QObject {
m_useHardLinks = useHard;
return *this;
}
create_link& matcher(const IPathMatcher* filter)
create_link& matcher(IPathMatcher::Ptr filter)
{
m_matcher = filter;
return *this;
@ -237,7 +237,7 @@ class create_link : public QObject {
private:
bool m_useHardLinks = false;
const IPathMatcher* m_matcher = nullptr;
IPathMatcher::Ptr m_matcher = nullptr;
bool m_whitelist = false;
bool m_recursive = true;
@ -461,7 +461,7 @@ class clone : public QObject {
m_src.setPath(src);
m_dst.setPath(dst);
}
clone& matcher(const IPathMatcher* filter)
clone& matcher(IPathMatcher::Ptr filter)
{
m_matcher = filter;
return *this;
@ -487,7 +487,7 @@ class clone : public QObject {
bool operator()(const QString& offset, bool dryRun = false);
private:
const IPathMatcher* m_matcher = nullptr;
IPathMatcher::Ptr m_matcher = nullptr;
bool m_whitelist = false;
QDir m_src;
QDir m_dst;

View File

@ -57,13 +57,13 @@ void InstanceCopyTask::executeTask()
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this, copySaves] {
if (m_useClone) {
FS::clone folderClone(m_origInstance->instanceRoot(), m_stagingPath);
folderClone.matcher(m_matcher.get());
folderClone.matcher(m_matcher);
return folderClone();
} else if (m_useLinks || m_useHardLinks) {
FS::create_link folderLink(m_origInstance->instanceRoot(), m_stagingPath);
int depth = m_linkRecursively ? -1 : 0; // we need to at least link the top level instead of the instance folder
folderLink.linkRecursively(true).setMaxDepth(depth).useHardLinks(m_useHardLinks).matcher(m_matcher.get());
folderLink.linkRecursively(true).setMaxDepth(depth).useHardLinks(m_useHardLinks).matcher(m_matcher);
bool there_were_errors = false;
@ -115,7 +115,7 @@ void InstanceCopyTask::executeTask()
return !there_were_errors;
} else {
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
folderCopy.followSymlinks(false).matcher(m_matcher.get());
folderCopy.followSymlinks(false).matcher(m_matcher);
return folderCopy();
}

View File

@ -27,7 +27,7 @@ class InstanceCopyTask : public InstanceTask {
InstancePtr m_origInstance;
QFuture<bool> m_copyFuture;
QFutureWatcher<bool> m_copyFutureWatcher;
std::unique_ptr<IPathMatcher> m_matcher;
IPathMatcher::Ptr m_matcher;
bool m_keepPlaytime;
bool m_useLinks = false;
bool m_useHardLinks = false;

View File

@ -122,7 +122,7 @@ void JavaCommon::TestCheck::run()
checker->performCheck();
}
void JavaCommon::TestCheck::checkFinished(JavaCheckResult result)
void JavaCommon::TestCheck::checkFinished(const JavaCheckResult& result)
{
if (result.validity != JavaCheckResult::Validity::Valid) {
javaBinaryWasBad(m_parent, result);
@ -141,7 +141,7 @@ void JavaCommon::TestCheck::checkFinished(JavaCheckResult result)
checker->performCheck();
}
void JavaCommon::TestCheck::checkFinishedWithArgs(JavaCheckResult result)
void JavaCommon::TestCheck::checkFinishedWithArgs(const JavaCheckResult& result)
{
if (result.validity == JavaCheckResult::Validity::Valid) {
javaWasOk(m_parent, result);

View File

@ -32,8 +32,8 @@ class TestCheck : public QObject {
void finished();
private slots:
void checkFinished(JavaCheckResult result);
void checkFinishedWithArgs(JavaCheckResult result);
void checkFinished(const JavaCheckResult& result);
void checkFinishedWithArgs(const JavaCheckResult& result);
private:
std::shared_ptr<JavaChecker> checker;

View File

@ -181,8 +181,8 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const
if (value.toBool()) {
return tr("Recommended");
} else if (hasLatest) {
auto value = sourceModel()->data(parentIndex, BaseVersionList::LatestRole);
if (value.toBool()) {
auto latest = sourceModel()->data(parentIndex, BaseVersionList::LatestRole);
if (latest.toBool()) {
return tr("Latest");
}
}
@ -191,33 +191,27 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const
}
}
case Qt::DecorationRole: {
switch (column) {
case Name: {
if (hasRecommended) {
auto recommenced = sourceModel()->data(parentIndex, BaseVersionList::RecommendedRole);
if (recommenced.toBool()) {
return APPLICATION->getThemedIcon("star");
} else if (hasLatest) {
auto latest = sourceModel()->data(parentIndex, BaseVersionList::LatestRole);
if (latest.toBool()) {
return APPLICATION->getThemedIcon("bug");
}
}
QPixmap pixmap;
QPixmapCache::find("placeholder", &pixmap);
if (!pixmap) {
QPixmap px(16, 16);
px.fill(Qt::transparent);
QPixmapCache::insert("placeholder", px);
return px;
}
return pixmap;
if (column == Name && hasRecommended) {
auto recommenced = sourceModel()->data(parentIndex, BaseVersionList::RecommendedRole);
if (recommenced.toBool()) {
return APPLICATION->getThemedIcon("star");
} else if (hasLatest) {
auto latest = sourceModel()->data(parentIndex, BaseVersionList::LatestRole);
if (latest.toBool()) {
return APPLICATION->getThemedIcon("bug");
}
}
default: {
return QVariant();
QPixmap pixmap;
QPixmapCache::find("placeholder", &pixmap);
if (!pixmap) {
QPixmap px(16, 16);
px.fill(Qt::transparent);
QPixmapCache::insert("placeholder", px);
return px;
}
return pixmap;
}
return QVariant();
}
default: {
if (roles.contains((BaseVersionList::ModelRoles)role)) {

View File

@ -38,7 +38,7 @@ class JavaChecker : public QObject {
int m_permGen = 64;
signals:
void checkFinished(JavaCheckResult result);
void checkFinished(const JavaCheckResult& result);
private:
QProcessPtr process;

View File

@ -17,7 +17,7 @@
#include <QDebug>
void JavaCheckerJob::partFinished(JavaCheckResult result)
void JavaCheckerJob::partFinished(const JavaCheckResult& result)
{
num_finished++;
qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/" << javacheckers.size();

View File

@ -43,7 +43,7 @@ class JavaCheckerJob : public Task {
QList<JavaCheckResult> getResults() { return javaresults; }
private slots:
void partFinished(JavaCheckResult result);
void partFinished(const JavaCheckResult& result);
protected:
virtual void executeTask() override;

View File

@ -43,7 +43,7 @@ QString JavaVersion::toString() const
return m_string;
}
bool JavaVersion::requiresPermGen()
bool JavaVersion::requiresPermGen() const
{
if (m_parseable) {
return m_major < 8;

View File

@ -23,7 +23,7 @@ class JavaVersion {
bool operator==(const JavaVersion& rhs);
bool operator>(const JavaVersion& rhs);
bool requiresPermGen();
bool requiresPermGen() const;
QString toString() const;

View File

@ -106,7 +106,7 @@ void CheckJava::executeTask()
emitSucceeded();
}
void CheckJava::checkJavaFinished(JavaCheckResult result)
void CheckJava::checkJavaFinished(const JavaCheckResult& result)
{
switch (result.validity) {
case JavaCheckResult::Validity::Errored: {

View File

@ -28,7 +28,7 @@ class CheckJava : public LaunchStep {
virtual void executeTask();
virtual bool canAbort() const { return false; }
private slots:
void checkJavaFinished(JavaCheckResult result);
void checkJavaFinished(const JavaCheckResult& result);
private:
void printJavaInfo(const QString& version, const QString& architecture, const QString& realArchitecture, const QString& vendor);

View File

@ -506,13 +506,9 @@ QVariant PackProfile::data(const QModelIndex& index, int role) const
switch (role) {
case Qt::CheckStateRole: {
switch (column) {
case NameColumn: {
return patch->isEnabled() ? Qt::Checked : Qt::Unchecked;
}
default:
return QVariant();
}
if (column == NameColumn)
return patch->isEnabled() ? Qt::Checked : Qt::Unchecked;
return QVariant();
}
case Qt::DisplayRole: {
switch (column) {

View File

@ -208,13 +208,9 @@ QVariant WorldList::data(const QModelIndex& index, int role) const
}
case Qt::UserRole:
switch (column) {
case SizeColumn:
return QVariant::fromValue<qlonglong>(world.bytes());
default:
return data(index, Qt::DisplayRole);
}
if (column == SizeColumn)
return QVariant::fromValue<qlonglong>(world.bytes());
return data(index, Qt::DisplayRole);
case Qt::ToolTipRole: {
if (column == InfoColumn) {

View File

@ -262,6 +262,30 @@ int AccountList::count() const
return m_accounts.count();
}
QString getAccountStatus(AccountState status)
{
switch (status) {
case AccountState::Unchecked:
return QObject::tr("Unchecked", "Account status");
case AccountState::Offline:
return QObject::tr("Offline", "Account status");
case AccountState::Online:
return QObject::tr("Ready", "Account status");
case AccountState::Working:
return QObject::tr("Working", "Account status");
case AccountState::Errored:
return QObject::tr("Errored", "Account status");
case AccountState::Expired:
return QObject::tr("Expired", "Account status");
case AccountState::Disabled:
return QObject::tr("Disabled", "Account status");
case AccountState::Gone:
return QObject::tr("Gone", "Account status");
default:
return QObject::tr("Unknown", "Account status");
}
}
QVariant AccountList::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
@ -275,51 +299,17 @@ QVariant AccountList::data(const QModelIndex& index, int role) const
switch (role) {
case Qt::DisplayRole:
switch (index.column()) {
case ProfileNameColumn: {
case ProfileNameColumn:
return account->profileName();
}
case NameColumn:
return account->accountDisplayString();
case TypeColumn: {
auto typeStr = account->typeString();
typeStr[0] = typeStr[0].toUpper();
return typeStr;
}
case StatusColumn: {
switch (account->accountState()) {
case AccountState::Unchecked: {
return tr("Unchecked", "Account status");
}
case AccountState::Offline: {
return tr("Offline", "Account status");
}
case AccountState::Online: {
return tr("Ready", "Account status");
}
case AccountState::Working: {
return tr("Working", "Account status");
}
case AccountState::Errored: {
return tr("Errored", "Account status");
}
case AccountState::Expired: {
return tr("Expired", "Account status");
}
case AccountState::Disabled: {
return tr("Disabled", "Account status");
}
case AccountState::Gone: {
return tr("Gone", "Account status");
}
default: {
return tr("Unknown", "Account status");
}
}
}
case StatusColumn:
return getAccountStatus(account->accountState());
default:
return QVariant();
}
@ -331,11 +321,9 @@ QVariant AccountList::data(const QModelIndex& index, int role) const
return QVariant::fromValue(account);
case Qt::CheckStateRole:
if (index.column() == ProfileNameColumn) {
if (index.column() == ProfileNameColumn)
return account == m_defaultAccount ? Qt::Checked : Qt::Unchecked;
} else {
return QVariant();
}
return QVariant();
default:
return QVariant();
@ -457,18 +445,14 @@ bool AccountList::loadList()
// Make sure the format version matches.
auto listVersion = root.value("formatVersion").toVariant().toInt();
switch (listVersion) {
case AccountListVersion::MojangMSA: {
return loadV3(root);
} break;
default: {
QString newName = "accounts-old.json";
qWarning() << "Unknown format version when loading account list. Existing one will be renamed to" << newName;
// Attempt to rename the old version.
file.rename(newName);
return false;
}
}
if (listVersion == AccountListVersion::MojangMSA)
return loadV3(root);
QString newName = "accounts-old.json";
qWarning() << "Unknown format version when loading account list. Existing one will be renamed to" << newName;
// Attempt to rename the old version.
file.rename(newName);
return false;
}
bool AccountList::loadV3(QJsonObject& root)

View File

@ -45,18 +45,12 @@ void AuthFlow::nextStep()
QString AuthFlow::getStateMessage() const
{
switch (m_taskState) {
case AccountTaskState::STATE_WORKING: {
if (m_currentStep) {
return m_currentStep->describe();
} else {
return tr("Working...");
}
}
default: {
return AccountTask::getStateMessage();
}
if (m_taskState == AccountTaskState::STATE_WORKING) {
if (m_currentStep)
return m_currentStep->describe();
return tr("Working...");
}
return AccountTask::getStateMessage();
}
void AuthFlow::stepFinished(AccountTaskState resultingState, QString message)

View File

@ -87,16 +87,12 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
if (row < 0 || row >= int(contents.size()))
return QVariant();
switch (role) {
case Qt::DisplayRole:
if (column == 0) {
return contents[row].key;
} else {
return contents[row].value;
}
default:
return QVariant();
if (role == Qt::DisplayRole) {
if (column == 0)
return contents[row].key;
return contents[row].value;
}
return QVariant();
}
int GameOptions::rowCount(const QModelIndex&) const

View File

@ -68,24 +68,18 @@ std::pair<Version, Version> DataPack::compatibleVersions() const
std::pair<int, bool> DataPack::compare(const Resource& other, SortType type) const
{
auto const& cast_other = static_cast<DataPack const&>(other);
if (type == SortType::PACK_FORMAT) {
auto this_ver = packFormat();
auto other_ver = cast_other.packFormat();
switch (type) {
default: {
auto res = Resource::compare(other, type);
if (res.first != 0)
return res;
break;
}
case SortType::PACK_FORMAT: {
auto this_ver = packFormat();
auto other_ver = cast_other.packFormat();
if (this_ver > other_ver)
return { 1, type == SortType::PACK_FORMAT };
if (this_ver < other_ver)
return { -1, type == SortType::PACK_FORMAT };
break;
}
if (this_ver > other_ver)
return { 1, type == SortType::PACK_FORMAT };
if (this_ver < other_ver)
return { -1, type == SortType::PACK_FORMAT };
} else {
auto res = Resource::compare(other, type);
if (res.first != 0)
return res;
}
return { 0, false };
}

View File

@ -132,12 +132,9 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
return {};
}
case Qt::CheckStateRole:
switch (column) {
case ActiveColumn:
return at(row)->enabled() ? Qt::Checked : Qt::Unchecked;
default:
return QVariant();
}
if (column == ActiveColumn)
return at(row)->enabled() ? Qt::Checked : Qt::Unchecked;
return QVariant();
default:
return QVariant();
}

View File

@ -440,12 +440,9 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const
return {};
}
case Qt::CheckStateRole:
switch (column) {
case ACTIVE_COLUMN:
return m_resources[row]->enabled() ? Qt::Checked : Qt::Unchecked;
default:
return {};
}
if (column == ACTIVE_COLUMN)
return m_resources[row]->enabled() ? Qt::Checked : Qt::Unchecked;
return {};
default:
return {};
}

View File

@ -97,24 +97,18 @@ std::pair<Version, Version> ResourcePack::compatibleVersions() const
std::pair<int, bool> ResourcePack::compare(const Resource& other, SortType type) const
{
auto const& cast_other = static_cast<ResourcePack const&>(other);
if (type == SortType::PACK_FORMAT) {
auto this_ver = packFormat();
auto other_ver = cast_other.packFormat();
switch (type) {
default: {
auto res = Resource::compare(other, type);
if (res.first != 0)
return res;
break;
}
case SortType::PACK_FORMAT: {
auto this_ver = packFormat();
auto other_ver = cast_other.packFormat();
if (this_ver > other_ver)
return { 1, type == SortType::PACK_FORMAT };
if (this_ver < other_ver)
return { -1, type == SortType::PACK_FORMAT };
break;
}
if (this_ver > other_ver)
return { 1, type == SortType::PACK_FORMAT };
if (this_ver < other_ver)
return { -1, type == SortType::PACK_FORMAT };
} else {
auto res = Resource::compare(other, type);
if (res.first != 0)
return res;
}
return { 0, false };
}

View File

@ -118,12 +118,9 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
return m_resources[row]->internal_id();
}
case Qt::CheckStateRole:
switch (column) {
case ActiveColumn:
return at(row)->enabled() ? Qt::Checked : Qt::Unchecked;
default:
return {};
}
if (column == ActiveColumn)
return at(row)->enabled() ? Qt::Checked : Qt::Unchecked;
return {};
default:
return {};
}

View File

@ -62,7 +62,7 @@ class UserInteractionSupport {
/**
* Requests a user interaction to select which optional mods should be installed.
*/
virtual std::optional<QVector<QString>> chooseOptionalMods(PackVersion version, QVector<ATLauncher::VersionMod> mods) = 0;
virtual std::optional<QVector<QString>> chooseOptionalMods(const PackVersion& version, QVector<ATLauncher::VersionMod> mods) = 0;
/**
* Requests a user interaction to select a component version from a given version list

View File

@ -40,7 +40,7 @@ class PackFetchTask : public QObject {
void failed(QString reason);
void aborted();
void privateFileDownloadFinished(Modpack modpack);
void privateFileDownloadFinished(const Modpack& modpack);
void privateFileDownloadFailed(QString reason, QString packCode);
};

View File

@ -52,7 +52,7 @@
namespace LegacyFTB {
PackInstallTask::PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, Modpack pack, QString version)
PackInstallTask::PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, const Modpack& pack, QString version)
{
m_pack = pack;
m_version = version;

View File

@ -18,7 +18,7 @@ class PackInstallTask : public InstanceTask {
Q_OBJECT
public:
explicit PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, Modpack pack, QString version);
explicit PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, const Modpack& pack, QString version);
virtual ~PackInstallTask() {}
bool canAbort() const override { return true; }

View File

@ -1,3 +1,5 @@
#pragma once
#include <SeparatorPrefixTree.h>
#include <QRegularExpression>
#include "IPathMatcher.h"

View File

@ -1,3 +1,5 @@
#pragma once
#include <QRegularExpression>
#include "IPathMatcher.h"

View File

@ -267,6 +267,7 @@ auto ModUpdateDialog::ensureMetadata() -> bool
bool skip_rest = false;
ModPlatform::ResourceProvider provider_rest = ModPlatform::ResourceProvider::MODRINTH;
// adds mod to list based on provider
auto addToTmp = [&](Mod* m, ModPlatform::ResourceProvider p) {
switch (p) {
case ModPlatform::ResourceProvider::MODRINTH:
@ -278,6 +279,7 @@ auto ModUpdateDialog::ensureMetadata() -> bool
}
};
// ask the user on what provider to seach for the mod first
for (auto candidate : m_candidates) {
if (candidate->status() != ModStatus::NoMetadata) {
onMetadataEnsured(candidate);
@ -320,6 +322,7 @@ auto ModUpdateDialog::ensureMetadata() -> bool
addToTmp(candidate, response.chosen);
}
// prepare task for the modrinth mods
if (!modrinth_tmp.empty()) {
auto modrinth_task = makeShared<EnsureMetadataTask>(modrinth_tmp, index_dir, ModPlatform::ResourceProvider::MODRINTH);
connect(modrinth_task.get(), &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
@ -333,6 +336,7 @@ auto ModUpdateDialog::ensureMetadata() -> bool
seq.addTask(modrinth_task);
}
// prepare task for the flame mods
if (!flame_tmp.empty()) {
auto flame_task = makeShared<EnsureMetadataTask>(flame_tmp, index_dir, ModPlatform::ResourceProvider::FLAME);
connect(flame_task.get(), &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
@ -348,6 +352,7 @@ auto ModUpdateDialog::ensureMetadata() -> bool
seq.addTask(m_second_try_metadata);
// execute all the tasks
ProgressDialog checking_dialog(m_parent);
checking_dialog.setSkipButton(true, tr("Abort"));
checking_dialog.setWindowTitle(tr("Generating metadata..."));
@ -444,13 +449,8 @@ void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info, QStri
auto changelog_area = new QTextBrowser();
QString text = info.changelog;
switch (info.provider) {
case ModPlatform::ResourceProvider::MODRINTH: {
text = markdownToHTML(info.changelog.toUtf8());
break;
}
default:
break;
if (info.provider == ModPlatform::ResourceProvider::MODRINTH) {
text = markdownToHTML(info.changelog.toUtf8());
}
changelog_area->setHtml(text);

View File

@ -316,10 +316,10 @@ class ServersModel : public QAbstractListModel {
if (row < 0 || row >= m_servers.size())
return QVariant();
switch (column) {
case 0:
switch (role) {
case Qt::DecorationRole: {
switch (role) {
case Qt::DecorationRole: {
switch (column) {
case 0: {
auto& bytes = m_servers[row].m_icon;
if (bytes.size()) {
QPixmap px;
@ -328,27 +328,24 @@ class ServersModel : public QAbstractListModel {
}
return APPLICATION->getThemedIcon("unknown_server");
}
case Qt::DisplayRole:
return m_servers[row].m_name;
case ServerPtrRole:
return QVariant::fromValue<void*>((void*)&m_servers[row]);
default:
return QVariant();
}
case 1:
switch (role) {
case Qt::DisplayRole:
case 1:
return m_servers[row].m_address;
default:
return QVariant();
}
case 2:
switch (role) {
case Qt::DisplayRole:
case 2:
return m_servers[row].m_ping;
default:
return QVariant();
}
}
case Qt::DisplayRole:
if (column == 0)
return m_servers[row].m_name;
else
return QVariant();
case ServerPtrRole:
if (column == 0)
return QVariant::fromValue<void*>((void*)&m_servers[row]);
else
return QVariant();
default:
return QVariant();
}

View File

@ -161,12 +161,9 @@ void WorldListPage::retranslate()
bool WorldListPage::worldListFilter(QKeyEvent* keyEvent)
{
switch (keyEvent->key()) {
case Qt::Key_Delete:
on_actionRemove_triggered();
return true;
default:
break;
if (keyEvent->key() == Qt::Key_Delete) {
on_actionRemove_triggered();
return true;
}
return QWidget::eventFilter(ui->worldTreeView, keyEvent);
}

View File

@ -45,7 +45,9 @@
#include "net/ApiDownload.h"
AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent,
const ATLauncher::PackVersion& version,
QVector<ATLauncher::VersionMod> mods)
: QAbstractListModel(parent), m_version(version), m_mods(mods)
{
// fill mod index
@ -233,7 +235,7 @@ void AtlOptionalModListModel::clearAll()
emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn));
}
void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index)
void AtlOptionalModListModel::toggleMod(const ATLauncher::VersionMod& mod, int index)
{
auto enable = !m_selection[mod.name];
@ -251,7 +253,7 @@ void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index)
setMod(mod, index, enable);
}
void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit)
void AtlOptionalModListModel::setMod(const ATLauncher::VersionMod& mod, int index, bool enable, bool shouldEmit)
{
if (m_selection[mod.name] == enable)
return;
@ -313,7 +315,7 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
}
}
AtlOptionalModDialog::AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
AtlOptionalModDialog::AtlOptionalModDialog(QWidget* parent, const ATLauncher::PackVersion& version, QVector<ATLauncher::VersionMod> mods)
: QDialog(parent), ui(new Ui::AtlOptionalModDialog)
{
ui->setupUi(this);

View File

@ -55,7 +55,7 @@ class AtlOptionalModListModel : public QAbstractListModel {
DescriptionColumn,
};
AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods);
AtlOptionalModListModel(QWidget* parent, const ATLauncher::PackVersion& version, QVector<ATLauncher::VersionMod> mods);
QVector<QString> getResult();
@ -78,8 +78,8 @@ class AtlOptionalModListModel : public QAbstractListModel {
void clearAll();
private:
void toggleMod(ATLauncher::VersionMod mod, int index);
void setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit = true);
void toggleMod(const ATLauncher::VersionMod& mod, int index);
void setMod(const ATLauncher::VersionMod& mod, int index, bool enable, bool shouldEmit = true);
private:
NetJob::Ptr m_jobPtr;
@ -97,7 +97,7 @@ class AtlOptionalModDialog : public QDialog {
Q_OBJECT
public:
AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods);
AtlOptionalModDialog(QWidget* parent, const ATLauncher::PackVersion& version, QVector<ATLauncher::VersionMod> mods);
~AtlOptionalModDialog() override;
QVector<QString> getResult() { return listModel->getResult(); }

View File

@ -41,7 +41,7 @@
AtlUserInteractionSupportImpl::AtlUserInteractionSupportImpl(QWidget* parent) : m_parent(parent) {}
std::optional<QVector<QString>> AtlUserInteractionSupportImpl::chooseOptionalMods(ATLauncher::PackVersion version,
std::optional<QVector<QString>> AtlUserInteractionSupportImpl::chooseOptionalMods(const ATLauncher::PackVersion& version,
QVector<ATLauncher::VersionMod> mods)
{
AtlOptionalModDialog optionalModDialog(m_parent, version, mods);

View File

@ -48,7 +48,8 @@ class AtlUserInteractionSupportImpl : public QObject, public ATLauncher::UserInt
private:
QString chooseVersion(Meta::VersionList::Ptr vlist, QString minecraftVersion) override;
std::optional<QVector<QString>> chooseOptionalMods(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) override;
std::optional<QVector<QString>> chooseOptionalMods(const ATLauncher::PackVersion& version,
QVector<ATLauncher::VersionMod> mods) override;
void displayMessage(QString message) override;
private:

View File

@ -73,9 +73,6 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
}
auto pack = modpacks.at(pos);
if (role == Qt::ToolTipRole) {
}
switch (role) {
case Qt::ToolTipRole:
return tr("Minecraft %1").arg(pack.mcVersion);

View File

@ -213,7 +213,7 @@ void ListModel::fill(ModpackList modpacks_)
endResetModel();
}
void ListModel::addPack(Modpack modpack)
void ListModel::addPack(const Modpack& modpack)
{
beginResetModel();
this->modpacks.append(modpack);

View File

@ -62,7 +62,7 @@ class ListModel : public QAbstractListModel {
Qt::ItemFlags flags(const QModelIndex& index) const override;
void fill(ModpackList modpacks);
void addPack(Modpack modpack);
void addPack(const Modpack& modpack);
void clear();
void remove(int row);

View File

@ -216,7 +216,7 @@ void Page::ftbPackDataDownloadAborted()
CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information)->show();
}
void Page::ftbPrivatePackDataDownloadSuccessfully(Modpack pack)
void Page::ftbPrivatePackDataDownloadSuccessfully(const Modpack& pack)
{
privateListModel->addPack(pack);
}

View File

@ -80,7 +80,7 @@ class Page : public QWidget, public BasePage {
void ftbPackDataDownloadFailed(QString reason);
void ftbPackDataDownloadAborted();
void ftbPrivatePackDataDownloadSuccessfully(Modpack pack);
void ftbPrivatePackDataDownloadSuccessfully(const Modpack& pack);
void ftbPrivatePackDataDownloadFailed(QString reason, QString packCode);
void onSortingSelectionChanged(QString data);

View File

@ -1,3 +1,5 @@
#pragma once
#include <QLineEdit>
class FocusLineEdit : public QLineEdit {

View File

@ -370,7 +370,7 @@ void JavaSettingsWidget::checkJavaPath(const QString& path)
m_checker->performCheck();
}
void JavaSettingsWidget::checkFinished(JavaCheckResult result)
void JavaSettingsWidget::checkFinished(const JavaCheckResult& result)
{
m_result = result;
switch (result.validity) {

View File

@ -50,7 +50,7 @@ class JavaSettingsWidget : public QWidget {
void javaVersionSelected(BaseVersion::Ptr version);
void on_javaBrowseBtn_clicked();
void on_javaStatusBtn_clicked();
void checkFinished(JavaCheckResult result);
void checkFinished(const JavaCheckResult& result);
protected: /* methods */
void checkJavaPathOnEdit(const QString& path);

View File

@ -2,6 +2,7 @@
#include <QStandardPaths>
#include <QTemporaryDir>
#include <QTest>
#include <memory>
#include <tasks/Task.h>
@ -42,7 +43,7 @@ class LinkTask : public Task {
~LinkTask() { delete m_lnk; }
void matcher(const IPathMatcher* filter) { m_lnk->matcher(filter); }
void matcher(IPathMatcher::Ptr filter) { m_lnk->matcher(filter); }
void linkRecursively(bool recursive)
{
@ -237,8 +238,8 @@ class FileSystemTest : public QObject {
qDebug() << tempDir.path();
qDebug() << target_dir.path();
FS::copy c(folder, target_dir.path());
RegexpMatcher re("[.]?mcmeta");
c.matcher(&re);
RegexpMatcher::Ptr re = std::make_shared<RegexpMatcher>("[.]?mcmeta");
c.matcher(re);
c();
for (auto entry : target_dir.entryList()) {
@ -270,8 +271,8 @@ class FileSystemTest : public QObject {
qDebug() << tempDir.path();
qDebug() << target_dir.path();
FS::copy c(folder, target_dir.path());
RegexpMatcher re("[.]?mcmeta");
c.matcher(&re);
RegexpMatcher::Ptr re = std::make_shared<RegexpMatcher>("[.]?mcmeta");
c.matcher(re);
c.whitelist(true);
c();
@ -462,8 +463,8 @@ class FileSystemTest : public QObject {
qDebug() << target_dir.path();
LinkTask lnk_tsk(folder, target_dir.path());
RegexpMatcher re("[.]?mcmeta");
lnk_tsk.matcher(&re);
RegexpMatcher::Ptr re = std::make_shared<RegexpMatcher>("[.]?mcmeta");
lnk_tsk.matcher(re);
lnk_tsk.linkRecursively(true);
QObject::connect(&lnk_tsk, &Task::finished,
[&] { QVERIFY2(lnk_tsk.wasSuccessful(), "Task finished but was not successful when it should have been."); });
@ -508,8 +509,8 @@ class FileSystemTest : public QObject {
qDebug() << target_dir.path();
LinkTask lnk_tsk(folder, target_dir.path());
RegexpMatcher re("[.]?mcmeta");
lnk_tsk.matcher(&re);
RegexpMatcher::Ptr re = std::make_shared<RegexpMatcher>("[.]?mcmeta");
lnk_tsk.matcher(re);
lnk_tsk.linkRecursively(true);
lnk_tsk.whitelist(true);
QObject::connect(&lnk_tsk, &Task::finished,