GUI: snippets: dont recreate the window each time, allow displaying data for multiple documents. restable: update snippets when changing current row

This commit is contained in:
Jean-Francois Dockes 2019-07-03 13:46:38 +02:00
parent 6b058e9758
commit d812fb8079
5 changed files with 99 additions and 86 deletions

View File

@ -31,6 +31,7 @@
#include "specialindex.h" #include "specialindex.h"
#include "rclmain_w.h" #include "rclmain_w.h"
#include "webcache.h" #include "webcache.h"
#include "restable.h"
using namespace std; using namespace std;
@ -453,16 +454,23 @@ void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups)
void RclMain::showSnippets(Rcl::Doc doc) void RclMain::showSnippets(Rcl::Doc doc)
{ {
if (m_snippets) { if (!m_snippets) {
deleteZ(m_snippets); m_snippets = new SnippetsW(doc, m_source);
connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()),
m_snippets, SLOT (close()));
if (restable) {
connect(
restable,
SIGNAL(detailDocChanged(Rcl::Doc, std::shared_ptr<DocSequence>)),
m_snippets,
SLOT(onSetDoc(Rcl::Doc, std::shared_ptr<DocSequence>)));
}
} else {
m_snippets->onSetDoc(doc, m_source);
} }
m_snippets = new SnippetsW(doc, m_source);
connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()),
m_snippets, SLOT (close()));
m_snippets->show(); m_snippets->show();
} }

View File

@ -666,6 +666,7 @@ void ResTable::onTableView_currentChanged(const QModelIndex& index)
m_detaildoc = doc; m_detaildoc = doc;
m_pager->displayDoc(theconfig, index.row(), m_detaildoc, m_pager->displayDoc(theconfig, index.row(), m_detaildoc,
m_model->m_hdata); m_model->m_hdata);
emit(detailDocChanged(doc, m_model->getDocSource()));
} else { } else {
m_detaildocnum = -1; m_detaildocnum = -1;
} }

View File

@ -167,7 +167,8 @@ signals:
void docExpand(Rcl::Doc); void docExpand(Rcl::Doc);
void showSubDocs(Rcl::Doc); void showSubDocs(Rcl::Doc);
void showSnippets(Rcl::Doc); void showSnippets(Rcl::Doc);
void detailDocChanged(Rcl::Doc, std::shared_ptr<DocSequence>);
friend class ResTablePager; friend class ResTablePager;
friend class ResTableDetailArea; friend class ResTableDetailArea;
private: private:

View File

@ -65,23 +65,18 @@ using namespace std;
class PlainToRichQtSnippets : public PlainToRich { class PlainToRichQtSnippets : public PlainToRich {
public: public:
virtual string startMatch(unsigned int) virtual string startMatch(unsigned int) {
{ return string("<span class='rclmatch' style='")
return string("<span class='rclmatch' style='") + qs2utf8s(prefs.qtermstyle) + string("'>");
+ qs2utf8s(prefs.qtermstyle) + string("'>");
} }
virtual string endMatch() virtual string endMatch() {
{ return string("</span>");
return string("</span>");
} }
}; };
static PlainToRichQtSnippets g_hiliter; static PlainToRichQtSnippets g_hiliter;
void SnippetsW::init() void SnippetsW::init()
{ {
if (!m_source)
return;
QPushButton *searchButton = new QPushButton(tr("Search")); QPushButton *searchButton = new QPushButton(tr("Search"));
searchButton->setAutoDefault(false); searchButton->setAutoDefault(false);
buttonBox->addButton(searchButton, QDialogButtonBox::ActionRole); buttonBox->addButton(searchButton, QDialogButtonBox::ActionRole);
@ -94,16 +89,16 @@ void SnippetsW::init()
new QShortcut(QKeySequence::FindNext, this, SLOT(slotEditFindNext())); new QShortcut(QKeySequence::FindNext, this, SLOT(slotEditFindNext()));
new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext())); new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext()));
new QShortcut(QKeySequence::FindPrevious, this, new QShortcut(QKeySequence::FindPrevious, this,
SLOT(slotEditFindPrevious())); SLOT(slotEditFindPrevious()));
new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F3), new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F3),
this, SLOT(slotEditFindPrevious())); this, SLOT(slotEditFindPrevious()));
QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close); QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close);
if (closeButton) if (closeButton)
connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
connect(searchButton, SIGNAL(clicked()), this, SLOT(slotEditFind())); connect(searchButton, SIGNAL(clicked()), this, SLOT(slotEditFind()));
connect(searchLE, SIGNAL(textChanged(const QString&)), connect(searchLE, SIGNAL(textChanged(const QString&)),
this, SLOT(slotSearchTextChanged(const QString&))); this, SLOT(slotSearchTextChanged(const QString&)));
connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext())); connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext()));
connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious())); connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious()));
@ -113,43 +108,50 @@ void SnippetsW::init()
verticalLayout->insertWidget(0, browserw); verticalLayout->insertWidget(0, browserw);
browser->setUrl(QUrl(QString::fromUtf8("about:blank"))); browser->setUrl(QUrl(QString::fromUtf8("about:blank")));
connect(browser, SIGNAL(linkClicked(const QUrl &)), connect(browser, SIGNAL(linkClicked(const QUrl &)),
this, SLOT(onLinkClicked(const QUrl &))); this, SLOT(onLinkClicked(const QUrl &)));
browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal,
Qt::ScrollBarAlwaysOff); Qt::ScrollBarAlwaysOff);
QWEBSETTINGS *ws = browser->page()->settings(); QWEBSETTINGS *ws = browser->page()->settings();
if (prefs.reslistfontfamily != "") { if (prefs.reslistfontfamily != "") {
ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily); ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily);
ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize); ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize);
} }
if (!prefs.snipCssFile.isEmpty()) if (!prefs.snipCssFile.isEmpty())
ws->setUserStyleSheetUrl(QUrl::fromLocalFile(prefs.snipCssFile)); ws->setUserStyleSheetUrl(QUrl::fromLocalFile(prefs.snipCssFile));
#elif defined(USING_WEBENGINE) #elif defined(USING_WEBENGINE)
browserw = new QWebEngineView(this); browserw = new QWebEngineView(this);
verticalLayout->insertWidget(0, browserw); verticalLayout->insertWidget(0, browserw);
browser->setPage(new SnipWebPage(this)); browser->setPage(new SnipWebPage(this));
QWEBSETTINGS *ws = browser->page()->settings(); QWEBSETTINGS *ws = browser->page()->settings();
if (prefs.reslistfontfamily != "") { if (prefs.reslistfontfamily != "") {
ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily); ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily);
ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize); ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize);
} }
// Stylesheet TBD // Stylesheet TBD
#else #else
browserw = new QTextBrowser(this); browserw = new QTextBrowser(this);
verticalLayout->insertWidget(0, browserw); verticalLayout->insertWidget(0, browserw);
connect(browser, SIGNAL(anchorClicked(const QUrl &)), connect(browser, SIGNAL(anchorClicked(const QUrl &)),
this, SLOT(onLinkClicked(const QUrl &))); this, SLOT(onLinkClicked(const QUrl &)));
browser->setReadOnly(true); browser->setReadOnly(true);
browser->setUndoRedoEnabled(false); browser->setUndoRedoEnabled(false);
browser->setOpenLinks(false); browser->setOpenLinks(false);
browser->setTabChangesFocus(true); browser->setTabChangesFocus(true);
if (prefs.reslistfontfamily.length()) { if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize); QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
browser->setFont(nfont); browser->setFont(nfont);
} else { } else {
browser->setFont(QFont()); browser->setFont(QFont());
} }
#endif #endif
}
void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source)
{
m_doc = doc;
if (!source)
return;
// Make title out of file name if none yet // Make title out of file name if none yet
string titleOrFilename; string titleOrFilename;
@ -157,7 +159,7 @@ void SnippetsW::init()
m_doc.getmeta(Rcl::Doc::keytt, &titleOrFilename); m_doc.getmeta(Rcl::Doc::keytt, &titleOrFilename);
m_doc.getmeta(Rcl::Doc::keyfn, &utf8fn); m_doc.getmeta(Rcl::Doc::keyfn, &utf8fn);
if (titleOrFilename.empty()) { if (titleOrFilename.empty()) {
titleOrFilename = utf8fn; titleOrFilename = utf8fn;
} }
QString title("Recoll - Snippets"); QString title("Recoll - Snippets");
if (!titleOrFilename.empty()) { if (!titleOrFilename.empty()) {
@ -166,17 +168,17 @@ void SnippetsW::init()
setWindowTitle(title); setWindowTitle(title);
vector<Rcl::Snippet> vpabs; vector<Rcl::Snippet> vpabs;
m_source->getAbstract(m_doc, vpabs, source->getAbstract(m_doc, vpabs,
prefs.snipwMaxLength, prefs.snipwSortByPage); prefs.snipwMaxLength, prefs.snipwSortByPage);
HighlightData hdata; HighlightData hdata;
m_source->getTerms(hdata); source->getTerms(hdata);
ostringstream oss; ostringstream oss;
oss << oss <<
"<html><head>" "<html><head>"
"<meta http-equiv=\"content-type\" " "<meta http-equiv=\"content-type\" "
"content=\"text/html; charset=utf-8\">"; "content=\"text/html; charset=utf-8\">";
oss << "<style type=\"text/css\">\nbody,table,select,input {\n"; oss << "<style type=\"text/css\">\nbody,table,select,input {\n";
oss << "color: " + qs2utf8s(prefs.fontcolor) + ";\n"; oss << "color: " + qs2utf8s(prefs.fontcolor) + ";\n";
@ -184,38 +186,38 @@ void SnippetsW::init()
oss << qs2utf8s(prefs.reslistheadertext); oss << qs2utf8s(prefs.reslistheadertext);
oss << oss <<
"</head>" "</head>"
"<body>" "<body>"
"<table class=\"snippets\">" "<table class=\"snippets\">"
; ;
g_hiliter.set_inputhtml(false); g_hiliter.set_inputhtml(false);
bool nomatch = true; bool nomatch = true;
for (const auto& snippet : vpabs) { for (const auto& snippet : vpabs) {
if (snippet.page == -1) { if (snippet.page == -1) {
oss << "<tr><td colspan=\"2\">" << oss << "<tr><td colspan=\"2\">" <<
snippet.snippet << "</td></tr>" << endl; snippet.snippet << "</td></tr>" << endl;
continue; continue;
} }
list<string> lr; list<string> lr;
if (!g_hiliter.plaintorich(snippet.snippet, lr, hdata)) { if (!g_hiliter.plaintorich(snippet.snippet, lr, hdata)) {
LOGDEB1("No match for [" << snippet.snippet << "]\n"); LOGDEB1("No match for [" << snippet.snippet << "]\n");
continue; continue;
} }
nomatch = false; nomatch = false;
oss << "<tr><td>"; oss << "<tr><td>";
if (snippet.page > 0) { if (snippet.page > 0) {
oss << "<a href=\"http://h/P" << snippet.page << "T" << oss << "<a href=\"http://h/P" << snippet.page << "T" <<
snippet.term << "\">" snippet.term << "\">"
<< "P.&nbsp;" << snippet.page << "</a>"; << "P.&nbsp;" << snippet.page << "</a>";
} }
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl; oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl;
} }
oss << "</table>" << endl; oss << "</table>" << endl;
if (nomatch) { if (nomatch) {
oss.str("<html><head></head><body>\n"); oss.str("<html><head></head><body>\n");
oss << qs2utf8s(tr("<p>Sorry, no exact match was found within limits. " oss << qs2utf8s(tr("<p>Sorry, no exact match was found within limits. "
"Probably the document is very big and the snippets " "Probably the document is very big and the snippets "
"generator got lost in a maze...</p>")); "generator got lost in a maze...</p>"));
} }
@ -239,7 +241,7 @@ void SnippetsW::slotEditFind()
void SnippetsW::slotEditFindNext() void SnippetsW::slotEditFindNext()
{ {
if (!searchFM->isVisible()) if (!searchFM->isVisible())
slotEditFind(); slotEditFind();
#if defined(USING_WEBKIT) || defined(USING_WEBENGINE) #if defined(USING_WEBKIT) || defined(USING_WEBENGINE)
browser->findText(searchLE->text()); browser->findText(searchLE->text());
@ -252,7 +254,7 @@ void SnippetsW::slotEditFindNext()
void SnippetsW::slotEditFindPrevious() void SnippetsW::slotEditFindPrevious()
{ {
if (!searchFM->isVisible()) if (!searchFM->isVisible())
slotEditFind(); slotEditFind();
#if defined(USING_WEBKIT) || defined(USING_WEBENGINE) #if defined(USING_WEBKIT) || defined(USING_WEBENGINE)
browser->findText(searchLE->text(), QWEBPAGE::FindBackward); browser->findText(searchLE->text(), QWEBPAGE::FindBackward);
@ -281,23 +283,23 @@ void SnippetsW::onLinkClicked(const QUrl &url)
LOGDEB("Snippets::onLinkClicked: [" << ascurl << "]\n"); LOGDEB("Snippets::onLinkClicked: [" << ascurl << "]\n");
if (ascurl.size() > 3) { if (ascurl.size() > 3) {
int what = ascurl[0]; int what = ascurl[0];
switch (what) { switch (what) {
case 'P': case 'P':
{ {
string::size_type numpos = ascurl.find_first_of("0123456789"); string::size_type numpos = ascurl.find_first_of("0123456789");
if (numpos == string::npos) if (numpos == string::npos)
return; return;
int page = atoi(ascurl.c_str() + numpos); int page = atoi(ascurl.c_str() + numpos);
string::size_type termpos = ascurl.find_first_of("T"); string::size_type termpos = ascurl.find_first_of("T");
string term; string term;
if (termpos != string::npos) if (termpos != string::npos)
term = ascurl.substr(termpos+1); term = ascurl.substr(termpos+1);
emit startNativeViewer(m_doc, page, emit startNativeViewer(m_doc, page,
QString::fromUtf8(term.c_str())); QString::fromUtf8(term.c_str()));
return; return;
} }
} }
} }
LOGERR("Snippets::onLinkClicked: bad link [" << ascurl << "]\n"); LOGERR("Snippets::onLinkClicked: bad link [" << ascurl << "]\n");
} }

View File

@ -35,13 +35,15 @@ class SnippetsW : public QWidget, public Ui::Snippets
public: public:
SnippetsW(Rcl::Doc doc, std::shared_ptr<DocSequence> source, SnippetsW(Rcl::Doc doc, std::shared_ptr<DocSequence> source,
QWidget* parent = 0) QWidget* parent = 0)
: QWidget(parent), m_doc(doc), m_source(source) { : QWidget(parent) {
setupUi((QDialog*)this); setupUi((QDialog*)this);
init(); init();
onSetDoc(doc, source);
} }
public slots: public slots:
virtual void onLinkClicked(const QUrl &); virtual void onLinkClicked(const QUrl &);
virtual void onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source);
protected slots: protected slots:
virtual void slotEditFind(); virtual void slotEditFind();
@ -54,7 +56,6 @@ signals:
private: private:
void init(); void init();
Rcl::Doc m_doc; Rcl::Doc m_doc;
std::shared_ptr<DocSequence> m_source;
}; };
#ifdef USING_WEBENGINE #ifdef USING_WEBENGINE