feat: add developer mode and incremental search cli options

This commit is contained in:
Michael Mandl 2024-03-23 10:25:50 +01:00
parent aa9c5e0ebc
commit 2ebc2107ba
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
4 changed files with 54 additions and 17 deletions

View file

@ -1,10 +1,26 @@
#include "mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
QApplication app(argc, argv);
QCommandLineParser cli_parser;
cli_parser.addHelpOption();
cli_parser.addVersionOption();
QCommandLineOption devModeOption({"d", "dev"}, "Run in dev mode");
cli_parser.addOption(devModeOption);
QCommandLineOption incrementalSearchOption({"i", "incremental"},
"Enable incremental search");
cli_parser.addOption(incrementalSearchOption);
cli_parser.process(app);
MainWindow main_window(nullptr, cli_parser.isSet(incrementalSearchOption),
cli_parser.isSet(devModeOption));
main_window.show();
return app.exec();
}

View file

@ -12,14 +12,18 @@
#include <sstream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
MainWindow::MainWindow(QWidget *parent, bool enableIncrementalSearch,
bool enableDevMode)
: QMainWindow(parent), ui(new Ui::MainWindow),
incremental_search_enabled_(enableIncrementalSearch) {
ui->setupUi(this);
ui->resultView->setModel(&result_model_);
ui->wordListSourceSelector->setModel(&word_list_sources_);
ui->searchAlgorithmSelector->setModel(&search_algorithms_);
setDevMode(enableDevMode);
setupAlgorithmSelector();
setupWordListSourceSelector();
setupWordList();
@ -28,6 +32,17 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() { delete ui; }
void MainWindow::setDevMode(bool enable) {
ui->searchAlgorithmLabel->setVisible(enable);
ui->searchAlgorithmSelector->setVisible(enable);
ui->selectWordListLabel->setVisible(enable);
ui->wordListSourceSelector->setVisible(enable);
ui->selectWordListSizeLabel->setVisible(enable);
ui->wordListSizeSelector->setVisible(enable);
}
void MainWindow::setupAlgorithmSelector() {
search_algorithms_.appendRow(new QStandardItem("Bucket search"));
search_algorithms_.appendRow(new QStandardItem("Linear search"));
@ -141,16 +156,19 @@ void MainWindow::showResults(const WordRefList &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();
if (!incremental_search_enabled_) {
return;
}
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());
QGuiApplication::restoreOverrideCursor();
}
@ -159,7 +177,6 @@ void MainWindow::on_wordListSourceSelector_currentIndexChanged(int) {
clearResults();
setupWordList();
createSelectedFinder();
// search(ui->searchInput->displayText());
QGuiApplication::restoreOverrideCursor();
}
@ -168,7 +185,6 @@ void MainWindow::on_wordListSizeSelector_valueChanged(int) {
clearResults();
setupWordList();
createSelectedFinder();
// search(ui->searchInput->displayText());
QGuiApplication::restoreOverrideCursor();
}

View file

@ -23,11 +23,16 @@ private:
QStandardItemModel search_algorithms_;
QStandardItemModel word_list_sources_;
std::unique_ptr<Finder> finder_;
bool incremental_search_enabled_;
public:
MainWindow(QWidget *parent = nullptr);
MainWindow(QWidget *parent = nullptr, bool enableIncrementalSearch = false,
bool enableDevMode = false);
~MainWindow();
/// Show additional widgets
void setDevMode(bool enable);
private:
void setupAlgorithmSelector();
void setupWordListSourceSelector();

View file

@ -36,7 +36,7 @@
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="selectWordListSizeLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select word-list size&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -46,7 +46,7 @@
<widget class="QComboBox" name="searchAlgorithmSelector"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="enterSearchTextLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -79,14 +79,14 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="searchAlgorithmLabel">
<property name="text">
<string>Select search algorithm</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="selectWordListLabel">
<property name="text">
<string>Select word-list source</string>
</property>