| 54 | } |
| 55 | |
| 56 | std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> |
| 57 | ModelLibrary::getModelTree(ModelFilter filter) const |
| 58 | { |
| 59 | std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> modelTree = |
| 60 | std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>(); |
| 61 | |
| 62 | auto models = ModelManager::getManager().libraryModels(getName()); |
| 63 | for (auto& it : *models) { |
| 64 | auto uuid = it.getUUID(); |
| 65 | auto path = it.getPath(); |
| 66 | auto filename = it.getName(); |
| 67 | |
| 68 | auto model = ModelManager::getManager().getModel(getName(), uuid); |
| 69 | if (ModelManager::passFilter(filter, model->getType())) { |
| 70 | QStringList list = path.split(QLatin1Char('/')); |
| 71 | |
| 72 | // Start at the root |
| 73 | std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> node = modelTree; |
| 74 | for (auto& itp : list) { |
| 75 | // Add the folder only if it's not already there |
| 76 | if (!node->contains(itp)) { |
| 77 | auto mapPtr = |
| 78 | std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>(); |
| 79 | std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>(); |
| 80 | child->setFolder(mapPtr); |
| 81 | (*node)[itp] = child; |
| 82 | node = mapPtr; |
| 83 | } |
| 84 | else { |
| 85 | node = (*node)[itp]->getFolder(); |
| 86 | } |
| 87 | } |
| 88 | std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>(); |
| 89 | child->setUUID(uuid); |
| 90 | child->setData(model); |
| 91 | (*node)[filename] = child; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return modelTree; |
| 96 | } |
| 97 | |
| 98 | TYPESYSTEM_SOURCE(Materials::ModelLibraryLocal, Materials::ModelLibrary) |
| 99 | |