feat: add option to load english words
This commit is contained in:
parent
10b19749f7
commit
dae5445efc
4 changed files with 370190 additions and 22 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include "tree_finder.h"
|
#include "tree_finder.h"
|
||||||
#include "word_list_generator.h"
|
#include "word_list_generator.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
@ -17,10 +18,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->resultView->setModel(&result_model_);
|
ui->resultView->setModel(&result_model_);
|
||||||
|
ui->wordListSourceSelector->setModel(&word_list_sources_);
|
||||||
ui->searchAlgorithmSelector->setModel(&search_algorithms_);
|
ui->searchAlgorithmSelector->setModel(&search_algorithms_);
|
||||||
|
|
||||||
setupAlgorithmSelector();
|
setupAlgorithmSelector();
|
||||||
generateWordList();
|
setupWordListSourceSelector();
|
||||||
|
setupWordList();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() { delete ui; }
|
MainWindow::~MainWindow() { delete ui; }
|
||||||
|
@ -33,6 +36,23 @@ void MainWindow::setupAlgorithmSelector() {
|
||||||
search_algorithms_.appendRow(new QStandardItem("Grouped search"));
|
search_algorithms_.appendRow(new QStandardItem("Grouped search"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupWordListSourceSelector() {
|
||||||
|
word_list_sources_.appendRow(new QStandardItem("All 4-caps words"));
|
||||||
|
word_list_sources_.appendRow(new QStandardItem("English words"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupWordList() {
|
||||||
|
switch (ui->wordListSourceSelector->currentIndex()) {
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
generateWordList();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
loadWordList("words.txt");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::generateWordList() {
|
void MainWindow::generateWordList() {
|
||||||
Timer timer;
|
Timer timer;
|
||||||
word_list_ = WordListGenerator::generate(ui->wordListSizeSelector->value());
|
word_list_ = WordListGenerator::generate(ui->wordListSizeSelector->value());
|
||||||
|
@ -43,6 +63,25 @@ void MainWindow::generateWordList() {
|
||||||
ui->mainStatusBar->showMessage(QString::fromStdString(status_message.str()));
|
ui->mainStatusBar->showMessage(QString::fromStdString(status_message.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadWordList(std::filesystem::path path) {
|
||||||
|
word_list_.clear();
|
||||||
|
|
||||||
|
Timer timer;
|
||||||
|
std::ifstream ifs(path);
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(ifs, line)) {
|
||||||
|
for (auto i = 0; i < ui->wordListSizeSelector->value(); ++i) {
|
||||||
|
word_list_.emplace_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timer.stop();
|
||||||
|
|
||||||
|
std::stringstream status_message;
|
||||||
|
status_message << "loaded " << word_list_.size() << " words in " << timer;
|
||||||
|
ui->mainStatusBar->showMessage(QString::fromStdString(status_message.str()));
|
||||||
|
}
|
||||||
|
|
||||||
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());
|
result_model_.setStringList(QStringList());
|
||||||
|
@ -108,9 +147,17 @@ void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_wordListSizeSelector_valueChanged(int) {
|
void MainWindow::on_wordListSourceSelector_currentIndexChanged(int) {
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
generateWordList();
|
setupWordList();
|
||||||
|
createSelectedFinder();
|
||||||
|
search(ui->searchInput->displayText());
|
||||||
|
QGuiApplication::restoreOverrideCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_wordListSizeSelector_valueChanged(int) {
|
||||||
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
setupWordList();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
search(ui->searchInput->displayText());
|
search(ui->searchInput->displayText());
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -19,6 +20,7 @@ private:
|
||||||
std::vector<std::string> word_list_;
|
std::vector<std::string> word_list_;
|
||||||
QStringListModel result_model_;
|
QStringListModel result_model_;
|
||||||
QStandardItemModel search_algorithms_;
|
QStandardItemModel search_algorithms_;
|
||||||
|
QStandardItemModel word_list_sources_;
|
||||||
std::unique_ptr<Finder> finder_;
|
std::unique_ptr<Finder> finder_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -27,7 +29,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupAlgorithmSelector();
|
void setupAlgorithmSelector();
|
||||||
|
void setupWordListSourceSelector();
|
||||||
|
void setupWordList();
|
||||||
void generateWordList();
|
void generateWordList();
|
||||||
|
void loadWordList(std::filesystem::path path);
|
||||||
void search(const QString &search_term);
|
void search(const QString &search_term);
|
||||||
void createSelectedFinder();
|
void createSelectedFinder();
|
||||||
void showResults(const std::forward_list<const std::string *> &results);
|
void showResults(const std::forward_list<const std::string *> &results);
|
||||||
|
@ -35,7 +40,8 @@ private:
|
||||||
private slots:
|
private slots:
|
||||||
void on_searchInput_textChanged(const QString &search_term);
|
void on_searchInput_textChanged(const QString &search_term);
|
||||||
void on_searchAlgorithmSelector_currentIndexChanged(int);
|
void on_searchAlgorithmSelector_currentIndexChanged(int);
|
||||||
void on_wordListSizeSelector_valueChanged(int new_value);
|
void on_wordListSourceSelector_currentIndexChanged(int);
|
||||||
|
void on_wordListSizeSelector_valueChanged(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
|
@ -35,20 +35,10 @@
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="1">
|
<item row="3" column="0">
|
||||||
<widget class="QLineEdit" name="searchInput">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Select search algorithm</string>
|
<string><html><head/><body><p>Select word-list size</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -68,14 +58,17 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLineEdit" name="searchInput">
|
||||||
<property name="text">
|
<property name="sizePolicy">
|
||||||
<string><html><head/><body><p>Select word-list size</p></body></html></string>
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QSpinBox" name="wordListSizeSelector">
|
<widget class="QSpinBox" name="wordListSizeSelector">
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>100</number>
|
<number>100</number>
|
||||||
|
@ -85,6 +78,23 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Select search algorithm</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Select word-list source</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QComboBox" name="wordListSourceSelector"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
Loading…
Reference in a new issue