Add a setting to show collection search results as a tree

#1051 replaced the filtered tree with a ranked flat list. A new checkbox
in Settings > General, "Afficher les résultats de recherche sous forme de
liste triée" (elementscollection/search-flat-list, default on), keeps the
ranked list; unticked restores the pre-#1051 filtered tree search.

The Insert picker and shortcut bar call rankedSearch() directly and are
unaffected. Down/Enter from the search field only apply to the flat list.

Requested by scorpio810 on #1051.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-09-28 05:43:11 +13:00
parent d56e99702c
commit f62a44827b
3 changed files with 38 additions and 1 deletions
@@ -1103,7 +1103,32 @@ void ElementsCollectionWidget::search()
return;
}
showFlatResults(rankedSearch(text, m_showed_index));
QSettings settings;
if (settings.value(QStringLiteral("elementscollection/search-flat-list"),
true).toBool())
{
showFlatResults(rankedSearch(text, m_showed_index));
return;
}
//Tree search: hide what does not match, expand what does.
clearFlatResults();
hideCollection(true);
const QStringList text_list = text.split("+", Qt::SkipEmptyParts);
QModelIndexList match_index;
for (const QString &txt : text_list) {
match_index << m_model->match(m_showed_index.isValid()
? m_model->index(0,0,m_showed_index)
: m_model->index(0,0),
Qt::UserRole+1,
QVariant(txt),
-1,
Qt::MatchContains
| Qt::MatchRecursive);
}
for (const QModelIndex &index : std::as_const(match_index))
showAndExpandItem(index);
}
/**