Update size order for folders
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
242ddbb7e1
commit
29d32f0d9a
@ -65,12 +65,12 @@ std::pair<Version, Version> DataPack::compatibleVersions() const
|
|||||||
return s_pack_format_versions.constFind(m_pack_format).value();
|
return s_pack_format_versions.constFind(m_pack_format).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataPack::compare(const Resource& other, SortType type, Qt::SortOrder order) const
|
int DataPack::compare(const Resource& other, SortType type) const
|
||||||
{
|
{
|
||||||
auto const& cast_other = static_cast<DataPack const&>(other);
|
auto const& cast_other = static_cast<DataPack const&>(other);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default:
|
default:
|
||||||
return Resource::compare(other, type, order);
|
return Resource::compare(other, type);
|
||||||
case SortType::PACK_FORMAT: {
|
case SortType::PACK_FORMAT: {
|
||||||
auto this_ver = packFormat();
|
auto this_ver = packFormat();
|
||||||
auto other_ver = cast_other.packFormat();
|
auto other_ver = cast_other.packFormat();
|
||||||
|
@ -56,7 +56,7 @@ class DataPack : public Resource {
|
|||||||
|
|
||||||
bool valid() const override;
|
bool valid() const override;
|
||||||
|
|
||||||
[[nodiscard]] int compare(Resource const& other, SortType type, Qt::SortOrder order = Qt::SortOrder::AscendingOrder) const override;
|
[[nodiscard]] int compare(Resource const& other, SortType type) const override;
|
||||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -78,11 +78,11 @@ void Mod::setDetails(const ModDetails& details)
|
|||||||
m_local_details = details;
|
m_local_details = details;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Mod::compare(const Resource& other, SortType type, Qt::SortOrder order) const
|
int Mod::compare(const Resource& other, SortType type) const
|
||||||
{
|
{
|
||||||
auto cast_other = dynamic_cast<Mod const*>(&other);
|
auto cast_other = dynamic_cast<Mod const*>(&other);
|
||||||
if (!cast_other)
|
if (!cast_other)
|
||||||
return Resource::compare(other, type, order);
|
return Resource::compare(other, type);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default:
|
default:
|
||||||
@ -90,7 +90,7 @@ int Mod::compare(const Resource& other, SortType type, Qt::SortOrder order) cons
|
|||||||
case SortType::NAME:
|
case SortType::NAME:
|
||||||
case SortType::DATE:
|
case SortType::DATE:
|
||||||
case SortType::SIZE:
|
case SortType::SIZE:
|
||||||
return Resource::compare(other, type, order);
|
return Resource::compare(other, type);
|
||||||
case SortType::VERSION: {
|
case SortType::VERSION: {
|
||||||
auto this_ver = Version(version());
|
auto this_ver = Version(version());
|
||||||
auto other_ver = Version(cast_other->version());
|
auto other_ver = Version(cast_other->version());
|
||||||
|
@ -88,7 +88,7 @@ class Mod : public Resource {
|
|||||||
|
|
||||||
bool valid() const override;
|
bool valid() const override;
|
||||||
|
|
||||||
[[nodiscard]] int compare(Resource const& other, SortType type, Qt::SortOrder order = Qt::SortOrder::AscendingOrder) const override;
|
[[nodiscard]] int compare(Resource const& other, SortType type) const override;
|
||||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||||
|
|
||||||
// Delete all the files of this mod
|
// Delete all the files of this mod
|
||||||
|
@ -79,7 +79,7 @@ static void removeThePrefix(QString& string)
|
|||||||
string = string.trimmed();
|
string = string.trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Resource::compare(const Resource& other, SortType type, Qt::SortOrder order) const
|
int Resource::compare(const Resource& other, SortType type) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default:
|
default:
|
||||||
@ -105,12 +105,11 @@ int Resource::compare(const Resource& other, SortType type, Qt::SortOrder order)
|
|||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case SortType::SIZE: {
|
case SortType::SIZE: {
|
||||||
auto order_op = order == Qt::SortOrder::AscendingOrder ? 1 : -1;
|
|
||||||
if (this->type() != other.type()) {
|
if (this->type() != other.type()) {
|
||||||
if (this->type() == ResourceType::FOLDER)
|
if (this->type() == ResourceType::FOLDER)
|
||||||
return -1 * order_op;
|
return -1;
|
||||||
if (other.type() == ResourceType::FOLDER)
|
if (other.type() == ResourceType::FOLDER)
|
||||||
return 1 * order_op;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizeInfo() > other.sizeInfo())
|
if (sizeInfo() > other.sizeInfo())
|
||||||
|
@ -55,11 +55,8 @@ class Resource : public QObject {
|
|||||||
* > 0: 'this' comes after 'other'
|
* > 0: 'this' comes after 'other'
|
||||||
* = 0: 'this' is equal to 'other'
|
* = 0: 'this' is equal to 'other'
|
||||||
* < 0: 'this' comes before 'other'
|
* < 0: 'this' comes before 'other'
|
||||||
* the order is used to force items to be allways at top and not used for sorting
|
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] virtual int compare(Resource const& other,
|
[[nodiscard]] virtual int compare(Resource const& other, SortType type = SortType::NAME) const;
|
||||||
SortType type = SortType::NAME,
|
|
||||||
Qt::SortOrder order = Qt::SortOrder::AscendingOrder) const;
|
|
||||||
|
|
||||||
/** Returns whether the given filter should filter out 'this' (false),
|
/** Returns whether the given filter should filter out 'this' (false),
|
||||||
* or if such filter includes the Resource (true).
|
* or if such filter includes the Resource (true).
|
||||||
|
@ -615,7 +615,7 @@ SortType ResourceFolderModel::columnToSortKey(size_t column) const
|
|||||||
auto const& resource_left = model->at(source_left.row());
|
auto const& resource_left = model->at(source_left.row());
|
||||||
auto const& resource_right = model->at(source_right.row());
|
auto const& resource_right = model->at(source_right.row());
|
||||||
|
|
||||||
auto compare_result = resource_left.compare(resource_right, column_sort_key, sortOrder());
|
auto compare_result = resource_left.compare(resource_right, column_sort_key);
|
||||||
if (compare_result == 0)
|
if (compare_result == 0)
|
||||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
||||||
|
|
||||||
|
@ -94,12 +94,12 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResourcePack::compare(const Resource& other, SortType type, Qt::SortOrder order) const
|
int ResourcePack::compare(const Resource& other, SortType type) const
|
||||||
{
|
{
|
||||||
auto const& cast_other = static_cast<ResourcePack const&>(other);
|
auto const& cast_other = static_cast<ResourcePack const&>(other);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default:
|
default:
|
||||||
return Resource::compare(other, type, order);
|
return Resource::compare(other, type);
|
||||||
case SortType::PACK_FORMAT: {
|
case SortType::PACK_FORMAT: {
|
||||||
auto this_ver = packFormat();
|
auto this_ver = packFormat();
|
||||||
auto other_ver = cast_other.packFormat();
|
auto other_ver = cast_other.packFormat();
|
||||||
|
@ -44,7 +44,7 @@ class ResourcePack : public Resource {
|
|||||||
|
|
||||||
bool valid() const override;
|
bool valid() const override;
|
||||||
|
|
||||||
[[nodiscard]] int compare(Resource const& other, SortType type, Qt::SortOrder order = Qt::SortOrder::AscendingOrder) const override;
|
[[nodiscard]] int compare(Resource const& other, SortType type) const override;
|
||||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user