refactor: make shared_qobject_ptr ctor explicit

This turns issues like creating two shared ptrs from a single raw ptr
from popping up at runtime, instead making them a compile error.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2023-01-24 16:52:09 -03:00
parent 5186ad95d3
commit 29f7ea752f
63 changed files with 301 additions and 287 deletions

View File

@ -130,7 +130,7 @@ static ComponentPtr componentFromJsonV1(PackProfile * parent, const QString & co
// critical
auto uid = Json::requireString(obj.value("uid"));
auto filePath = componentJsonPattern.arg(uid);
auto component = new Component(parent, uid);
auto component = makeShared<Component>(parent, uid);
component->m_version = Json::ensureString(obj.value("version"));
component->m_dependencyOnly = Json::ensureBoolean(obj.value("dependencyOnly"), false);
component->m_important = Json::ensureBoolean(obj.value("important"), false);
@ -518,23 +518,23 @@ bool PackProfile::revertToBase(int index)
return true;
}
Component * PackProfile::getComponent(const QString &id)
ComponentPtr PackProfile::getComponent(const QString &id)
{
auto iter = d->componentIndex.find(id);
if (iter == d->componentIndex.end())
{
return nullptr;
}
return (*iter).get();
return (*iter);
}
Component * PackProfile::getComponent(int index)
ComponentPtr PackProfile::getComponent(int index)
{
if(index < 0 || index >= d->components.size())
{
return nullptr;
}
return d->components[index].get();
return d->components[index];
}
QVariant PackProfile::data(const QModelIndex &index, int role) const
@ -765,7 +765,7 @@ bool PackProfile::installEmpty(const QString& uid, const QString& name)
file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
file.close();
appendComponent(new Component(this, f->uid, f));
appendComponent(makeShared<Component>(this, f->uid, f));
scheduleSave();
invalidateLaunchProfile();
return true;
@ -872,7 +872,7 @@ bool PackProfile::installJarMods_internal(QStringList filepaths)
file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
file.close();
appendComponent(new Component(this, f->uid, f));
appendComponent(makeShared<Component>(this, f->uid, f));
}
scheduleSave();
invalidateLaunchProfile();
@ -933,7 +933,7 @@ bool PackProfile::installCustomJar_internal(QString filepath)
file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
file.close();
appendComponent(new Component(this, f->uid, f));
appendComponent(makeShared<Component>(this, f->uid, f));
scheduleSave();
invalidateLaunchProfile();
@ -989,7 +989,7 @@ bool PackProfile::installAgents_internal(QStringList filepaths)
patchFile.write(OneSixVersionFormat::versionFileToJson(versionFile).toJson());
patchFile.close();
appendComponent(new Component(this, versionFile->uid, versionFile));
appendComponent(makeShared<Component>(this, versionFile->uid, versionFile));
}
scheduleSave();
@ -1038,7 +1038,7 @@ bool PackProfile::setComponentVersion(const QString& uid, const QString& version
else
{
// add new
auto component = new Component(this, uid);
auto component = makeShared<Component>(this, uid);
component->m_version = version;
component->m_important = important;
appendComponent(component);