reslist orthographic suggestions: link clicks did not work anymore because of change to url.toString() in qt5

This commit is contained in:
Jean-Francois Dockes 2017-12-21 10:18:43 +01:00
parent 3779323ef9
commit f51a4f4bc9
2 changed files with 27 additions and 24 deletions

View File

@ -839,10 +839,14 @@ void ResList::showQueryDetails()
void ResList::linkWasClicked(const QUrl &url) void ResList::linkWasClicked(const QUrl &url)
{ {
string ascurl = qs2utf8s(url.toString()); // qt5: url.toString() does not accept FullyDecoded, but that's what we
LOGDEB("ResList::linkWasClicked: [" << ascurl << "]\n"); // want. e.g. Suggestions links are like Sterm|spelling which we
// receive as Sterm%7CSpelling
string strurl = url_decode(qs2utf8s(url.toString()));
int what = ascurl[0]; LOGDEB("ResList::linkWasClicked: [" << strurl << "]\n");
int what = strurl[0];
switch (what) { switch (what) {
// Open abstract/snippets window // Open abstract/snippets window
@ -850,7 +854,7 @@ void ResList::linkWasClicked(const QUrl &url)
{ {
if (!m_source) if (!m_source)
return; return;
int i = atoi(ascurl.c_str()+1) - 1; int i = atoi(strurl.c_str()+1) - 1;
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(i, doc)) { if (!getDoc(i, doc)) {
LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n"); LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n");
@ -865,7 +869,7 @@ void ResList::linkWasClicked(const QUrl &url)
{ {
if (!m_source) if (!m_source)
return; return;
int i = atoi(ascurl.c_str()+1) - 1; int i = atoi(strurl.c_str()+1) - 1;
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(i, doc)) { if (!getDoc(i, doc)) {
LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n"); LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n");
@ -881,7 +885,7 @@ void ResList::linkWasClicked(const QUrl &url)
// Open parent folder // Open parent folder
case 'F': case 'F':
{ {
int i = atoi(ascurl.c_str()+1) - 1; int i = atoi(strurl.c_str()+1) - 1;
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(i, doc)) { if (!getDoc(i, doc)) {
LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n"); LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n");
@ -903,7 +907,7 @@ void ResList::linkWasClicked(const QUrl &url)
case 'P': case 'P':
case 'E': case 'E':
{ {
int i = atoi(ascurl.c_str()+1) - 1; int i = atoi(strurl.c_str()+1) - 1;
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(i, doc)) { if (!getDoc(i, doc)) {
LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n"); LOGERR("ResList::linkWasClicked: can't get doc for " << i << "\n");
@ -932,7 +936,7 @@ void ResList::linkWasClicked(const QUrl &url)
// Run script. Link format Rnn|Script Name // Run script. Link format Rnn|Script Name
case 'R': case 'R':
{ {
int i = atoi(ascurl.c_str() + 1) - 1; int i = atoi(strurl.c_str() + 1) - 1;
QString s = url.toString(); QString s = url.toString();
int bar = s.indexOf("|"); int bar = s.indexOf("|");
if (bar == -1 || bar >= s.size()-1) if (bar == -1 || bar >= s.size()-1)
@ -953,20 +957,21 @@ void ResList::linkWasClicked(const QUrl &url)
// Spelling: replacement suggestion clicked // Spelling: replacement suggestion clicked
case 'S': case 'S':
{ {
QString s = url.toString(); string s;
if (!s.isEmpty()) if (!strurl.empty())
s = s.right(s.size()-1); s = strurl.substr(1);
int bar = s.indexOf("|"); string::size_type bar = s.find_first_of("|");
if (bar != -1 && bar < s.size()-1) { if (bar != string::npos && bar < s.size() - 1) {
QString o = s.left(bar); string o = s.substr(0, bar);
QString n = s.right(s.size() - (bar+1)); string n = s.substr(bar+1);
emit wordReplace(o, n); LOGDEB2("Emitting wordreplace " << o << " -> " << n << std::endl);
emit wordReplace(u8s2qs(o), u8s2qs(n));
} }
} }
break; break;
default: default:
LOGERR("ResList::linkWasClicked: bad link [" << ascurl << "]\n"); LOGERR("ResList::linkWasClicked: bad link [" << strurl << "]\n");
break;// ?? break;// ??
} }
} }

View File

@ -397,15 +397,13 @@ void ResListPager::displayPage(RclConfig *config)
} }
for (map<string, vector<string> >::const_iterator it0 = for (const auto& entry: spellings) {
spellings.begin(); it0 != spellings.end(); it0++) { chunk << "<b>" << entry.first << "</b> : ";
chunk << "<b>" << it0->first << "</b> : "; for (const auto& spelling : entry.second) {
for (vector<string>::const_iterator it = chunk << spelling << " ";
it0->second.begin();
it != it0->second.end(); it++) {
chunk << *it << " ";
} }
chunk << "<br />"; chunk << "<br />";
std::cerr << chunk.str() << endl;
} }
chunk << "</blockquote></p>"; chunk << "</blockquote></p>";
} }