-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththing.cpp
More file actions
65 lines (51 loc) · 1.39 KB
/
thing.cpp
File metadata and controls
65 lines (51 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "thing.h"
#include "iostream"
#include <string>
#include <utility>
#include "QJsonObject"
Thing::Thing(){
name_ = QString("table");
price_ = 1;
volume_ = 1;
}
Thing::Thing(QString name, double price, double volume){
name_ = name;
if (price <= 1) price_ = 1;
else price_ = price;
if (volume <= 1) volume_ = 1;
else volume_ = volume;
}
Thing::Thing(const Thing &thing):ParentClass(){
name_ = thing.name_;
price_ = thing.price_;
volume_ = thing.volume_;
}
void Thing::setName(QString name){
if (name.isEmpty()) name_ = QString("table");
else name_= name;
}
QString &Thing::getName(){
return name_;
}
void Thing::setVolume(double volume){
if(volume <= 0) return;
else this->volume_ = volume;
}
double Thing::getVolume() const {
return this->volume_;
}
bool Thing::operator==(Thing &thing){
return this->getInfo() == thing.getInfo();
}
QJsonObject Thing::getInfo(){
return QJsonObject({
qMakePair(QString("class"), how()),
qMakePair(QString("name"), name_),
qMakePair(QString("price"), QJsonValue(this->getPrice())),
qMakePair(QString("volume"), QJsonValue(volume_))
});
}
bool Thing::how(){
return true;
}
Thing::~Thing(){}