-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewproductwindow.cpp
140 lines (117 loc) · 3.73 KB
/
newproductwindow.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses
*/
#include "newproductwindow.h"
/**
* Constructeur de l'interface d'ajout/edition d'un produit
* @param parent pointeur vers la fenetre principale
*/
NewProductWindow::NewProductWindow(QMainWindow *parent) :QWidget(parent)
{
idProduct=-1;
this->parent=parent;
createInterface();
}
/**
* Constructeur de l'interface d'ajout/edition d'un produit
* Interface initialiser grace au info de la BDD
* @param parent pointeur vers la fenetre principale
* @param id identifiant du produit au sein de la BDD
*/
NewProductWindow::NewProductWindow(QMainWindow *parent,int id) :QWidget(parent)
{
idProduct=id;
this->parent=parent;
createInterface();
initByBDD();
}
/**
* Methode qui construit l'interface
*/
void NewProductWindow::createInterface(){
QVBoxLayout *layoutPrinc=new QVBoxLayout;
/** ********************* **/
/** Formulaire **/
/** ********************* **/
QFormLayout *layoutForm = new QFormLayout;
name=new QLineEdit();
name->setMinimumWidth(250);
layoutForm->addRow(trUtf8("Nom du produit: "),name);
description=new QLineEdit();
layoutForm->addRow(trUtf8("Description du produit: "),description);
price=new QDoubleSpinBox ();
price->setMaximum(9999999.9);
layoutForm->addRow(trUtf8("Prix unitaire HT: "),price);
layoutPrinc->addLayout(layoutForm);
/** ********************* **/
/** Boutons **/
/** ********************* **/
QHBoxLayout *layoutBouton = new QHBoxLayout;
validate=new QPushButton(trUtf8("Valider"));
layoutBouton->addStretch();
layoutBouton->addWidget(validate);
layoutBouton->addStretch();
layoutPrinc->addStretch();
layoutPrinc->addLayout(layoutBouton);
setLayout(layoutPrinc);
/** ********************* **/
/** Slots **/
/** ********************* **/
connect(validate, SIGNAL(clicked()), this, SLOT(validateProduct()));
}
/**
* Methode (Slot) qui va mettre a jour les infos du produit
* (creation d'un nouveau produit ou mise a jour du produit)
*/
void NewProductWindow::validateProduct(){
if(idProduct==-1){
// creation d'un nouveau produit
Product p;
p.name=name->text();
p.description=description->text();
p.price=price->value();
p.save();
}
else{
// mise a jour d'un produit
Product p(idProduct);
p.name=name->text();
p.description=description->text();
p.price=price->value();
p.save();
p.updateDocumentPrice();
}
QStatusBar *statBar = parent->statusBar();
statBar->showMessage(trUtf8("Informations produit sauvegardé"), 4000);
clean();
}
/**
* Methode qui initialise les champs grace au info de la BDD
*/
void NewProductWindow::initByBDD(){
Product p(idProduct);
name->setText(p.name);
description->setText(p.description);
price->setValue(p.price);
}
/**
* Methode permettant de remettre l'interface pret pour l'ajout
* d'un autre produit
*/
void NewProductWindow::clean(){
idProduct=-1;
name->setText("");
description->setText("");
price->setValue(0.0);
}