-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindowinteractor.cpp
More file actions
128 lines (104 loc) · 3.7 KB
/
mainwindowinteractor.cpp
File metadata and controls
128 lines (104 loc) · 3.7 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "mainwindowinteractor.h"
#include "database.h"
#include "iterator.h"
MainWindowInteractor * MainWindowInteractor::p_instance = nullptr;
MainWindowInteractorDestroyer MainWindowInteractor::destroyer;
MainWindowInteractorDestroyer::~MainWindowInteractorDestroyer() {
delete p_instance;
}
void MainWindowInteractorDestroyer::initialize( MainWindowInteractor* p ) {
p_instance = p;
}
MainWindowInteractor& MainWindowInteractor::getInstance() {
if(!p_instance) {
p_instance = new MainWindowInteractor(DataBase::getInstance());
p_instance->tempBouquet = Bouquet();
p_instance->fileName = "DB.json";
destroyer.initialize( p_instance);
}
return *p_instance;
}
QList<QString> MainWindowInteractor::getFlourColors(QString name) const{
QList<int> ids = this->db.getFloursIds(this->fileName);
QList<QString> colors;
for (int t: ids){
Flour *flour = db.getFlourFromDb(this->fileName, t);
if (flour != nullptr){
if (flour->getName() == name) colors.append(flour->getColor());
}
}
return colors;
}
void MainWindowInteractor::addToTemporaryBouquet(QString name,
QString color, int number){
QList<int> ids = this->db.getFloursIds(this->fileName);
for (int t: ids){
Flour *flour = db.getFlourFromDb(this->fileName, t);
if (flour != nullptr){
if (flour->getName() == name && flour->getColor() == color){
for (int i = 0; i < number; ++i){
this->tempBouquet.add(*flour);
}
}
}
}
}
int MainWindowInteractor::getFlourPrice(QString name, QString color) const{
QList<int> ids = this->db.getFloursIds(this->fileName);
for (int t: ids){
Flour *flour = db.getFlourFromDb(this->fileName, t);
if(flour != nullptr){
if (flour->getName() == name && flour->getColor() == color)
return flour->getPrice();
}
}
return 0;
}
QList<QList<QString>> MainWindowInteractor::getBouquetInfo() const{
QList<QList<QString>> temp;
for (Iterator itr = this->tempBouquet.begin();
itr != this->tempBouquet.end(); ++itr){
QList<QString> tmp;
tmp.append({(*itr)->getName(), (*itr)->getColor(),
QString::number((*itr)->getPrice())});
temp.append(tmp);
}
return temp;
}
void MainWindowInteractor::clearTempBouquet(){
this->tempBouquet.clearBouquet();
}
void MainWindowInteractor::deleteFlourInTempBouquet(QString name, QString color){
QList<int> ids = this->db.getFloursIds(this->fileName);
for (int t: ids){
Flour *flour = db.getFlourFromDb(this->fileName, t);
if (flour != nullptr){
if (flour->getName() == name && flour->getColor() == color)
this->tempBouquet.deleteElement(*flour);
}
}
}
void MainWindowInteractor::saveBouuetToDb() const{
db.addBouquetToFile(this->tempBouquet, this->fileName);
}
void MainWindowInteractor::saveBouquetToFIle(QString fileName) const{
db.addBouquetToFile(this->tempBouquet, fileName);
}
void MainWindowInteractor::setDbFile(QString fileName){
this->fileName = fileName;
}
int MainWindowInteractor::getTempBouquetPrice() const{
return this->tempBouquet.price();
}
QString MainWindowInteractor::getFlourPic(QString name, QString color) const{
QList<int> ids = this->db.getFloursIds(this->fileName);
QString url;
for (int t: ids){
Flour *flour = db.getFlourFromDb(this->fileName, t);
if (flour != nullptr){
if (flour->getName() == name && flour->getColor() == color)
url = flour->getPicUrl();
}
}
return url;
}