diff -r 6988973515d2 -r ca23936b455b src/documentmanager.cpp --- a/src/documentmanager.cpp Wed May 25 20:36:34 2022 +0300 +++ b/src/documentmanager.cpp Mon Jun 06 22:01:22 2022 +0300 @@ -21,8 +21,6 @@ #include #include #include "documentmanager.h" -#include "modeleditor.h" -#include "linetypes/subfilereference.h" #include "parser.h" /** @@ -43,7 +41,7 @@ const ModelId modelId{++this->modelIdCounter}; const QString name = makeNewModelName(); this->openModels[modelId] = ModelInfo{ - .model = std::make_unique(), + .model = std::make_unique(this), .id = modelId, .opentype = OpenType::ManuallyOpened, }; @@ -400,6 +398,16 @@ return referencedFilePath; } +template +void iterate(const Model& model, std::function fn) +{ + for (int i = 0; i < model.size(); ++i) { + if (std::holds_alternative(model[i])) { + fn(std::get(model[i])); + } + } +} + void DocumentManager::loadDependenciesForModel( const ModelId modelId, const QString &path, @@ -418,9 +426,8 @@ } ModelInfo& modelInfo = this->openModels[modelId]; modelInfo.dependencies.clear(); - for (int i = 0; i < modelInfo.model->size(); i += 1) - { - const QString referenceName = (*modelInfo.model)[i]->getProperty(ldraw::Property::ReferenceName).toString(); + iterate>(*modelInfo.model, [&](const SubfileReference& ref) { + const QString referenceName = ref.name; if (not referenceName.isEmpty() and modelInfo.dependencies.count(referenceName) == 0 and not failedToOpen.contains(referenceName)) @@ -458,5 +465,5 @@ bag.missing.append(referenceName); } } - } + }); }