22 #include <QSaveFile> |
22 #include <QSaveFile> |
23 #include <deque> |
23 #include <deque> |
24 #include "documentmanager.h" |
24 #include "documentmanager.h" |
25 #include "parser.h" |
25 #include "parser.h" |
26 |
26 |
27 DocumentManager::DocumentManager() |
27 DocumentManager::DocumentManager(QObject *parent) : |
|
28 QObject{parent} |
28 { |
29 { |
29 } |
30 } |
30 |
31 |
31 /** |
32 /** |
32 * @brief Creates a new model. |
33 * @brief Creates a new model. |
33 * @returns the ID of the new model |
34 * @returns the ID of the new model |
34 */ |
35 */ |
35 ModelId DocumentManager::newModel() |
36 ModelId DocumentManager::newModel() |
36 { |
37 { |
37 const ModelId modelId{++this->modelIdCounter}; |
38 const ModelId modelId{++this->modelIdCounter}; |
38 this->openModels[modelId].id = modelId; |
39 this->openModels.emplace(std::make_pair(modelId, ModelInfo{ |
39 this->openModels[modelId].opentype = OpenType::ManuallyOpened; |
40 .id = modelId, |
|
41 .opentype = OpenType::ManuallyOpened, |
|
42 })); |
40 this->makePolygonCacheForModel(modelId); |
43 this->makePolygonCacheForModel(modelId); |
41 return modelId; |
44 return modelId; |
42 } |
45 } |
43 |
46 |
44 Model* DocumentManager::findDependencyByName(const ModelId modelId, const QString& name) |
47 Model* DocumentManager::findDependencyByName(const ModelId modelId, const QString& name) |
120 parser.parseBody(*newModel); |
123 parser.parseBody(*newModel); |
121 std::optional<ModelId> result; |
124 std::optional<ModelId> result; |
122 if (file.error() == QFile::NoError) |
125 if (file.error() == QFile::NoError) |
123 { |
126 { |
124 const ModelId modelId{++this->modelIdCounter}; |
127 const ModelId modelId{++this->modelIdCounter}; |
125 this->openModels[modelId] = { |
128 this->openModels.emplace(std::make_pair(modelId, ModelInfo{ |
126 .model = std::move(newModel), |
129 .model = std::move(newModel), |
127 .id = modelId, |
130 .id = modelId, |
128 .path = path, |
131 .path = path, |
129 .opentype = openType, |
132 .opentype = openType, |
130 .polygonCache = {}, |
133 .polygonCache = {}, |
131 }; |
134 })); |
132 this->makePolygonCacheForModel(modelId); |
135 this->makePolygonCacheForModel(modelId); |
133 result = modelId; |
136 result = modelId; |
134 } |
137 } |
135 else |
138 else |
136 { |
139 { |
239 else { |
242 else { |
240 return nullptr; |
243 return nullptr; |
241 } |
244 } |
242 } |
245 } |
243 |
246 |
244 const DocumentManager::ModelInfo *DocumentManager::infoForModel(ModelId modelId) const |
247 const DocumentManager::ModelInfo *DocumentManager::find(ModelId modelId) const |
245 { |
248 { |
246 return findInMap(this->openModels, modelId); |
249 return findInMap(this->openModels, modelId); |
|
250 } |
|
251 |
|
252 void DocumentManager::setModelPayload(ModelId modelId, QObject *object) |
|
253 { |
|
254 ModelInfo* info = findInMap(this->openModels, modelId); |
|
255 if (info != nullptr) { |
|
256 info->payload = object; |
|
257 object->setParent(this); |
|
258 } |
247 } |
259 } |
248 |
260 |
249 QString errorStringFromMissingDependencies(const DocumentManager::MissingDependencies& missing) |
261 QString errorStringFromMissingDependencies(const DocumentManager::MissingDependencies& missing) |
250 { |
262 { |
251 QString missingString; |
263 QString missingString; |