diff --git a/CMakeLists.txt b/CMakeLists.txt index a8572f2..5f7dd56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ set(PROJECT_SOURCES settings/settings.h settings/settings.cpp - widgets/checklistviewwidget.h widgets/checklistviewwidget.cpp + widgets/outputcolumn.h widgets/outputcolumn.cpp widgets/outputcolumnmodel.h widgets/outputcolumnmodel.cpp diff --git a/mainwindow.cpp b/mainwindow.cpp index 3cc8176..1aec818 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #ifdef BUILD_OFD_BINARYEYE_SCAN # include @@ -33,17 +32,17 @@ MainWindow::MainWindow(QWidget *parent) ui->setupUi(this); ui->stop_server_button->hide(); - ui->checks_to_parse_label->hide(); ui->checkQueueTable->hide(); + ui->deleteSelectedButton->hide(); + ui->parse_button->hide(); model = new CheckQueueTableModel(&checks, this); ui->checkQueueTable->setModel(model); ui->checkQueueTable->viewport()->setAcceptDrops(true); ui->checkQueueTable->setDragDropMode(QAbstractItemView::DragDrop); - // ui-> - // connect(this, &MainWindow::deleteCheckFromList, this, &MainWindow::deleteCheckFromListHandler); + ui->checkQueueTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); #ifdef BUILD_OFD_BINARYEYE_SCAN QObject::connect(this, &MainWindow::httpErrorOccured, this, &MainWindow::notifyHttpServerFailure); @@ -139,7 +138,6 @@ void MainWindow::httpNewMessageHandler(QString message) { emit onDataDecode(paramsMap); } - #endif //ifdef BUILD_OFD_BINARYEYE_SCAN #ifdef BUILD_OFD_LOCAL_QR_SCAN @@ -195,7 +193,6 @@ void MainWindow::on_parse_email_button_clicked() { return; } - #endif // ifdef BUILD_EMAIL_MODE void MainWindow::on_parse_button_clicked() { @@ -213,30 +210,6 @@ void MainWindow::on_parse_button_clicked() { d.exec(); } -// void MainWindow::deleteCheckFromListHandler(Check &check) { -// for (unsigned int i = 0; i < ui->scrollAreaWidgetContents->layout()->count(); i ++) { -// QLayoutItem *item = ui->scrollAreaWidgetContents->layout()->itemAt(i); -// QObject *child = item->widget(); -// CheckListViewWidget *c = (CheckListViewWidget *)child; -// if (c->get_check() == check) { -// ui->scrollAreaWidgetContents->layout()->removeItem(item); -// delete item; -// delete child; -// ui->scrollAreaWidgetContents->layout()->update(); -// ui->scrollAreaWidgetContents->update(); - -// } -// } - -// int position = std::find(checks.begin(), checks.end(), check) - checks.begin() - 1; -// checks.erase(checks.begin() + position); - -// if (ui->scrollAreaWidgetContents->layout()->count() == 0) { -// ui->checks_to_parse_label->hide(); -// ui->checks_scroll_area->hide(); -// } -// } - void MainWindow::on_add_new_check_button_clicked() { Check *new_check = new Check();/* parse_new_check(); if (new_check == nullptr) { @@ -257,6 +230,8 @@ void MainWindow::on_add_new_check_button_clicked() { if (checks.size() > 0) { ui->checkQueueTable->show(); ui->checks_to_parse_label->show(); + ui->deleteSelectedButton->show(); + ui->parse_button->show(); } } @@ -321,3 +296,24 @@ Check *MainWindow::parse_new_check() { MainWindow::~MainWindow() { delete ui; } + +void MainWindow::on_deleteSelectedButton_clicked() { + QItemSelectionModel *select = ui->checkQueueTable->selectionModel(); + std::vector to_delete_positions = {}; + for (auto &row : select->selectedIndexes()) { + if (row.column() != 0) continue; + to_delete_positions.push_back(row.row()); + // model->removeRows(row.row(), 1); + // checks.erase(std::next(checks.begin() + row.row())); + // std::cout << row.data().toString().toStdString() << std::endl; + } + std::sort(to_delete_positions.begin(), to_delete_positions.end(), std::greater()); + for (unsigned int position : to_delete_positions) { + model->removeRows(position, 1); + // checks.erase(checks.begin() + position); + // emit model->dataChanged(model->index(position, 0), model->index(position, 1)); + } + emit model->dataChanged(model->index(checks.size(), 0), model->index(checks.size() + to_delete_positions.size(), 1)); + ui->checkQueueTable->clearSelection(); +} + diff --git a/mainwindow.h b/mainwindow.h index c84efe1..6503baa 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -55,6 +55,9 @@ private slots: void on_parse_email_button_clicked(); #endif void on_add_new_check_button_clicked(); + + void on_deleteSelectedButton_clicked(); + private: Ui::MainWindow *ui; std::vector checks; diff --git a/scenes/mainwindow.ui b/scenes/mainwindow.ui index e8a5c61..f4ca6e1 100644 --- a/scenes/mainwindow.ui +++ b/scenes/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1269 - 490 + 987 + 426 @@ -26,26 +26,23 @@ Form - - - - Checks to parse - - - Qt::AlignmentFlag::AlignCenter + + + + 4294967296.000000000000000 - - + + - + 0 0 - Parse an E-Mail + Add to queue @@ -62,53 +59,7 @@ - - - - - 0 - 0 - - - - Choose image on your PC - - - - - - - Date and time of purchase - - - - - - - - 0 - 0 - - - - or - - - - - - - - 0 - 0 - - - - Parse - - - - + @@ -132,7 +83,7 @@ - + @@ -145,8 +96,60 @@ - - + + + + + + + Date and time of purchase + + + + + + + + 0 + 0 + + + + or + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + + + + + + + + Checks to parse + + + Qt::AlignmentFlag::AlignCenter + + + + + 0 @@ -154,44 +157,89 @@ - Use your phone as a QR code scanner + Parse queue - - - - - + + - + 0 0 - FN (Fiscal Number) + or - - - - - + + + + + 0 + 0 + + - Operation type + QR image - - - - 4294967296.000000000000000 + + + + + 0 + 0 + + + + - + + + + + 0 + 0 + + + + Scan QR using phone + + + + + + + + 0 + 0 + + + + Settings + + + + + + + + 0 + 0 + + + + Clear data + + + + QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed @@ -222,16 +270,19 @@ - - + + + + + - + 0 0 - + Parse an E-Mail @@ -242,9 +293,6 @@ - - - @@ -252,67 +300,48 @@ - - + + + + Operation type + + + + + - + 0 0 - Settings + FN (Fiscal Number) - - - - - 0 - 0 - - + + - or + Delete selected - - - - - 0 - 0 - + + + + Qt::Orientation::Horizontal - - - - - - - 0 - 0 - + + QSizePolicy::Policy::MinimumExpanding - - Clear + + + 40 + 20 + - - - - - - - 0 - 0 - - - - Add new check - - + diff --git a/translations/en_US.ts b/translations/en_US.ts index a49bcbd..9c8f64b 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -70,9 +70,8 @@ Store type - Parse - Parse + Parse Preferences @@ -113,13 +112,13 @@ 0000000000000000 - + FN (Fiscal Number) FN = Фискальный Номер FN (Fiscal Number) - + FD (Fiscal Document) FD = Фискальный Документ FD (Fiscal Document) @@ -133,93 +132,119 @@ Back - + Stop server Stop server - Choose image on your PC - Choose image on your PC + Choose image on your PC - - + + or or - Use your phone as a QR code scanner - Use your phone as a QR code scanner + Use your phone as a QR code scanner - + FI (Fiscal Identifier) FI = Фискальный Признак FI (Fiscal Identifier) - + + Delete selected + + + Add new check - Add new check + Add new check - Clear - Clear + Clear - + Date and time of purchase Date and time of purchase - + Operation type Operation type - + Parse an E-Mail Parse an E-Mail - + + Add to queue + + + + Funds income Приход средств Funds income - + Funds return Возврат средств Funds return - + Funds spend Расход средств Funds spend - + Spends return Возврат расхода Spends return - + Checks to parse Checks to parse - + + Parse queue + + + + + QR image + + + + + Scan QR using phone + + + + Settings Settings - + + Clear data + + + + Total Total @@ -228,77 +253,77 @@ checks parser - + QR code for binaryeye to connect QR code for binaryeye to connect - + I've scanned I've scanned - + Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer. Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer. - + Could not start http server. Could not start http server. - + Selected image: Selected image: - + This feature is under development. Wait it to appear in next updates. This feature is under development. Wait for it to appear in next updates. - + Under development Under development - + Please, add check(s) to parse Please, add check(s) to parse - + No checks to parse No checks to parse - + Captcha was not solved correctly! Captcha was not solved correctly! - + Captcha is incorrect Captcha is incorrect - + Internal server error. Please, try again later. Internal server error. Please, try again later. - + Internal server error Internal server error - + Check not found. Please, ensure correctness of entered data. Check not found. Please, ensure correctness of entered data. - + Check was not found Check was not found @@ -311,12 +336,12 @@ Error in parsing - + Please, select a picture where QR code that contains info about check is present Please, select a picture where QR code that contains info about check is present - + Picture was not selected Picture was not selected diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index 201f5ea..45ccf44 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -70,9 +70,8 @@ Магазин - Parse - Парсить + Парсить Preferences @@ -113,13 +112,13 @@ 0000000000000000 - + FN (Fiscal Number) Фискальный Норма ФН - + FD (Fiscal Document) Фискальный Документ ФД @@ -133,89 +132,107 @@ Назад - + Stop server Остановить сервер - Choose image on your PC - Выбрать изображение на компьютере + Выбрать изображение на компьютере - - + + or или - Use your phone as a QR code scanner - Использовать телефон как сканнер QR + Использовать телефон как сканнер QR - + FI (Fiscal Identifier) Фискальный Признак ФП - - Add new check + + Delete selected - - Clear - - - - + Date and time of purchase Дата и время покупки - + Operation type Тип операции - + Parse an E-Mail Парсить E-Mail - + + Add to queue + + + + Funds income Приход средств - + Funds return Возврат средств - + Funds spend Расход средств - + Spends return Возврат расхода - + Checks to parse - + + Parse queue + + + + + QR image + + + + + Scan QR using phone + + + + Settings Настройки - + + Clear data + + + + Total Итого @@ -224,77 +241,77 @@ Парсер чеков - + QR code for binaryeye to connect QR код для подключения BinaryEye - + I've scanned Просканировал - + Could not start http server. 10 times in a row random port was occupied. Either you should run for a lottery ticket, or the problem is in the program. If the lottery ticket wasn't lucky, please, contact the developer. Не смог поднять HTTP сервер. 10 раз подряд случайно выбранный порт был занят. Либо Вам следует бежать за лоттерейным билетом, или в программе баг. Если лотерейный билет не был выигрышным, пожалуйста, сообщите разработчику. - + Could not start http server. Не получилось запустить HTTP сервер. - + Selected image: Выбранное изображение: - + This feature is under development. Wait it to appear in next updates. - + Under development - + Please, add check(s) to parse - + No checks to parse - + Captcha was not solved correctly! Капча была решена неверно! - + Captcha is incorrect Капча введена неверно - + Internal server error. Please, try again later. Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже. - + Internal server error Внутренняя ошибка сервера - + Check not found. Please, ensure correctness of entered data. Чек не найден. Пожалуйста, убедитесь в правильности введённых данных. - + Check was not found Чек не найден @@ -307,12 +324,12 @@ Ошибка в парсинге - + Please, select a picture where QR code that contains info about check is present Пожалуйста, выберете изображение, содержащее QR код с информацией о чеке - + Picture was not selected Изображение не было выбрано diff --git a/widgets/checklistviewwidget.cpp b/widgets/checklistviewwidget.cpp deleted file mode 100644 index 7a01382..0000000 --- a/widgets/checklistviewwidget.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "checklistviewwidget.h" - -#include -#include -#include -#include -#include - -CheckListViewWidget::CheckListViewWidget(QWidget *parent, Check check) : QWidget(parent), check(check) { - mw = (MainWindow*) parent; - QHBoxLayout *layout = new QHBoxLayout; - - QLabel *date_label = new QLabel(QString::fromStdString(check.get_date())); - QLabel *summ_label = new QLabel(QString::number(check.get_total())); - - QPushButton *deleteButton = new QPushButton(tr("Delete")); - - deleteButton->connect(deleteButton, &QPushButton::clicked, this, &CheckListViewWidget::delete_button_pressed); - - layout->addWidget(date_label); - layout->addWidget(summ_label); - layout->addSpacing(10); - layout->addWidget(deleteButton); - - setLayout(layout); -} - -Check &CheckListViewWidget::get_check(){ - return check; -} - -void CheckListViewWidget::delete_button_pressed() { - emit mw->deleteCheckFromList(this->check); -} diff --git a/widgets/checklistviewwidget.h b/widgets/checklistviewwidget.h deleted file mode 100644 index e079425..0000000 --- a/widgets/checklistviewwidget.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef CHECKLISTVIEWWIDGET_H -#define CHECKLISTVIEWWIDGET_H - -#include -#include -#include - -#include - -class CheckListViewWidget : public QWidget -{ - Q_OBJECT - Check check; - MainWindow* mw; -public: - explicit CheckListViewWidget(QWidget *parent = nullptr, Check check = Check()); - - Check &get_check(); - void delete_button_pressed(); -signals: - Check deleteButtonPressed(); -}; - -#endif // CHECKLISTVIEWWIDGET_H diff --git a/widgets/checkqueuetablemodel.cpp b/widgets/checkqueuetablemodel.cpp index bac1766..b6a33e5 100644 --- a/widgets/checkqueuetablemodel.cpp +++ b/widgets/checkqueuetablemodel.cpp @@ -8,7 +8,7 @@ CheckQueueTableModel::CheckQueueTableModel(std::vector *checks, QObject * {} int CheckQueueTableModel::rowCount(const QModelIndex &parent) const { return checks->size(); } -int CheckQueueTableModel::columnCount(const QModelIndex &parent) const { return 3; } +int CheckQueueTableModel::columnCount(const QModelIndex &parent) const { return 2; } QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() >= checks->size()) @@ -22,9 +22,6 @@ QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const { case 1: return QVariant::fromValue(c.get_total()); break; - case 2: - return QVariant::fromValue(QString("кнопка")); - break; } return QVariant(); @@ -32,7 +29,7 @@ QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const { bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role == Qt::EditRole) { - if (!checkIndex(index)) + if (!index.isValid() || index.row() >= checks->size()) return false; unsigned int row = index.row(); switch (index.column()) { @@ -42,9 +39,6 @@ bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &val } case 1: checks->at(row).set_total(value.value()); break; - case 2: - // delete Button - break; } return true; } @@ -60,10 +54,9 @@ QVariant CheckQueueTableModel::headerData(int section, Qt::Orientation orientati case 1: return tr("Total"); break; - case 2: - return tr("Delete button"); - break; } + } else if (role == Qt::DisplayRole && orientation == Qt::Vertical) { + return section + 1; } return QVariant(); } @@ -85,7 +78,6 @@ Qt::DropActions CheckQueueTableModel::supportedDropActions() const { bool CheckQueueTableModel::insertRows(int position, int rows, const QModelIndex &index) { beginInsertRows(QModelIndex(), position, position+rows-1); - for (int i = 0; i < rows; ++i) checks->emplace(checks->begin() + position, Check()); @@ -109,9 +101,10 @@ QStringList CheckQueueTableModel::mimeTypes() const { return types; } -bool CheckQueueTableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &) { +bool CheckQueueTableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int, const QModelIndex &) { if (action != Qt::MoveAction || !data->hasFormat(CheckQueueTableModel::MimeType)) return false; + if (row > checks->size()) return false; return true; } @@ -133,12 +126,11 @@ QMimeData* CheckQueueTableModel::mimeData(const QModelIndexList &indexes) const } bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { - if (!canDropMimeData(data, action, row, column, parent)) - return false; - if (action == Qt::IgnoreAction) - return true; - else if (action != Qt::MoveAction) - return false; + if (!canDropMimeData(data, action, row, column, parent)) return false; + if (action == Qt::IgnoreAction) return true; + else if (action != Qt::MoveAction) return false; + if (row > checks->size()) return false; + QByteArray encodedData = data->data(CheckQueueTableModel::MimeType); QDataStream stream(&encodedData, QIODevice::ReadOnly); std::vector newItems; @@ -156,6 +148,7 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac } insertRows(row, rows, QModelIndex()); + for (Check &c : newItems) { QModelIndex date_index = index(row, 0, QModelIndex()); QModelIndex total_index = index(row, 1, QModelIndex()); @@ -164,5 +157,6 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac row++; } + return true; } diff --git a/widgets/outputcolumnmodel.cpp b/widgets/outputcolumnmodel.cpp index bdd8d32..917d235 100644 --- a/widgets/outputcolumnmodel.cpp +++ b/widgets/outputcolumnmodel.cpp @@ -132,8 +132,7 @@ bool OutputColumnModel::dropMimeData(const QMimeData *data, Qt::DropAction actio } insertRows(row, rows, QModelIndex()); - for (const OutputColumn &column : newItems) - { + for (const OutputColumn &column : newItems) { QModelIndex idx = index(row, 0, QModelIndex()); setData(idx, QVariant::fromValue(column), 0x102); row++; @@ -141,4 +140,3 @@ bool OutputColumnModel::dropMimeData(const QMimeData *data, Qt::DropAction actio return true; } - diff --git a/widgets/outputcolumnmodel.h b/widgets/outputcolumnmodel.h index ee1ed7e..f1bd864 100644 --- a/widgets/outputcolumnmodel.h +++ b/widgets/outputcolumnmodel.h @@ -30,8 +30,8 @@ public: // QStringList mimeTypes() const override; bool canDropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex&); - QMimeData* mimeData(const QModelIndexList &indexes) const; - bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + QMimeData* mimeData(const QModelIndexList &indexes) const override; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; }; #endif // OUTPUTCOLUMNMODEL_H