Skip to content

Commit

Permalink
Confirmation page
Browse files Browse the repository at this point in the history
  • Loading branch information
gnuvince committed Apr 27, 2011
1 parent 7353bec commit 3061d31
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
41 changes: 38 additions & 3 deletions pages/confirmpage.cpp
Expand Up @@ -2,13 +2,27 @@

#include "page.h"
#include "confirmpage.h"
#include "vehicule.h"

ConfirmPage::ConfirmPage(QWidget *parent) :
Page(parent)
ConfirmPage::ConfirmPage(Reservation *reservation,
UsagerModel *umodel,
VehiculeModel *vmodel,
StationModel *smodel,
QWidget *parent) :
Page(parent),
reservation(reservation),
umodel(umodel),
vmodel(vmodel),
smodel(smodel)
{
addTitle(trUtf8("Confirmer la réservation"));

QPlainTextEdit *editor = new QPlainTextEdit(this);

editor = new QPlainTextEdit(this);
editor->setReadOnly(true);
editor->setFont(QFont("Courier"));


addWidget(editor);

QPushButton *btnPrevious = new QPushButton(this);
Expand All @@ -23,3 +37,24 @@ ConfirmPage::ConfirmPage(QWidget *parent) :
connect(btnMenu, SIGNAL(clicked()), SIGNAL(Menu()));
connect(btnConfirm, SIGNAL(clicked()), SIGNAL(Confirm()));
}

void ConfirmPage::setEditorText() {
QString username = umodel->getUsager(reservation->getUsager())->getNom();
QString station = smodel->getStation(reservation->getStation())->getNom();
Vehicule *vehicule = vmodel->getVehicule(reservation->getVehicule());
QString vehiculeName = trUtf8("%1 %2 (%3)").arg(vehicule->getMarque())
.arg(vehicule->getModele()).arg(vehicule->getCouleur());

editor->setPlainText(
trUtf8("Usager : %1\n"
"Station : %2\n"
"Véhicule: %3\n"
"Départ : %4\n"
"Retour : %5\n")
.arg(username)
.arg(station)
.arg(vehiculeName)
.arg(reservation->getDebut().toString("dd MMM yyyy hh:mm"))
.arg(reservation->getFin().toString("dd MMM yyyy hh:mm"))
);
}
20 changes: 19 additions & 1 deletion pages/confirmpage.h
Expand Up @@ -4,17 +4,35 @@
#include <QtGui>

#include "page.h"
#include "reservation.h"
#include "usagermodel.h"
#include "vehiculemodel.h"
#include "reservationmodel.h"
#include "stationmodel.h"

class ConfirmPage : public Page
{
Q_OBJECT
public:
explicit ConfirmPage(QWidget *parent = 0);
explicit ConfirmPage(Reservation *reservation,
UsagerModel *umodel,
VehiculeModel *vmodel,
StationModel *smodel,
QWidget *parent = 0);

private:
Reservation *reservation;
UsagerModel *umodel;
VehiculeModel *vmodel;
StationModel *smodel;
QPlainTextEdit *editor;


signals:
void Confirm();

public slots:
void setEditorText();

};

Expand Down
28 changes: 25 additions & 3 deletions userinterface.cpp
Expand Up @@ -35,15 +35,15 @@ UserInterface::UserInterface(
stationModel(smodel),
vehiculeModel(vmodel),
usagerModel(umodel),
reservationModel(rmodel),
ui(new Ui::UserInterface)
{
ui->setupUi(this);

pages = new QMap<PageName, Page*>;

reservation = new Reservation(this);
reservation = new Reservation(QDateTime::currentDateTime(), QDateTime::currentDateTime(), 0, 0, 0, this);
currentPosition = new GeoPosition(0, 0);
stationModel->updateCurrentPosition(*currentPosition);

stationProxy = new StationSortProxy(this);
stationProxy->setSourceModel(stationModel);
Expand All @@ -63,7 +63,11 @@ void UserInterface::createPages() {
pages->insert(Page_SelectStation, new SelectStationPage(stationProxy, this));
pages->insert(Page_SelectTime, new SelectTimePage(this));
pages->insert(Page_SelectCar, new SelectCarPage(vehiculeProxy, this));
pages->insert(Page_Confirm, new ConfirmPage(this));
pages->insert(Page_Confirm, new ConfirmPage(reservation,
usagerModel,
vehiculeModel,
stationModel,
this));
pages->insert(Page_Bookings, new BookingsPage(this));
pages->insert(Page_Comments, new CommentsPage(this)); // comments main page
pages->insert(Page_WriteComment, new WriteCommentPage(this)); // comment editing
Expand All @@ -88,6 +92,7 @@ void UserInterface::createPages() {

// Connections for main menu
connect(getPage(Page_MainMenu), SIGNAL(BookCar()), this, SLOT(gotoFindStationPage()));
connect(getPage(Page_MainMenu), SIGNAL(BookCar()), this, SLOT(resetReservation()));
connect(getPage(Page_MainMenu), SIGNAL(ViewBookings()), this, SLOT(gotoBookings()));
connect(getPage(Page_MainMenu), SIGNAL(LeaveComment()), this, SLOT(gotoCommentPage()));
connect(getPage(Page_MainMenu), SIGNAL(ReportUnexpected()), this, SLOT(gotoUnexpected()));
Expand Down Expand Up @@ -125,11 +130,14 @@ void UserInterface::createPages() {
connect(getPage(Page_SelectCar), SIGNAL(Previous()), this, SLOT(gotoSelectTime()));
connect(getPage(Page_SelectCar), SIGNAL(Next()), this, SLOT(gotoConfirm()));
connect(getPage(Page_SelectCar), SIGNAL(carSelected(qint64)), this, SLOT(setCarId(qint64)));
connect(getPage(Page_SelectCar), SIGNAL(Next()), getPage(Page_Confirm), SLOT(setEditorText()));

// Connections for confirm
connect(getPage(Page_Confirm), SIGNAL(Menu()), this, SLOT(gotoMainMenu()));
connect(getPage(Page_Confirm), SIGNAL(Previous()), this, SLOT(gotoSelectCar()));
connect(getPage(Page_Confirm), SIGNAL(Confirm()), this, SLOT(gotoMainMenu()));
connect(getPage(Page_Confirm), SIGNAL(Confirm()), this, SLOT(saveReservation()));


// Connections for bookings
connect(getPage(Page_Bookings), SIGNAL(Menu()), this, SLOT(gotoMainMenu()));
Expand Down Expand Up @@ -251,3 +259,17 @@ void UserInterface::setStationId(qint64 stationId) {
void UserInterface::setCarId(qint64 carId) {
reservation->setVehicule(carId);
}


void UserInterface::resetReservation() {
reservation->setDebut(QDateTime::currentDateTime());
reservation->setFin(QDateTime::currentDateTime());
reservation->setStation(0);
reservation->setVehicule(0);
reservation->setUsager(user->getId());
}


void UserInterface::saveReservation() {
reservationModel->addReservation(reservation);
}
3 changes: 3 additions & 0 deletions userinterface.h
Expand Up @@ -52,6 +52,7 @@ class UserInterface : public QMainWindow
UsagerModel *usagerModel;
GeoPosition *currentPosition;
Reservation *reservation;
ReservationModel *reservationModel;


public slots:
Expand All @@ -74,6 +75,8 @@ public slots:
void setStationId(qint64 stationId);
void setCarId(qint64 carId);
void setUser(qint64 id);
void resetReservation();
void saveReservation();
};

#endif // USERINTERFACE_H

0 comments on commit 3061d31

Please sign in to comment.