]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Build with QT_NO_KEYWORDS
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index 8e36294e901e127a604ac90c30801d3bd35c4b2f..886a1c6de52e72b3e0651b2797d6717256905a36 100644 (file)
@@ -1,34 +1,24 @@
-/***************************************************************************
- *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #ifndef KFILEITEMMODEL_H
 #define KFILEITEMMODEL_H
 
-#include "libdolphin_export.h"
+#include "dolphin_export.h"
+#include "kitemviews/kitemmodelbase.h"
+#include "kitemviews/private/kfileitemmodelfilter.h"
+
 #include <KFileItem>
-#include <QUrl>
-#include <kitemviews/kitemmodelbase.h>
-#include <kitemviews/private/kfileitemmodelfilter.h>
 
 #include <QCollator>
 #include <QHash>
 #include <QSet>
+#include <QUrl>
+
+#include <functional>
 
 class KFileItemModelDirLister;
 class QTimer;
@@ -43,13 +33,13 @@ class QTimer;
  * Recursive expansion of sub-directories is supported by
  * KFileItemModel::setExpanded().
  */
-class LIBDOLPHINPRIVATE_EXPORT KFileItemModel : public KItemModelBase
+class DOLPHIN_EXPORT KFileItemModel : public KItemModelBase
 {
     Q_OBJECT
 
 public:
-    explicit KFileItemModel(QObject* parent = 0);
-    virtual ~KFileItemModel();
+    explicit KFileItemModel(QObject* parent = nullptr);
+    ~KFileItemModel() override;
 
     /**
      * Loads the directory specified by \a url. The signals
@@ -71,7 +61,7 @@ public:
      *         the root-parent of all items.
      * @see rootItem()
      */
-    QUrl directory() const;
+    QUrl directory() const override;
 
     /**
      * Cancels the loading of a directory which has been started by either
@@ -79,9 +69,9 @@ public:
      */
     void cancelDirectoryLoading();
 
-    virtual int count() const Q_DECL_OVERRIDE;
-    virtual QHash<QByteArray, QVariant> data(int index) const Q_DECL_OVERRIDE;
-    virtual bool setData(int index, const QHash<QByteArray, QVariant>& values) Q_DECL_OVERRIDE;
+    int count() const override;
+    QHash<QByteArray, QVariant> data(int index) const override;
+    bool setData(int index, const QHash<QByteArray, QVariant>& values) override;
 
     /**
      * Sets a separate sorting with directories first (true) or a mixed
@@ -100,15 +90,15 @@ public:
     void setShowDirectoriesOnly(bool enabled);
     bool showDirectoriesOnly() const;
 
-    virtual QMimeData* createMimeData(const KItemSet& indexes) const Q_DECL_OVERRIDE;
+    QMimeData* createMimeData(const KItemSet& indexes) const override;
 
-    virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const Q_DECL_OVERRIDE;
+    int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const override;
 
-    virtual bool supportsDropping(int index) const Q_DECL_OVERRIDE;
+    bool supportsDropping(int index) const override;
 
-    virtual QString roleDescription(const QByteArray& role) const Q_DECL_OVERRIDE;
+    QString roleDescription(const QByteArray& role) const override;
 
-    virtual QList<QPair<int, QVariant> > groups() const Q_DECL_OVERRIDE;
+    QList<QPair<int, QVariant> > groups() const override;
 
     /**
      * @return The file-item for the index \a index. If the index is in a valid
@@ -154,10 +144,10 @@ public:
     void setRoles(const QSet<QByteArray>& roles);
     QSet<QByteArray> roles() const;
 
-    virtual bool setExpanded(int index, bool expanded) Q_DECL_OVERRIDE;
-    virtual bool isExpanded(int index) const Q_DECL_OVERRIDE;
-    virtual bool isExpandable(int index) const Q_DECL_OVERRIDE;
-    virtual int expandedParentsCount(int index) const Q_DECL_OVERRIDE;
+    bool setExpanded(int index, bool expanded) override;
+    bool isExpanded(int index) const override;
+    bool isExpandable(int index) const override;
+    int expandedParentsCount(int index) const override;
 
     QSet<QUrl> expandedDirectories() const;
 
@@ -195,7 +185,7 @@ public:
      */
     static QList<RoleInfo> rolesInformation();
 
-signals:
+Q_SIGNALS:
     /**
      * Is emitted if the loading of a directory has been started. It is
      * assured that a signal directoryLoadingCompleted() will be send after
@@ -256,11 +246,11 @@ signals:
     void urlIsFileError(const QUrl& url);
 
 protected:
-    virtual void onGroupedSortingChanged(bool current) Q_DECL_OVERRIDE;
-    virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous) Q_DECL_OVERRIDE;
-    virtual void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) Q_DECL_OVERRIDE;
+    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) override;
 
-private slots:
+private Q_SLOTS:
     /**
      * Resorts all items dependent on the set sortRole(), sortOrder()
      * and foldersFirst() settings.
@@ -273,21 +263,21 @@ private slots:
     void slotItemsDeleted(const KFileItemList& items);
     void slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items);
     void slotClear();
-    void slotNaturalSortingChanged();
+    void slotSortingChoiceChanged();
 
     void dispatchPendingItemsToInsert();
 
 private:
     enum RoleType {
         // User visible roles:
-        NoRole, NameRole, SizeRole, DateRole, PermissionsRole, OwnerRole,
-        GroupRole, TypeRole, DestinationRole, PathRole,
+        NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole,
+        GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole,
         // User visible roles available with Baloo:
-        CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole,
-        WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
-        CopiedFromRole,
+        CommentRole, TagsRole, RatingRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole,
+        WordCountRole, TitleRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole,
+        BitrateRole, OriginUrlRole, AspectRatioRole, FrameRateRole,
         // Non-visible roles:
-        IsDirRole, IsLinkRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
+        IsDirRole, IsLinkRole, IsHiddenRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
         // Mandatory last entry:
         RolesCount
     };
@@ -352,6 +342,11 @@ private:
 
     QHash<QByteArray, QVariant> retrieveData(const KFileItem& item, const ItemData* parent) const;
 
+    /**
+     * @return True if role values benefit from natural or case insensitive sorting.
+     */
+    static bool isRoleValueNatural(const RoleType roleType);
+
     /**
      * @return True if \a a has a KFileItem whose text is 'less than' the one
      *         of \a b according to QString::operator<(const QString&).
@@ -368,7 +363,7 @@ private:
      * Sorts the items between \a begin and \a end using the comparison
      * function lessThan().
      */
-    void sort(QList<ItemData*>::iterator begin, QList<ItemData*>::iterator end) const;
+    void sort(const QList<ItemData*>::iterator &begin, const QList<ItemData*>::iterator &end) const;
 
     /**
      * Helper method for lessThan() and expandedParentsCountCompare(): Compares
@@ -379,11 +374,9 @@ private:
 
     int stringCompare(const QString& a, const QString& b, const QCollator& collator) const;
 
-    bool useMaximumUpdateInterval() const;
-
     QList<QPair<int, QVariant> > nameRoleGroups() const;
     QList<QPair<int, QVariant> > sizeRoleGroups() const;
-    QList<QPair<int, QVariant> > dateRoleGroups() 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> > genericStringRoleGroups(const QByteArray& typeForRole) const;
@@ -415,6 +408,11 @@ private:
      */
     void removeFilteredChildren(const KItemRangeList& parents);
 
+    /**
+     * Loads the selected choice of sorting method from Dolphin General Settings
+     */
+    void loadSortingSettings();
+
     /**
      * Maps the QByteArray-roles to RoleTypes and provides translation- and
      * group-contexts.
@@ -491,7 +489,6 @@ private:
     // and done step after step in slotCompleted().
     QSet<QUrl> m_urlsToExpand;
 
-    friend class KFileItemModelLessThan;       // Accesses lessThan() method
     friend class KFileItemModelRolesUpdater;   // Accesses emitSortProgress() method
     friend class KFileItemModelTest;           // For unit testing
     friend class KFileItemModelBenchmark;      // For unit testing
@@ -499,12 +496,27 @@ private:
     friend class DolphinPart;                  // Accesses m_dirLister
 };
 
+inline bool KFileItemModel::isRoleValueNatural(RoleType roleType)
+{
+    return (roleType == TypeRole ||
+            roleType == TagsRole ||
+            roleType == CommentRole ||
+            roleType == TitleRole ||
+            roleType == ArtistRole ||
+            roleType == GenreRole ||
+            roleType == AlbumRole ||
+            roleType == PathRole ||
+            roleType == DestinationRole ||
+            roleType == OriginUrlRole ||
+            roleType == OwnerRole ||
+            roleType == GroupRole);
+}
+
 inline bool KFileItemModel::nameLessThan(const ItemData* a, const ItemData* b)
 {
     return a->item.text() < b->item.text();
 }
 
-
 inline bool KFileItemModel::isChildItem(int index) const
 {
     if (m_itemData.at(index)->parent) {