GUI: Fix a couple cases where a null lineedit completer could cause a crash

This commit is contained in:
Jean-Francois Dockes 2019-11-28 18:22:03 +01:00
parent f42338c026
commit f5418aa263

View File

@ -77,7 +77,7 @@ int RclCompleterModel::rowCount(const QModelIndex &) const
QVariant RclCompleterModel::data(const QModelIndex &index, int role) const QVariant RclCompleterModel::data(const QModelIndex &index, int role) const
{ {
LOGDEB1("RclCompleterModel::data: row: " << index.row() << " role " << LOGDEB1("RclCompleterModel::data: row: " << index.row() << " role " <<
role << "\n"); role << "\n");
if (role != Qt::DisplayRole && role != Qt::EditRole && if (role != Qt::DisplayRole && role != Qt::EditRole &&
role != Qt::DecorationRole) { role != Qt::DecorationRole) {
return QVariant(); return QVariant();
@ -216,7 +216,7 @@ void SSearch::onCompleterShown()
LOGDEB0("SSearch::onCompleterShown: no completer\n"); LOGDEB0("SSearch::onCompleterShown: no completer\n");
return; return;
} }
QAbstractItemView *popup = queryText->completer()->popup(); QAbstractItemView *popup = completer->popup();
if (!popup) { if (!popup) {
LOGDEB0("SSearch::onCompleterShown: no popup\n"); LOGDEB0("SSearch::onCompleterShown: no popup\n");
return; return;
@ -320,7 +320,8 @@ void SSearch::onCompletionActivated(const QString& text)
void SSearch::onHistoryClicked() void SSearch::onHistoryClicked()
{ {
if (m_completermodel) { if (m_completermodel) {
queryText->setCompleter(m_completer);
m_completermodel->onPartialWord(SST_LANG, "", ""); m_completermodel->onPartialWord(SST_LANG, "", "");
queryText->completer()->complete(); queryText->completer()->complete();
} }
@ -373,42 +374,42 @@ void SSearch::searchTypeChanged(int typ)
switch (typ) { switch (typ) {
case SST_LANG: case SST_LANG:
queryText->setToolTip( queryText->setToolTip(
// Do not modify the text here, test with the // Do not modify the text here, test with the
// sshelp/qhelp.html file and a browser, then use // sshelp/qhelp.html file and a browser, then use
// sshelp/helphtmltoc.sh to turn to code and insert here // sshelp/helphtmltoc.sh to turn to code and insert here
tr("<html><head><style>") + tr("<html><head><style>") +
tr("table, th, td {") + tr("table, th, td {") +
tr("border: 1px solid black;") + tr("border: 1px solid black;") +
tr("border-collapse: collapse;") + tr("border-collapse: collapse;") +
tr("}") + tr("}") +
tr("th,td {") + tr("th,td {") +
tr("text-align: center;") + tr("text-align: center;") +
tr("}") + tr("}") +
tr("</style></head><body>") + tr("</style></head><body>") +
tr("<p>Query language cheat-sheet. In doubt: click <b>Show Query</b>.&nbsp;") + tr("<p>Query language cheat-sheet. In doubt: click <b>Show Query</b>.&nbsp;") +
tr("You should really look at the manual (F1)</p>") + tr("You should really look at the manual (F1)</p>") +
tr("<table border='1' cellspacing='0'>") + tr("<table border='1' cellspacing='0'>") +
tr("<tr><th>What</th><th>Examples</th>") + tr("<tr><th>What</th><th>Examples</th>") +
tr("<tr><td>And</td><td>one two&nbsp;&nbsp;&nbsp;one AND two&nbsp;&nbsp;&nbsp;one && two</td></tr>") + tr("<tr><td>And</td><td>one two&nbsp;&nbsp;&nbsp;one AND two&nbsp;&nbsp;&nbsp;one && two</td></tr>") +
tr("<tr><td>Or</td><td>one OR two&nbsp;&nbsp;&nbsp;one || two</td></tr>") + tr("<tr><td>Or</td><td>one OR two&nbsp;&nbsp;&nbsp;one || two</td></tr>") +
tr("<tr><td>Complex boolean. OR has priority, use parentheses&nbsp;") + tr("<tr><td>Complex boolean. OR has priority, use parentheses&nbsp;") +
tr("where needed</td><td>(one AND two) OR three</td></tr>") + tr("where needed</td><td>(one AND two) OR three</td></tr>") +
tr("<tr><td>Not</td><td>-term</td></tr>") + tr("<tr><td>Not</td><td>-term</td></tr>") +
tr("<tr><td>Phrase</td><td>\"pride and prejudice\"</td></tr>") + tr("<tr><td>Phrase</td><td>\"pride and prejudice\"</td></tr>") +
tr("<tr><td>Ordered proximity (slack=1)</td><td>\"pride prejudice\"o1</td></tr>") + tr("<tr><td>Ordered proximity (slack=1)</td><td>\"pride prejudice\"o1</td></tr>") +
tr("<tr><td>Unordered proximity (slack=1)</td><td>\"prejudice pride\"po1</td></tr>") + tr("<tr><td>Unordered proximity (slack=1)</td><td>\"prejudice pride\"po1</td></tr>") +
tr("<tr><td>Unordered prox. (default slack=10)</td><td>\"prejudice&nbsp;pride\"p</td></tr>") + tr("<tr><td>Unordered prox. (default slack=10)</td><td>\"prejudice&nbsp;pride\"p</td></tr>") +
tr("<tr><td>No stem expansion: capitalize</td><td>Floor</td></tr>") + tr("<tr><td>No stem expansion: capitalize</td><td>Floor</td></tr>") +
tr("<tr><td>Field-specific</td><td>author:austen&nbsp;&nbsp;title:prejudice</td></tr>") + tr("<tr><td>Field-specific</td><td>author:austen&nbsp;&nbsp;title:prejudice</td></tr>") +
tr("<tr><td>AND inside field (no order)</td><td>author:jane,austen</td></tr>") + tr("<tr><td>AND inside field (no order)</td><td>author:jane,austen</td></tr>") +
tr("<tr><td>OR inside field</td><td>author:austen/bronte</td></tr>") + tr("<tr><td>OR inside field</td><td>author:austen/bronte</td></tr>") +
tr("<tr><td>Field names</td><td>title/subject/caption&nbsp;&nbsp;author/from<br>recipient/to&nbsp;&nbsp;filename&nbsp;&nbsp;ext</td></tr>") + tr("<tr><td>Field names</td><td>title/subject/caption&nbsp;&nbsp;author/from<br>recipient/to&nbsp;&nbsp;filename&nbsp;&nbsp;ext</td></tr>") +
tr("<tr><td>Directory path filter</td><td>dir:/home/me&nbsp;&nbsp;dir:doc</td></tr>") + tr("<tr><td>Directory path filter</td><td>dir:/home/me&nbsp;&nbsp;dir:doc</td></tr>") +
tr("<tr><td>MIME type filter</td><td>mime:text/plain mime:video/*</td></tr>") + tr("<tr><td>MIME type filter</td><td>mime:text/plain mime:video/*</td></tr>") +
tr("<tr><td>Date intervals</td><td>date:2018-01-01/2018-31-12<br>") + tr("<tr><td>Date intervals</td><td>date:2018-01-01/2018-31-12<br>") +
tr("date:2018&nbsp;&nbsp;date:2018-01-01/P12M</td></tr>") + tr("date:2018&nbsp;&nbsp;date:2018-01-01/P12M</td></tr>") +
tr("<tr><td>Size</td><td>size&gt;100k size&lt;1M</td></tr>") + tr("<tr><td>Size</td><td>size&gt;100k size&lt;1M</td></tr>") +
tr("</table></body></html>") tr("</table></body></html>")
); );
break; break;
case SST_FNM: case SST_FNM:
@ -423,7 +424,7 @@ tr("</table></body></html>")
void SSearch::startSimpleSearch() void SSearch::startSimpleSearch()
{ {
if (queryText->completer()->popup()->isVisible()) { if (queryText->completer() && queryText->completer()->popup()->isVisible()) {
return; return;
} }
string u8 = qs2u8s(queryText->text()); string u8 = qs2u8s(queryText->text());
@ -446,7 +447,7 @@ void SSearch::startSimpleSearch()
if (prefs.historysize >= 0) { if (prefs.historysize >= 0) {
for (int i = (int)prefs.ssearchHistory.count(); for (int i = (int)prefs.ssearchHistory.count();
i > prefs.historysize; i--) { i > prefs.historysize; i--) {
prefs.ssearchHistory.removeLast(); prefs.ssearchHistory.removeLast();
} }
} }
} }