--- a/src/documentmanager.cpp Sat Jun 11 15:20:24 2022 +0300 +++ b/src/documentmanager.cpp Sun Jun 12 20:47:04 2022 +0300 @@ -24,7 +24,8 @@ #include "documentmanager.h" #include "parser.h" -DocumentManager::DocumentManager() +DocumentManager::DocumentManager(QObject *parent) : + QObject{parent} { } @@ -35,8 +36,10 @@ ModelId DocumentManager::newModel() { const ModelId modelId{++this->modelIdCounter}; - this->openModels[modelId].id = modelId; - this->openModels[modelId].opentype = OpenType::ManuallyOpened; + this->openModels.emplace(std::make_pair(modelId, ModelInfo{ + .id = modelId, + .opentype = OpenType::ManuallyOpened, + })); this->makePolygonCacheForModel(modelId); return modelId; } @@ -122,13 +125,13 @@ if (file.error() == QFile::NoError) { const ModelId modelId{++this->modelIdCounter}; - this->openModels[modelId] = { + this->openModels.emplace(std::make_pair(modelId, ModelInfo{ .model = std::move(newModel), .id = modelId, .path = path, .opentype = openType, .polygonCache = {}, - }; + })); this->makePolygonCacheForModel(modelId); result = modelId; } @@ -241,11 +244,20 @@ } } -const DocumentManager::ModelInfo *DocumentManager::infoForModel(ModelId modelId) const +const DocumentManager::ModelInfo *DocumentManager::find(ModelId modelId) const { return findInMap(this->openModels, modelId); } +void DocumentManager::setModelPayload(ModelId modelId, QObject *object) +{ + ModelInfo* info = findInMap(this->openModels, modelId); + if (info != nullptr) { + info->payload = object; + object->setParent(this); + } +} + QString errorStringFromMissingDependencies(const DocumentManager::MissingDependencies& missing) { QString missingString;