gui: PreviewGeneratorPlaintext: Add MAX_SNIPPETS const, remove redundant loop
This commit is contained in:
parent
ad06497b4b
commit
89bf65d9bb
@ -14,14 +14,13 @@ QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderCo
|
|||||||
|
|
||||||
QHash<QString, int> countmap;
|
QHash<QString, int> countmap;
|
||||||
|
|
||||||
const unsigned int maxSnippets = 7;
|
|
||||||
unsigned int currentSnippets = 0;
|
unsigned int currentSnippets = 0;
|
||||||
for(QString &word : config.wordsToHighlight)
|
for(QString &word : config.wordsToHighlight)
|
||||||
{
|
{
|
||||||
|
|
||||||
int lastPos = 0;
|
int lastPos = 0;
|
||||||
int index = content.indexOf(word, lastPos, Qt::CaseInsensitive);
|
int index = content.indexOf(word, lastPos, Qt::CaseInsensitive);
|
||||||
while(index != -1 && currentSnippets < maxSnippets)
|
while(index != -1 && currentSnippets < MAX_SNIPPETS)
|
||||||
{
|
{
|
||||||
countmap[word] = countmap.value(word, 0) + 1;
|
countmap[word] = countmap.value(word, 0) + 1;
|
||||||
|
|
||||||
@ -57,17 +56,14 @@ QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderCo
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(QString &word : config.wordsToHighlight)
|
|
||||||
{
|
|
||||||
resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString header = "<b>" + fileName + "</b> ";
|
QString header = "<b>" + fileName + "</b> ";
|
||||||
for(QString &word : config.wordsToHighlight)
|
for(QString &word : config.wordsToHighlight)
|
||||||
{
|
{
|
||||||
|
resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive);
|
||||||
header += word + ": " + QString::number(countmap[word]) + " ";
|
header += word + ": " + QString::number(countmap[word]) + " ";
|
||||||
}
|
}
|
||||||
if(currentSnippets == maxSnippets)
|
|
||||||
|
if(currentSnippets == MAX_SNIPPETS)
|
||||||
{
|
{
|
||||||
header += "(truncated)";
|
header += "(truncated)";
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
class PreviewGeneratorPlainText : public PreviewGenerator
|
class PreviewGeneratorPlainText : public PreviewGenerator
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
const unsigned int MAX_SNIPPETS = 7;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using PreviewGenerator::PreviewGenerator;
|
using PreviewGenerator::PreviewGenerator;
|
||||||
QString generatePreviewText(QString content, RenderConfig config, QString fileName);
|
QString generatePreviewText(QString content, RenderConfig config, QString fileName);
|
||||||
|
Caricamento…
Fai riferimento in un nuovo problema
Block a user