Skip to content

Commit f30c489

Browse files
committed
finish handouts form exercise
1 parent 3ee3561 commit f30c489

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

handouts/forms/manual/manual.pro

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
include (../../../../common.pri)
2-
HEADERS += order.h \
3-
orderform.h
4-
SOURCES += main.cpp \
5-
order.cpp \
6-
orderform.cpp
7-
OTHER_FILES += readme.txt
1+
######################################################################
2+
# Automatically generated by qmake (3.0) Wed 29. May 12:31:52 2013
3+
######################################################################
4+
5+
QT += widgets
6+
7+
TEMPLATE = app
8+
TARGET = manual
9+
INCLUDEPATH += .
10+
11+
# Input
12+
HEADERS += order.h orderform.h
13+
SOURCES += main.cpp order.cpp orderform.cpp

handouts/forms/manual/orderform.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
11
#include "orderform.h"
22
/* You must implement the missing methods in this file */
33

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+
}

handouts/forms/manual/orderform.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
#ifndef ORDERFORM_H
22
#define ORDERFORM_H
33

4-
#include <QtGui>
4+
#include <QtWidgets>
55

6-
class Order;
6+
//class Order;
7+
#include "order.h"
78

89
class OrderForm : public QWidget {
910
Q_OBJECT
1011
public:
1112
OrderForm(QWidget* parent =0);
12-
1313
void setOrder(Order* prod);
14+
1415
public slots:
16+
void updateTotal();
1517
void submit();
16-
void cancel();
17-
1818

1919
private:
2020
QLineEdit* m_nameEdit;
2121
QDateEdit* m_dateEdit;
2222
QSpinBox* m_quantitySpin;
23+
QDoubleSpinBox* m_unitPrice;
24+
QDoubleSpinBox* m_totalPrice;
2325
QPushButton* m_submitButton;
2426
QPushButton* m_cancelButton;
2527

0 commit comments

Comments
 (0)