feat: Improved searching for hotkeys (#5884)

This commit is contained in:
apa420
2025-03-04 14:15:50 +00:00
committed by GitHub
parent 8dd19d2d5e
commit c053fd5c60
5 changed files with 97 additions and 1 deletions
+59
View File
@@ -150,6 +150,65 @@ void EditableModelView::addRegexHelpLink()
this->addCustomButton(regexHelpLabel);
}
bool EditableModelView::filterSearchResults(const QString &query,
std::span<const int> columnSelect)
{
bool searchFoundSomething = false;
auto rowAmount = this->model_->rowCount();
// make sure to show the page even if the table is empty,
// but only if we aren't search something
if (rowAmount == 0 && query.isEmpty())
{
return true;
}
for (int i = 0; i < rowAmount; i++)
{
bool foundMatch = false;
for (int j : columnSelect)
{
QModelIndex idx = model_->index(i, j);
QVariant a = model_->data(idx);
if (a.toString().contains(query, Qt::CaseInsensitive))
{
foundMatch = true;
searchFoundSomething = true;
break;
}
}
tableView_->setRowHidden(i, !foundMatch);
}
return searchFoundSomething;
}
void EditableModelView::filterSearchResultsHotkey(
const QKeySequence &keySequenceQuery)
{
auto rowAmount = this->model_->rowCount();
for (int i = 0; i < rowAmount; i++)
{
QModelIndex idx = model_->index(i, 1);
QVariant a = model_->data(idx);
auto seq = qvariant_cast<QKeySequence>(a);
// todo: Make this fuzzy match, right now only exact matches happen
// so ctrl+f won't match ctrl+shift+f shortcuts
if (keySequenceQuery.matches(seq) != QKeySequence::NoMatch)
{
tableView_->showRow(i);
}
else
{
tableView_->hideRow(i);
}
}
}
void EditableModelView::moveRow(int dir)
{
auto selected = this->getTableView()->selectionModel()->selectedRows(0);