diff --git a/mainwindow.cpp b/mainwindow.cpp index 1aec818..7244b56 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -211,14 +211,10 @@ void MainWindow::on_parse_button_clicked() { } void MainWindow::on_add_new_check_button_clicked() { - Check *new_check = new Check();/* parse_new_check(); + Check *new_check = parse_new_check(); if (new_check == nullptr) { return; - }*/ - new_check->set_date("123"); - new_check->set_total(rand() * 1800); - - // checks.push_back(*new_check); + } unsigned int newRowIndex = checks.size(); model->insertRows(newRowIndex, 1); @@ -303,15 +299,10 @@ void MainWindow::on_deleteSelectedButton_clicked() { 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/translations/en_US.ts b/translations/en_US.ts index d2e8f1c..e5aeafa 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -298,32 +298,32 @@ 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 diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index ee1ae23..52576e4 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -286,32 +286,32 @@ - + 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 Чек не найден diff --git a/widgets/checkqueuetablemodel.cpp b/widgets/checkqueuetablemodel.cpp index b6a33e5..057c820 100644 --- a/widgets/checkqueuetablemodel.cpp +++ b/widgets/checkqueuetablemodel.cpp @@ -2,6 +2,7 @@ #include #include +#include CheckQueueTableModel::CheckQueueTableModel(std::vector *checks, QObject *parent) : checks(checks), QAbstractTableModel{parent} @@ -160,3 +161,45 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac return true; } + +void CheckQueueTableModel::sort(int column, Qt::SortOrder order) { + beginResetModel(); + switch (column) { + case 0: + std::sort(checks->begin(), checks->end(), + [&](const Check& a, const Check& b) { + if (order == Qt::AscendingOrder) { + return compare(a, b, column); + } else { + return !compare(a, b, column); + } + }); + break; + case 1: + std::sort(checks->begin(), checks->end(), + [&](const Check& a, const Check& b) { + if (order == Qt::AscendingOrder) { + return compare(a, b, column); + } else { + return !compare(a, b, column); + } + }); + } + + endResetModel(); +} + +bool CheckQueueTableModel::compare(const Check &check_a, const Check &check_b, int column) { + switch (column) { + case 0: + return + QDateTime::fromString(QString::fromStdString(((Check &)check_a).get_date()), "yyyyMMddThhmm") + > + QDateTime::fromString(QString::fromStdString(((Check &)check_b).get_date()), "yyyyMMddThhmm"); + break; + case 1: + return ((Check &)check_a).get_total() > ((Check &)check_b).get_total(); + break; + default: return false; + } +} diff --git a/widgets/checkqueuetablemodel.h b/widgets/checkqueuetablemodel.h index 8092ca5..3a6f8f1 100644 --- a/widgets/checkqueuetablemodel.h +++ b/widgets/checkqueuetablemodel.h @@ -29,8 +29,11 @@ public: bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &); QMimeData* mimeData(const QModelIndexList &indexes) const override; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; + + void sort(int column, Qt::SortOrder order) override; private: std::vector *checks; + bool compare(const Check& check_a, const Check& check_b, int column); signals: void editCompleted(const QString &); };