170 //! to be resolved differently. As such, dependencies need to be resolved for |
170 //! to be resolved differently. As such, dependencies need to be resolved for |
171 //! all files after this operation. |
171 //! all files after this operation. |
172 void DocumentManager::setModelPath( |
172 void DocumentManager::setModelPath( |
173 const ModelId modelId, |
173 const ModelId modelId, |
174 const QString &newPath, |
174 const QString &newPath, |
175 const LibraryManager &libraries, |
175 const LibrariesModel &libraries, |
176 QTextStream &errorStream) |
176 QTextStream &errorStream) |
177 { |
177 { |
178 ModelInfo* info = findInMap(this->openModels, modelId); |
178 ModelInfo* info = findInMap(this->openModels, modelId); |
179 if (info != nullptr and info->opentype == OpenType::ManuallyOpened) { |
179 if (info != nullptr and info->opentype == OpenType::ManuallyOpened) { |
180 info->path = newPath; |
180 info->path = newPath; |
335 } |
335 } |
336 |
336 |
337 static QString findFile( |
337 static QString findFile( |
338 QString referenceName, |
338 QString referenceName, |
339 const QString& modelPath, |
339 const QString& modelPath, |
340 const LibraryManager& libraries) |
340 const LibrariesModel& libraries) |
341 { |
341 { |
342 // Try to find the file in the same place as the model itself |
342 // Try to find the file in the same place as the model itself |
343 referenceName.replace("\\", "/"); |
343 referenceName.replace("\\", "/"); |
344 const QDir dir = QFileInfo{modelPath}.dir(); |
344 const QDir dir = QFileInfo{modelPath}.dir(); |
345 QString referencedFilePath = dir.filePath(referenceName); |
345 QString referencedFilePath = dir.filePath(referenceName); |
375 } |
375 } |
376 }; |
376 }; |
377 |
377 |
378 static std::set<Dependency> resolveReferencePaths( |
378 static std::set<Dependency> resolveReferencePaths( |
379 const DocumentManager::ModelInfo* modelInfo, |
379 const DocumentManager::ModelInfo* modelInfo, |
380 const LibraryManager* libraries) |
380 const LibrariesModel* libraries) |
381 { |
381 { |
382 std::set<Dependency> result; |
382 std::set<Dependency> result; |
383 const std::set<QString> refNames = referenceNames(modelInfo->model.get()); |
383 const std::set<QString> refNames = referenceNames(modelInfo->model.get()); |
384 if (modelInfo != nullptr) { |
384 if (modelInfo != nullptr) { |
385 for (const QString& name : refNames) { |
385 for (const QString& name : refNames) { |
393 } |
393 } |
394 |
394 |
395 static void loadDependenciesForModel( |
395 static void loadDependenciesForModel( |
396 DocumentManager::ModelInfo* info, |
396 DocumentManager::ModelInfo* info, |
397 DocumentManager* documents, |
397 DocumentManager* documents, |
398 const LibraryManager* libraries, |
398 const LibrariesModel* libraries, |
399 std::map<QString, QString>& missing) |
399 std::map<QString, QString>& missing) |
400 { |
400 { |
401 bool repeat = true; |
401 bool repeat = true; |
402 info->dependencies.clear(); |
402 info->dependencies.clear(); |
403 while (repeat) { |
403 while (repeat) { |
423 } |
423 } |
424 } |
424 } |
425 } |
425 } |
426 } |
426 } |
427 |
427 |
428 std::map<QString, QString> DocumentManager::loadDependenciesForAllModels(const LibraryManager& libraries) |
428 std::map<QString, QString> DocumentManager::loadDependenciesForAllModels(const LibrariesModel& libraries) |
429 { |
429 { |
430 std::map<QString, QString> missing; |
430 std::map<QString, QString> missing; |
431 for (auto& modelInfoPair : this->openModels) |
431 for (auto& modelInfoPair : this->openModels) |
432 { |
432 { |
433 loadDependenciesForModel(&modelInfoPair.second, this, &libraries, missing); |
433 loadDependenciesForModel(&modelInfoPair.second, this, &libraries, missing); |