Commit b7704709 authored by Alexander Neundorf's avatar Alexander Neundorf Committed by Alexander Neundorf
Browse files

Search&Replace: improve filtering behaviour and match counts

The filter now only checks the displayed part of the file path,
and excludes the base search path (which is the same for all
results anyway, so if it would match there, it would match for
all search results).

Also, the filtering for the filename is moved from the proxymodel
into the actual filter function in MatchModel. This way the displayed
match count is updated correctly (and it's less code).
parent ee29b74d
Pipeline #147079 passed with stage
in 7 minutes and 44 seconds
......@@ -501,6 +501,11 @@ bool MatchModel::matchesFilter(const QModelIndex &index)
int matchRow = index.internalId() == InfoItemId || index.internalId() == FileItemId ? -1 : index.row();
if ((fileRow >= 0) && (fileRow < m_matchFiles.size()) && (matchRow >= 0) && (matchRow < m_matchFiles[fileRow].matches.size())) {
// also match by filename
if (matches == false) {
const QString fileStr = fileToPlainText(m_matchFiles[fileRow]);
matches = fileStr.contains(m_filterText, Qt::CaseInsensitive);
}
m_matchFiles[fileRow].matches[matchRow].matchesFilter = matches;
}
......@@ -737,9 +742,10 @@ QString MatchModel::infoToPlainText() const
return QString();
}
QString MatchModel::fileToPlainText(const MatchFile &matchFile)
QString MatchModel::fileToPlainText(const MatchFile &matchFile) const
{
QString path = matchFile.fileUrl.isLocalFile() ? localFileDirUp(matchFile.fileUrl).path() : matchFile.fileUrl.url();
path.remove(m_resultBaseDir);
if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) {
path += QLatin1Char('/');
}
......
......@@ -208,7 +208,7 @@ private:
QString matchToHtmlString(const Match &match) const;
QString infoToPlainText() const;
static QString fileToPlainText(const MatchFile &matchFile);
QString fileToPlainText(const MatchFile &matchFile) const;
static QString matchToPlainText(const Match &match);
bool setFileChecked(int fileRow, bool checked);
......
......@@ -30,32 +30,5 @@ bool MatchProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent)
auto *matchModel = dynamic_cast<MatchModel *>(sourceModel());
bool matches = matchModel->matchesFilter(index);
if (matches) {
return true;
}
// text didn't match. Check if this is a match item & its parent is accepted
if (isMatchItem(index) && parentAcceptsRow(parent)) {
return true;
}
// filter it out
return false;
}
bool MatchProxyModel::isMatchItem(const QModelIndex &index)
{
return index.parent().isValid() && index.parent().parent().isValid();
}
bool MatchProxyModel::parentAcceptsRow(const QModelIndex &source_parent) const
{
if (source_parent.isValid()) {
const QModelIndex index = source_parent.parent();
if (filterAcceptsRow(source_parent.row(), index)) {
return true;
}
// we don't want to recurse because our root item is always accepted
}
return false;
return matches;
}
......@@ -18,10 +18,6 @@ public:
Q_SLOT void setFilterText(const QString &text);
static bool isMatchItem(const QModelIndex &index);
private:
bool parentAcceptsRow(const QModelIndex &source_parent) const;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment