ssearch:indent, log messages etc.

This commit is contained in:
Jean-Francois Dockes 2018-11-24 17:25:52 +01:00
parent a193412fa1
commit 4d6ad4c3ea

View File

@ -71,7 +71,8 @@ void SSearch::init()
connect(clearqPB, SIGNAL(clicked()),
queryText->lineEdit(), SLOT(clear()));
connect(searchPB, SIGNAL(clicked()), this, SLOT(startSimpleSearch()));
connect(searchTypCMB, SIGNAL(activated(int)), this, SLOT(searchTypeChanged(int)));
connect(searchTypCMB, SIGNAL(activated(int)), this,
SLOT(searchTypeChanged(int)));
queryText->installEventFilter(this);
queryText->view()->installEventFilter(this);
@ -96,7 +97,7 @@ void SSearch::init()
void SSearch::takeFocus()
{
LOGDEB2("SSearch: take focus\n" );
LOGDEB2("SSearch: take focus\n");
queryText->setFocus(Qt::ShortcutFocusReason);
// If the focus was already in the search entry, the text is not selected.
// Do it for consistency
@ -106,14 +107,15 @@ void SSearch::takeFocus()
void SSearch::timerDone()
{
QString qs = queryText->currentText();
LOGDEB1("SSearch::timerDone: qs [" << (qs2utf8s(qs)) << "]\n" );
LOGDEB1("SSearch::timerDone: qs [" << qs2utf8s(qs) << "]\n");
searchTextChanged(qs);
}
void SSearch::searchTextChanged(const QString& text)
{
QString qs = queryText->currentText();
LOGDEB1("SSearch::searchTextChanged. ks " << (m_keystroke) << " qs [" << (qs2utf8s(text)) << "]\n" );
LOGDEB1("SSearch::searchTextChanged. ks " << m_keystroke << " qs [" <<
qs2utf8s(text) << "]\n");
if (text.isEmpty()) {
searchPB->setEnabled(false);
clearqPB->setEnabled(false);
@ -130,7 +132,8 @@ void SSearch::searchTextChanged(const QString& text)
m_disableAutosearch = true;
string s;
int cs = partialWord(s);
LOGDEB1("SSearch::searchTextChanged: autosearch. cs " << (cs) << " s [" << (s) << "]\n" );
LOGDEB1("SSearch::searchTextChanged: autosearch. cs " << cs <<
" s [" << s << "]\n");
if (cs < 0) {
startSimpleSearch();
} else if (!m_stroketimeout->isActive() && s.size() >= 2) {
@ -145,19 +148,20 @@ void SSearch::searchTextChanged(const QString& text)
void SSearch::searchTypeChanged(int typ)
{
LOGDEB("Search type now " << (typ) << "\n" );
LOGDEB("Search type now " << typ << "\n");
// Adjust context help
if (typ == SST_LANG)
if (typ == SST_LANG) {
HelpClient::installMap((const char *)this->objectName().toUtf8(),
"RCL.SEARCH.LANG");
else
} else {
HelpClient::installMap((const char *)this->objectName().toUtf8(),
"RCL.SEARCH.GUI.SIMPLE");
}
// Also fix tooltips
switch (typ) {
case SST_LANG:
queryText->setToolTip(tr(
queryText->setToolTip(
tr(
"Enter query language expression. Cheat sheet:<br>\n"
"<i>term1 term2</i> : 'term1' and 'term2' in any field.<br>\n"
"<i>field:term1</i> : 'term1' in field 'field'.<br>\n"
@ -178,7 +182,8 @@ void SSearch::searchTypeChanged(int typ)
case SST_ANY:
case SST_ALL:
default:
queryText->setToolTip(tr(
queryText->setToolTip(
tr(
"Enter search terms here. Type ESC SPC for completions of current term."
));
}
@ -187,7 +192,7 @@ void SSearch::searchTypeChanged(int typ)
void SSearch::startSimpleSearch()
{
QString qs = queryText->currentText();
LOGDEB("SSearch::startSimpleSearch(): qs [" << (qs2utf8s(qs)) << "]\n" );
LOGDEB("SSearch::startSimpleSearch(): qs [" << qs2utf8s(qs) << "]\n");
if (qs.length() == 0)
return;
@ -200,7 +205,7 @@ void SSearch::startSimpleSearch()
if (!startSimpleSearch(u8))
return;
LOGDEB("startSimpleSearch: updating history\n" );
LOGDEB("startSimpleSearch: updating history\n");
// Search terms history:
// We want to have the new text at the top and any older identical
// entry to be erased. There is no standard qt policy to do this ?
@ -241,7 +246,7 @@ string SSearch::asXML()
bool SSearch::startSimpleSearch(const string& u8, int maxexp)
{
LOGDEB("SSearch::startSimpleSearch(" << (u8) << ")\n" );
LOGDEB("SSearch::startSimpleSearch(" << u8 << ")\n");
string stemlang = prefs.stemlang();
ostringstream xml;
@ -307,7 +312,7 @@ bool SSearch::startSimpleSearch(const string& u8, int maxexp)
xml << "</SD>\n";
m_xml = xml.str();
LOGDEB("SSearch::startSimpleSearch:xml:[" << (m_xml) << "]\n" );
LOGDEB("SSearch::startSimpleSearch:xml:[" << m_xml << "]\n");
std::shared_ptr<Rcl::SearchData> rsdata(sdata);
emit startSearch(rsdata, true);
@ -393,7 +398,7 @@ bool SSearch::hasSearchString()
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void SSearch::addTerm(QString term)
{
LOGDEB("SSearch::AddTerm: [" << ((const char *)term.toUtf8()) << "]\n" );
LOGDEB("SSearch::AddTerm: [" << qs2utf8s(term) << "]\n");
string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos)
@ -415,7 +420,8 @@ void SSearch::addTerm(QString term)
void SSearch::onWordReplace(const QString& o, const QString& n)
{
LOGDEB("SSearch::onWordReplace: o [" << (qs2utf8s(o)) << "] n [" << (qs2utf8s(n)) << "]\n" );
LOGDEB("SSearch::onWordReplace: o [" << qs2utf8s(o) << "] n [" <<
qs2utf8s(n) << "]\n");
QString txt = queryText->currentText();
QRegExp exp = QRegExp(QString("\\b") + o + QString("\\b"));
exp.setCaseSensitivity(Qt::CaseInsensitive);
@ -466,9 +472,8 @@ int SSearch::completionList(string s, QStringList& lst, int max)
tmres.entries.size() == 0) {
return 0;
}
for (vector<Rcl::TermMatchEntry>::iterator it = tmres.entries.begin();
it != tmres.entries.end(); it++) {
lst.push_back(QString::fromUtf8(it->term.c_str()));
for (const auto& entry: tmres.entries) {
lst.push_back(u8s2qs(entry.term));
}
return lst.size();
}
@ -476,7 +481,7 @@ int SSearch::completionList(string s, QStringList& lst, int max)
// Complete last word in input by querying db for all possible terms.
void SSearch::completion()
{
LOGDEB("SSearch::completion\n" );
LOGDEB("SSearch::completion\n");
m_disableAutosearch = true;
m_stroketimeout->stop();
@ -506,7 +511,7 @@ void SSearch::completion()
return;
}
if (lst.size() >= maxdpy) {
LOGDEB0("SSearch::completion(): truncating list\n" );
LOGDEB0("SSearch::completion(): truncating list\n");
lst = lst.mid(0, maxdpy);
lst.append("[...]");
}
@ -542,7 +547,7 @@ void SSearch::completionTermChosen(const QString& text)
void SSearch::wrapupCompletion()
{
LOGDEB("SSearch::wrapupCompletion\n" );
LOGDEB("SSearch::wrapupCompletion\n");
queryText->clear();
queryText->addItems(prefs.ssearchHistory);
@ -707,7 +712,9 @@ bool SSearch::eventFilter(QObject *target, QEvent *event)
event->type() == QEvent::UpdateRequest ||
event->type() == QEvent::Paint)
return false;
LOGDEB2("SSearch::eventFilter: target " << (target) << " (" << (queryText->lineEdit()) << ") type " << (eventTypeToStr(event->type())) << "\n" );
LOGDEB2("SSearch::eventFilter: target " << target << " (" <<
queryText->lineEdit() << ") type " <<
eventTypeToStr(event->type()) << "\n");
#endif
if (target == (QObject*)(queryText->view())) {
@ -723,15 +730,16 @@ bool SSearch::eventFilter(QObject *target, QEvent *event)
if (event->type() == QEvent::KeyPress) {
QKeyEvent *ke = (QKeyEvent *)event;
LOGDEB1("SSearch::eventFilter: keyPress (m_escape " << (m_escape) << ") key " << (ke->key()) << "\n" );
LOGDEB1("SSearch::eventFilter: keyPress (m_escape " << m_escape <<
") key " << ke->key() << "\n");
if (ke->key() == Qt::Key_Escape) {
LOGDEB("Escape\n" );
LOGDEB("Escape\n");
m_escape = true;
m_disableAutosearch = true;
m_stroketimeout->stop();
return true;
} else if (m_escape && ke->key() == Qt::Key_Space) {
LOGDEB("Escape space\n" );
LOGDEB("Escape space\n");
ke->accept();
completion();
m_escape = false;
@ -747,11 +755,11 @@ bool SSearch::eventFilter(QObject *target, QEvent *event)
if (prefs.ssearchAsYouType) {
m_disableAutosearch = false;
QString qs = queryText->currentText();
LOGDEB0("SSearch::eventFilter: start timer, qs [" << (qs2utf8s(qs)) << "]\n" );
LOGDEB0("SSearch::eventFilter: start timer, qs [" <<
qs2utf8s(qs) << "]\n");
m_stroketimeout->start(strokeTimeoutMS);
}
}
}
return false;
}