KIO

kdirsortfilterproxymodel.h
1/*
2 SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
3 SPDX-FileCopyrightText: 2006 Dominic Battre <dominic@battre.de>
4 SPDX-FileCopyrightText: 2006 Martin Pool <mbp@canonical.com>
5
6 Separated from Dolphin by Nick Shaforostoff <shafff@ukr.net>
7
8 SPDX-License-Identifier: LGPL-2.0-only
9*/
10
11#ifndef KDIRSORTFILTERPROXYMODEL_H
12#define KDIRSORTFILTERPROXYMODEL_H
13
14#include <QFileInfo>
15
16#include <KCategorizedSortFilterProxyModel>
17
18#include "kiofilewidgets_export.h"
19
20#include <memory>
21
22/**
23 * @class KDirSortFilterProxyModel kdirsortfilterproxymodel.h <KDirSortFilterProxyModel>
24 *
25 * @brief Acts as proxy model for KDirModel to sort and filter
26 * KFileItems.
27 *
28 * A natural sorting is done. This means that items like:
29 * - item_10.png
30 * - item_1.png
31 * - item_2.png
32 *
33 * are sorted like
34 * - item_1.png
35 * - item_2.png
36 * - item_10.png
37 *
38 * Don't use it with non-KDirModel derivatives.
39 *
40 * @author Dominic Battre, Martin Pool and Peter Penz
41 */
42class KIOFILEWIDGETS_EXPORT KDirSortFilterProxyModel : public KCategorizedSortFilterProxyModel
43{
45
46public:
47 explicit KDirSortFilterProxyModel(QObject *parent = nullptr);
48 ~KDirSortFilterProxyModel() override;
49
50 /** Reimplemented from QAbstractItemModel. Returns true for directories. */
51 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
52
53 /**
54 * Reimplemented from QAbstractItemModel.
55 * Returns true for 'empty' directories so they can be populated later.
56 */
57 bool canFetchMore(const QModelIndex &parent) const override;
58
59 /**
60 * Returns the permissions in "points". This is useful for sorting by
61 * permissions.
62 */
63 static int pointsForPermissions(const QFileInfo &info);
64
65 /**
66 * Choose if files and folders are sorted separately (with folders first) or not.
67 */
68 void setSortFoldersFirst(bool foldersFirst);
69
70 /**
71 * Returns if files and folders are sorted separately (with folders first) or not.
72 */
73 bool sortFoldersFirst() const;
74
75 /**
76 * Sets a separate sorting with hidden files and folders last (true) or not (false).
77 * @since 5.95
78 */
79 void setSortHiddenFilesLast(bool hiddenFilesLast);
80 bool sortHiddenFilesLast() const;
81
82 Qt::DropActions supportedDragOptions() const;
83
84protected:
85 /**
86 * Reimplemented from KCategorizedSortFilterProxyModel.
87 */
88 bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
89
90private:
91 class KDirSortFilterProxyModelPrivate;
92 std::unique_ptr<KDirSortFilterProxyModelPrivate> const d;
93};
94
95#endif
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const
static int pointsForPermissions(const QFileInfo &info)
Returns the permissions in "points".
void setSortHiddenFilesLast(bool hiddenFilesLast)
Sets a separate sorting with hidden files and folders last (true) or not (false).
bool sortFoldersFirst() const
Returns if files and folders are sorted separately (with folders first) or not.
void setSortFoldersFirst(bool foldersFirst)
Choose if files and folders are sorted separately (with folders first) or not.
Q_OBJECTQ_OBJECT
virtual bool canFetchMore(const QModelIndex &parent) const const override
virtual bool hasChildren(const QModelIndex &parent) const const override
virtual QModelIndex parent(const QModelIndex &child) const const override
typedef DropActions
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 14 2025 11:55:30 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.