Skip to content

Commit

Permalink
Implement minunique1 in the Qt port
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Feb 25, 2024
1 parent 19ad4b7 commit cbea7c5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
60 changes: 60 additions & 0 deletions qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void addBiblesThread(MainWindow* window) {
window->lookup2Act->setEnabled(true);
window->find1Act->setEnabled(true);
window->find2Act->setEnabled(true);
window->minunique1Act->setEnabled(true);
}

void MainWindow::addBibles()
Expand Down Expand Up @@ -281,6 +282,57 @@ void MainWindow::lookup2()
this->lookupN(1);
}

void MainWindow::minunique1()
{
// Taken mostly from cli:
if (text[0].length() == 0) {
statusBar()->showMessage("Clipboard is empty, no search possible.");
return;
}

QInputDialog inputDialog;

QStringList items;
extern vector<Book> books;
// This is not the best way to collect the available Bible editions,
// because we iterate on each Bible book (for each edition).
// It would be better to maintain the available Bible editions by storing it globally.
for (Book book : books) {
string moduleName = book.getModuleName();
if (!items.contains(moduleName.c_str())) {
items.append(moduleName.c_str());
}
}
inputDialog.setOptions(QInputDialog::UseListViewForComboBoxItems);
inputDialog.setComboBoxItems(items);
inputDialog.setWindowTitle("Min. unique 1");
inputDialog.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
inputDialog.setLabelText("Select a Bible edition:");
inputDialog.setFixedSize(200,3);

if (inputDialog.exec() != QDialog::Accepted)
return;
const QString value = inputDialog.textValue().trimmed();
if (value.isEmpty())
return;
string rest = value.toStdString();

collect_info = "";

extern vector<string> find_min_unique(string text, const string& moduleName, bool verbose);
find_min_unique(text[0], rest, true);

boost::trim(collect_info);
boost::replace_all(collect_info, "\n", "<br>");

passageInfos->append(("<b>Minimal unique subtexts of " + text[0] + " in " + rest + "</b>" + "<br>" + collect_info).c_str());

QTextCursor tc = passageInfos->textCursor();
tc.setPosition(passageInfos->document()->characterCount() - 1);
passageInfos->setTextCursor(tc); // Move cursor to the end.

}

void MainWindow::findN(int index)
{
// Taken mostly from cli:
Expand Down Expand Up @@ -401,6 +453,11 @@ void MainWindow::createActions()
connect(find2Act, &QAction::triggered, this, &MainWindow::find2);
find2Act->setDisabled(true);

minunique1Act = new QAction(tr("Min. unique 1"), this);
minunique1Act->setStatusTip(tr("Search for minimal unique passages in clipboard 1 in a Bible"));
connect(minunique1Act, &QAction::triggered, this, &MainWindow::minunique1);
minunique1Act->setDisabled(true);

lookupAct = new QAction(tr("&Lookup"), this);
lookupAct->setStatusTip(tr("Search for a verse in a book in the given Bible"));
connect(lookupAct, &QAction::triggered, this, &MainWindow::lookup);
Expand Down Expand Up @@ -447,6 +504,9 @@ void MainWindow::createMenus()
passageMenu->addAction(lookup1Act);
passageMenu->addAction(lookup2Act);

quotationsMenu = menuBar()->addMenu(tr("&Quotations"));
quotationsMenu->addAction(minunique1Act);

helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
Expand Down
3 changes: 3 additions & 0 deletions qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MainWindow : public QMainWindow
QAction *lookup2Act;
QAction *find1Act;
QAction *find2Act;
QAction *minunique1Act;

protected:

Expand All @@ -36,6 +37,7 @@ private slots:
void lookup2();
void find1();
void find2();
void minunique1();
void about();
void aboutQt();

Expand All @@ -50,6 +52,7 @@ private slots:
QMenu *fileMenu;
QMenu *editMenu;
QMenu *passageMenu;
QMenu *quotationsMenu;
QMenu *helpMenu;
QAction *exitAct;
QAction *greekText1Act;
Expand Down

0 comments on commit cbea7c5

Please sign in to comment.