File indexing completed on 2024-05-12 15:59:52
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISSTORAGEFILTERPROXYMODEL_H 0008 #define KISSTORAGEFILTERPROXYMODEL_H 0009 0010 #include <QSortFilterProxyModel> 0011 #include <QObject> 0012 #include <KisResourceStorage.h> 0013 #include <KisStorageModel.h> 0014 #include "kritaresources_export.h" 0015 0016 /** 0017 * KisStorageFilterProxyModel provides a filtered view on the available storages. 0018 * It can be used to find the storages that have resource with a particular file 0019 * name, or storages of particular types. 0020 * 0021 * Filtering by file name takes a string, filtering by storage type a list 0022 * of untranslated strings (there is a method in KisResourceStorage for retrieving 0023 * those strings from the ResourceType). 0024 */ 0025 class KRITARESOURCES_EXPORT KisStorageFilterProxyModel : public QSortFilterProxyModel 0026 { 0027 Q_OBJECT 0028 public: 0029 KisStorageFilterProxyModel(QObject *parent = 0); 0030 ~KisStorageFilterProxyModel() override; 0031 0032 enum FilterType { 0033 ByFileName = 0, ///< Pass a string: all storages whose name contains the 0034 /// string will be returned. 0035 ByStorageType, ///< Pass a string list of storage types 0036 ByActive ///< Pass a boolean, false to filter out active bundles, 0037 /// true to filter out inactive bundles 0038 }; 0039 0040 KisResourceStorageSP storageForIndex(QModelIndex index = QModelIndex()) const; 0041 0042 void setFilter(FilterType filterType, QVariant filter); 0043 0044 protected: 0045 0046 bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override; 0047 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0048 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; 0049 0050 private Q_SLOTS: 0051 void slotModelReset(); 0052 0053 0054 private: 0055 struct Private; 0056 Private *const d; 0057 0058 Q_DISABLE_COPY(KisStorageFilterProxyModel) 0059 }; 0060 0061 #endif