gui: disable searchbar when search is running

avoids waiting in the gui thread. does not try to cancel
the QFuture that actually cannot be cancelled anyway.

sidesteps a strange bug which rethrows already caught exception.
This commit is contained in:
Albert S. 2020-06-06 23:18:33 +02:00
parent 072996e0d3
commit 1e10d12f34

View File

@ -49,14 +49,15 @@ void MainWindow::connectSignals()
connect(&searchWatcher, &QFutureWatcher<SearchResult>::finished, this, [&]{ connect(&searchWatcher, &QFutureWatcher<SearchResult>::finished, this, [&]{
try try
{ {
this->ui->txtSearch->setEnabled(true);
auto results = searchWatcher.future().result(); auto results = searchWatcher.future().result();
handleSearchResults(results); handleSearchResults(results);
} }
catch(QSSGeneralException &e) catch(QSSGeneralException &e)
{ {
handleSearchError(e.message); handleSearchError(e.message);
} }
}); });
connect(&pdfWorkerWatcher, &QFutureWatcher<PdfPreview>::resultReadyAt, this, [&](int index) { connect(&pdfWorkerWatcher, &QFutureWatcher<PdfPreview>::resultReadyAt, this, [&](int index) {
@ -165,8 +166,7 @@ void MainWindow::lineEditReturnPressed()
} }
//TODO: validate q; //TODO: validate q;
ui->lblSearchResults->setText("Searching..."); ui->lblSearchResults->setText("Searching...");
searchWatcher.cancel(); this->ui->txtSearch->setEnabled(false);
searchWatcher.waitForFinished();
QFuture<QVector<SearchResult>> searchFuture = QtConcurrent::run([&, q]() { QFuture<QVector<SearchResult>> searchFuture = QtConcurrent::run([&, q]() {
SqliteSearch searcher(db); SqliteSearch searcher(db);
this->currentQuery = QSSQuery::build(q); this->currentQuery = QSSQuery::build(q);