]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Merge remote-tracking branch 'fork/work/zakharafoniam/useful-groups'
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index ea72a48a4660f3de930bf82c62f65a676d087a41..13554d8c7fa1999dc62e8fd355c71967096ca9e5 100644 (file)
@@ -211,6 +211,13 @@ public:
      */
     static QList<RoleInfo> rolesInformation();
 
+    /**
+     * @return Provides static information for all available grouping
+     *         behaviors supported by KFileItemModel but not directly
+     *         mapped to roles of KFileItemModel.
+     */
+    static QList<RoleInfo> extraGroupingInformation();
+
     /** set to true to hide application/x-trash files */
     void setShowTrashMime(bool show);
 
@@ -265,7 +272,7 @@ Q_SIGNALS:
      * Is emitted if an error message (e.g. "Unknown location")
      * should be shown.
      */
-    void errorMessage(const QString &message);
+    void errorMessage(const QString &message, const int kioErrorCode);
 
     /**
      * Is emitted if a redirection from the current URL \a oldUrl
@@ -293,9 +300,9 @@ Q_SIGNALS:
 protected:
     void onGroupedSortingChanged(bool current) override;
     void onSortRoleChanged(const QByteArray &current, const QByteArray &previous, bool resortItems = true) override;
-    void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous, bool resortItems = true) override;
+    void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
     void onGroupRoleChanged(const QByteArray &current, const QByteArray &previous, bool resortItems = true) override;
-    void onGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous, bool resortItems = true) override;
+    void onGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
 
 private Q_SLOTS:
     /**
@@ -373,7 +380,7 @@ private:
         QHash<QByteArray, QVariant> values;
         ItemData *parent;
     };
-
+    
     struct ItemGroupInfo {
         int comparable;
         QString text;
@@ -396,6 +403,12 @@ private:
      */
     QList<ItemData *> createItemDataList(const QUrl &parentUrl, const KFileItemList &items) const;
 
+    /**
+     * Helper method for prepareItemsForSorting(). 
+     * For a set role, fills 'values' of ItemData non-lazily.
+     */
+    void prepareItemsWithRole(QList<ItemData *> &itemDataList, RoleType roleType);
+
     /**
      * Prepares the items for sorting. Normally, the hash 'values' in ItemData is filled
      * lazily to save time and memory, but for some sort roles, it is expected that the
@@ -477,13 +490,15 @@ private:
     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;
+    ItemGroupInfo typeRoleGroup(const ItemData *itemData) const;
+    ItemGroupInfo 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;
     QList<QPair<int, QVariant>> permissionRoleGroups() const;
     QList<QPair<int, QVariant>> ratingRoleGroups() const;
+    QList<QPair<int, QVariant>> typeRoleGroups() const;
     QList<QPair<int, QVariant>> genericStringRoleGroups(const QByteArray &typeForRole) const;
 
     /**
@@ -624,7 +639,9 @@ inline bool KFileItemModel::isRoleValueNatural(RoleType roleType)
 
 inline bool KFileItemModel::nameLessThan(const ItemData *a, const ItemData *b)
 {
-    return a->item.text() < b->item.text();
+    // Split extension, taking into account it can be empty
+    constexpr QString::SectionFlags flags = QString::SectionSkipEmpty | QString::SectionIncludeLeadingSep;
+    return a->item.text().section('.', 0, 0, flags) < b->item.text().section('.', 0, 0, flags);
 }
 
 inline bool KFileItemModel::isChildItem(int index) const
@@ -646,13 +663,4 @@ inline bool KFileItemModel::ItemGroupInfo::operator!=(const ItemGroupInfo &other
     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