dont highlight terms in very big docs: too slow
This commit is contained in:
parent
ce622e2be4
commit
92b5cb001d
@ -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,45 +456,53 @@ 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):
|
||||||
progress.setLabelText(tr("Creating preview text"));
|
|
||||||
list<string> terms;
|
|
||||||
rcldb->getQueryTerms(terms);
|
|
||||||
list<pair<int, int> > termoffsets;
|
|
||||||
QString richTxt;
|
QString richTxt;
|
||||||
ToRichThread rthr(fdoc.text, terms, termoffsets, richTxt);
|
list<pair<int, int> > termoffsets;
|
||||||
rthr.start();
|
bool highlightTerms = fdoc.text.length() < 1000 *1024;
|
||||||
|
|
||||||
for (;;prog++) {
|
if (highlightTerms) {
|
||||||
waiter.start(); waiter.wait();
|
progress.setLabelText(tr("Creating preview text"));
|
||||||
if (rthr.finished())
|
list<string> terms;
|
||||||
break;
|
rcldb->getQueryTerms(terms);
|
||||||
progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
|
ToRichThread rthr(fdoc.text, terms, termoffsets, richTxt);
|
||||||
qApp->processEvents();
|
rthr.start();
|
||||||
if (progress.wasCanceled()) {
|
|
||||||
CancelCheck::instance().setCancel();
|
for (;;prog++) {
|
||||||
cancel = true;
|
waiter.start(); waiter.wait();
|
||||||
|
if (rthr.finished())
|
||||||
|
break;
|
||||||
|
progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
|
||||||
|
qApp->processEvents();
|
||||||
|
if (progress.wasCanceled()) {
|
||||||
|
CancelCheck::instance().setCancel();
|
||||||
|
cancel = true;
|
||||||
|
}
|
||||||
|
if (prog >= 5)
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
if (prog >= 5)
|
if (cancel) {
|
||||||
sleep(1);
|
if (richTxt.length() == 0) {
|
||||||
}
|
// We cant call closeCurrentTab here as it might delete
|
||||||
if (cancel) {
|
// the object which would be a nasty surprise to our
|
||||||
if (richTxt.length() == 0) {
|
// caller.
|
||||||
// We cant call closeCurrentTab here as it might delete
|
return false;
|
||||||
// the object which would be a nasty surprise to our
|
} else {
|
||||||
// caller.
|
richTxt += "<b>Cancelled !</b>";
|
||||||
return false;
|
}
|
||||||
} else {
|
|
||||||
richTxt += "<b>Cancelled !</b>";
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
richTxt = fdoc.text.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load into editor
|
// Load into editor
|
||||||
QTextEdit *editor = getCurrentEditor();
|
QTextEdit *editor = getCurrentEditor();
|
||||||
QStyleSheetItem *item =
|
if (highlightTerms) {
|
||||||
new QStyleSheetItem(editor->styleSheet(), "termtag" );
|
QStyleSheetItem *item =
|
||||||
item->setColor("blue");
|
new QStyleSheetItem(editor->styleSheet(), "termtag" );
|
||||||
item->setFontWeight(QFont::Bold);
|
item->setColor("blue");
|
||||||
|
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,12 +515,13 @@ 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())
|
||||||
if (richTxt[pos+l+i] == '<') {
|
for (int i = -15; i < 0; i++) {
|
||||||
l = l+i;
|
if (richTxt[pos+l+i] == '<') {
|
||||||
break;
|
l = l+i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
editor->append(richTxt.mid(pos, l));
|
editor->append(richTxt.mid(pos, l));
|
||||||
// Stay at top
|
// Stay at top
|
||||||
@ -527,17 +536,20 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int para = 0, index = 1;
|
|
||||||
if (!termoffsets.empty()) {
|
|
||||||
index = (termoffsets.begin())->first;
|
|
||||||
LOGDEB(("Set cursor position: para %d, character index %d\n",
|
|
||||||
para,index));
|
|
||||||
editor->setCursorPosition(0, index);
|
|
||||||
}
|
|
||||||
editor->ensureCursorVisible();
|
|
||||||
editor->getCursorPosition(¶, &index);
|
|
||||||
|
|
||||||
LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n",
|
if (highlightTerms) {
|
||||||
editor->length(), editor->paragraphs(), para, index));
|
int para = 0, index = 1;
|
||||||
|
if (!termoffsets.empty()) {
|
||||||
|
index = (termoffsets.begin())->first;
|
||||||
|
LOGDEB(("Set cursor position: para %d, character index %d\n",
|
||||||
|
para,index));
|
||||||
|
editor->setCursorPosition(0, index);
|
||||||
|
}
|
||||||
|
editor->ensureCursorVisible();
|
||||||
|
editor->getCursorPosition(¶, &index);
|
||||||
|
|
||||||
|
LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n",
|
||||||
|
editor->length(), editor->paragraphs(), para, index));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user