mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-04 17:30:55 +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:
parent
9663bfbc23
commit
2b6d8aac0b
|
@ -39,6 +39,7 @@ KFileItemModel::KFileItemModel(QObject *parent)
|
||||||
, m_sortDirsFirst(true)
|
, m_sortDirsFirst(true)
|
||||||
, m_sortHiddenLast(false)
|
, m_sortHiddenLast(false)
|
||||||
, m_sortRole(NameRole)
|
, m_sortRole(NameRole)
|
||||||
|
, m_groupRole(NoRole)
|
||||||
, m_sortingProgressPercent(-1)
|
, m_sortingProgressPercent(-1)
|
||||||
, m_roles()
|
, m_roles()
|
||||||
, m_itemData()
|
, 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
|
KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *itemData, bool withString) const
|
||||||
{
|
{
|
||||||
|
static bool oldWithString;
|
||||||
static ItemGroupInfo oldGroupInfo;
|
static ItemGroupInfo oldGroupInfo;
|
||||||
static QChar oldFirstChar;
|
static QChar oldFirstChar;
|
||||||
ItemGroupInfo groupInfo;
|
ItemGroupInfo groupInfo;
|
||||||
|
@ -2451,7 +2453,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *item
|
||||||
// Use the first character of the name as group indication
|
// Use the first character of the name as group indication
|
||||||
firstChar = name.at(0).toUpper();
|
firstChar = name.at(0).toUpper();
|
||||||
|
|
||||||
if (firstChar == oldFirstChar) {
|
if (firstChar == oldFirstChar && withString == oldWithString) {
|
||||||
return oldGroupInfo;
|
return oldGroupInfo;
|
||||||
}
|
}
|
||||||
if (firstChar == QLatin1Char('~') && name.length() > 1) {
|
if (firstChar == QLatin1Char('~') && name.length() > 1) {
|
||||||
|
@ -2506,6 +2508,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *item
|
||||||
}
|
}
|
||||||
groupInfo.comparable = (int)'.';
|
groupInfo.comparable = (int)'.';
|
||||||
}
|
}
|
||||||
|
oldWithString = withString;
|
||||||
oldFirstChar = firstChar;
|
oldFirstChar = firstChar;
|
||||||
oldGroupInfo = groupInfo;
|
oldGroupInfo = groupInfo;
|
||||||
return groupInfo;
|
return groupInfo;
|
||||||
|
@ -2547,6 +2550,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::sizeRoleGroup(const ItemData *item
|
||||||
KFileItemModel::ItemGroupInfo
|
KFileItemModel::ItemGroupInfo
|
||||||
KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &fileTimeCb, const ItemData *itemData, bool withString) const
|
KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &fileTimeCb, const ItemData *itemData, bool withString) const
|
||||||
{
|
{
|
||||||
|
static bool oldWithString;
|
||||||
static ItemGroupInfo oldGroupInfo;
|
static ItemGroupInfo oldGroupInfo;
|
||||||
static QDate oldFileDate;
|
static QDate oldFileDate;
|
||||||
ItemGroupInfo groupInfo;
|
ItemGroupInfo groupInfo;
|
||||||
|
@ -2556,6 +2560,9 @@ KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &
|
||||||
const QDate fileDate = fileTime.date();
|
const QDate fileDate = fileTime.date();
|
||||||
const int daysDistance = fileDate.daysTo(currentDate);
|
const int daysDistance = fileDate.daysTo(currentDate);
|
||||||
|
|
||||||
|
if (fileDate == oldFileDate && withString == oldWithString) {
|
||||||
|
return oldGroupInfo;
|
||||||
|
}
|
||||||
// Simplified grouping algorithm, preserving dates
|
// Simplified grouping algorithm, preserving dates
|
||||||
// but not taking "pretty printing" into account
|
// but not taking "pretty printing" into account
|
||||||
if (currentDate.year() == fileDate.year() && currentDate.month() == fileDate.month()) {
|
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;
|
oldFileDate = fileDate;
|
||||||
oldGroupInfo = groupInfo;
|
oldGroupInfo = groupInfo;
|
||||||
return 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
|
KFileItemModel::ItemGroupInfo KFileItemModel::permissionRoleGroup(const ItemData *itemData, bool withString) const
|
||||||
{
|
{
|
||||||
|
static bool oldWithString;
|
||||||
static ItemGroupInfo oldGroupInfo;
|
static ItemGroupInfo oldGroupInfo;
|
||||||
static QFileDevice::Permissions oldPermissions;
|
static QFileDevice::Permissions oldPermissions;
|
||||||
ItemGroupInfo groupInfo;
|
ItemGroupInfo groupInfo;
|
||||||
|
|
||||||
const QFileInfo info(itemData->item.url().toLocalFile());
|
const QFileInfo info(itemData->item.url().toLocalFile());
|
||||||
const QFileDevice::Permissions permissions = info.permissions();
|
const QFileDevice::Permissions permissions = info.permissions();
|
||||||
if (permissions == oldPermissions) {
|
if (permissions == oldPermissions && withString == oldWithString) {
|
||||||
return oldGroupInfo;
|
return oldGroupInfo;
|
||||||
}
|
}
|
||||||
groupInfo.comparable = (int)permissions;
|
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);
|
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);
|
groupInfo.text = i18nc("@title:group Files and folders by permissions", "User: %1 | Group: %2 | Others: %3", user, group, others);
|
||||||
}
|
}
|
||||||
|
oldWithString = withString;
|
||||||
oldPermissions = permissions;
|
oldPermissions = permissions;
|
||||||
oldGroupInfo = groupInfo;
|
oldGroupInfo = groupInfo;
|
||||||
return groupInfo;
|
return groupInfo;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
KItemModelBase::KItemModelBase(QObject *parent)
|
KItemModelBase::KItemModelBase(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_groupedSorting(false)
|
, m_groupedSorting(true)
|
||||||
, m_sortRole()
|
, m_sortRole()
|
||||||
, m_sortOrder(Qt::AscendingOrder)
|
, m_sortOrder(Qt::AscendingOrder)
|
||||||
, m_groupRole()
|
, m_groupRole()
|
||||||
|
@ -20,7 +20,7 @@ KItemModelBase::KItemModelBase(QObject *parent)
|
||||||
|
|
||||||
KItemModelBase::KItemModelBase(const QByteArray &sortRole, const QByteArray &groupRole, QObject *parent)
|
KItemModelBase::KItemModelBase(const QByteArray &sortRole, const QByteArray &groupRole, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_groupedSorting(false)
|
, m_groupedSorting(true)
|
||||||
, m_sortRole(sortRole)
|
, m_sortRole(sortRole)
|
||||||
, m_sortOrder(Qt::AscendingOrder)
|
, m_sortOrder(Qt::AscendingOrder)
|
||||||
, m_groupRole(groupRole)
|
, m_groupRole(groupRole)
|
||||||
|
|
|
@ -164,7 +164,7 @@ void KFileItemModelTest::testDefaultSortRole()
|
||||||
|
|
||||||
void KFileItemModelTest::testDefaultGroupedSorting()
|
void KFileItemModelTest::testDefaultGroupedSorting()
|
||||||
{
|
{
|
||||||
QCOMPARE(m_model->groupedSorting(), false);
|
QCOMPARE(m_model->groupedSorting(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KFileItemModelTest::testNewItems()
|
void KFileItemModelTest::testNewItems()
|
||||||
|
@ -2007,6 +2007,7 @@ void KFileItemModelTest::testNameRoleGroups()
|
||||||
m_testDir->createFiles({"b.txt", "c.txt", "d.txt", "e.txt"});
|
m_testDir->createFiles({"b.txt", "c.txt", "d.txt", "e.txt"});
|
||||||
|
|
||||||
m_model->setGroupedSorting(true);
|
m_model->setGroupedSorting(true);
|
||||||
|
m_model->setGroupRole("text");
|
||||||
m_model->loadDirectory(m_testDir->url());
|
m_model->loadDirectory(m_testDir->url());
|
||||||
QVERIFY(itemsInsertedSpy.wait());
|
QVERIFY(itemsInsertedSpy.wait());
|
||||||
QCOMPARE(itemsInModel(),
|
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_testDir->createFiles({"a/b.txt", "a/c.txt", "d/e.txt", "d/f.txt"});
|
||||||
|
|
||||||
m_model->setGroupedSorting(true);
|
m_model->setGroupedSorting(true);
|
||||||
|
m_model->setGroupRole("text");
|
||||||
|
|
||||||
m_model->loadDirectory(m_testDir->url());
|
m_model->loadDirectory(m_testDir->url());
|
||||||
QVERIFY(itemsInsertedSpy.wait());
|
QVERIFY(itemsInsertedSpy.wait());
|
||||||
QCOMPARE(itemsInModel(),
|
QCOMPARE(itemsInModel(),
|
||||||
|
@ -2102,6 +2105,7 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
|
||||||
QList<QPair<int, QVariant>> expectedGroups;
|
QList<QPair<int, QVariant>> expectedGroups;
|
||||||
expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
|
expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
|
||||||
expectedGroups << QPair<int, QVariant>(1, QLatin1String("D"));
|
expectedGroups << QPair<int, QVariant>(1, QLatin1String("D"));
|
||||||
|
|
||||||
QCOMPARE(m_model->groups(), expectedGroups);
|
QCOMPARE(m_model->groups(), expectedGroups);
|
||||||
|
|
||||||
// Verify that expanding "a" and "d" will not change the groups (except for the index of "D").
|
// Verify that expanding "a" and "d" will not change the groups (except for the index of "D").
|
||||||
|
|
Loading…
Reference in New Issue
Block a user