feat: don't search while typing
This commit is contained in:
parent
8c9a1522a0
commit
f080d00697
@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
setupAlgorithmSelector();
|
setupAlgorithmSelector();
|
||||||
setupWordListSourceSelector();
|
setupWordListSourceSelector();
|
||||||
setupWordList();
|
setupWordList();
|
||||||
|
createSelectedFinder();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() { delete ui; }
|
MainWindow::~MainWindow() { delete ui; }
|
||||||
@ -79,8 +80,7 @@ void MainWindow::loadWordList(std::filesystem::path path) {
|
|||||||
|
|
||||||
void MainWindow::search(const QString &search_term) {
|
void MainWindow::search(const QString &search_term) {
|
||||||
if (search_term.isEmpty()) {
|
if (search_term.isEmpty()) {
|
||||||
result_model_.setStringList(QStringList());
|
clearResults();
|
||||||
ui->mainStatusBar->clearMessage();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +99,7 @@ void MainWindow::search(const QString &search_term) {
|
|||||||
void MainWindow::createSelectedFinder() {
|
void MainWindow::createSelectedFinder() {
|
||||||
auto selectedFinder = ui->searchAlgorithmSelector->currentIndex();
|
auto selectedFinder = ui->searchAlgorithmSelector->currentIndex();
|
||||||
|
|
||||||
|
Timer timer;
|
||||||
switch (selectedFinder) {
|
switch (selectedFinder) {
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
@ -120,6 +121,12 @@ void MainWindow::createSelectedFinder() {
|
|||||||
finder_ = std::make_unique<GroupedFinder>(word_list_);
|
finder_ = std::make_unique<GroupedFinder>(word_list_);
|
||||||
break;
|
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) {
|
void MainWindow::showResults(const WordRefList &results) {
|
||||||
@ -131,32 +138,37 @@ void MainWindow::showResults(const WordRefList &results) {
|
|||||||
result_model_.setStringList(ui_results);
|
result_model_.setStringList(ui_results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::clearResults() { result_model_.setStringList({}); }
|
||||||
|
|
||||||
void MainWindow::on_searchInput_textChanged(const QString &search_term) {
|
void MainWindow::on_searchInput_textChanged(const QString &search_term) {
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
// QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
search(search_term);
|
// search(search_term);
|
||||||
QGuiApplication::restoreOverrideCursor();
|
// QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
|
void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
clearResults();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
search(ui->searchInput->displayText());
|
// search(ui->searchInput->displayText());
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_wordListSourceSelector_currentIndexChanged(int) {
|
void MainWindow::on_wordListSourceSelector_currentIndexChanged(int) {
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
clearResults();
|
||||||
setupWordList();
|
setupWordList();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
search(ui->searchInput->displayText());
|
// search(ui->searchInput->displayText());
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_wordListSizeSelector_valueChanged(int) {
|
void MainWindow::on_wordListSizeSelector_valueChanged(int) {
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
clearResults();
|
||||||
setupWordList();
|
setupWordList();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
search(ui->searchInput->displayText());
|
// search(ui->searchInput->displayText());
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ private:
|
|||||||
void search(const QString &search_term);
|
void search(const QString &search_term);
|
||||||
void createSelectedFinder();
|
void createSelectedFinder();
|
||||||
void showResults(const WordRefList &results);
|
void showResults(const WordRefList &results);
|
||||||
|
void clearResults();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_searchInput_textChanged(const QString &search_term);
|
void on_searchInput_textChanged(const QString &search_term);
|
||||||
|
Reference in New Issue
Block a user