MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / recursiveFindOrCreateFolderNode

Method recursiveFindOrCreateFolderNode

src/plugins/smartut/utils/utils.cpp:33–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33FolderNode *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
82bool Utils::isChildOf(const QString &path, const QString &subPath)
83{

Callers

nothing calls this directly

Calls 9

factoryFunction · 0.85
folderNodeMethod · 0.80
addNodeMethod · 0.80
isEmptyMethod · 0.45
filePathMethod · 0.45
countMethod · 0.45
clearMethod · 0.45
setDisplayNameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected