MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / goTo

Method goTo

src/document/UBDocumentController.cpp:1210–1257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1208}
1209
1210QModelIndex UBDocumentTreeModel::goTo(const QString &dir)
1211{
1212 QStringList pathList = dir.split("/", UB::SplitBehavior::SkipEmptyParts);
1213
1214 if (pathList.isEmpty()) {
1215 return untitledDocumentsIndex();
1216 }
1217
1218 if (pathList.first() != UBPersistenceManager::myDocumentsName
1219 && pathList.first() != UBSettings::trashedDocumentGroupNamePrefix
1220 && pathList.first() != UBPersistenceManager::modelsName) {
1221 pathList.prepend(UBPersistenceManager::myDocumentsName);
1222 }
1223
1224 QModelIndex parentIndex;
1225
1226 bool searchingNode = true;
1227 while (!pathList.isEmpty())
1228 {
1229 QString curLevelName = pathList.takeFirst();
1230 if (searchingNode) {
1231 searchingNode = false;
1232 int irowCount = rowCount(parentIndex);
1233 for (int i = 0; i < irowCount; ++i) {
1234 QModelIndex curChildIndex = index(i, 0, parentIndex);
1235 UBDocumentTreeNode* currentNode = nodeFromIndex(curChildIndex);
1236 if (currentNode->nodeName() == curLevelName && currentNode->nodeType() == UBDocumentTreeNode::Catalog)
1237 {
1238 searchingNode = true;
1239 parentIndex = curChildIndex;
1240 break;
1241 }
1242 }
1243 }
1244
1245 if (!searchingNode) {
1246 UBDocumentTreeNode *newChild = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, curLevelName);
1247 parentIndex = addNode(newChild, parentIndex);
1248
1249 if (!parentIndex.isValid())
1250 {
1251 delete newChild;
1252 }
1253 }
1254 }
1255
1256 return parentIndex;
1257}
1258
1259bool UBDocumentTreeModel::inTrash(const QModelIndex &index) const
1260{

Calls 4

nodeNameMethod · 0.80
nodeTypeMethod · 0.80
isEmptyMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected