Skip to content

Commit

Permalink
Added comments page
Browse files Browse the repository at this point in the history
  • Loading branch information
gnuvince committed Apr 29, 2011
1 parent c40589f commit 80db356
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 48 deletions.
5 changes: 2 additions & 3 deletions pages/confirmpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ 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"
Expand All @@ -51,7 +50,7 @@ void ConfirmPage::setEditorText() {
"Retour : %5\n")
.arg(username)
.arg(station)
.arg(vehiculeName)
.arg(vehicule->getName())
.arg(reservation->getDebut().toString("dd MMM yyyy hh:mm"))
.arg(reservation->getFin().toString("dd MMM yyyy hh:mm"))
);
Expand Down
4 changes: 4 additions & 0 deletions pages/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ void Page::addBottomButtons(QPushButton *left, QPushButton *middle, QPushButton
QHBoxLayout *bottomLayout = new QHBoxLayout;
if (left != 0)
bottomLayout->addWidget(left);
else
bottomLayout->addWidget(new QWidget(this));
bottomLayout->addStretch();

bottomLayout->addWidget(middle);

bottomLayout->addStretch();
if (right!= 0)
bottomLayout->addWidget(right);
else
bottomLayout->addWidget(new QWidget(this));

QWidget *widget = new QWidget;
widget->setLayout(bottomLayout);
Expand Down
112 changes: 84 additions & 28 deletions pages/writecommentpage.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,99 @@
#include <QtGui>
#include <QTableView>
#include <QDebug>

#include "page.h"
#include "writecommentpage.h"
#include "station.h"
#include "vehicule.h"
#include "reservation.h"
#include "note.h"

WriteCommentPage::WriteCommentPage(QWidget *parent) :
Page(parent)
WriteCommentPage::WriteCommentPage(qint64 uid, NoteModel *nmodel, ReservationModel *rmodel, StationModel *smodel, VehiculeModel *vmodel, QWidget *parent) :
Page(parent),
reservationModel(rmodel),
noteModel(nmodel),
stationModel(smodel),
vehiculeModel(vmodel),
userId(uid)
{
addTitle(trUtf8("Écrire un commentaire"));

QWidget *subjectsWidget = new QWidget(this);
QHBoxLayout *subjectLayout = new QHBoxLayout(this);
QLabel *subjectLabel = new QLabel("Sujet:");
QComboBox *type = new QComboBox(this);
type->addItem(trUtf8("Véhicule"));
type->addItem(trUtf8("Station"));
//type->addItem(trUtf8("Réservation"));
subjectLayout->addWidget(subjectLabel);
subjectLayout->addWidget(type);
subjectsWidget->setLayout(subjectLayout);
addWidget(subjectsWidget);

QWidget *commentWidget = new QWidget(this);
QHBoxLayout *commentLayout = new QHBoxLayout(this);
QLabel *commentLabel = new QLabel("Commentaire:");
QTextEdit *comment = new QTextEdit(this);
commentLayout->addWidget(commentLabel);
commentLayout->addWidget(comment);
commentWidget->setLayout(commentLayout);
addWidget(commentWidget);

QPushButton *btnPrevious = new QPushButton(this);
btnPrevious->setIcon(QIcon(":/icones/data/icons/arrow_left.png"));
QPushButton *btnSend = new QPushButton(trUtf8("Envoyer"), this);
type = new QComboBox(this);
type->addItem(trUtf8("Véhicule"), 0);
type->addItem(trUtf8("Station"), 1);

comment = new QTextEdit(this);

QWidget *widget = new QWidget(this);
QFormLayout *layout = new QFormLayout(this);

subject = new QComboBox(this);
subject->setSizeAdjustPolicy(QComboBox::AdjustToContents);

layout->addRow(trUtf8("Type:"), type);
layout->addRow(trUtf8("Sujet:"), subject);
layout->addRow(trUtf8("Message:"), comment);

widget->setLayout(layout);
addWidget(widget);

btnSend = new QPushButton(trUtf8("Envoyer"), this);
btnSend->setEnabled(false);
btnSend->setIcon(QIcon(":/icones/data/icons/email.png"));
QPushButton *btnMenu = new QPushButton(trUtf8("Menu"), this);

addBottomButtons(btnPrevious, btnMenu, btnSend);
addBottomButtons(0, btnMenu, btnSend);

connect(btnPrevious, SIGNAL(clicked()), SIGNAL(Previous()));
connect(btnMenu, SIGNAL(clicked()), SIGNAL(Menu()));
connect(btnSend, SIGNAL(clicked()), SIGNAL(Send()));
connect(btnSend, SIGNAL(clicked()), this, SLOT(addNote()));
connect(subject, SIGNAL(currentIndexChanged(int)), this, SLOT(enableSend()));
connect(type, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSubjects(int)));
}

void WriteCommentPage::updateSubjects(int x) {
subject->clear();
if (x == 0) {
foreach (Reservation *r, reservationModel->getReservations()) {
if (r->getUsager() == userId) {
Vehicule *v = vehiculeModel->getVehicule(r->getVehicule());
subject->addItem(v->getName(), v->getId());
}
}
}
else if (x == 1) {
foreach (Reservation *r, reservationModel->getReservations()) {
if (r->getUsager() == userId) {
Station *s = stationModel->getStation(r->getStation());
subject->addItem(s->getNom(), s->getId());
}
}
}
}

void WriteCommentPage::addNote() {
qint64 messageType, id;

if (type->itemData(type->currentIndex()).toInt() == 0)
messageType = Note::TYPE_VEHICULE;
else
messageType = Note::TYPE_STATION;
id = subject->itemData(subject->currentIndex()).toInt();

noteModel->addNote(new Note(userId,
QDateTime::currentDateTime(),
messageType,
id,
comment->toPlainText(),
this));
comment->clear();
QMessageBox::information(this,
trUtf8("Commentaire ajouté"),
trUtf8("Votre commentaire a été ajouté"),
QMessageBox::Ok);
}

void WriteCommentPage::enableSend() {
btnSend->setEnabled(true);
}
20 changes: 19 additions & 1 deletion pages/writecommentpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,37 @@
#include <QtGui>

#include "page.h"
#include "stationmodel.h"
#include "vehiculemodel.h"
#include "reservationmodel.h"
#include "notemodel.h"

class WriteCommentPage : public Page
{
Q_OBJECT
public:
explicit WriteCommentPage(QWidget *parent = 0);
explicit WriteCommentPage(qint64 uid, NoteModel *nmodel, ReservationModel *rmodel, StationModel *smodel, VehiculeModel *vmodel, QWidget *parent = 0);

private:
StationModel *stationModel;
VehiculeModel *vehiculeModel;
ReservationModel *reservationModel;
NoteModel *noteModel;
QComboBox *subject;
QComboBox *type;
QPushButton *btnSend;
QTextEdit *comment;
qint64 userId;

signals:
void Previous();
void Menu();
void Send();

public slots:
void updateSubjects(int x=0);
void addNote();
void enableSend();

};

Expand Down
2 changes: 1 addition & 1 deletion qrc_icones.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
** Resource object code
**
** Created: Thu Apr 28 12:01:14 2011
** Created: Fri Apr 29 12:11:34 2011
** by: The Resource Compiler for Qt version 4.7.2
**
** WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion ui_cartewidget.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'cartewidget.ui'
**
** Created: Thu Apr 28 11:58:49 2011
** Created: Fri Apr 29 12:09:02 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
Expand Down
2 changes: 1 addition & 1 deletion ui_mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created: Thu Apr 28 11:58:49 2011
** Created: Fri Apr 29 12:09:02 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
Expand Down
2 changes: 1 addition & 1 deletion ui_userinterface.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'userinterface.ui'
**
** Created: Thu Apr 28 13:27:40 2011
** Created: Fri Apr 29 12:09:02 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
Expand Down
15 changes: 3 additions & 12 deletions userinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ void UserInterface::createPages() {
this));
pages->insert(Page_Bookings, new BookingsPage(reservationProxy,
this));
pages->insert(Page_Comments, new CommentsPage(this)); // comments main page
pages->insert(Page_WriteComment, new WriteCommentPage(this)); // comment editing
//pages->insert(Page_Unexpected, new UnexpectedPage(this));
pages->insert(Page_WriteComment, new WriteCommentPage(user->getId(), noteModel, reservationModel, stationModel, vehiculeModel, this));
pages->insert(Page_Email, new MyMessagesPage(this));

for (int i = 0; i < ui->stackedWidget->count(); ++i) {
Expand All @@ -102,7 +100,8 @@ void UserInterface::createPages() {
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(LeaveComment()), this, SLOT(gotoWriteComment()));
connect(getPage(Page_MainMenu), SIGNAL(LeaveComment()), getPage(Page_WriteComment), SLOT(updateSubjects()));
connect(getPage(Page_MainMenu), SIGNAL(ReportUnexpected()), this, SLOT(gotoUnexpected()));

// Connections for find station
Expand Down Expand Up @@ -154,15 +153,7 @@ void UserInterface::createPages() {
connect(getPage(Page_Bookings), SIGNAL(includeCurrentRes(bool)), reservationProxy, SLOT(includeCurrentRes(bool)));
connect(getPage(Page_Bookings), SIGNAL(includeFuturRes(bool)), reservationProxy, SLOT(includeFuturRes(bool)));

// Connections for comments
connect(getPage(Page_Comments), SIGNAL(Menu()), this, SLOT(gotoMainMenu()));
connect(getPage(Page_Comments), SIGNAL(VehiculeComment()), this, SLOT(gotoWriteComment()));
connect(getPage(Page_Comments), SIGNAL(StationComment()), this, SLOT(gotoWriteComment()));
connect(getPage(Page_Comments), SIGNAL(ReservationComment()), this, SLOT(gotoWriteComment()));
//connect(getPage(Page_Comments), SIGNAL(ToUserComment()), this, SLOT(gotoWriteComment()));

// Connections for writecomment
connect(getPage(Page_WriteComment), SIGNAL(Previous()), this, SLOT(gotoCommentPage()));
connect(getPage(Page_WriteComment), SIGNAL(Menu()), this, SLOT(gotoMainMenu()));
connect(getPage(Page_WriteComment), SIGNAL(Send()), this, SLOT(gotoMainMenu()));

Expand Down
4 changes: 4 additions & 0 deletions vehicule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Vehicule::Vehicule(qint64 id,QString marque,QString modele,QString couleur,QStri
{
}

QString Vehicule::getName() const {
return QString("%1 %2 (%3)").arg(marque).arg(modele).arg(couleur);
}

QVariant Vehicule::field(uint column, int role) const
{

Expand Down
2 changes: 2 additions & 0 deletions vehicule.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Vehicule : public QObject
QPixmap getPhoto() const { return photo; }
//void setPhoto(const QPixmap &photo) { if (!photo.isNull()) this->photo = photo; }

QString getName() const;

static uint headerCount();
static QVariant header(uint column);

Expand Down

0 comments on commit 80db356

Please sign in to comment.