File indexing completed on 2024-05-12 15:59:53
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISTAGFILTERRESOURCEPROXYMODEL_H 0008 #define KISTAGFILTERRESOURCEPROXYMODEL_H 0009 0010 #include <QSortFilterProxyModel> 0011 #include <QObject> 0012 0013 #include "KoResource.h" 0014 #include "KisResourceModel.h" 0015 #include "KisTag.h" 0016 #include "KisTagModel.h" 0017 #include "KisTagResourceModel.h" 0018 0019 #include "kritaresources_export.h" 0020 0021 /** 0022 * @brief The KisTagFilterResourceProxyModel class filters the resources by tag or resource name 0023 */ 0024 class KRITARESOURCES_EXPORT KisTagFilterResourceProxyModel 0025 : public QSortFilterProxyModel 0026 , public KisAbstractResourceModel 0027 , public KisAbstractResourceFilterInterface 0028 { 0029 Q_OBJECT 0030 public: 0031 0032 KisTagFilterResourceProxyModel(const QString &resourceType, QObject *parent = 0); 0033 ~KisTagFilterResourceProxyModel() override; 0034 0035 void setResourceFilter(ResourceFilter filter) override; 0036 void setStorageFilter(StorageFilter filter) override; 0037 0038 // To be used if we need an extra proxy model, like for 0039 void setResourceModel(KisResourceModel *resourceModel); 0040 0041 // KisAbstractResourceModel interface 0042 0043 KoResourceSP resourceForIndex(QModelIndex index = QModelIndex()) const override; 0044 QModelIndex indexForResource(KoResourceSP resource) const override; 0045 QModelIndex indexForResourceId(int resourceId) const override; 0046 bool setResourceActive(const QModelIndex &index, bool value) override; 0047 KoResourceSP importResourceFile(const QString &filename, const bool allowOverwrite, const QString &storageId = QString()) override; 0048 KoResourceSP importResource(const QString &filename, QIODevice *device, const bool allowOverwrite, const QString &storageId = QString()) override; 0049 bool importWillOverwriteResource(const QString &fileName, const QString &storageLocation) const override; 0050 bool exportResource(KoResourceSP resource, QIODevice *device) override; 0051 bool addResource(KoResourceSP resource, const QString &storageId = QString()) override; 0052 bool updateResource(KoResourceSP resource) override; 0053 bool reloadResource(KoResourceSP resource) override; 0054 bool renameResource(KoResourceSP resource, const QString &name) override; 0055 bool setResourceMetaData(KoResourceSP resource, QMap<QString, QVariant> metadata) override; 0056 0057 0058 /** 0059 * @brief setMetaDataFilter provides a set of metadata to filter on, for instance 0060 * by paintop id category. 0061 * @param metaDataMap 0062 */ 0063 void setMetaDataFilter(QMap<QString, QVariant> metaDataMap); 0064 0065 /** 0066 * @brief setTagFilter sets the tag to filter with 0067 * @param tag a valid tag with a valid id, or 0 to clear the filter 0068 */ 0069 void setTagFilter(const KisTagSP tag); 0070 0071 0072 void setStorageFilter(bool useFilter, int storageId); 0073 0074 /** 0075 * @brief setResourceFilter sets the resource to filter with 0076 * @param resource a valid resource with a valid id, or 0 to clear the filter 0077 */ 0078 void setResourceFilter(const KoResourceSP resource); 0079 0080 void setSearchText(const QString& seatchText); 0081 0082 void setFilterInCurrentTag(bool filterInCurrentTag); 0083 0084 bool tagResources(const KisTagSP tag, const QVector<int> &resourceIds); 0085 bool untagResources(const KisTagSP tag, const QVector<int> &resourceIds); 0086 int isResourceTagged(const KisTagSP tag, const int resourceId); 0087 0088 Q_SIGNALS: 0089 0090 void beforeFilterChanges(); 0091 void afterFilterChanged(); 0092 0093 protected: 0094 0095 bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override; 0096 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0097 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; 0098 0099 private: 0100 void updateTagFilter(); 0101 0102 private: 0103 struct Private; 0104 Private *const d; 0105 0106 Q_DISABLE_COPY(KisTagFilterResourceProxyModel) 0107 }; 0108 0109 #endif // KISTAGFILTERRESOURCEPROXYMODEL_H