feat: don't search while typing

This commit is contained in:
mandlm 2024-03-22 10:59:13 +01:00
parent 8c9a1522a0
commit f080d00697
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
2 changed files with 21 additions and 8 deletions

View File

@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
setupAlgorithmSelector();
setupWordListSourceSelector();
setupWordList();
createSelectedFinder();
}
MainWindow::~MainWindow() { delete ui; }
@ -79,8 +80,7 @@ void MainWindow::loadWordList(std::filesystem::path path) {
void MainWindow::search(const QString &search_term) {
if (search_term.isEmpty()) {
result_model_.setStringList(QStringList());
ui->mainStatusBar->clearMessage();
clearResults();
return;
}
@ -99,6 +99,7 @@ void MainWindow::search(const QString &search_term) {
void MainWindow::createSelectedFinder() {
auto selectedFinder = ui->searchAlgorithmSelector->currentIndex();
Timer timer;
switch (selectedFinder) {
case 0:
default:
@ -120,6 +121,12 @@ void MainWindow::createSelectedFinder() {
finder_ = std::make_unique<GroupedFinder>(word_list_);
break;
}
timer.stop();
std::stringstream status_message;
status_message << "finder initialized in " << timer << ", "
<< word_list_.size() << " words loaded";
ui->mainStatusBar->showMessage(QString::fromStdString(status_message.str()));
}
void MainWindow::showResults(const WordRefList &results) {
@ -131,32 +138,37 @@ void MainWindow::showResults(const WordRefList &results) {
result_model_.setStringList(ui_results);
}
void MainWindow::clearResults() { result_model_.setStringList({}); }
void MainWindow::on_searchInput_textChanged(const QString &search_term) {
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
search(search_term);
QGuiApplication::restoreOverrideCursor();
// QGuiApplication::setOverrideCursor(Qt::WaitCursor);
// search(search_term);
// QGuiApplication::restoreOverrideCursor();
}
void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
clearResults();
createSelectedFinder();
search(ui->searchInput->displayText());
// search(ui->searchInput->displayText());
QGuiApplication::restoreOverrideCursor();
}
void MainWindow::on_wordListSourceSelector_currentIndexChanged(int) {
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
clearResults();
setupWordList();
createSelectedFinder();
search(ui->searchInput->displayText());
// search(ui->searchInput->displayText());
QGuiApplication::restoreOverrideCursor();
}
void MainWindow::on_wordListSizeSelector_valueChanged(int) {
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
clearResults();
setupWordList();
createSelectedFinder();
search(ui->searchInput->displayText());
// search(ui->searchInput->displayText());
QGuiApplication::restoreOverrideCursor();
}

View File

@ -37,6 +37,7 @@ private:
void search(const QString &search_term);
void createSelectedFinder();
void showResults(const WordRefList &results);
void clearResults();
private slots:
void on_searchInput_textChanged(const QString &search_term);