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
const int nsteps = 20;
QProgressDialog progress(msg, tr("Cancel"), nsteps, this, "Loading", FALSE);
progress.setMinimumDuration(1000);
progress.setMinimumDuration(2000);
WaiterThread waiter(100);
// 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.
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"));
list<string> terms;
rcldb->getQueryTerms(terms);
list<pair<int, int> > termoffsets;
QString richTxt;
ToRichThread rthr(fdoc.text, terms, termoffsets, richTxt);
rthr.start();
@ -488,13 +491,18 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
richTxt += "<b>Cancelled !</b>";
}
}
} else {
richTxt = fdoc.text.c_str();
}
// Load into editor
QTextEdit *editor = getCurrentEditor();
if (highlightTerms) {
QStyleSheetItem *item =
new QStyleSheetItem(editor->styleSheet(), "termtag" );
item->setColor("blue");
item->setFontWeight(QFont::Bold);
}
prog = 2 * nsteps / 3;
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);
// 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] == '<') {
l = l+i;
break;
@ -527,6 +536,8 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
break;
}
}
if (highlightTerms) {
int para = 0, index = 1;
if (!termoffsets.empty()) {
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",
editor->length(), editor->paragraphs(), para, index));
}
return true;
}