mirror of
https://invent.kde.org/system/dolphin
synced 2024-06-30 23:46:46 +00:00
Fixed crashing when initial grouping is by size. Fixed size grouping ignoring directory size.
This commit is contained in:
parent
6f6f080bb8
commit
e7804cff52
|
@ -1040,6 +1040,7 @@ void KFileItemModel::loadSortingSettings()
|
|||
// Workaround for bug https://bugreports.qt.io/browse/QTBUG-69361
|
||||
// Force the clean state of QCollator in single thread to avoid thread safety problems in sort
|
||||
m_collator.compare(QString(), QString());
|
||||
m_dirSizeMode = ContentDisplaySettings::directorySizeMode();
|
||||
}
|
||||
|
||||
void KFileItemModel::resortAllItems()
|
||||
|
@ -1105,7 +1106,8 @@ void KFileItemModel::resortAllItems()
|
|||
}
|
||||
|
||||
Q_EMIT itemsMoved(KItemRange(firstMovedIndex, movedItemsCount), movedToIndexes);
|
||||
} else if (groupedSorting()) {
|
||||
}
|
||||
if (groupedSorting()) {
|
||||
// The groups might have changed even if the order of the items has not.
|
||||
const QList<QPair<int, QVariant>> oldGroups = m_groups;
|
||||
m_groups.clear();
|
||||
|
@ -2129,8 +2131,7 @@ bool KFileItemModel::lessThan(const ItemData *a, const ItemData *b, const QColla
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if (m_sortDirsFirst
|
||||
|| (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && m_sortRole == SizeRole)) {
|
||||
if (m_sortDirsFirst || (m_dirSizeMode == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && m_sortRole == SizeRole)) {
|
||||
const bool isDirA = a->item.isDir();
|
||||
const bool isDirB = b->item.isDir();
|
||||
if (isDirA && !isDirB) {
|
||||
|
@ -2184,7 +2185,7 @@ int KFileItemModel::sortRoleCompare(const ItemData *a, const ItemData *b, const
|
|||
break;
|
||||
|
||||
case SizeRole: {
|
||||
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && itemA.isDir()) {
|
||||
if (m_dirSizeMode == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && itemA.isDir()) {
|
||||
// folders first then
|
||||
// items A and B are folders thanks to lessThan checks
|
||||
auto valueA = a->values.value("count");
|
||||
|
@ -2542,7 +2543,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::sizeRoleGroup(const ItemData *item
|
|||
|
||||
groupInfo.comparable = -1; // None
|
||||
if (!item.isNull() && item.isDir()) {
|
||||
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || m_sortDirsFirst) {
|
||||
if (m_dirSizeMode == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount) {
|
||||
groupInfo.comparable = 0; // Folders
|
||||
} else {
|
||||
fileSize = itemData->values.value("size").toULongLong();
|
||||
|
|
|
@ -574,6 +574,7 @@ private:
|
|||
bool m_naturalSorting;
|
||||
bool m_sortDirsFirst;
|
||||
bool m_sortHiddenLast;
|
||||
int m_dirSizeMode;
|
||||
|
||||
RoleType m_sortRole;
|
||||
RoleType m_groupRole;
|
||||
|
|
|
@ -368,7 +368,7 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList &itemRan
|
|||
timer.start();
|
||||
|
||||
// Determine the sort role synchronously for as many items as possible.
|
||||
if (m_resolvableRoles.contains(m_model->sortRole())) {
|
||||
if (m_resolvableRoles.contains(m_model->sortRole()) || m_resolvableRoles.contains(m_model->groupRole())) {
|
||||
int insertedCount = 0;
|
||||
for (const KItemRange &range : itemRanges) {
|
||||
const int lastIndex = insertedCount + range.index + range.count - 1;
|
||||
|
@ -1218,13 +1218,14 @@ void KFileItemModelRolesUpdater::applySortRole(int index)
|
|||
QHash<QByteArray, QVariant> data;
|
||||
const KFileItem item = m_model->fileItem(index);
|
||||
|
||||
if (m_model->sortRole() == "type") {
|
||||
// Despite the name, this handles both sorting and grouping, as they happen at the same time (resorting items).
|
||||
if (m_model->sortRole() == "type" || m_model->groupRole() == "type") {
|
||||
if (!item.isMimeTypeKnown()) {
|
||||
item.determineMimeType();
|
||||
}
|
||||
|
||||
data.insert("type", item.mimeComment());
|
||||
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
|
||||
} else if ((m_model->sortRole() == "size" || m_model->groupRole() == "size") && item.isLocalFile() && item.isDir()) {
|
||||
startDirectorySizeCounting(item, index);
|
||||
return;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user