File indexing completed on 2024-05-12 05:39:42
0001 #ifndef CHARACTERSHEET_IMAGEMODEL_H 0002 #define CHARACTERSHEET_IMAGEMODEL_H 0003 0004 #include <QAbstractTableModel> 0005 #include <QJsonArray> 0006 #include <QJsonObject> 0007 #include <QPixmap> 0008 #include <vector> 0009 0010 #include <charactersheet/charactersheet_global.h> 0011 0012 namespace charactersheet 0013 { 0014 0015 class CHARACTERSHEET_EXPORT ImageModel : public QAbstractTableModel 0016 { 0017 Q_OBJECT 0018 Q_PROPERTY(QSize backgroundSize READ backgroundSize NOTIFY backgroundSizeChanged) 0019 public: 0020 enum Role 0021 { 0022 KeyRole= Qt::UserRole + 1, 0023 UrlRole, 0024 FilenameRole, 0025 BackgroundRole 0026 }; 0027 struct ImageInfo 0028 { 0029 QPixmap pixmap; 0030 bool isBackground; 0031 QString filename; 0032 QString key; 0033 }; 0034 explicit ImageModel(QObject* parent= nullptr); 0035 0036 // Header: 0037 QVariant headerData(int section, Qt::Orientation orientation, int role= Qt::DisplayRole) const override; 0038 0039 // Basic functionality: 0040 int rowCount(const QModelIndex& parent= QModelIndex()) const override; 0041 int columnCount(const QModelIndex& parent= QModelIndex()) const override; 0042 QModelIndex index(int row, int col, const QModelIndex& parent) const override; 0043 QVariant data(const QModelIndex& index, int role= Qt::DisplayRole) const override; 0044 bool setData(const QModelIndex& index, const QVariant& value, int role) override; 0045 0046 bool insertImage(const QPixmap& pix, const QString& key, const QString& path, bool isBg); 0047 Qt::ItemFlags flags(const QModelIndex& index) const override; 0048 0049 void clear(); 0050 0051 void removeImageAt(const QModelIndex& index); 0052 void setPathFor(const QModelIndex& index, const QString& path); 0053 void setPixList(QHash<QString, QPixmap*>& list); 0054 bool isBackgroundById(QString id) const; 0055 void removeImageByKey(const QString& key); 0056 0057 QSize backgroundSize() const; 0058 void removeImage(int i); 0059 QPixmap pixmapFromKey(QString id); 0060 void reloadImage(const QModelIndex& index); 0061 0062 const std::vector<ImageInfo>& imageInfos() const; 0063 signals: 0064 void backgroundSizeChanged(); 0065 void internalDataChanged(); 0066 0067 private: 0068 QStringList m_column; 0069 std::vector<ImageInfo> m_data; 0070 }; 0071 } // namespace charactersheet 0072 #endif // CHARACTERSHEET_IMAGEMODEL_H