feat: add developer mode and incremental search cli options
parent
aa9c5e0ebc
commit
06f468f8fd
|
@ -1,10 +1,26 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QApplication a(argc, argv);
|
QApplication app(argc, argv);
|
||||||
MainWindow w;
|
|
||||||
w.show();
|
QCommandLineParser cli_parser;
|
||||||
return a.exec();
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,18 @@
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent, bool enableIncrementalSearch,
|
||||||
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
bool enableDevMode)
|
||||||
|
: QMainWindow(parent), ui(new Ui::MainWindow),
|
||||||
|
incremental_search_(enableIncrementalSearch) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->resultView->setModel(&result_model_);
|
ui->resultView->setModel(&result_model_);
|
||||||
ui->wordListSourceSelector->setModel(&word_list_sources_);
|
ui->wordListSourceSelector->setModel(&word_list_sources_);
|
||||||
ui->searchAlgorithmSelector->setModel(&search_algorithms_);
|
ui->searchAlgorithmSelector->setModel(&search_algorithms_);
|
||||||
|
|
||||||
|
setDevMode(enableDevMode);
|
||||||
|
|
||||||
setupAlgorithmSelector();
|
setupAlgorithmSelector();
|
||||||
setupWordListSourceSelector();
|
setupWordListSourceSelector();
|
||||||
setupWordList();
|
setupWordList();
|
||||||
|
@ -28,6 +32,17 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
MainWindow::~MainWindow() { delete ui; }
|
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() {
|
void MainWindow::setupAlgorithmSelector() {
|
||||||
search_algorithms_.appendRow(new QStandardItem("Bucket search"));
|
search_algorithms_.appendRow(new QStandardItem("Bucket search"));
|
||||||
search_algorithms_.appendRow(new QStandardItem("Linear 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::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);
|
if (!incremental_search_) {
|
||||||
// search(search_term);
|
return;
|
||||||
// QGuiApplication::restoreOverrideCursor();
|
}
|
||||||
|
|
||||||
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
search(search_term);
|
||||||
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
|
void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
clearResults();
|
clearResults();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
// search(ui->searchInput->displayText());
|
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +177,6 @@ void MainWindow::on_wordListSourceSelector_currentIndexChanged(int) {
|
||||||
clearResults();
|
clearResults();
|
||||||
setupWordList();
|
setupWordList();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
// search(ui->searchInput->displayText());
|
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +185,6 @@ void MainWindow::on_wordListSizeSelector_valueChanged(int) {
|
||||||
clearResults();
|
clearResults();
|
||||||
setupWordList();
|
setupWordList();
|
||||||
createSelectedFinder();
|
createSelectedFinder();
|
||||||
// search(ui->searchInput->displayText());
|
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,16 @@ private:
|
||||||
QStandardItemModel search_algorithms_;
|
QStandardItemModel search_algorithms_;
|
||||||
QStandardItemModel word_list_sources_;
|
QStandardItemModel word_list_sources_;
|
||||||
std::unique_ptr<Finder> finder_;
|
std::unique_ptr<Finder> finder_;
|
||||||
|
bool incremental_search_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr, bool enableIncrementalSearch = false,
|
||||||
|
bool enableDevMode = false);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
/// Show additional widgets
|
||||||
|
void setDevMode(bool enable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupAlgorithmSelector();
|
void setupAlgorithmSelector();
|
||||||
void setupWordListSourceSelector();
|
void setupWordListSourceSelector();
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
</property>
|
</property>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="selectWordListSizeLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><html><head/><body><p>Select word-list size</p></body></html></string>
|
<string><html><head/><body><p>Select word-list size</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
<widget class="QComboBox" name="searchAlgorithmSelector"/>
|
<widget class="QComboBox" name="searchAlgorithmSelector"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="enterSearchTextLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -79,14 +79,14 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="searchAlgorithmLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Select search algorithm</string>
|
<string>Select search algorithm</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="selectWordListLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Select word-list source</string>
|
<string>Select word-list source</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in New Issue