fixed only handling two fields of a check
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "goods.h"
|
||||
#include <string>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
Goods::Goods() { }
|
||||
|
||||
Goods::Goods(std::string name, double price_per_unit, std::string net_weight, double quantity) :
|
||||
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(QString name) { this->name = name.toStdString(); }
|
||||
|
||||
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(QString net_weight) { this->net_weight = net_weight.toStdString(); }
|
||||
|
||||
void Goods::set_price_per_unit(double 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
|
||||
|
||||
#include <string>
|
||||
#include <QDataStream>
|
||||
|
||||
class Goods
|
||||
{
|
||||
@@ -10,6 +11,7 @@ class Goods
|
||||
std::string net_weight; // will contain values like "5мл" or "10г"
|
||||
double price_per_unit;
|
||||
public:
|
||||
Goods();
|
||||
Goods(std::string name, double quantity, std::string net_weight, double price_per_unit);
|
||||
double calculate_total_price();
|
||||
|
||||
@@ -19,9 +21,16 @@ public:
|
||||
double get_price_per_unit();
|
||||
|
||||
void set_name(std::string);
|
||||
void set_name(QString);
|
||||
void set_quantity(double);
|
||||
void set_net_weight(std::string);
|
||||
void set_net_weight(QString);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user