fixed only handling two fields of a check
This commit is contained in:
parent
20b08f493d
commit
1507faef6e
|
@ -1,9 +1,19 @@
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "../goods/goods.h"
|
#include "../goods/goods.h"
|
||||||
#include <iostream>
|
#include <QObject>
|
||||||
|
|
||||||
Check::Check() {}
|
Check::Check() {}
|
||||||
|
|
||||||
|
Check::Check(std::string date, double total, OperationType type, std::string fn, std::string fd, std::string fi, std::vector<Goods> goods) {
|
||||||
|
set_date(date);
|
||||||
|
set_total(total);
|
||||||
|
set_operation_type(type);
|
||||||
|
set_fn(fn);
|
||||||
|
set_fd(fd);
|
||||||
|
set_fi(fi);
|
||||||
|
set_goods(goods);
|
||||||
|
}
|
||||||
|
|
||||||
void Check::add_goods(Goods goods) {
|
void Check::add_goods(Goods goods) {
|
||||||
this->goods.push_back(goods);
|
this->goods.push_back(goods);
|
||||||
this->total = this->calculae_total_price();
|
this->total = this->calculae_total_price();
|
||||||
|
@ -25,50 +35,24 @@ double Check::calculae_total_price() {
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Goods>& Check::get_goods() {
|
std::vector<Goods>& Check::get_goods() { return goods; }
|
||||||
return goods;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Check::set_fn(std::string fn) {
|
void Check::set_fn(std::string fn) { this->fn = fn; }
|
||||||
this->fn = fn;
|
void Check::set_fd(std::string fd) { this->fd = fd; }
|
||||||
}
|
void Check::set_fi(std::string fi) { this->fi = fi; }
|
||||||
|
std::string Check::get_date() { return date; }
|
||||||
|
|
||||||
void Check::set_fd(std::string fd) {
|
OperationType Check::get_operationType() { return operation_type; }
|
||||||
this->fd = fd;
|
void Check::set_date(std::string date) { this->date = date; }
|
||||||
}
|
void Check::set_operation_type(OperationType t) { this->operation_type = t; }
|
||||||
|
void Check::set_total(double total) { this->total = total; }
|
||||||
void Check::set_fi(std::string fi) {
|
void Check::set_goods(std::vector<Goods> goods) { this->goods = goods; }
|
||||||
this->fi = fi;
|
std::string Check::get_fn() { return fn; }
|
||||||
}
|
std::string Check::get_fd() { return fd; }
|
||||||
|
std::string Check::get_fi() { return fi; }
|
||||||
std::string Check::get_date() {
|
double Check::get_total() { return total; }
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Check::set_date(std::string date) {
|
|
||||||
this->date = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Check::set_operation_type(OperationType t) {
|
|
||||||
this->operation_type = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Check::set_total(double total){
|
|
||||||
this->total = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Check::get_total() {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Check::operator==(Check &c) {
|
bool Check::operator==(Check &c) {
|
||||||
// std::cout << "Comparing" << std::endl;
|
|
||||||
// std::cout << this->date << " <>" << c.date << std::endl;
|
|
||||||
// std::cout << this->fd << " <>" << c.fd << std::endl;
|
|
||||||
// std::cout << this->fi<< " <>" << c.fi << std::endl;
|
|
||||||
// std::cout << this->fn<< " <>" << c.fn << std::endl;
|
|
||||||
// std::cout << this->operation_type << " <>" << c.operation_type << std::endl;
|
|
||||||
// std::cout << this->total<< " <>" << c.total<< std::endl;
|
|
||||||
return
|
return
|
||||||
this->date == c.date &&
|
this->date == c.date &&
|
||||||
this->fd == c.fd &&
|
this->fd == c.fd &&
|
||||||
|
@ -79,13 +63,6 @@ bool Check::operator==(Check &c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Check::operator==(const Check &c) {
|
bool Check::operator==(const Check &c) {
|
||||||
// std::cout << "Comparing" << std::endl;
|
|
||||||
// std::cout << this->date << " <>" << c.date << std::endl;
|
|
||||||
// std::cout << this->fd << " <>" << c.fd << std::endl;
|
|
||||||
// std::cout << this->fi<< " <>" << c.fi << std::endl;
|
|
||||||
// std::cout << this->fn<< " <>" << c.fn << std::endl;
|
|
||||||
// std::cout << this->operation_type << " <>" << c.operation_type << std::endl;
|
|
||||||
// std::cout << this->total<< " <>" << c.total<< std::endl;
|
|
||||||
return
|
return
|
||||||
this->date == c.date &&
|
this->date == c.date &&
|
||||||
this->fd == c.fd &&
|
this->fd == c.fd &&
|
||||||
|
@ -94,3 +71,5 @@ bool Check::operator==(const Check &c) {
|
||||||
this->operation_type == c.operation_type &&
|
this->operation_type == c.operation_type &&
|
||||||
this->total == c.total;
|
this->total == c.total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Check)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CHECK_H
|
#ifndef CHECK_H
|
||||||
#define CHECK_H
|
#define CHECK_H
|
||||||
#include "../goods/goods.h"
|
#include "../goods/goods.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
typedef enum OperationTypes {
|
typedef enum OperationTypes {
|
||||||
|
@ -23,6 +24,7 @@ class Check {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Check();
|
Check();
|
||||||
|
Check(std::string date, double total, OperationType type, std::string fn, std::string fd, std::string fi, std::vector<Goods> goods);
|
||||||
void add_goods(Goods);
|
void add_goods(Goods);
|
||||||
void add_goods(std::vector<Goods> &goods);
|
void add_goods(std::vector<Goods> &goods);
|
||||||
|
|
||||||
|
@ -37,6 +39,8 @@ public:
|
||||||
void set_operation_type(OperationType);
|
void set_operation_type(OperationType);
|
||||||
void set_total(double);
|
void set_total(double);
|
||||||
|
|
||||||
|
void set_goods(std::vector<Goods>);
|
||||||
|
|
||||||
std::string get_fn();
|
std::string get_fn();
|
||||||
std::string get_fd();
|
std::string get_fd();
|
||||||
std::string get_fi();
|
std::string get_fi();
|
||||||
|
@ -48,4 +52,5 @@ public:
|
||||||
bool operator==(const Check &);
|
bool operator==(const Check &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // CHECK_H
|
#endif // CHECK_H
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include "goods.h"
|
#include "goods.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <QString>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
Goods::Goods() { }
|
||||||
|
|
||||||
Goods::Goods(std::string name, double price_per_unit, std::string net_weight, double quantity) :
|
Goods::Goods(std::string name, double price_per_unit, std::string net_weight, double quantity) :
|
||||||
name(name), price_per_unit(price_per_unit),
|
name(name), price_per_unit(price_per_unit),
|
||||||
|
@ -19,10 +23,53 @@ double Goods::get_price_per_unit() { return this->price_per_unit; }
|
||||||
|
|
||||||
void Goods::set_name(std::string name) { this->name = name; }
|
void Goods::set_name(std::string name) { this->name = name; }
|
||||||
|
|
||||||
|
void Goods::set_name(QString name) { this->name = name.toStdString(); }
|
||||||
|
|
||||||
void Goods::set_quantity(double quantity) { this->quantity = quantity; }
|
void Goods::set_quantity(double quantity) { this->quantity = quantity; }
|
||||||
|
|
||||||
void Goods::set_net_weight(std::string net_weight) { this->net_weight = net_weight; }
|
void Goods::set_net_weight(std::string net_weight) { this->net_weight = net_weight; }
|
||||||
|
|
||||||
|
void Goods::set_net_weight(QString net_weight) { this->net_weight = net_weight.toStdString(); }
|
||||||
|
|
||||||
void Goods::set_price_per_unit(double price_per_unit) {
|
void Goods::set_price_per_unit(double price_per_unit) {
|
||||||
this->price_per_unit = price_per_unit;
|
this->price_per_unit = price_per_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Goods)
|
||||||
|
|
||||||
|
QDataStream &operator<<(QDataStream &in, Goods &goods) {
|
||||||
|
in << QString::fromStdString(goods.get_name()) << goods.get_quantity() << QString::fromStdString(goods.get_net_weight()) << goods.get_price_per_unit();
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream &operator>>(QDataStream &out, Goods &goods) {
|
||||||
|
QString name, net_weight;
|
||||||
|
double quantity, price_per_unit;
|
||||||
|
out >> name >> quantity >> net_weight >> price_per_unit;
|
||||||
|
goods.set_name(name);
|
||||||
|
goods.set_quantity(quantity);
|
||||||
|
goods.set_net_weight(net_weight);
|
||||||
|
goods.set_price_per_unit(price_per_unit);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDataStream &operator<<(QDataStream &stream, std::vector<Goods> &goods) {
|
||||||
|
stream << (unsigned int )goods.size();
|
||||||
|
for (Goods &g : goods) {
|
||||||
|
stream << g;
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream &operator>>(QDataStream &stream, std::vector<Goods> &goods) {
|
||||||
|
unsigned int size;
|
||||||
|
stream >> size;
|
||||||
|
for (unsigned int i = 0 ; i < size; i ++) {
|
||||||
|
Goods g = Goods();
|
||||||
|
stream >> g;
|
||||||
|
goods.push_back(g);
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define GOODS_H
|
#define GOODS_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <QDataStream>
|
||||||
|
|
||||||
class Goods
|
class Goods
|
||||||
{
|
{
|
||||||
|
@ -10,6 +11,7 @@ class Goods
|
||||||
std::string net_weight; // will contain values like "5мл" or "10г"
|
std::string net_weight; // will contain values like "5мл" or "10г"
|
||||||
double price_per_unit;
|
double price_per_unit;
|
||||||
public:
|
public:
|
||||||
|
Goods();
|
||||||
Goods(std::string name, double quantity, std::string net_weight, double price_per_unit);
|
Goods(std::string name, double quantity, std::string net_weight, double price_per_unit);
|
||||||
double calculate_total_price();
|
double calculate_total_price();
|
||||||
|
|
||||||
|
@ -19,9 +21,16 @@ public:
|
||||||
double get_price_per_unit();
|
double get_price_per_unit();
|
||||||
|
|
||||||
void set_name(std::string);
|
void set_name(std::string);
|
||||||
|
void set_name(QString);
|
||||||
void set_quantity(double);
|
void set_quantity(double);
|
||||||
void set_net_weight(std::string);
|
void set_net_weight(std::string);
|
||||||
|
void set_net_weight(QString);
|
||||||
void set_price_per_unit(double);
|
void set_price_per_unit(double);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QDataStream &operator<<(QDataStream &, Goods &);
|
||||||
|
QDataStream &operator>>(QDataStream &, Goods &);
|
||||||
|
|
||||||
|
QDataStream &operator<<(QDataStream &, std::vector<Goods> &);
|
||||||
|
QDataStream &operator>>(QDataStream &, std::vector<Goods> &);
|
||||||
#endif // GOODS_H
|
#endif // GOODS_H
|
||||||
|
|
2
main.cpp
2
main.cpp
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
qRegisterMetaType<Check>("Check");
|
||||||
|
|
||||||
std::string program_data_path = get_path_relative_to_home(".local/share/checks_parser");
|
std::string program_data_path = get_path_relative_to_home(".local/share/checks_parser");
|
||||||
create_directories(program_data_path);
|
create_directories(program_data_path);
|
||||||
|
|
|
@ -218,8 +218,10 @@ void MainWindow::on_add_new_check_button_clicked() {
|
||||||
|
|
||||||
unsigned int newRowIndex = checks.size();
|
unsigned int newRowIndex = checks.size();
|
||||||
model->insertRows(newRowIndex, 1);
|
model->insertRows(newRowIndex, 1);
|
||||||
model->setData(model->index(newRowIndex, 0), QVariant::fromValue(new_check->get_date()));
|
|
||||||
model->setData(model->index(newRowIndex, 1), QVariant::fromValue(new_check->get_total()));
|
checks.at(newRowIndex) = *new_check;
|
||||||
|
|
||||||
|
emit model->dataChanged(model->index(newRowIndex, 0), model->index(newRowIndex, 1));
|
||||||
|
|
||||||
delete new_check;
|
delete new_check;
|
||||||
|
|
||||||
|
@ -260,6 +262,7 @@ Check *MainWindow::parse_new_check() {
|
||||||
check->set_fd(ui->fd_line_edit->text().toStdString());
|
check->set_fd(ui->fd_line_edit->text().toStdString());
|
||||||
check->set_fi(ui->fi_line_edit->text().toStdString());
|
check->set_fi(ui->fi_line_edit->text().toStdString());
|
||||||
check->set_operation_type(OperationType(ui->operation_type_combo_box->currentIndex() + 1));
|
check->set_operation_type(OperationType(ui->operation_type_combo_box->currentIndex() + 1));
|
||||||
|
|
||||||
return check;
|
return check;
|
||||||
} catch(OfdRequestException e) {
|
} catch(OfdRequestException e) {
|
||||||
if (!strcmp(e.what(), "Incorrect captcha")) {
|
if (!strcmp(e.what(), "Incorrect captcha")) {
|
||||||
|
|
|
@ -20,6 +20,13 @@ OutputDialog::OutputDialog(QWidget *parent, std::vector<Check> *checks)
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
for (Check &c : *checks) {
|
||||||
|
std::cout << "Check: " << c.get_date() << " " << c.get_total() << std::endl;
|
||||||
|
for (Goods &g : c.get_goods()) {
|
||||||
|
std::cout << g.get_name() << " " << g.get_net_weight() << " " << g.get_price_per_unit() << " " << g.get_quantity() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
columns = new std::vector<OutputColumn>;
|
columns = new std::vector<OutputColumn>;
|
||||||
|
|
||||||
OutputColumnModel *model = new OutputColumnModel(columns, this);
|
OutputColumnModel *model = new OutputColumnModel(columns, this);
|
||||||
|
@ -34,8 +41,12 @@ OutputDialog::OutputDialog(QWidget *parent, std::vector<Check> *checks)
|
||||||
unsigned short position = settings->get_all_settings()["output_order"][column.first]["position"];
|
unsigned short position = settings->get_all_settings()["output_order"][column.first]["position"];
|
||||||
ColumnType type = column.second;
|
ColumnType type = column.second;
|
||||||
columns->at(position - 1) = (OutputColumn(QString::fromStdString(name), type));
|
columns->at(position - 1) = (OutputColumn(QString::fromStdString(name), type));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (unsigned short i = 0; i < 6; i ++)
|
||||||
|
emit model->dataChanged(model->index(i, 0), model->index(i, 0));
|
||||||
|
|
||||||
ui->printHeaderCheckBox->setChecked(settings->get_all_settings()["print_header"]);
|
ui->printHeaderCheckBox->setChecked(settings->get_all_settings()["print_header"]);
|
||||||
ui->printTotalCheckBox->setChecked(settings->get_all_settings()["print_total"]);
|
ui->printTotalCheckBox->setChecked(settings->get_all_settings()["print_total"]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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="267"/>
|
<location filename="../mainwindow.cpp" line="270"/>
|
||||||
<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="269"/>
|
<location filename="../mainwindow.cpp" line="272"/>
|
||||||
<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="274"/>
|
<location filename="../mainwindow.cpp" line="277"/>
|
||||||
<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="276"/>
|
<location filename="../mainwindow.cpp" line="279"/>
|
||||||
<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="281"/>
|
<location filename="../mainwindow.cpp" line="284"/>
|
||||||
<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="283"/>
|
<location filename="../mainwindow.cpp" line="286"/>
|
||||||
<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>
|
||||||
|
@ -645,7 +645,7 @@
|
||||||
<translation>Print total</translation>
|
<translation>Print total</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../outputdialog.cpp" line="30"/>
|
<location filename="../outputdialog.cpp" line="37"/>
|
||||||
<source>Кто здесь?</source>
|
<source>Кто здесь?</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -286,32 +286,32 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="267"/>
|
<location filename="../mainwindow.cpp" line="270"/>
|
||||||
<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="269"/>
|
<location filename="../mainwindow.cpp" line="272"/>
|
||||||
<source>Captcha is incorrect</source>
|
<source>Captcha is incorrect</source>
|
||||||
<translation>Капча введена неверно</translation>
|
<translation>Капча введена неверно</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="274"/>
|
<location filename="../mainwindow.cpp" line="277"/>
|
||||||
<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="276"/>
|
<location filename="../mainwindow.cpp" line="279"/>
|
||||||
<source>Internal server error</source>
|
<source>Internal server error</source>
|
||||||
<translation>Внутренняя ошибка сервера</translation>
|
<translation>Внутренняя ошибка сервера</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="281"/>
|
<location filename="../mainwindow.cpp" line="284"/>
|
||||||
<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="283"/>
|
<location filename="../mainwindow.cpp" line="286"/>
|
||||||
<source>Check was not found</source>
|
<source>Check was not found</source>
|
||||||
<translation>Чек не найден</translation>
|
<translation>Чек не найден</translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -629,7 +629,7 @@
|
||||||
<translation>Печатать Итого</translation>
|
<translation>Печатать Итого</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../outputdialog.cpp" line="30"/>
|
<location filename="../outputdialog.cpp" line="37"/>
|
||||||
<source>Кто здесь?</source>
|
<source>Кто здесь?</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QVector>
|
||||||
CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *parent)
|
CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *parent)
|
||||||
: checks(checks), QAbstractTableModel{parent}
|
: checks(checks), QAbstractTableModel{parent}
|
||||||
{}
|
{}
|
||||||
|
@ -33,13 +33,15 @@ bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &val
|
||||||
if (!index.isValid() || index.row() >= checks->size())
|
if (!index.isValid() || index.row() >= checks->size())
|
||||||
return false;
|
return false;
|
||||||
unsigned int row = index.row();
|
unsigned int row = index.row();
|
||||||
|
Check &c = checks->at(row);
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: {
|
case 0:
|
||||||
checks->at(row).set_date(value.value<std::string>());
|
c.set_date(value.value<std::string>());
|
||||||
break;
|
break;
|
||||||
} case 1:
|
case 1:
|
||||||
checks->at(row).set_total(value.value<double>());
|
c.set_total(value.value<double>());
|
||||||
break;
|
break;
|
||||||
|
emit dataChanged(index, index, {role});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -51,10 +53,8 @@ QVariant CheckQueueTableModel::headerData(int section, Qt::Orientation orientati
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0:
|
case 0:
|
||||||
return tr("Date&Time");
|
return tr("Date&Time");
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
return tr("Total");
|
return tr("Total");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if (role == Qt::DisplayRole && orientation == Qt::Vertical) {
|
} else if (role == Qt::DisplayRole && orientation == Qt::Vertical) {
|
||||||
return section + 1;
|
return section + 1;
|
||||||
|
@ -117,9 +117,16 @@ QMimeData* CheckQueueTableModel::mimeData(const QModelIndexList &indexes) const
|
||||||
|
|
||||||
for (const QModelIndex &i : indexes) {
|
for (const QModelIndex &i : indexes) {
|
||||||
if (i.isValid() && i.column() == 0) {
|
if (i.isValid() && i.column() == 0) {
|
||||||
QString date = data(i, Qt::DisplayRole).toString();
|
Check &c = checks->at(i.row());
|
||||||
double total = data(index(i.row(), i.column() + 1), Qt::DisplayRole).toDouble();
|
QString date = QString::fromStdString(c.get_date()),
|
||||||
stream << date << total;
|
fn = QString::fromStdString(c.get_fn()),
|
||||||
|
fd = QString::fromStdString(c.get_fd()),
|
||||||
|
fi = QString::fromStdString(c.get_fi());
|
||||||
|
double total = c.get_total();
|
||||||
|
OperationType type = c.get_operationType();
|
||||||
|
std::vector<Goods> goods = c.get_goods();
|
||||||
|
|
||||||
|
stream << date << total << type << fn << fd << fi << goods;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mimeData->setData(CheckQueueTableModel::MimeType, encodedData);
|
mimeData->setData(CheckQueueTableModel::MimeType, encodedData);
|
||||||
|
@ -138,23 +145,40 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
|
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
QString date;
|
QString date, fn, fd, fi;
|
||||||
double total;
|
double total;
|
||||||
stream >> date >> total;
|
OperationType type;
|
||||||
Check c;
|
std::vector<Goods> goods;
|
||||||
c.set_date(date.toStdString());
|
|
||||||
c.set_total(total);
|
stream >> date >> total >> type >> fn >> fd >> fi >> goods;
|
||||||
|
Check c = Check(
|
||||||
|
date.toStdString(),
|
||||||
|
total,
|
||||||
|
type,
|
||||||
|
fn.toStdString(),
|
||||||
|
fd.toStdString(),
|
||||||
|
fi.toStdString(),
|
||||||
|
goods
|
||||||
|
);
|
||||||
newItems.push_back(c);
|
newItems.push_back(c);
|
||||||
++rows;
|
++rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
insertRows(row, rows, QModelIndex());
|
insertRows(row, rows, QModelIndex());
|
||||||
|
|
||||||
for (Check &c : newItems) {
|
for (Check item : newItems) {
|
||||||
QModelIndex date_index = index(row, 0, QModelIndex());
|
// (*checks)[row] = std::move(item);
|
||||||
QModelIndex total_index = index(row, 1, QModelIndex());
|
Check &c = checks->at(row);
|
||||||
setData(date_index, QVariant::fromValue(c.get_date()), Qt::EditRole);
|
c.set_date(item.get_date());
|
||||||
setData(total_index, QVariant::fromValue(c.get_total()), Qt::EditRole);
|
c.set_total(item.get_total());
|
||||||
|
c.set_fn(item.get_fn());
|
||||||
|
c.set_fd(item.get_fd());
|
||||||
|
c.set_fi(item.get_fi());
|
||||||
|
c.set_operation_type(item.get_operationType());
|
||||||
|
for (Goods &g : item.get_goods()) {
|
||||||
|
c.add_goods(g);
|
||||||
|
}
|
||||||
|
emit dataChanged(index(row, 0), index(row, 1));
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue