# HG changeset patch # User Teemu Piippo # Date 1681933363 -10800 # Node ID 16f6717a218b5f63604b4131b4f0e7747d6408b7 # Parent 8d88adffb779d744cbe5fa27fac9b2f129e04514 Use QFileInfo to represent paths diff -r 8d88adffb779 -r 16f6717a218b src/documentmanager.cpp --- a/src/documentmanager.cpp Wed Apr 12 01:53:42 2023 +0300 +++ b/src/documentmanager.cpp Wed Apr 19 22:42:43 2023 +0300 @@ -341,7 +341,7 @@ } } -static QString findFile( +static QFileInfo findFile( QString referenceName, const QString& modelPath, const LibrariesModel& libraries) @@ -349,8 +349,8 @@ // Try to find the file in the same place as the model itself referenceName.replace("\\", "/"); const QDir dir = QFileInfo{modelPath}.dir(); - QString referencedFilePath = dir.filePath(referenceName); - if (not QFileInfo{referencedFilePath}.exists()) + QFileInfo referencedFilePath = {dir.filePath(referenceName)}; + if (not referencedFilePath.exists()) { // Look for it in the libraries referencedFilePath = libraries.findFile(referenceName); @@ -373,14 +373,14 @@ struct Dependency { QString name; - QString path; + QFileInfo path; bool operator<(const Dependency& other) const { if (this->name != other.name) { return this->name < other.name; } else { - return this->path < other.path; + return this->path.absoluteFilePath() < other.path.absoluteFilePath(); } } }; @@ -393,8 +393,9 @@ const std::set refNames = referenceNames(modelInfo->model.get()); if (modelInfo != nullptr) { for (const QString& name : refNames) { - const QString path = findFile(name, modelInfo->path, *libraries); - if (not path.isEmpty()) { + const QFileInfo path = findFile(name, modelInfo->path, *libraries); + if (path.exists()) + { result.insert(Dependency{.name = name, .path = path}); } } @@ -419,17 +420,17 @@ if (idp != nullptr) { info->dependencies[dep.name] = *idp; } - else if (not info->dependencies.contains(dep.name) and not missing.contains(dep.path)) { + else if (not info->dependencies.contains(dep.name) and not missing.contains(dep.path.absoluteFilePath())) { QString loadErrorString; QTextStream localErrorStream{&loadErrorString}; const std::optional modelIdOpt = documents->openModel( - dep.path, + dep.path.absoluteFilePath(), localErrorStream, OpenType::AutomaticallyOpened); if (not modelIdOpt.has_value()) { const QString& errorMessage = QObject::tr("could not load '%1': %2") - .arg(dep.path, loadErrorString); - missing[dep.path] = errorMessage; + .arg(dep.path.absoluteFilePath(), loadErrorString); + missing[dep.path.absoluteFilePath()] = errorMessage; } else { info->dependencies[dep.name] = modelIdOpt.value(); diff -r 8d88adffb779 -r 16f6717a218b src/libraries.cpp --- a/src/libraries.cpp Wed Apr 12 01:53:42 2023 +0300 +++ b/src/libraries.cpp Wed Apr 19 22:42:43 2023 +0300 @@ -34,9 +34,9 @@ * @param fileName File to search for * @return Full path to the file, or empty string if not found. */ -QString LibrariesModel::findFile(QString fileName) const +QFileInfo LibrariesModel::findFile(QString fileName) const { - QString path; + QFileInfo result; fileName.replace("\\", "/"); bool found = false; for (const Library& library : this->libraries) @@ -48,7 +48,7 @@ QFileInfo fileInfo{directory.absoluteFilePath(fileName)}; if (fileInfo.exists() && fileInfo.isFile()) { - path = fileInfo.absoluteFilePath(); + result = fileInfo; found = true; break; } @@ -58,7 +58,7 @@ break; } } - return path; + return result; } /** diff -r 8d88adffb779 -r 16f6717a218b src/libraries.h --- a/src/libraries.h Wed Apr 12 01:53:42 2023 +0300 +++ b/src/libraries.h Wed Apr 19 22:42:43 2023 +0300 @@ -53,7 +53,7 @@ LibrariesModel(QObject* parent = nullptr); auto begin() const { return this->libraries.begin(); } auto end() const { return this->libraries.end(); } - QString findFile(QString fileName) const; + QFileInfo findFile(QString fileName) const; void addLibrary(const Library& library); void removeLibrary(const index_t libraryIndex); const Library& library(index_t libraryIndex) const;