Commit f6ab51d9 authored by Kåre Särs's avatar Kåre Särs
Browse files

Rebase on the grouped emits

parent 4798781e
......@@ -53,7 +53,7 @@ int MatchModel::matchFileRow(const QUrl& fileUrl)
static const int totalContectLen = 150;
/** This function is used to add a match to a new file */
void MatchModel::addMatch(const QUrl &fileUrl, const QString &lineContent, int matchLen, int line, int column, int endLine, int endColumn)
void MatchModel::addMatches(const QUrl &fileUrl, const QVector<KateSearchMatch> &searchMatches)
{
int fileIndex = matchFileRow(fileUrl);
if (fileIndex == -1) {
......@@ -65,29 +65,31 @@ void MatchModel::addMatch(const QUrl &fileUrl, const QString &lineContent, int m
m_matchFiles[fileIndex].fileUrl = fileUrl;
endInsertRows();
}
MatchModel::Match match;
match.matchLen = matchLen;
match.startLine = line;
match.startColumn = column;
match.endLine = endLine;
match.endColumn = endColumn;
int contextLen = totalContectLen - matchLen;
int preLen = qMin(contextLen/3, column);
int postLen = contextLen - preLen;
int matchIndex = m_matchFiles[fileIndex].matches.size();
beginInsertRows(index(fileIndex, 0), matchIndex, matchIndex + searchMatches.size()-1);
for (const auto &sMatch: searchMatches) {
MatchModel::Match match;
match.matchLen = sMatch.matchLen;
match.startLine = sMatch.matchRange.start().line();
match.startColumn = sMatch.matchRange.start().column();
match.endLine = sMatch.matchRange.end().line();
match.endColumn = sMatch.matchRange.end().column();
match.preMatchStr = lineContent.mid(column-preLen, preLen);
if (column > preLen) match.preMatchStr.prepend(QLatin1String("..."));
int contextLen = totalContectLen - sMatch.matchLen;
int preLen = qMin(contextLen/3, match.startColumn);
int postLen = contextLen - preLen;
match.postMatchStr = lineContent.mid(endColumn, postLen);
if (endColumn+preLen < lineContent.size()) match.postMatchStr.append(QLatin1String("..."));
match.preMatchStr = sMatch.lineContent.mid(match.startColumn-preLen, preLen);
if (match.startColumn > preLen) match.preMatchStr.prepend(QLatin1String("..."));
match.matchStr = lineContent.mid(column, matchLen);
match.postMatchStr = sMatch.lineContent.mid(match.endColumn, postLen);
if (match.endColumn+preLen < sMatch.lineContent.size()) match.postMatchStr.append(QLatin1String("..."));
int matchIndex = m_matchFiles[fileIndex].matches.size();
beginInsertRows(index(fileIndex, 0), matchIndex, matchIndex);
// We are always starting the insert at the end, so we could optimize by delaying/grouping the signaling of the updates
m_matchFiles[fileIndex].matches.append(match);
match.matchStr = sMatch.lineContent.mid(match.startColumn, sMatch.matchLen);
m_matchFiles[fileIndex].matches.append(match);
}
endInsertRows();
}
......
......@@ -13,6 +13,25 @@
#include <QUrl>
#include <QBrush>
#include <KTextEditor/Range>
/**
* data holder for one match in one file
* used to transfer multiple matches at once via signals to avoid heavy costs for files with a lot of matches
*/
class KateSearchMatch
{
public:
QString lineContent;
int matchLen;
KTextEditor::Range matchRange;
};
Q_DECLARE_METATYPE(KateSearchMatch)
class MatchModel : public QAbstractItemModel
{
Q_OBJECT
......@@ -68,7 +87,7 @@ public Q_SLOTS:
int matchFileRow(const QUrl& fileUrl);
/** This function is used to add a new file */
void addMatch(const QUrl &fileUrl, const QString &lineContent, int matchLen, int line, int column, int endLine, int endColumn);
void addMatches(const QUrl &fileUrl, const QVector<KateSearchMatch> &searchMatches);
// /** This function is used to modify a match */
// void replaceMatch(const QModelIndex &matchIndex, const QRegularExpression &regexp, const QString &replaceText);
......
......@@ -26,21 +26,7 @@
#include <QThread>
#include <QVector>
#include <KTextEditor/Range>
/**
* data holder for one match in one file
* used to transfer multiple matches at once via signals to avoid heavy costs for files with a lot of matches
*/
class KateSearchMatch
{
public:
QString lineContent;
int matchLen;
KTextEditor::Range matchRange;
};
Q_DECLARE_METATYPE(KateSearchMatch)
#include "MatchModel.h"
class SearchDiskFiles : public QThread
{
......
......@@ -966,6 +966,8 @@ void KatePluginSearchView::matchesFound(const QUrl &url, const QVector<KateSearc
const QString bgColor = m_searchBackgroundColor.color().name();
const QString fgColor = m_foregroundColor.color().name();
m_curResults->matchModel.addMatches(url, searchMatches);
/**
* handle all received matches, add them as one operation to the widget afterwards
*/
......
......@@ -24,7 +24,7 @@
#include <QTimer>
#include <ktexteditor/document.h>
#include "SearchDiskFiles.h"
#include "MatchModel.h"
class SearchOpenFiles : public QObject
{
......
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