File indexing completed on 2024-04-28 05:48:12

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0003 
0004 #pragma once
0005 
0006 #include <memory>
0007 
0008 #include <QAbstractListModel>
0009 
0010 class Folder;
0011 class File;
0012 
0013 namespace Filelight
0014 {
0015 
0016 class FileModel : public QAbstractListModel
0017 {
0018     Q_OBJECT
0019     Q_PROPERTY(QUrl url READ url NOTIFY treeChanged /* derives from tree */)
0020 
0021 public:
0022     Q_SIGNAL void treeChanged();
0023     std::shared_ptr<Folder> m_tree;
0024 
0025     void setTree(const std::shared_ptr<Folder> &tree);
0026 
0027     QUrl url() const;
0028 
0029 public:
0030     enum class Role { HumanReadableSize = Qt::UserRole, IsFolder, URL, Segment };
0031     Q_ENUM(Role)
0032 
0033     using QAbstractListModel::QAbstractListModel;
0034 
0035     [[nodiscard]] int rowCount(const QModelIndex &parent) const override;
0036     [[nodiscard]] QVariant data(const QModelIndex &index, int intRole) const override;
0037     [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
0038 
0039     Q_INVOKABLE [[nodiscard]] std::shared_ptr<File> file(int row) const;
0040 };
0041 
0042 } // namespace Filelight