src/documentmanager.h

changeset 212
27259810da6d
parent 193
b4beff48bb7a
child 213
ee5758ddb6d2
equal deleted inserted replaced
211:b27b90fb993f 212:27259810da6d
19 #pragma once 19 #pragma once
20 #include "libraries.h" 20 #include "libraries.h"
21 #include "model.h" 21 #include "model.h"
22 #include "polygoncache.h" 22 #include "polygoncache.h"
23 23
24 class DocumentManager : public QObject 24 enum OpenType
25 { 25 {
26 Q_OBJECT 26 //! \brief Document was opened manually by the user
27 ManuallyOpened,
28 //! \brief Document was opened automatically in order to resolve subfile references
29 AutomaticallyOpened,
30 };
31
32 class DocumentManager
33 {
27 public: 34 public:
28 enum OpenType 35 struct ModelInfo
29 { 36 {
30 /** 37 std::unique_ptr<Model> model;
31 * Document was opened manually by the user 38 ModelId id;
32 */ 39 QString path;
33 ManuallyOpened, 40 OpenType opentype;
34 /** 41 std::map<QString, ModelId> dependencies = {};
35 * Document was opened automatically in order to resolve subfile references 42 PolygonCache polygonCache;
36 */
37 AutomaticallyOpened,
38 }; 43 };
39 DocumentManager(QObject* parent = nullptr); 44 using MissingDependencies = std::map<QString, QString>;
45 DocumentManager();
40 ModelId newModel(); 46 ModelId newModel();
41 Model* findDependencyByName(const ModelId modelId, const QString& name); 47 Model* findDependencyByName(const ModelId modelId, const QString& name);
42 Model* getModelById(ModelId modelId); 48 Model* getModelById(ModelId modelId);
43 std::optional<ModelId> openModel(const QString& path, QTextStream& errorStream, const OpenType openType); 49 std::optional<ModelId> openModel(const QString& path, QTextStream& errorStream, const OpenType openType);
44 QString makeNewModelName(); 50 std::map<QString, QString> loadDependenciesForAllModels(const LibraryManager &libraries);
45 void loadDependenciesForAllModels(const LibraryManager &libraries, QTextStream &errorStream);
46 void loadDependenciesForModel(const ModelId modelId,
47 const QString& path,
48 const LibraryManager& libraries,
49 QTextStream& errorStream);
50 void closeDocument(const ModelId modelId); 51 void closeDocument(const ModelId modelId);
51 const QString* modelPath(ModelId modelId) const; 52 const QString* modelPath(ModelId modelId) const;
52 void setModelPath( 53 void setModelPath(
53 const ModelId modelId, 54 const ModelId modelId,
54 const QString& newPath, 55 const QString& newPath,
55 const LibraryManager &libraries, 56 const LibraryManager &libraries,
56 QTextStream &errorStream); 57 QTextStream &errorStream);
57 bool saveModel(const ModelId modelId, QTextStream& errors); 58 bool saveModel(const ModelId modelId, QTextStream& errors);
58 std::optional<ModelId> findIdForModel(const Model* model) const; 59 std::optional<ModelId> findIdForModel(const Model* model) const;
59 PolygonCache* getPolygonCacheForModel(ModelId modelId); 60 PolygonCache* getPolygonCacheForModel(ModelId modelId);
61 const ModelInfo* infoForModel(ModelId modelId) const;
60 private: 62 private:
61 struct ModelInfo
62 {
63 std::unique_ptr<Model> model;
64 ModelId id;
65 QString path;
66 OpenType opentype;
67 std::map<QString, ModelId> dependencies = {};
68 };
69 struct LoadDepedenciesBag;
70 int modelIdCounter = 0; 63 int modelIdCounter = 0;
71 int untitledNameCounter = 0;
72 std::map<ModelId, ModelInfo> openModels; 64 std::map<ModelId, ModelInfo> openModels;
73 std::map<ModelId, PolygonCache> polygonCaches;
74 void loadDependenciesForModel(const ModelId modelId, const QString& path, LoadDepedenciesBag& bag);
75 void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model); 65 void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model);
76 void updateDependencies(ModelInfo* model); 66 void updateDependencies(ModelInfo* model);
77 void prune(); 67 void prune();
78 Q_SLOT void modelModified();
79 bool isReferencedByAnything(const ModelId modelId) const; 68 bool isReferencedByAnything(const ModelId modelId) const;
80 void makePolygonCacheForModel(const ModelId modelId); 69 void makePolygonCacheForModel(const ModelId modelId);
81 }; 70 };
82 71
72 QString errorStringFromMissingDependencies(const DocumentManager::MissingDependencies& missing);
83 QString pathToName(const QFileInfo& path); 73 QString pathToName(const QFileInfo& path);

mercurial