| 871 | } |
| 872 | |
| 873 | QModelIndex ProjectModel::pathToIndex(const QStringList& tofetch_) const |
| 874 | { |
| 875 | if(tofetch_.isEmpty()) |
| 876 | return QModelIndex(); |
| 877 | QStringList tofetch(tofetch_); |
| 878 | if(tofetch.last().isEmpty()) |
| 879 | tofetch.removeLast(); |
| 880 | |
| 881 | QModelIndex current=index(0,0, QModelIndex()); |
| 882 | |
| 883 | QModelIndex ret; |
| 884 | for(int a = 0; a < tofetch.size(); ++a) |
| 885 | { |
| 886 | const QString& currentName = tofetch[a]; |
| 887 | |
| 888 | bool matched = false; |
| 889 | const QModelIndexList l = match(current, Qt::DisplayRole, currentName, -1, Qt::MatchExactly); |
| 890 | for (const QModelIndex& idx : l) { |
| 891 | //If this is not the last item, only match folders, as there may be targets and folders with the same name |
| 892 | if(a == tofetch.size()-1 || itemFromIndex(idx)->folder()) { |
| 893 | ret = idx; |
| 894 | current = index(0,0, ret); |
| 895 | matched = true; |
| 896 | break; |
| 897 | } |
| 898 | } |
| 899 | if(!matched) { |
| 900 | ret = QModelIndex(); |
| 901 | break; |
| 902 | } |
| 903 | } |
| 904 | Q_ASSERT(!ret.isValid() || data(ret).toString()==tofetch.last()); |
| 905 | return ret; |
| 906 | } |
| 907 | |
| 908 | QStringList ProjectModel::pathFromIndex(const QModelIndex& index) const |
| 909 | { |