| 59 | {} |
| 60 | |
| 61 | std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>> |
| 62 | MaterialLibrary::getMaterialTree(const Materials::MaterialFilter& filter, |
| 63 | const Materials::MaterialFilterOptions& options) const |
| 64 | { |
| 65 | std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>> materialTree = |
| 66 | std::make_shared<std::map<QString, std::shared_ptr<MaterialTreeNode>>>(); |
| 67 | |
| 68 | auto materials = MaterialManager::getManager().libraryMaterials(getName(), filter, options, isLocal()); |
| 69 | for (auto& it : *materials) { |
| 70 | auto uuid = it.getUUID(); |
| 71 | auto path = it.getPath(); |
| 72 | auto filename = it.getName(); |
| 73 | |
| 74 | QStringList list = path.split(QStringLiteral("/")); |
| 75 | |
| 76 | // Start at the root |
| 77 | std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>> node = |
| 78 | materialTree; |
| 79 | for (auto& itp : list) { |
| 80 | if (!itp.isEmpty()) { |
| 81 | // Add the folder only if it's not already there |
| 82 | if (!node->contains(itp)) { |
| 83 | auto mapPtr = std::make_shared< |
| 84 | std::map<QString, std::shared_ptr<MaterialTreeNode>>>(); |
| 85 | std::shared_ptr<MaterialTreeNode> child = |
| 86 | std::make_shared<MaterialTreeNode>(); |
| 87 | child->setFolder(mapPtr); |
| 88 | child->setReadOnly(isReadOnly()); |
| 89 | (*node)[itp] = child; |
| 90 | node = mapPtr; |
| 91 | } |
| 92 | else { |
| 93 | node = (*node)[itp]->getFolder(); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | std::shared_ptr<MaterialTreeNode> child = std::make_shared<MaterialTreeNode>(); |
| 98 | child->setUUID(uuid); |
| 99 | child->setReadOnly(isReadOnly()); |
| 100 | if (isLocal()) { |
| 101 | auto material = MaterialManager::getManager().getMaterial(uuid); |
| 102 | child->setOldFormat(material->isOldFormat()); |
| 103 | } |
| 104 | (*node)[filename] = child; |
| 105 | } |
| 106 | |
| 107 | // // Empty folders aren't included in _materialPathMap, so we add them by looking at the file |
| 108 | // // system |
| 109 | // if (!filter || options.includeEmptyFolders()) { |
| 110 | // if (isLocal()) { |
| 111 | // auto& materialLibrary = |
| 112 | // *(reinterpret_cast<const Materials::MaterialLibraryLocal*>(this)); |
| 113 | // auto folderList = MaterialLoader::getMaterialFolders(materialLibrary); |
| 114 | // for (auto& folder : *folderList) { |
| 115 | // QStringList list = folder.split(QStringLiteral("/")); |
| 116 | |
| 117 | // // Start at the root |
| 118 | // auto node = materialTree; |