From a3ad10b459b285ca51a743954f0899909f1104e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Tue, 26 Jan 2021 11:18:32 +0100 Subject: [PATCH] fixed two issues regarding ubx import where import could fail if some folders and files had the same name --- src/document/UBDocumentController.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 7dd80544..12171d2c 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1028,8 +1028,14 @@ QStringList UBDocumentTreeModel::nodeNameList(const QModelIndex &pIndex) const return QStringList(); } - foreach (UBDocumentTreeNode *curNode, catalog->children()) { - result << curNode->nodeName(); + foreach (UBDocumentTreeNode *curNode, catalog->children()) + { + /* this function is only used (at this time) to compare filenames eachother, so it has to distinguish a folder named "A" from a file named "A" + // notice that it is a really poor way to search for file indexes, and that the code where it is called should be entirely reworked, when the time permits it. */ + if (curNode->nodeType() != UBDocumentTreeNode::Catalog) + result << curNode->nodeName(); + else + result << "folder - " + curNode->nodeName(); } return result; @@ -1070,9 +1076,12 @@ QModelIndex UBDocumentTreeModel::goTo(const QString &dir) QString curLevelName = pathList.takeFirst(); if (searchingNode) { searchingNode = false; - for (int i = 0; i < rowCount(parentIndex); ++i) { + int irowCount = rowCount(parentIndex); + for (int i = 0; i < irowCount; ++i) { QModelIndex curChildIndex = index(i, 0, parentIndex); - if (nodeFromIndex(curChildIndex)->nodeName() == curLevelName) { + UBDocumentTreeNode* currentNode = nodeFromIndex(curChildIndex); + if (currentNode->nodeName() == curLevelName && currentNode->nodeType() == UBDocumentTreeNode::Catalog) + { searchingNode = true; parentIndex = curChildIndex; break;