diff --git a/CMakeLists.txt b/CMakeLists.txt index 071ed1a..631b6da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ set(PROJECT_SOURCES emailtextscene.h emailtextscene.cpp scenes/emailtextscene.ui ocrscene.h ocrscene.cpp scenes/ocrscene.ui ofdscene.h ofdscene.cpp scenes/ofdscene.ui + outputdialog.h outputdialog.cpp scenes/outputdialog.ui + # adjustpicturedialog.h adjustpicturedialog.cpp scenes/adjustpicturedialog.ui ) set(TRANSLATION_SOURCES @@ -47,6 +49,8 @@ set(TRANSLATION_SOURCES emailtextscene.cpp emailtextscene.h scenes/emailtextscene.ui ocrscene.cpp ocrscene.h scenes/ocrscene.ui ofdscene.cpp ofdscene.h scenes/ofdscene.ui + outputdialog.h outputdialog.cpp scenes/outputdialog.ui + # adjustpicturedialog.h adjustpicturedialog.cpp scenes/adjustpicturedialog.ui ) set(TS_FILES diff --git a/check/check.cpp b/check/check.cpp index 6a1881a..587d0eb 100644 --- a/check/check.cpp +++ b/check/check.cpp @@ -5,10 +5,16 @@ Check::Check() {} void Check::add_goods(Goods goods) { this->goods.push_back(goods); } +void Check::add_goods(std::vector &goods) { + for (auto g : goods) { + this->goods.push_back(g); + } +} + double Check::calculae_total_price() { double total = 0.0; - for (Goods g : this->goods) { + for (Goods &g : goods) { total += g.calculate_total_price(); } diff --git a/check/check.h b/check/check.h index a7b8299..01af62b 100644 --- a/check/check.h +++ b/check/check.h @@ -9,6 +9,7 @@ class Check { public: Check(); void add_goods(Goods); + void add_goods(std::vector &goods); double calculae_total_price(); diff --git a/emailtextscene.cpp b/emailtextscene.cpp index 221a010..5c70c11 100644 --- a/emailtextscene.cpp +++ b/emailtextscene.cpp @@ -1,14 +1,45 @@ #include "emailtextscene.h" #include "ui_emailtextscene.h" +#include +#include +#include +#include EmailTextScene::EmailTextScene(QWidget *parent) : QWidget(parent) - , ui(new Ui::EmailTextScene) -{ + , ui(new Ui::EmailTextScene) { ui->setupUi(this); + + auto modules = parser.get_modules_names(); + + for (auto &module : modules) { + ui->store_combo_box->addItem(QString::fromStdString(module)); + } } -EmailTextScene::~EmailTextScene() -{ +EmailTextScene::~EmailTextScene() { delete ui; } + +void EmailTextScene::on_parse_button_clicked() { + std::wstring checkContent = ui->check_content->toPlainText().toStdWString(); + parser.set_module(parser.search_modules()[ui->store_combo_box->currentIndex()]); + + std::vector goods = parser.parse(checkContent); + if (goods.size() == 0) { + QMessageBox infoDialog; + infoDialog.setText(tr("An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.")); + infoDialog.setIcon(QMessageBox::Critical); + infoDialog.setWindowTitle(tr("Error in parsing")); + infoDialog.exec(); + return; + } + + Check check; + check.add_goods(goods); + + OutputDialog d(this, check); + d.show(); + d.exec(); +} + diff --git a/emailtextscene.h b/emailtextscene.h index 7b55eea..4a8739a 100644 --- a/emailtextscene.h +++ b/emailtextscene.h @@ -1,6 +1,7 @@ #ifndef EMAILTEXTSCENE_H #define EMAILTEXTSCENE_H +#include "parser/parser.h" #include namespace Ui { @@ -15,8 +16,12 @@ public: explicit EmailTextScene(QWidget *parent = nullptr); ~EmailTextScene(); +private slots: + void on_parse_button_clicked(); + private: Ui::EmailTextScene *ui; + Parser parser; }; #endif // EMAILTEXTSCENE_H diff --git a/main.cpp b/main.cpp index c516e06..fda2410 100644 --- a/main.cpp +++ b/main.cpp @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include #include @@ -48,31 +51,38 @@ int main(int argc, char *argv[]) { QObject::connect(text_from_email_button, &QPushButton::clicked, [&]() { // Text from email scene sceneLayout->setCurrentIndex(1); + sceneLayout->widget(1)->show(); }); QObject::connect(ocr_button, &QPushButton::clicked, [&]() { // OCR scene sceneLayout->setCurrentIndex(2); + sceneLayout->widget(2)->show(); }); QObject::connect(ofd_button, &QPushButton::clicked, [&]() { // OCR scene sceneLayout->setCurrentIndex(3); + sceneLayout->widget(3)->show(); }); - // Text from email setup - QWidget *emailtextscene = loadUI(window, ":/scenes/scenes/emailtextscene.ui"); + // // Text from email setup + // QWidget *emailtextscene = loadUI(window, ":/scenes/scenes/emailtextscene.ui"); + // emailtextscene->show(); //OCR scene - QWidget *ocrscene = loadUI(window, ":/scenes/scenes/ocrscene.ui"); + // QWidget *ocrscene = loadUI(window, ":/scenes/scenes/ocrscene.ui"); //OFD scene - QWidget *ofdscene = loadUI(window, ":/scenes/scenes/ofdscene.ui"); + // QWidget *ofdscene = loadUI(window, ":/scenes/scenes/ofdscene.ui"); + EmailTextScene *emailTextScene = new EmailTextScene(); + OCRScene *ocrscene = new OCRScene(); + OFDScene *ofdscene = new OFDScene(); sceneLayout->addWidget(mainwindowscene); - sceneLayout->addWidget(emailtextscene); + sceneLayout->addWidget(emailTextScene); sceneLayout->addWidget(ocrscene); sceneLayout->addWidget(ofdscene); diff --git a/mainwindow.cpp b/mainwindow.cpp index ebbb084..177df99 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,10 +1,13 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include MainWindow::MainWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + + std::cout << "test" << std::endl; } MainWindow::~MainWindow() { diff --git a/ocrscene.cpp b/ocrscene.cpp index 6d3821e..dc1e782 100644 --- a/ocrscene.cpp +++ b/ocrscene.cpp @@ -1,12 +1,73 @@ #include "ocrscene.h" #include "ui_ocrscene.h" +#include +#include +#include + +#include + +#include + OCRScene::OCRScene(QWidget *parent) : QWidget(parent) , ui(new Ui::OCRScene) { ui->setupUi(this); + + auto modules = parser.get_modules_names(); + + for (auto &module : modules) { + ui->store_combo_box->addItem(QString::fromStdString(module)); + } } OCRScene::~OCRScene() { delete ui; } + +void OCRScene::on_parse_button_clicked() { + std::wstring checkContent = ui->check_text_edit->toPlainText().toStdWString(); + + parser.set_module(parser.search_modules()[ui->store_combo_box->currentIndex()]); + + std::vector goods = parser.parse(checkContent); + if (goods.size() == 0) { + QMessageBox infoDialog; + infoDialog.setText(tr("An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer.")); + infoDialog.setIcon(QMessageBox::Critical); + infoDialog.setWindowTitle(tr("Error in parsing")); + infoDialog.exec(); + return; + } + + Check check; + check.add_goods(goods); + + OutputDialog d(this, check); + d.show(); + d.exec(); +} + +void OCRScene::on_choose_image_button_clicked() { + QString filename = QFileDialog::getOpenFileName(); + + if (filename == "") { + QMessageBox infoDialog; + infoDialog.setText(tr("Please, select a picture to scan")); + infoDialog.setIcon(QMessageBox::Critical); + infoDialog.setWindowTitle(tr("Picture was not selected")); + infoDialog.exec(); + return; + } + + std::string new_text = "Selected: " + filename.toStdString(); + ui->path_to_image_label->setText(tr("Path to image: ")+ filename); + + CheckImage i(filename.toStdString()); + std::string parsed = i.parse_text(); + + ui->check_text_edit->setPlainText(QString::fromStdString(parsed)); + + +} + diff --git a/ocrscene.h b/ocrscene.h index 64ede02..2909825 100644 --- a/ocrscene.h +++ b/ocrscene.h @@ -1,6 +1,7 @@ #ifndef OCRSCENE_H #define OCRSCENE_H +#include "parser/parser.h" #include namespace Ui { @@ -15,8 +16,14 @@ public: explicit OCRScene(QWidget *parent = nullptr); ~OCRScene(); +private slots: + void on_parse_button_clicked(); + + void on_choose_image_button_clicked(); + private: Ui::OCRScene *ui; + Parser parser; }; #endif // OCRSCENE_H diff --git a/outputdialog.ui b/outputdialog.ui deleted file mode 100644 index c6e462f..0000000 --- a/outputdialog.ui +++ /dev/null @@ -1,215 +0,0 @@ - - - OutputDialog - - - - 0 - 0 - 586 - 431 - - - - Dialog - - - - - 410 - 390 - 166 - 26 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 10 - 20 - 271 - 18 - - - - Path to export: - - - - - - 290 - 20 - 80 - 26 - - - - Choose - - - - - - 10 - 50 - 371 - 24 - - - - Print header - - - - - - 10 - 130 - 401 - 221 - - - - - Goods name - - - - - Goods price - - - - - Goods quantity - - - - - Goods net weight - - - - - Goods total - - - - - position - - - - - name - - - - - 1 - - - - - Name - - - - - 2 - - - - - Price - - - - - 3 - - - - - Quantity - - - - - 4 - - - - - Net weight - - - - - 5 - - - - - Total price - - - - - - - 10 - 90 - 381 - 24 - - - - Print total - - - - - - - buttonBox - accepted() - OutputDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - OutputDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/parser/module.cpp b/parser/module.cpp index ebdc002..dba8d44 100644 --- a/parser/module.cpp +++ b/parser/module.cpp @@ -31,7 +31,7 @@ StoreModule::StoreModule(std::string path) { std::vector StoreModule::parse_name(std::wstring str) { std::vector result; - std::wregex r(this->goods_name_regex, std::regex::collate); + std::wregex r(this->goods_name_regex, std::regex_constants::multiline); for (std::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end; it++) { diff --git a/parser/parser.cpp b/parser/parser.cpp index a35a2b1..d15a0ff 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -4,6 +4,7 @@ #include "../settings/settings.h" #include "../utils/utils.h" #include +#include #if __GNUC__ < 8 && __clang_major__ < 17 # include @@ -14,6 +15,27 @@ using namespace std::filesystem; #endif +static void dumpVectorsToStdErr(std::vector &goods_names, std::vector &goods_prices, std::vector& goods_quantities) { + std::cerr << goods_names.size() << " " << goods_prices.size() << " " << goods_quantities.size() << std::endl; + std::cerr << "Found goods names: "; + for (auto &goods_name : goods_names) { + std::cerr << goods_name << " "; + } + std::cerr << std::endl; + + std::cerr << "Found goods prices: "; + for (auto &goods_price : goods_prices) { + std::cerr << goods_price << " "; + } + std::cerr << std::endl; + + std::cerr << "Found goods names: "; + for (auto &goods_quantity : goods_quantities) { + std::cerr << goods_quantity << " "; + } + std::cerr << std::endl; +} + Parser::Parser() {} std::vector Parser::search_modules() { @@ -31,13 +53,28 @@ std::vector Parser::search_modules() { std::vector modules_files; - for (auto file : directory_iterator(path)) { + for (auto &file : directory_iterator(path)) { modules_files.push_back(file.path()); } return modules_files; } +std::vector Parser::get_modules_names() { + std::vector modules = this->search_modules(); + std::vector names = {}; + + for (std::string &modulePath : modules) { + std::ifstream inputFile(modulePath); + + nlohmann::json module = nlohmann::json::parse(inputFile); + std::string name = module["name"]; + names.push_back(name); + } + + return names; +} + void Parser::set_module(std::string path) { module = StoreModule(path); } std::vector Parser::parse(std::wstring check_plaintext) { @@ -53,6 +90,9 @@ std::vector Parser::parse(std::wstring check_plaintext) { if (goods_names.size() != goods_prices.size() || goods_names.size() != goods_quantities.size() || goods_prices.size() != goods_quantities.size()) { + + dumpVectorsToStdErr(goods_names, goods_prices, goods_quantities); + //Error. Amount of names, prices or quantities are not equal. That means, that some regex(es) has mismatched. return {}; } diff --git a/parser/parser.h b/parser/parser.h index 5e4136f..c845785 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -15,6 +15,8 @@ public: std::vector search_modules(); + std::vector get_modules_names(); + std::vector check_updates(); void set_module(std::string); diff --git a/scenes.qrc b/scenes.qrc index 790004d..026d8a5 100644 --- a/scenes.qrc +++ b/scenes.qrc @@ -1,5 +1,6 @@ + scenes/outputdialog.ui scenes/emailtextscene.ui scenes/ocrscene.ui scenes/mainwindow.ui diff --git a/adjustpicturedialog.ui b/scenes/adjustpicturedialog.ui similarity index 100% rename from adjustpicturedialog.ui rename to scenes/adjustpicturedialog.ui diff --git a/scenes/emailtextscene.ui b/scenes/emailtextscene.ui index b8677ba..84573c2 100644 --- a/scenes/emailtextscene.ui +++ b/scenes/emailtextscene.ui @@ -14,30 +14,7 @@ Form - - - - - - - Parse - - - - - - - - 0 - 0 - - - - Back - - - - + @@ -50,6 +27,52 @@ + + + + Parse + + + + + + + + 0 + 0 + + + + Store: + + + + + + + + + + + 0 + 0 + + + + Back + + + + + + + + 0 + 0 + + + + diff --git a/scenes/ocrscene.ui b/scenes/ocrscene.ui index 18d4477..1c9aa59 100644 --- a/scenes/ocrscene.ui +++ b/scenes/ocrscene.ui @@ -23,7 +23,30 @@ 8 - + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Parse + + + + @@ -42,36 +65,7 @@ - - - - - 0 - 0 - - - - Path to image: - - - - - - - - 0 - 0 - - - - Recognized text will be shown below as soon as image will be processed. Please, edit it - - - - - - - + @@ -84,16 +78,45 @@ - - + + - + 0 0 - Parse + Recognized text will be shown below as soon as image will be processed. Please, edit it + + + + + + + + 0 + 0 + + + + Path to image: + + + + + + + + + + + 0 + 0 + + + + Store: diff --git a/scenes/outputdialog.ui b/scenes/outputdialog.ui new file mode 100644 index 0000000..f458fdf --- /dev/null +++ b/scenes/outputdialog.ui @@ -0,0 +1,187 @@ + + + OutputDialog + + + + 0 + 0 + 892 + 537 + + + + Dialog + + + + + + Path to export: + + + + + + + Choose + + + + + + + Print header + + + + + + + Print total + + + + + + + + 0 + 0 + + + + + Goods name + + + + + Goods price + + + + + Goods quantity + + + + + Goods net weight + + + + + Goods total + + + + + position + + + + + name + + + + + 1 + + + + + Name + + + + + 2 + + + + + Price + + + + + 3 + + + + + Quantity + + + + + 4 + + + + + Net weight + + + + + 5 + + + + + Total price + + + + + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + + + + + + + buttonBox + accepted() + OutputDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + OutputDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/translations/en_US.ts b/translations/en_US.ts index 132bb08..fce0d7f 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -28,20 +28,39 @@ - + Store type + Store type + + + Check content Check content - + Parse Parse - + + Store: + + + + Back + + + An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer. + An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer. + + + + Error in parsing + Error in parsing + MainWindow @@ -206,30 +225,60 @@ - + Choose Choose - + Path to image: - + + Store: + + + + Recognized text will be shown below as soon as image will be processed. Please, edit it - + Back - + Parse Parse + + + An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer. + An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer. + + + + Error in parsing + Error in parsing + + + + Please, select a picture to scan + Please, select a picture to scan + + + + Picture was not selected + Picture was not selected + + + + Path to image: + Path to image: + OFDScene @@ -300,7 +349,7 @@ - Choose image + Choose image on your PC @@ -317,92 +366,114 @@ OutputDialog + Dialog - Dialog + Dialog + Path to export: - Path to export: + Path to export: + Choose - Choose + Choose + Print header - Print header + Print header + Goods name - Goods name + Goods name + Goods price - Goods price + Goods price + Goods quantity - Goods quality + Goods quality + Goods net weight - Goods net weight + Goods net weight + Goods total - Goods total + Goods total + position - position + position + name - name + name + 1 - 1 + 1 + Name - Name + Name + 2 - 2 + 2 + Price - Price + Price + 3 - 3 + 3 + Quantity - Quantity + Quantity + 4 - 4 + 4 + Net weight - Net Weight + Net Weight + 5 - 5 + 5 + Total price - Total price + Total price + Print total - Print total + Print total diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index 4336f73..4e7fe60 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -28,20 +28,39 @@ - + Store type + Магазин + + + Check content Контент чека - + Parse Парсить - + + Store: + + + + Back + + + An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer. + Произошла ошибка. Чек был прочитан неверно. Размеры векторов различаются. Пожалуйста, сообщите об этом разработчику. + + + + Error in parsing + Ошибка в парсинге + MainWindow @@ -206,30 +225,60 @@ - + Choose Выбрать - + Path to image: - + + Store: + + + + Recognized text will be shown below as soon as image will be processed. Please, edit it - + Back - + Parse Парсить + + + An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer. + Произошла ошибка. Чек был прочитан неверно. Размеры векторов различаются. Пожалуйста, сообщите об этом разработчику. + + + + Error in parsing + Ошибка в парсинге + + + + Please, select a picture to scan + Пожалуйста, выберете изображение для сканирования + + + + Picture was not selected + Изображение не было выбрано + + + + Path to image: + Путь к изображению: + OFDScene @@ -300,7 +349,7 @@ - Choose image + Choose image on your PC @@ -317,92 +366,114 @@ OutputDialog + Dialog - Диалог + Диалог + Path to export: - Путь для экспорта: + Путь для экспорта: + Choose - Выбрать + Выбрать + Print header - Печатать заголовок + Печатать заголовок + Goods name - Имя товара + Имя товара + Goods price - Цена товара + Цена товара + Goods quantity - Количество товара + Количество товара + Goods net weight - Масса нетто товара + Масса нетто товара + Goods total - Всего за товар + Всего за товар + position - позиция + позиция + name - алиас + алиас + 1 - 1 + 1 + Name - Имя + Имя + 2 - 2 + 2 + Price - Цена + Цена + 3 - 3 + 3 + Quantity - Количество + Количество + 4 - 4 + 4 + Net weight - Масса нетто + Масса нетто + 5 - 5 + 5 + Total price - Всего + Всего + Print total - Печатать Итого + Печатать Итого