, m_sortDirsFirst(true)
, m_sortHiddenLast(false)
, m_sortRole(NameRole)
+ , m_groupRole(NoRole)
, m_sortingProgressPercent(-1)
, m_roles()
, m_itemData()
KFileItemModel::ItemGroupInfo KFileItemModel::nameRoleGroup(const ItemData *itemData, bool withString) const
{
+ static bool oldWithString;
static ItemGroupInfo oldGroupInfo;
static QChar oldFirstChar;
ItemGroupInfo groupInfo;
// 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) {
}
groupInfo.comparable = (int)'.';
}
+ oldWithString = withString;
oldFirstChar = firstChar;
oldGroupInfo = groupInfo;
return groupInfo;
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;
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()) {
}
}
}
+ oldWithString = withString;
oldFileDate = fileDate;
oldGroupInfo = groupInfo;
return groupInfo;
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;
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;
KItemModelBase::KItemModelBase(QObject *parent)
: QObject(parent)
- , m_groupedSorting(false)
+ , m_groupedSorting(true)
, m_sortRole()
, m_sortOrder(Qt::AscendingOrder)
, m_groupRole()
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)
void KFileItemModelTest::testDefaultGroupedSorting()
{
- QCOMPARE(m_model->groupedSorting(), false);
+ QCOMPARE(m_model->groupedSorting(), true);
}
void KFileItemModelTest::testNewItems()
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(),
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(),
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").