Plasma Engine  2.0
Loading...
Searching...
No Matches
AssetBrowserModel.moc.h
1#pragma once
2
3#include <EditorFramework/EditorFrameworkDLL.h>
4#include <Foundation/Containers/DynamicArray.h>
5#include <Foundation/Containers/Set.h>
6#include <Foundation/Types/Uuid.h>
7#include <QAbstractItemModel>
8#include <QFileIconProvider>
9#include <ToolsFoundation/FileSystem/FileSystemModel.h>
10
11struct plAssetInfo;
13struct plSubAsset;
14class plQtAssetFilter;
15
17class PL_EDITORFRAMEWORK_DLL plQtAssetFilter : public QObject
18{
19 Q_OBJECT
20public:
21 explicit plQtAssetFilter(QObject* pParent);
22 virtual bool IsAssetFiltered(plStringView sDataDirParentRelativePath, bool bIsFolder, const plSubAsset* pInfo) const = 0;
23 virtual plStringView GetFilterRelativePath(plStringView sDataDirParentRelativePath) const { return sDataDirParentRelativePath; }
24 virtual bool GetSortByRecentUse() const { return false; }
25
26Q_SIGNALS:
27 void FilterChanged();
28};
29
32struct PL_EDITORFRAMEWORK_DLL plAssetBrowserItemFlags
33{
34 using StorageType = plUInt8;
35
36 enum Enum
37 {
38 Folder = PL_BIT(0), // Any folder inside a data directory
39 DataDirectory = PL_BIT(1), // mutually exclusive with Folder
40 File = PL_BIT(2), // any file, could also be an Asset
41 Asset = PL_BIT(3), // main asset: mutually exclusive with SubAsset
42 SubAsset = PL_BIT(4), // sub-asset (imaginary, not a File or Asset)
43 Default = 0
44 };
45
46 struct Bits
47 {
48 StorageType Folder : 1;
49 StorageType DataDirectory : 1;
50 StorageType File : 1;
51 StorageType Asset : 1;
52 StorageType SubAsset : 1;
53 };
54};
55PL_DECLARE_FLAGS_OPERATORS(plAssetBrowserItemFlags);
56
58class PL_EDITORFRAMEWORK_DLL plQtAssetBrowserModel : public QAbstractItemModel
59{
60 Q_OBJECT
61public:
62 enum UserRoles
63 {
64 SubAssetGuid = Qt::UserRole + 0, // plUuid
65 AssetGuid, // plUuid
66 AbsolutePath, // QString
67 RelativePath, // QString
68 AssetIcon, // QIcon
69 TransformState, // QString
70 Importable, // bool
71 ItemFlags, // plAssetBrowserItemFlags as int
72 };
73
74 plQtAssetBrowserModel(QObject* pParent, plQtAssetFilter* pFilter);
76
77 void resetModel();
78
79 void SetIconMode(bool bIconMode) { m_bIconMode = bIconMode; }
80 bool GetIconMode() { return m_bIconMode; }
81
82 plInt32 FindAssetIndex(const plUuid& assetGuid) const;
83 plInt32 FindIndex(plStringView sAbsPath) const;
84
85public Q_SLOTS:
86 void ThumbnailLoaded(QString sPath, QModelIndex index, QVariant userData1, QVariant userData2);
87 void ThumbnailInvalidated(QString sPath, plUInt32 uiImageID);
88 void OnFileSystemUpdate();
89
90signals:
91 void editingFinished(const QString& sAbsPath, const QString& sNewName, bool bIsAsset) const;
92
93public: // QAbstractItemModel interface
94 virtual QVariant data(const QModelIndex& index, int iRole) const override;
95 virtual bool setData(const QModelIndex& index, const QVariant& value, int iRole = Qt::EditRole) override;
96 virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
97 virtual QVariant headerData(int iSection, Qt::Orientation orientation, int iRole = Qt::DisplayRole) const override;
98 virtual QModelIndex index(int iRow, int iColumn, const QModelIndex& parent = QModelIndex()) const override;
99 virtual QModelIndex parent(const QModelIndex& index) const override;
100 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
101 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
102 virtual QStringList mimeTypes() const override;
103 virtual QMimeData* mimeData(const QModelIndexList& indexes) const override;
104 virtual Qt::DropActions supportedDropActions() const override;
105
106private:
107 friend struct FileComparer;
108
109 enum class AssetOp
110 {
111 Add,
112 Remove,
113 Updated,
114 };
115
116 struct VisibleEntry
117 {
118 plDataDirPath m_sAbsFilePath;
119 plUuid m_Guid;
121 mutable plUInt32 m_uiThumbnailID;
122 };
123
124 struct FsEvent
125 {
126 plFileChangedEvent m_FileEvent;
127 plFolderChangedEvent m_FolderEvent;
128 };
129
130private:
131 void AssetCuratorEventHandler(const plAssetCuratorEvent& e);
132 void HandleEntry(const VisibleEntry& entry, AssetOp op);
133 void FileSystemFileEventHandler(const plFileChangedEvent& e);
134 void FileSystemFolderEventHandler(const plFolderChangedEvent& e);
135 void HandleFile(const plFileChangedEvent& e);
136 void HandleFolder(const plFolderChangedEvent& e);
137
138private:
139 plQtAssetFilter* m_pFilter = nullptr;
140 bool m_bIconMode = true;
141 plSet<plString> m_ImportExtensions;
142
143 plMutex m_Mutex;
144 plDynamicArray<FsEvent> m_QueuedFileSystemEvents;
145
146 plDynamicArray<VisibleEntry> m_EntriesToDisplay;
147 plSet<plUuid> m_DisplayedEntries;
148
149 QFileIconProvider m_IconProvider;
150};
Definition EditorApp.moc.h:27
A reference to a file or folder inside a data directory.
Definition DataDirPath.h:18
Definition DynamicArray.h:81
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Model of the item view in the asset browser.
Definition AssetBrowserModel.moc.h:59
Interface class of the asset filter used to decide which items are shown in the asset browser.
Definition AssetBrowserModel.moc.h:18
Definition Set.h:238
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Definition AssetBrowserModel.moc.h:47
Each item in the asset browser can be multiple things at the same time as described by these flags....
Definition AssetBrowserModel.moc.h:33
Definition AssetCurator.h:122
Definition AssetCurator.h:62
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Information about an asset or sub-asset.
Definition AssetCurator.h:107