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