aboutsummaryrefslogtreecommitdiff
path: root/src/completion/FuzzySearchProxyModel.cpp
blob: 151f60eea6ca15a95a167b938f8b924ce2e29b6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <QWidget>
#include <QtCore>

#include "completion/FuzzySearchProxyModel.hpp"

bool FuzzySearchProxyModel::filterAcceptsRow(
    int sourceRow, const QModelIndex &sourceParent) const {
  QAbstractItemModel *model = sourceModel();
  QString filterText = filterRegularExpression().pattern();
  qDebug() << "Searching: " << filterText;

  for (int col = 0; col < model->columnCount(); ++col) {
    QModelIndex index = model->index(sourceRow, col, sourceParent);
    QString data = model->data(index, Qt::AccessibleDescriptionRole).toString();

    qDebug() << "    against: " << data;

    // TODO: Fuzzy eet up
    if (data.contains(filterText, Qt::CaseInsensitive)) {
      return true;
    }
  }
  return false;
}