]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Implemented ItemGroupInfo in place of QVariant in roleRoleGroup functions
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index 6cbfab6037aa25d2e25efa05423e1f155da6de14..152321f94f3e87459d3cccb7961bedc80eb98659 100644 (file)
@@ -113,8 +113,6 @@ public:
 
     QString roleDescription(const QByteArray &role) const override;
 
-    QList<QPair<int, QVariant>> groups() const override;
-
     /**
      * @return The file-item for the index \a index. If the index is in a valid
      *         range it is assured that the file-item is not null. The runtime
@@ -198,7 +196,7 @@ public:
 
     /**
      * @return Provides static information for a role that is supported
-     *         by KFileItemModel. Some roles can only be determined if 
+     *         by KFileItemModel. Some roles can only be determined if
      *         Baloo is enabled and/or the Baloo indexing is enabled.
      */
     static RoleInfo roleInformation(const QByteArray &role);
@@ -211,6 +209,8 @@ public:
      */
     static QList<RoleInfo> rolesInformation();
 
+    QList<QPair<int, QVariant>> groups() const override;
+
     /** set to true to hide application/x-trash files */
     void setShowTrashMime(bool show);
 
@@ -374,6 +374,15 @@ private:
         ItemData *parent;
     };
 
+    struct ItemGroupInfo {
+        int comparable;
+        QString text;
+
+        bool operator==(const ItemGroupInfo &other) const;
+        bool operator!=(const ItemGroupInfo &other) const;
+        bool operator<(const ItemGroupInfo &other) const;
+    };
+
     enum RemoveItemsBehavior { KeepItemData, DeleteItemData, DeleteItemDataIfUnfiltered };
 
     void insertItems(QList<ItemData *> &items);
@@ -454,8 +463,22 @@ private:
      */
     int sortRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const;
 
+    /**
+     * Helper method for lessThan() and expandedParentsCountCompare(): Compares
+     * the passed item-data using m_groupRole as criteria. Both items must
+     * have the same parent item, otherwise the comparison will be wrong.
+     */
+    int groupRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const;
+
     int stringCompare(const QString &a, const QString &b, const QCollator &collator) const;
 
+    ItemGroupInfo nameRoleGroup(const ItemData *itemData, bool withString = true) const;
+    ItemGroupInfo sizeRoleGroup(const ItemData *itemData, bool withString = true) const;
+    ItemGroupInfo timeRoleGroup(const std::function<QDateTime(const ItemData *)> &fileTimeCb, const ItemData *itemData, bool withString = true) const;
+    ItemGroupInfo permissionRoleGroup(const ItemData *itemData, bool withString = true) const;
+    ItemGroupInfo ratingRoleGroup(const ItemData *itemData, bool withString = true) const;
+    QString genericStringRoleGroup(const QByteArray &role, const ItemData *itemData) const;
+
     QList<QPair<int, QVariant>> nameRoleGroups() const;
     QList<QPair<int, QVariant>> sizeRoleGroups() const;
     QList<QPair<int, QVariant>> timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const;
@@ -610,4 +633,23 @@ inline bool KFileItemModel::isChildItem(int index) const
     }
 }
 
+inline bool KFileItemModel::ItemGroupInfo::operator==(const ItemGroupInfo &other) const
+{
+    return comparable == other.comparable && text == other.text;
+}
+
+inline bool KFileItemModel::ItemGroupInfo::operator!=(const ItemGroupInfo &other) const
+{
+    return comparable != other.comparable || text != other.text;
+}
+
+inline bool KFileItemModel::ItemGroupInfo::operator<(const ItemGroupInfo &other) const
+{
+    if (comparable == other.comparable) {
+        return text < other.text;
+    } else {
+        return comparable < other.comparable;
+    }
+}
+
 #endif