checks-parser/mainwindow.cpp

101 lines
2.5 KiB
C++
Raw Normal View History

2024-08-18 13:57:57 +03:00
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "check/check.h"
#include "goods/goods.h"
#include "outputdialog.h"
2024-10-05 13:52:44 +03:00
#include "settingsdialog.h"
#include <iostream>
2024-09-01 16:15:00 +03:00
#include <QFileDialog>
2024-09-01 16:57:25 +03:00
#include "image/checkimage.h"
2024-08-18 13:57:57 +03:00
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
2024-08-18 13:57:57 +03:00
ui->setupUi(this);
this->setupStoresList();
}
MainWindow::~MainWindow() { delete ui; }
void MainWindow::setupStoresList() {
parser = *(new Parser());
std::vector<std::string> modules_names = parser.search_modules();
for (std::string name : modules_names) {
StoreModule m(name);
std::wstring module_name = m.get_name();
QString s = QString::fromStdWString(module_name);
ui->storeType->addItem(s);
}
2024-08-20 02:38:40 +03:00
#ifdef DEBUG
for (auto module : parser.search_modules()) {
2024-08-20 02:38:40 +03:00
std::cout << "Module: " << module << std::endl;
}
2024-08-20 02:38:40 +03:00
#endif
}
2024-10-22 13:18:19 +03:00
// void MainWindow::on_checkType_currentIndexChanged(int index) {
// ui->inputHolder->setCurrentIndex(index);
// }
2024-08-18 13:57:57 +03:00
void MainWindow::on_parseButton_clicked() {
2024-09-01 16:57:25 +03:00
QString s;
switch (ui->checkType->currentIndex()) {
case 0:
s = ui->checkContent->toPlainText();
break;
case 1:
s = ui->checkContentFromImage->toPlainText();
break;
}
2024-08-20 02:38:40 +03:00
std::wstring check_plaintext = s.toStdWString();
parser.set_module(parser.search_modules()[0]);
std::vector<Goods> c = parser.parse(check_plaintext);
if (c.size() == 0) {
std::cerr << "An error has occured. Check was matched incorrectly. Vector sizes are different" << std::endl;
return;
}
2024-08-20 02:38:40 +03:00
Check check;
2024-08-30 22:12:14 +03:00
for (auto& g : c) {
2024-08-20 02:38:40 +03:00
check.add_goods(g);
}
2024-10-05 13:52:44 +03:00
OutputDialog d = OutputDialog(this, check);
d.show();
d.exec();
}
void MainWindow::on_storeType_currentIndexChanged(int index) {
std::string module = parser.search_modules()[index];
parser.set_module(module);
2024-08-18 13:57:57 +03:00
}
2024-09-01 16:15:00 +03:00
void MainWindow::on_chooseImageButton_clicked() {
QString filename = QFileDialog::getOpenFileName();
std::cout << filename.toStdString() << std::endl;
// this->options.set_path(filename.toStdString());
2024-10-22 13:18:19 +03:00
std::string new_text = "Selected: " + filename.toStdString();
2024-09-01 16:57:25 +03:00
ui->pathLabel->setText(QString::fromStdString(new_text));
CheckImage i(filename.toStdString());
std::string parsed = i.parse_text();
ui->checkContentFromImage->setPlainText(QString::fromStdString(parsed));
2024-09-01 16:15:00 +03:00
}
2024-10-05 13:52:44 +03:00
void MainWindow::on_preferencesButton_clicked() {
SettingsDialog s = SettingsDialog();
s.show();
s.exec();
}