refactor(Mods): make provider() return a std::optional
This makes it easier to check if a mod has a provider or not, without having to do a string comparison. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
aa3633d2d7
commit
257970c27d
@ -93,10 +93,11 @@ std::pair<int, bool> Mod::compare(const Resource& other, SortType type) const
|
|||||||
if (this_ver < other_ver)
|
if (this_ver < other_ver)
|
||||||
return { -1, type == SortType::VERSION };
|
return { -1, type == SortType::VERSION };
|
||||||
}
|
}
|
||||||
case SortType::PROVIDER:
|
case SortType::PROVIDER: {
|
||||||
auto compare_result = QString::compare(provider(), cast_other->provider(), Qt::CaseInsensitive);
|
auto compare_result = QString::compare(provider().value_or("Unknown"), cast_other->provider().value_or("Unknown"), Qt::CaseInsensitive);
|
||||||
if (compare_result != 0)
|
if (compare_result != 0)
|
||||||
return { compare_result, type == SortType::PROVIDER };
|
return { compare_result, type == SortType::PROVIDER };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { 0, false };
|
return { 0, false };
|
||||||
}
|
}
|
||||||
@ -197,11 +198,9 @@ void Mod::finishResolvingWithDetails(ModDetails&& details)
|
|||||||
setMetadata(std::move(metadata));
|
setMetadata(std::move(metadata));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto Mod::provider() const -> QString
|
auto Mod::provider() const -> std::optional<QString>
|
||||||
{
|
{
|
||||||
if (metadata()) {
|
if (metadata())
|
||||||
return ProviderCaps.readableName(metadata()->provider);
|
return ProviderCaps.readableName(metadata()->provider);
|
||||||
}
|
return {};
|
||||||
//: Unknown mod provider (i.e. not Modrinth, CurseForge, etc...)
|
|
||||||
return tr("Unknown");
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include "ModDetails.h"
|
#include "ModDetails.h"
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ public:
|
|||||||
auto description() const -> QString;
|
auto description() const -> QString;
|
||||||
auto authors() const -> QStringList;
|
auto authors() const -> QStringList;
|
||||||
auto status() const -> ModStatus;
|
auto status() const -> ModStatus;
|
||||||
auto provider() const -> QString;
|
auto provider() const -> std::optional<QString>;
|
||||||
|
|
||||||
auto metadata() -> std::shared_ptr<Metadata::ModStruct>;
|
auto metadata() -> std::shared_ptr<Metadata::ModStruct>;
|
||||||
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;
|
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;
|
||||||
|
@ -83,8 +83,15 @@ QVariant ModFolderModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
case DateColumn:
|
case DateColumn:
|
||||||
return m_resources[row]->dateTimeChanged();
|
return m_resources[row]->dateTimeChanged();
|
||||||
case ProviderColumn:
|
case ProviderColumn: {
|
||||||
return at(row)->provider();
|
auto provider = at(row)->provider();
|
||||||
|
if (!provider.has_value()) {
|
||||||
|
//: Unknown mod provider (i.e. not Modrinth, CurseForge, etc...)
|
||||||
|
return tr("Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
return provider.value();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user