|
1 | 1 | #include "orderform.h"
|
2 | 2 | /* You must implement the missing methods in this file */
|
3 | 3 |
|
| 4 | +OrderForm::OrderForm(QWidget* parent) |
| 5 | +{ |
| 6 | + m_nameEdit = new QLineEdit(); |
| 7 | + m_dateEdit = new QDateEdit; |
| 8 | + m_dateEdit->setDisplayFormat("dd/MM/yyyy"); |
| 9 | + m_quantitySpin = new QSpinBox(); |
| 10 | + m_unitPrice = new QDoubleSpinBox(); |
| 11 | + m_totalPrice = new QDoubleSpinBox(); |
| 12 | + m_totalPrice->setReadOnly(true); |
| 13 | + m_submitButton = new QPushButton(tr("submit")); |
| 14 | + m_cancelButton = new QPushButton(tr("cancel")); |
| 15 | + |
| 16 | + QVBoxLayout* vbox = new QVBoxLayout; |
| 17 | + QHBoxLayout* hbox = new QHBoxLayout; |
| 18 | + QFormLayout* layout = new QFormLayout; |
| 19 | + |
| 20 | + layout->addRow(tr("Name"), m_nameEdit); |
| 21 | + layout->addRow(tr("Date"), m_dateEdit); |
| 22 | + layout->addRow(tr("Quantity"), m_quantitySpin); |
| 23 | + layout->addRow(tr("Unit Price"), m_unitPrice); |
| 24 | + layout->addRow(tr("Total Price"), m_totalPrice); |
| 25 | + |
| 26 | + hbox->addStretch(); |
| 27 | + hbox->addWidget(m_submitButton); |
| 28 | + hbox->addWidget(m_cancelButton); |
| 29 | + |
| 30 | + vbox->addLayout(layout); |
| 31 | + vbox->addLayout(hbox); |
| 32 | + |
| 33 | + setLayout(vbox); |
| 34 | + |
| 35 | + // connections |
| 36 | + connect (m_unitPrice, SIGNAL(valueChanged(double)), this, SLOT(updateTotal())); |
| 37 | + connect (m_quantitySpin, SIGNAL(valueChanged(int)), this, SLOT(updateTotal())); |
| 38 | + connect (m_submitButton, SIGNAL(pressed()), this, SLOT(submit())); |
| 39 | + connect (m_cancelButton, SIGNAL(pressed()), this, SLOT(close())); |
| 40 | +} |
| 41 | + |
| 42 | +void OrderForm::setOrder(Order* prod) |
| 43 | +{ |
| 44 | + prod->setName(m_nameEdit->text()); |
| 45 | + prod->setDateAdded(m_dateEdit->date()); |
| 46 | + prod->setQuantity(m_quantitySpin->value()); |
| 47 | + prod->setPrice(m_unitPrice->value()); |
| 48 | +} |
| 49 | + |
| 50 | +void OrderForm::updateTotal() |
| 51 | +{ |
| 52 | + m_totalPrice->setValue(m_unitPrice->value() * m_quantitySpin->value()); |
| 53 | +} |
| 54 | + |
| 55 | +void OrderForm::submit() |
| 56 | +{ |
| 57 | + if(m_nameEdit->text() == "") { |
| 58 | + QMessageBox msgBox; |
| 59 | + msgBox.setWindowTitle("dude."); |
| 60 | + msgBox.setText("Please enter name."); |
| 61 | + msgBox.exec(); |
| 62 | + return; |
| 63 | + } |
| 64 | + setOrder(m_Order); |
| 65 | + QMessageBox msgBox; |
| 66 | + msgBox.setText(m_Order->toString()); |
| 67 | + msgBox.exec(); |
| 68 | +} |
0 commit comments