-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRatingDialog.cpp
More file actions
106 lines (72 loc) · 2.72 KB
/
RatingDialog.cpp
File metadata and controls
106 lines (72 loc) · 2.72 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
#include "RatingDialog.h"
#include "ui_RatingDialog.h"
#include "Global.h"
#include "DetailOfBoughtProducts.h"
#include <QMessageBox>
using namespace GlobalNameSpace;
RatingDialog::RatingDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::RatingDialog)
{
ui->setupUi(this);
NodeProduct *temp = &Globals::PRODUCT_LIST.getByKey(Globals::KEY_PRODUCT);
p = temp->getData();
ui->totalRatingL->setText(QString::number(p.getRating()));
ui->yourRateSpin->setRange(1, 5);
if (DetailOfBoughtProducts::givenRating > 0){
ui->yourRateSpin->setValue(DetailOfBoughtProducts::givenRating);
}
}
RatingDialog::~RatingDialog()
{
delete ui;
}
void RatingDialog::on_confirmB_clicked()
{
NodeProduct *temp = &Globals::PRODUCT_LIST.getByKey(Globals::KEY_PRODUCT);
p = temp->getData();
float totalRating = (float)(p.getRating() * p.getVoteNumber() - DetailOfBoughtProducts::givenRating);
if (DetailOfBoughtProducts::givenRating == 0){
p.setVoteNumber(p.getVoteNumber() + 1);
}
DetailOfBoughtProducts::givenRating = ui->yourRateSpin->value();
totalRating += (float) DetailOfBoughtProducts::givenRating;
float aveRating = (float) (totalRating / p.getVoteNumber());
p.setRating(aveRating);
if (Globals::TYPE_USER == DEALER){
TNodeUser<Dealer>* d_node = &Globals::DEALER_LIST.getByKey(Globals::KEY_USER);
Dealer d_data = d_node->getData();
d_data.deleteProductFromListOfBuyBefore(p);
d_data.addKeyToListOfBuyBefore(p);
////////////////////////////////////////////// Added By Arash
if (d_data.getListOfInterestKeyLinkedList().containsKey(p.getKey())){
d_data.deleteProductToListOfInterest(p);
d_data.addKeyToListOfInterest(p);
}
//////////////////////////////////////////////
d_node->setData(d_data);
Globals::DEALER_LIST.writeToFileUser();
}
else{
TNodeUser<Users>* d_node = &Globals::USER_LIST.getByKey(Globals::KEY_USER);
Users d_data = d_node->getData();
d_data.deleteProductFromListOfBuyBefore(p);
d_data.addKeyToListOfBuyBefore(p);
////////////////////////////////////////////// Added By Arash
if (d_data.getListOfInterestKeyLinkedList().containsKey(p.getKey())){
d_data.deleteProductToListOfInterest(p);
d_data.addKeyToListOfInterest(p);
}
//////////////////////////////////////////////
d_node->setData(d_data);
Globals::USER_LIST.writeToFileUser();
}
temp->setData(p);
Globals::PRODUCT_LIST.writeFile();
QMessageBox::information(this, "Done", "Thank you for your review");
close();
}
void RatingDialog::on_cancelB_clicked()
{
close();
}