dont highlight terms in very big docs: too slow

This commit is contained in:
dockes 2006-01-30 10:01:05 +00:00
parent ce622e2be4
commit 92b5cb001d

View File

@ -420,7 +420,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
// Create progress dialog and aux objects // Create progress dialog and aux objects
const int nsteps = 20; const int nsteps = 20;
QProgressDialog progress(msg, tr("Cancel"), nsteps, this, "Loading", FALSE); QProgressDialog progress(msg, tr("Cancel"), nsteps, this, "Loading", FALSE);
progress.setMinimumDuration(1000); progress.setMinimumDuration(2000);
WaiterThread waiter(100); WaiterThread waiter(100);
// Load and convert file // Load and convert file
@ -456,12 +456,15 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
// Reset config just in case. // Reset config just in case.
rclconfig->setKeyDir(""); rclconfig->setKeyDir("");
// Create preview text: highlight search terms: // Create preview text: highlight search terms (if not too big):
QString richTxt;
list<pair<int, int> > termoffsets;
bool highlightTerms = fdoc.text.length() < 1000 *1024;
if (highlightTerms) {
progress.setLabelText(tr("Creating preview text")); progress.setLabelText(tr("Creating preview text"));
list<string> terms; list<string> terms;
rcldb->getQueryTerms(terms); rcldb->getQueryTerms(terms);
list<pair<int, int> > termoffsets;
QString richTxt;
ToRichThread rthr(fdoc.text, terms, termoffsets, richTxt); ToRichThread rthr(fdoc.text, terms, termoffsets, richTxt);
rthr.start(); rthr.start();
@ -488,13 +491,18 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
richTxt += "<b>Cancelled !</b>"; richTxt += "<b>Cancelled !</b>";
} }
} }
} else {
richTxt = fdoc.text.c_str();
}
// Load into editor // Load into editor
QTextEdit *editor = getCurrentEditor(); QTextEdit *editor = getCurrentEditor();
if (highlightTerms) {
QStyleSheetItem *item = QStyleSheetItem *item =
new QStyleSheetItem(editor->styleSheet(), "termtag" ); new QStyleSheetItem(editor->styleSheet(), "termtag" );
item->setColor("blue"); item->setColor("blue");
item->setFontWeight(QFont::Bold); item->setFontWeight(QFont::Bold);
}
prog = 2 * nsteps / 3; prog = 2 * nsteps / 3;
progress.setLabelText(tr("Loading preview text into editor")); progress.setLabelText(tr("Loading preview text into editor"));
@ -507,7 +515,8 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
l = MIN(CHUNKL, richTxt.length() - pos); l = MIN(CHUNKL, richTxt.length() - pos);
// Avoid breaking inside a tag. Our tags are short (ie: <br>) // Avoid breaking inside a tag. Our tags are short (ie: <br>)
for (int i = -4; i < 0; i++) { if (pos + l != richTxt.length())
for (int i = -15; i < 0; i++) {
if (richTxt[pos+l+i] == '<') { if (richTxt[pos+l+i] == '<') {
l = l+i; l = l+i;
break; break;
@ -527,6 +536,8 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
break; break;
} }
} }
if (highlightTerms) {
int para = 0, index = 1; int para = 0, index = 1;
if (!termoffsets.empty()) { if (!termoffsets.empty()) {
index = (termoffsets.begin())->first; index = (termoffsets.begin())->first;
@ -539,5 +550,6 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n", LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n",
editor->length(), editor->paragraphs(), para, index)); editor->length(), editor->paragraphs(), para, index));
}
return true; return true;
} }