File indexing completed on 2024-04-28 11:41:17

0001 /*
0002     SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
0003     SPDX-FileCopyrightText: 2006 Dominic Battre <dominic@battre.de>
0004     SPDX-FileCopyrightText: 2006 Martin Pool <mbp@canonical.com>
0005 
0006     Separated from Dolphin by Nick Shaforostoff <shafff@ukr.net>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-only
0009 */
0010 
0011 #ifndef KDIRSORTFILTERPROXYMODEL_H
0012 #define KDIRSORTFILTERPROXYMODEL_H
0013 
0014 #include <QFileInfo>
0015 
0016 #include <KCategorizedSortFilterProxyModel>
0017 
0018 #include "kiofilewidgets_export.h"
0019 
0020 #include <memory>
0021 
0022 /**
0023  * @class KDirSortFilterProxyModel kdirsortfilterproxymodel.h <KDirSortFilterProxyModel>
0024  *
0025  * @brief Acts as proxy model for KDirModel to sort and filter
0026  *        KFileItems.
0027  *
0028  * A natural sorting is done. This means that items like:
0029  * - item_10.png
0030  * - item_1.png
0031  * - item_2.png
0032  *
0033  * are sorted like
0034  * - item_1.png
0035  * - item_2.png
0036  * - item_10.png
0037  *
0038  * Don't use it with non-KDirModel derivatives.
0039  *
0040  * @author Dominic Battre, Martin Pool and Peter Penz
0041  */
0042 class KIOFILEWIDGETS_EXPORT KDirSortFilterProxyModel : public KCategorizedSortFilterProxyModel
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     explicit KDirSortFilterProxyModel(QObject *parent = nullptr);
0048     ~KDirSortFilterProxyModel() override;
0049 
0050     /** Reimplemented from QAbstractItemModel. Returns true for directories. */
0051     bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
0052 
0053     /**
0054      * Reimplemented from QAbstractItemModel.
0055      * Returns true for 'empty' directories so they can be populated later.
0056      */
0057     bool canFetchMore(const QModelIndex &parent) const override;
0058 
0059     /**
0060      * Returns the permissions in "points". This is useful for sorting by
0061      * permissions.
0062      */
0063     static int pointsForPermissions(const QFileInfo &info);
0064 
0065     /**
0066      * Choose if files and folders are sorted separately (with folders first) or not.
0067      * @since 4.3
0068      */
0069     void setSortFoldersFirst(bool foldersFirst);
0070 
0071     /**
0072      * Returns if files and folders are sorted separately (with folders first) or not.
0073      * @since 4.3
0074      */
0075     bool sortFoldersFirst() const;
0076 
0077     /**
0078      * Sets a separate sorting with hidden files and folders last (true) or not (false).
0079      * @since 5.95
0080      */
0081     void setSortHiddenFilesLast(bool hiddenFilesLast);
0082     bool sortHiddenFilesLast() const;
0083 
0084     Qt::DropActions supportedDragOptions() const;
0085 
0086 protected:
0087     /**
0088      * Reimplemented from KCategorizedSortFilterProxyModel.
0089      */
0090     virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
0091 
0092 private:
0093     class KDirSortFilterProxyModelPrivate;
0094     std::unique_ptr<KDirSortFilterProxyModelPrivate> const d;
0095 };
0096 
0097 #endif