File indexing completed on 2024-05-12 15:59:52
0001 /* 0002 * SPDX-FileCopyrightText: 2019 boud <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KISSTORAGEMODEL_H 0007 #define KISSTORAGEMODEL_H 0008 0009 #include <QAbstractTableModel> 0010 #include <QObject> 0011 #include <QScopedPointer> 0012 0013 #include "KisResourceStorage.h" 0014 #include "kritaresources_export.h" 0015 0016 /** 0017 * KisStorageModel provides a model of all registered storages, like 0018 * the folder storages, the bundle storages or the memory storages. Note 0019 * that inactive storages are also part of this model. 0020 */ 0021 class KRITARESOURCES_EXPORT KisStorageModel : public QAbstractTableModel 0022 { 0023 Q_OBJECT 0024 public: 0025 0026 enum Columns { 0027 Id = 0, 0028 StorageType, 0029 Location, 0030 TimeStamp, 0031 PreInstalled, 0032 Active, 0033 Thumbnail, 0034 DisplayName, 0035 MetaData 0036 }; 0037 0038 enum StorageImportOption { 0039 None, 0040 Overwrite, 0041 Rename, 0042 }; 0043 0044 KisStorageModel(QObject *parent = 0); 0045 ~KisStorageModel() override; 0046 0047 static KisStorageModel * instance(); 0048 0049 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0050 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0051 QVariant data(const QModelIndex &index, int role) const override; 0052 0053 /// Enable and disable the storage represented by index 0054 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0055 Qt::ItemFlags flags(const QModelIndex &index) const override; 0056 0057 KisResourceStorageSP storageForIndex(const QModelIndex &index) const; 0058 KisResourceStorageSP storageForId(const int storageId) const; 0059 0060 bool importStorage(QString filename, StorageImportOption importOption) const; 0061 0062 0063 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0064 0065 Q_SIGNALS: 0066 0067 void storageEnabled(const QString &storage); 0068 void storageDisabled(const QString &storage); 0069 0070 private Q_SLOTS: 0071 0072 /// Called whenever a storage is added 0073 void addStorage(const QString &location); 0074 0075 /// This is called when a storage really is deleted both from database and anywhere else 0076 void removeStorage(const QString &location); 0077 0078 private: 0079 0080 KisStorageModel(const KisStorageModel&); 0081 KisStorageModel operator=(const KisStorageModel&); 0082 0083 struct Private; 0084 QScopedPointer<Private> d; 0085 0086 0087 }; 0088 0089 #endif // KISSTORAGEMODEL_H