diff -r 6da867fa5429 -r 3387a84ddaba src/documentmanager.cpp --- a/src/documentmanager.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/documentmanager.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -97,12 +97,13 @@ void DocumentManager::loadDependenciesForModel( const QString& modelName, + const QString& path, const LibraryManager& libraries, QTextStream& errorStream) { QStringList missing; QStringList processed; - loadDependenciesForModel(modelName, libraries, missing, processed, errorStream); + loadDependenciesForModel(modelName, path, libraries, missing, processed, errorStream); if (not missing.empty()) { missing.sort(Qt::CaseInsensitive); @@ -112,8 +113,23 @@ } } +static QString findFile(QString referenceName, const QString& path, const LibraryManager& libraries) +{ + // Try to find the file in the same place as the model itself + referenceName.replace("\\", "/"); + const QDir dir = QFileInfo{path}.dir(); + QString referencedFilePath = dir.filePath(referenceName); + if (not QFileInfo{referencedFilePath}.exists()) + { + // Look for it in the libraries + referencedFilePath = libraries.findFile(referenceName); + } + return referencedFilePath; +} + void DocumentManager::loadDependenciesForModel( const QString& modelName, + const QString &path, const LibraryManager& libraries, QStringList& missing, QStringList& processed, @@ -134,24 +150,24 @@ { try { - const QString path = libraries.findFile(referenceName); - if (path.isEmpty()) + const QString referencedFilePath = findFile(referenceName, path, libraries); + if (referencedFilePath.isEmpty()) { throw LoadingError{utility::format("'%1' was not found.", referenceName)}; } QString errorString; QTextStream localErrorStream{&errorString}; - QString resultName = this->openModel(path, localErrorStream); + QString resultName = this->openModel(referencedFilePath, localErrorStream); if (resultName.isEmpty()) { throw LoadingError{utility::format( "could not load '%1': %2", - path, + referencedFilePath, errorString)}; } if (not processed.contains(referenceName)) { - loadDependenciesForModel(referenceName, libraries, missing, processed, errorStream); + loadDependenciesForModel(referenceName, path, libraries, missing, processed, errorStream); } } catch(const LoadingError& error)