| 127 | } |
| 128 | |
| 129 | void ProjectItemDataProvider::setFilterText(const QString& text) |
| 130 | { |
| 131 | m_addedItems.clear(); |
| 132 | m_addedItemsCountCache.markDirty(); |
| 133 | |
| 134 | QStringList search(text.split(QStringLiteral("::"), Qt::SkipEmptyParts)); |
| 135 | for (auto& s : search) { |
| 136 | if (s.endsWith(QLatin1Char(':'))) { //Don't get confused while the :: is being typed |
| 137 | s.chop(1); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (!search.isEmpty() && search.back().endsWith(QLatin1Char('('))) { |
| 142 | search.back().chop(1); |
| 143 | } |
| 144 | |
| 145 | if (text.isEmpty() || search.isEmpty()) { |
| 146 | m_filteredItems = m_currentItems; |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | KDevVarLengthArray<SubstringCache, 5> cache; |
| 151 | for (const QString& searchPart : std::as_const(search)) { |
| 152 | cache.append(SubstringCache(searchPart)); |
| 153 | } |
| 154 | |
| 155 | if (!text.startsWith(m_currentFilter)) { |
| 156 | m_filteredItems = m_currentItems; |
| 157 | } |
| 158 | |
| 159 | m_currentFilter = text; |
| 160 | |
| 161 | const QVector<CodeModelViewItem> oldFiltered = m_filteredItems; |
| 162 | QHash<int, int> heights; |
| 163 | |
| 164 | m_filteredItems.clear(); |
| 165 | |
| 166 | for (const CodeModelViewItem& item : oldFiltered) { |
| 167 | const QualifiedIdentifier& currentId = item.m_id; |
| 168 | |
| 169 | int last_pos = currentId.count() - 1; |
| 170 | int current_height = 0; |
| 171 | int distance = 0; |
| 172 | |
| 173 | //iter over each search item from last to first |
| 174 | //this makes easier to calculate the distance based on where we hit the result or nothing |
| 175 | //Iterating from the last item to the first is more efficient, as we want to match the |
| 176 | //class/function name, which is the last item on the search fields and on the identifier. |
| 177 | for (int b = search.count() - 1; b >= 0; --b) { |
| 178 | //iter over each id for the current identifier, from last to first |
| 179 | for (; last_pos >= 0; --last_pos, distance++) { |
| 180 | // the more distant we are from the class definition, the less priority it will have |
| 181 | current_height += distance * 10000; |
| 182 | int result; |
| 183 | //if the current search item is contained on the current identifier |
| 184 | if ((result = cache[b].containedIn(currentId.at(last_pos))) >= 0) { |
| 185 | //when we find a hit, we add the distance to the searched word. |
| 186 | //so the closest item will be displayed first |
nothing calls this directly
no test coverage detected