fix: sorting by pack format
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
f21ae66265
commit
3ab17a97a8
@ -20,6 +20,7 @@ enum class SortType {
|
|||||||
DATE,
|
DATE,
|
||||||
VERSION,
|
VERSION,
|
||||||
ENABLED,
|
ENABLED,
|
||||||
|
PACK_FORMAT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class EnableAction {
|
enum class EnableAction {
|
||||||
|
@ -46,3 +46,26 @@ std::pair<Version, Version> ResourcePack::compatibleVersions() const
|
|||||||
|
|
||||||
return s_pack_format_versions.constFind(m_pack_format).value();
|
return s_pack_format_versions.constFind(m_pack_format).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<int, bool> ResourcePack::compare(const Resource& other, SortType type) const
|
||||||
|
{
|
||||||
|
auto const& cast_other = static_cast<ResourcePack const&>(other);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
default: {
|
||||||
|
auto res = Resource::compare(other, type);
|
||||||
|
if (res.first != 0)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
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 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { 0, false };
|
||||||
|
}
|
||||||
|
@ -34,6 +34,8 @@ class ResourcePack : public Resource {
|
|||||||
/** Thread-safe. */
|
/** Thread-safe. */
|
||||||
void setDescription(QString new_description);
|
void setDescription(QString new_description);
|
||||||
|
|
||||||
|
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable QMutex m_data_lock;
|
mutable QMutex m_data_lock;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir) : ResourceFolderModel(QDir(dir))
|
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir) : ResourceFolderModel(QDir(dir))
|
||||||
{
|
{
|
||||||
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE };
|
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE };
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
|
QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
|
||||||
|
Loading…
Reference in New Issue
Block a user