| 31 | } |
| 32 | |
| 33 | FolderNode *Utils::recursiveFindOrCreateFolderNode(FolderNode *folder, |
| 34 | const QString &directory, |
| 35 | const QString &workspace, |
| 36 | const FolderNode::FolderNodeFactory &factory) |
| 37 | { |
| 38 | QString path = workspace.isEmpty() ? folder->filePath() : workspace; |
| 39 | QString directoryWithoutPrefix; |
| 40 | bool isRelative = false; |
| 41 | |
| 42 | if (path.isEmpty() || path == "/") { |
| 43 | directoryWithoutPrefix = directory; |
| 44 | isRelative = false; |
| 45 | } else { |
| 46 | if (isChildOf(path, directory) || directory == path) { |
| 47 | isRelative = true; |
| 48 | directoryWithoutPrefix = relativeChildPath(path, directory); |
| 49 | } else { |
| 50 | const QString relativePath = relativeChildPath(path, directory); |
| 51 | if (relativePath.count("../") < 5) { |
| 52 | isRelative = true; |
| 53 | directoryWithoutPrefix = relativePath; |
| 54 | } else { |
| 55 | isRelative = false; |
| 56 | path.clear(); |
| 57 | directoryWithoutPrefix = directory; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | QStringList parts = directoryWithoutPrefix.split('/', QString::SkipEmptyParts); |
| 62 | if (!isRelative && !parts.isEmpty()) |
| 63 | parts[0].prepend('/'); |
| 64 | |
| 65 | FolderNode *parent = folder; |
| 66 | for (const QString &part : std::as_const(parts)) { |
| 67 | path += QLatin1Char('/') + part; |
| 68 | // Find folder in subFolders |
| 69 | FolderNode *next = parent->folderNode(path); |
| 70 | if (!next) { |
| 71 | // No FolderNode yet, so create it |
| 72 | auto tmp = factory(path); |
| 73 | tmp->setDisplayName(part); |
| 74 | next = tmp.get(); |
| 75 | parent->addNode(std::move(tmp)); |
| 76 | } |
| 77 | parent = next; |
| 78 | } |
| 79 | return parent; |
| 80 | } |
| 81 | |
| 82 | bool Utils::isChildOf(const QString &path, const QString &subPath) |
| 83 | { |
nothing calls this directly
no test coverage detected