1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-06-30 15:36:30 +00:00

"Grouped sorting" defaults to true. Grouping is still disabled by default because of "none" as default group role.

This commit is contained in:
Zakhar Afonin 2024-06-24 01:19:31 +03:00
parent 9663bfbc23
commit 2b6d8aac0b
3 changed files with 20 additions and 6 deletions

View File

@ -39,6 +39,7 @@ KFileItemModel::KFileItemModel(QObject *parent)
, m_sortDirsFirst(true)
, m_sortHiddenLast(false)
, m_sortRole(NameRole)
, m_groupRole(NoRole)
, m_sortingProgressPercent(-1)
, m_roles()
, m_itemData()
@ -2439,6 +2440,7 @@ int KFileItemModel::stringCompare(const QString &a, const QString &b, const QCol
KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *itemData, bool withString) const
{
static bool oldWithString;
static ItemGroupInfo oldGroupInfo;
static QChar oldFirstChar;
ItemGroupInfo groupInfo;
@ -2450,8 +2452,8 @@ KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *item
// Use the first character of the name as group indication
firstChar = name.at(0).toUpper();
if (firstChar == oldFirstChar) {
if (firstChar == oldFirstChar && withString == oldWithString) {
return oldGroupInfo;
}
if (firstChar == QLatin1Char('~') && name.length() > 1) {
@ -2506,6 +2508,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *item
}
groupInfo.comparable = (int)'.';
}
oldWithString = withString;
oldFirstChar = firstChar;
oldGroupInfo = groupInfo;
return groupInfo;
@ -2547,6 +2550,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::sizeRoleGroup(const ItemData *item
KFileItemModel::ItemGroupInfo
KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &fileTimeCb, const ItemData *itemData, bool withString) const
{
static bool oldWithString;
static ItemGroupInfo oldGroupInfo;
static QDate oldFileDate;
ItemGroupInfo groupInfo;
@ -2556,6 +2560,9 @@ KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &
const QDate fileDate = fileTime.date();
const int daysDistance = fileDate.daysTo(currentDate);
if (fileDate == oldFileDate && withString == oldWithString) {
return oldGroupInfo;
}
// Simplified grouping algorithm, preserving dates
// but not taking "pretty printing" into account
if (currentDate.year() == fileDate.year() && currentDate.month() == fileDate.month()) {
@ -2759,6 +2766,7 @@ KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &
}
}
}
oldWithString = withString;
oldFileDate = fileDate;
oldGroupInfo = groupInfo;
return groupInfo;
@ -2766,13 +2774,14 @@ KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &
KFileItemModel::ItemGroupInfo KFileItemModel::permissionRoleGroup(const ItemData *itemData, bool withString) const
{
static bool oldWithString;
static ItemGroupInfo oldGroupInfo;
static QFileDevice::Permissions oldPermissions;
ItemGroupInfo groupInfo;
const QFileInfo info(itemData->item.url().toLocalFile());
const QFileDevice::Permissions permissions = info.permissions();
if (permissions == oldPermissions) {
if (permissions == oldPermissions && withString == oldWithString) {
return oldGroupInfo;
}
groupInfo.comparable = (int)permissions;
@ -2818,6 +2827,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::permissionRoleGroup(const ItemData
others = others.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : others.mid(0, others.length() - 2);
groupInfo.text = i18nc("@title:group Files and folders by permissions", "User: %1 | Group: %2 | Others: %3", user, group, others);
}
oldWithString = withString;
oldPermissions = permissions;
oldGroupInfo = groupInfo;
return groupInfo;

View File

@ -10,7 +10,7 @@
KItemModelBase::KItemModelBase(QObject *parent)
: QObject(parent)
, m_groupedSorting(false)
, m_groupedSorting(true)
, m_sortRole()
, m_sortOrder(Qt::AscendingOrder)
, m_groupRole()
@ -20,7 +20,7 @@ KItemModelBase::KItemModelBase(QObject *parent)
KItemModelBase::KItemModelBase(const QByteArray &sortRole, const QByteArray &groupRole, QObject *parent)
: QObject(parent)
, m_groupedSorting(false)
, m_groupedSorting(true)
, m_sortRole(sortRole)
, m_sortOrder(Qt::AscendingOrder)
, m_groupRole(groupRole)

View File

@ -164,7 +164,7 @@ void KFileItemModelTest::testDefaultSortRole()
void KFileItemModelTest::testDefaultGroupedSorting()
{
QCOMPARE(m_model->groupedSorting(), false);
QCOMPARE(m_model->groupedSorting(), true);
}
void KFileItemModelTest::testNewItems()
@ -2007,6 +2007,7 @@ void KFileItemModelTest::testNameRoleGroups()
m_testDir->createFiles({"b.txt", "c.txt", "d.txt", "e.txt"});
m_model->setGroupedSorting(true);
m_model->setGroupRole("text");
m_model->loadDirectory(m_testDir->url());
QVERIFY(itemsInsertedSpy.wait());
QCOMPARE(itemsInModel(),
@ -2093,6 +2094,8 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
m_testDir->createFiles({"a/b.txt", "a/c.txt", "d/e.txt", "d/f.txt"});
m_model->setGroupedSorting(true);
m_model->setGroupRole("text");
m_model->loadDirectory(m_testDir->url());
QVERIFY(itemsInsertedSpy.wait());
QCOMPARE(itemsInModel(),
@ -2102,6 +2105,7 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
QList<QPair<int, QVariant>> expectedGroups;
expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
expectedGroups << QPair<int, QVariant>(1, QLatin1String("D"));
QCOMPARE(m_model->groups(), expectedGroups);
// Verify that expanding "a" and "d" will not change the groups (except for the index of "D").