summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <peter.penz19@gmail.com>2012-01-31 13:58:25 (GMT)
committerPeter Penz <peter.penz19@gmail.com>2012-01-31 13:59:34 (GMT)
commit86a49188f5a917386e0be7c7c5a6183663073b11 (patch)
treebf811e891a6b179bcfd0caad57b4809e199e8c18
parent47b4e1dfdc7f9480dd6daf2b0867376ef859b707 (diff)
Fix sorting issues
For some roles the sorting has not been implemented. BUG: 292941 FIXED-IN: 4.8.1
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.cpp76
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.h10
2 files changed, 58 insertions, 28 deletions
diff --git a/dolphin/src/kitemviews/kfileitemmodel.cpp b/dolphin/src/kitemviews/kfileitemmodel.cpp
index 163db82..d649546 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.cpp
+++ b/dolphin/src/kitemviews/kfileitemmodel.cpp
@@ -1125,6 +1125,30 @@ KFileItemModel::Role KFileItemModel::roleIndex(const QByteArray& role) const
return rolesHash.value(role, NoRole);
}
+QByteArray KFileItemModel::roleByteArray(Role role) const
+{
+ static const char* const roles[RolesCount] = {
+ 0, // NoRole
+ "name",
+ "size",
+ "date",
+ "permissions",
+ "owner",
+ "group",
+ "type",
+ "destination",
+ "path",
+ "comment",
+ "tags",
+ "rating",
+ "isDir",
+ "isExpanded",
+ "isExpandable",
+ "expansionLevel"
+ };
+ return roles[role];
+}
+
QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item) const
{
// It is important to insert only roles that are fast to retrieve. E.g.
@@ -1274,18 +1298,7 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
case NameRole:
// The name role is handled as default fallback after the switch
break;
-
- case DateRole: {
- const KDateTime dateTimeA = itemA.time(KFileItem::ModificationTime);
- const KDateTime dateTimeB = itemB.time(KFileItem::ModificationTime);
- if (dateTimeA < dateTimeB) {
- result = -1;
- } else if (dateTimeA > dateTimeB) {
- result = +1;
- }
- break;
- }
-
+
case SizeRole: {
if (itemA.isDir()) {
Q_ASSERT(itemB.isDir()); // see "if (m_sortFoldersFirst || m_sortRole == SizeRole)" above
@@ -1307,29 +1320,36 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
break;
}
- case TypeRole: {
- result = QString::compare(a->values.value("type").toString(),
- b->values.value("type").toString());
+ case DateRole: {
+ const KDateTime dateTimeA = itemA.time(KFileItem::ModificationTime);
+ const KDateTime dateTimeB = itemB.time(KFileItem::ModificationTime);
+ if (dateTimeA < dateTimeB) {
+ result = -1;
+ } else if (dateTimeA > dateTimeB) {
+ result = +1;
+ }
break;
}
-
- case CommentRole: {
- result = QString::compare(a->values.value("comment").toString(),
- b->values.value("comment").toString());
+
+ case RatingRole: {
+ result = a->values.value("rating").toInt() - b->values.value("rating").toInt();
break;
}
-
+
+ case PermissionsRole:
+ case OwnerRole:
+ case GroupRole:
+ case TypeRole:
+ case DestinationRole:
+ case PathRole:
+ case CommentRole:
case TagsRole: {
- result = QString::compare(a->values.value("tags").toString(),
- b->values.value("tags").toString());
+ const QByteArray role = roleByteArray(m_sortRole);
+ result = QString::compare(a->values.value(role).toString(),
+ b->values.value(role).toString());
break;
}
-
- case RatingRole: {
- result = a->values.value("rating").toInt() - b->values.value("rating").toInt();
- break;
- }
-
+
default:
break;
}
diff --git a/dolphin/src/kitemviews/kfileitemmodel.h b/dolphin/src/kitemviews/kfileitemmodel.h
index 6276dc2..ff816c8 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.h
+++ b/dolphin/src/kitemviews/kfileitemmodel.h
@@ -237,7 +237,17 @@ private:
*/
void resetRoles();
+ /**
+ * @return Role-index for the given role byte-array.
+ * Runtime complexity is O(1).
+ */
Role roleIndex(const QByteArray& role) const;
+
+ /**
+ * @return Role-byte-array for the given role-index.
+ * Runtime complexity is O(1).
+ */
+ QByteArray roleByteArray(Role role) const;
QHash<QByteArray, QVariant> retrieveData(const KFileItem& item) const;