File indexing completed on 2024-03-24 05:49:22
0001 // SPDX-FileCopyrightText: 2003 Scott Wheeler <wheeler@kde.org> 0002 // SPDX-FileCopyrightText: 2004 Max Howell <max.howell@methylblue.com> 0003 // SPDX-FileCopyrightText: 2004 Mark Kretschmann <markey@web.de> 0004 // SPDX-FileCopyrightText: 2008 Seb Ruiz <ruiz@kde.org> 0005 // SPDX-FileCopyrightText: 2008 Sebastian Trueg <trueg@kde.org> 0006 // SPDX-FileCopyrightText: 2020 Simon Persson <simon.persson@mykolab.com> 0007 // 0008 // SPDX-License-Identifier: GPL-2.0-only 0009 0010 #ifndef FOLDER_SELECTION_MODEL_H 0011 #define FOLDER_SELECTION_MODEL_H 0012 0013 #include <QFileSystemModel> 0014 #include <QSet> 0015 0016 0017 class FolderSelectionModel : public QFileSystemModel 0018 { 0019 Q_OBJECT 0020 0021 public: 0022 explicit FolderSelectionModel(bool pHiddenFoldersVisible = false, QObject *pParent = nullptr); 0023 0024 enum InclusionState { 0025 StateNone, 0026 StateIncluded, 0027 StateExcluded, 0028 StateIncludeInherited, 0029 StateExcludeInherited 0030 }; 0031 0032 enum CustomRoles { 0033 IncludeStateRole = 7777 0034 }; 0035 0036 Qt::ItemFlags flags(const QModelIndex &pIndex) const override; 0037 QVariant data(const QModelIndex& pIndex, int pRole = Qt::DisplayRole) const override; 0038 bool setData(const QModelIndex& pIndex, const QVariant& pValue, int pRole = Qt::EditRole) override; 0039 0040 void setIncludedPaths(const QSet<QString> &pIncludedPaths); 0041 void setExcludedPaths(const QSet<QString> &pExcludedPaths); 0042 QSet<QString> includedPaths() const; 0043 QSet<QString> excludedPaths() const; 0044 0045 /** 0046 * Include the specified path. All subdirs will be reset. 0047 */ 0048 void includePath(const QString &pPath); 0049 0050 /** 0051 * Exclude the specified path. All subdirs will be reset. 0052 */ 0053 void excludePath(const QString &pPath); 0054 0055 int columnCount(const QModelIndex&) const override { return 1; } 0056 0057 InclusionState inclusionState(const QModelIndex &pIndex) const; 0058 InclusionState inclusionState(const QString &pPath) const; 0059 0060 bool hiddenFoldersVisible() const; 0061 0062 public slots: 0063 void setHiddenFoldersVisible(bool pVisible); 0064 0065 signals: 0066 void includedPathAdded(const QString &pPath); 0067 void excludedPathAdded(const QString &pPath); 0068 void includedPathRemoved(const QString &pPath); 0069 void excludedPathRemoved(const QString &pPath); 0070 0071 private: 0072 QModelIndex findLastLeaf(const QModelIndex& index); 0073 void removeSubDirs(const QString& path); 0074 0075 QSet<QString> mIncludedPaths; 0076 QSet<QString> mExcludedPaths; 0077 }; 0078 0079 #endif