+int KFileItemModel::groupRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const
+{
+ // Unlike sortRoleCompare, this function can and often will return 0.
+ int result = 0;
+
+ int groupA, groupB;
+ switch (m_groupRole) {
+ case NoRole:
+ // Non-trivial grouping behavior might be handled there in the future.
+ return 0;
+ case NameRole:
+ groupA = nameRoleGroup(a, false).comparable;
+ groupB = nameRoleGroup(b, false).comparable;
+ break;
+ case SizeRole:
+ groupA = sizeRoleGroup(a, false).comparable;
+ groupB = sizeRoleGroup(b, false).comparable;
+ break;
+ case ModificationTimeRole:
+ groupA = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->item.time(KFileItem::ModificationTime);
+ },
+ a,
+ false)
+ .comparable;
+ groupB = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->item.time(KFileItem::ModificationTime);
+ },
+ b,
+ false)
+ .comparable;
+ break;
+ case CreationTimeRole:
+ groupA = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->item.time(KFileItem::CreationTime);
+ },
+ a,
+ false)
+ .comparable;
+ groupB = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->item.time(KFileItem::CreationTime);
+ },
+ b,
+ false)
+ .comparable;
+ break;
+ case AccessTimeRole:
+ groupA = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->item.time(KFileItem::AccessTime);
+ },
+ a,
+ false)
+ .comparable;
+ groupB = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->item.time(KFileItem::AccessTime);
+ },
+ b,
+ false)
+ .comparable;
+ break;
+ case DeletionTimeRole:
+ groupA = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->values.value("deletiontime").toDateTime();
+ },
+ a,
+ false)
+ .comparable;
+ groupB = timeRoleGroup(
+ [](const ItemData *item) {
+ return item->values.value("deletiontime").toDateTime();
+ },
+ b,
+ false)
+ .comparable;
+ break;
+ case PermissionsRole:
+ groupA = permissionRoleGroup(a, false).comparable;
+ groupB = permissionRoleGroup(b, false).comparable;
+ break;
+ case RatingRole:
+ groupA = ratingRoleGroup(a, false).comparable;
+ groupB = ratingRoleGroup(b, false).comparable;
+ break;
+ default: {
+ QString strGroupA = genericStringRoleGroup(groupRole(), a);
+ QString strGroupB = genericStringRoleGroup(groupRole(), b);
+ result = stringCompare(strGroupA, strGroupB, collator);
+ break;
+ }
+ }
+ if (result == 0) {
+ if (groupA < groupB) {
+ result = -1;
+ } else if (groupA > groupB) {
+ result = 1;
+ }
+ }
+ return result;
+}
+