sorting, cleanup
This commit is contained in:
parent
ac355b7d9e
commit
20b08f493d
|
@ -211,14 +211,10 @@ void MainWindow::on_parse_button_clicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_add_new_check_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) {
|
if (new_check == nullptr) {
|
||||||
return;
|
return;
|
||||||
}*/
|
}
|
||||||
new_check->set_date("123");
|
|
||||||
new_check->set_total(rand() * 1800);
|
|
||||||
|
|
||||||
// checks.push_back(*new_check);
|
|
||||||
|
|
||||||
unsigned int newRowIndex = checks.size();
|
unsigned int newRowIndex = checks.size();
|
||||||
model->insertRows(newRowIndex, 1);
|
model->insertRows(newRowIndex, 1);
|
||||||
|
@ -303,15 +299,10 @@ void MainWindow::on_deleteSelectedButton_clicked() {
|
||||||
for (auto &row : select->selectedIndexes()) {
|
for (auto &row : select->selectedIndexes()) {
|
||||||
if (row.column() != 0) continue;
|
if (row.column() != 0) continue;
|
||||||
to_delete_positions.push_back(row.row());
|
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<unsigned int>());
|
std::sort(to_delete_positions.begin(), to_delete_positions.end(), std::greater<unsigned int>());
|
||||||
for (unsigned int position : to_delete_positions) {
|
for (unsigned int position : to_delete_positions) {
|
||||||
model->removeRows(position, 1);
|
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));
|
emit model->dataChanged(model->index(checks.size(), 0), model->index(checks.size() + to_delete_positions.size(), 1));
|
||||||
ui->checkQueueTable->clearSelection();
|
ui->checkQueueTable->clearSelection();
|
||||||
|
|
|
@ -298,32 +298,32 @@
|
||||||
<translation>No checks to parse</translation>
|
<translation>No checks to parse</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="271"/>
|
<location filename="../mainwindow.cpp" line="267"/>
|
||||||
<source>Captcha was not solved correctly!</source>
|
<source>Captcha was not solved correctly!</source>
|
||||||
<translation>Captcha was not solved correctly!</translation>
|
<translation>Captcha was not solved correctly!</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="273"/>
|
<location filename="../mainwindow.cpp" line="269"/>
|
||||||
<source>Captcha is incorrect</source>
|
<source>Captcha is incorrect</source>
|
||||||
<translation>Captcha is incorrect</translation>
|
<translation>Captcha is incorrect</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="278"/>
|
<location filename="../mainwindow.cpp" line="274"/>
|
||||||
<source>Internal server error. Please, try again later.</source>
|
<source>Internal server error. Please, try again later.</source>
|
||||||
<translation>Internal server error. Please, try again later.</translation>
|
<translation>Internal server error. Please, try again later.</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="280"/>
|
<location filename="../mainwindow.cpp" line="276"/>
|
||||||
<source>Internal server error</source>
|
<source>Internal server error</source>
|
||||||
<translation>Internal server error</translation>
|
<translation>Internal server error</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="285"/>
|
<location filename="../mainwindow.cpp" line="281"/>
|
||||||
<source>Check not found. Please, ensure correctness of entered data.</source>
|
<source>Check not found. Please, ensure correctness of entered data.</source>
|
||||||
<translation>Check not found. Please, ensure correctness of entered data.</translation>
|
<translation>Check not found. Please, ensure correctness of entered data.</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="287"/>
|
<location filename="../mainwindow.cpp" line="283"/>
|
||||||
<source>Check was not found</source>
|
<source>Check was not found</source>
|
||||||
<translation>Check was not found</translation>
|
<translation>Check was not found</translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -286,32 +286,32 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="271"/>
|
<location filename="../mainwindow.cpp" line="267"/>
|
||||||
<source>Captcha was not solved correctly!</source>
|
<source>Captcha was not solved correctly!</source>
|
||||||
<translation>Капча была решена неверно!</translation>
|
<translation>Капча была решена неверно!</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="273"/>
|
<location filename="../mainwindow.cpp" line="269"/>
|
||||||
<source>Captcha is incorrect</source>
|
<source>Captcha is incorrect</source>
|
||||||
<translation>Капча введена неверно</translation>
|
<translation>Капча введена неверно</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="278"/>
|
<location filename="../mainwindow.cpp" line="274"/>
|
||||||
<source>Internal server error. Please, try again later.</source>
|
<source>Internal server error. Please, try again later.</source>
|
||||||
<translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation>
|
<translation>Внутренняя ошибка сервера. Пожалуйста, попробуйте снова позже.</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="280"/>
|
<location filename="../mainwindow.cpp" line="276"/>
|
||||||
<source>Internal server error</source>
|
<source>Internal server error</source>
|
||||||
<translation>Внутренняя ошибка сервера</translation>
|
<translation>Внутренняя ошибка сервера</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="285"/>
|
<location filename="../mainwindow.cpp" line="281"/>
|
||||||
<source>Check not found. Please, ensure correctness of entered data.</source>
|
<source>Check not found. Please, ensure correctness of entered data.</source>
|
||||||
<translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation>
|
<translation>Чек не найден. Пожалуйста, убедитесь в правильности введённых данных.</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="287"/>
|
<location filename="../mainwindow.cpp" line="283"/>
|
||||||
<source>Check was not found</source>
|
<source>Check was not found</source>
|
||||||
<translation>Чек не найден</translation>
|
<translation>Чек не найден</translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *parent)
|
CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *parent)
|
||||||
: checks(checks), QAbstractTableModel{parent}
|
: checks(checks), QAbstractTableModel{parent}
|
||||||
|
@ -160,3 +161,45 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac
|
||||||
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -29,8 +29,11 @@ public:
|
||||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &);
|
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &);
|
||||||
QMimeData* mimeData(const QModelIndexList &indexes) const override;
|
QMimeData* mimeData(const QModelIndexList &indexes) const override;
|
||||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) 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:
|
private:
|
||||||
std::vector<Check> *checks;
|
std::vector<Check> *checks;
|
||||||
|
bool compare(const Check& check_a, const Check& check_b, int column);
|
||||||
signals:
|
signals:
|
||||||
void editCompleted(const QString &);
|
void editCompleted(const QString &);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue