Skip to content

Commit

Permalink
Creating reservation view
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriano committed Apr 27, 2011
1 parent 2f54672 commit a88c343
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 8 deletions.
26 changes: 24 additions & 2 deletions pages/bookingspage.cpp
Expand Up @@ -3,14 +3,36 @@

#include "page.h"
#include "bookingspage.h"
#include "reservationfilterproxy.h"

BookingsPage::BookingsPage(QWidget *parent) :
Page(parent)

BookingsPage::BookingsPage(
ReservationFilterProxy *rmodel,
QWidget *parent) :
Page(parent),
reservationModel(rmodel)
{
addTitle(trUtf8("Mes réservations"));

QTableView *bookings = new QTableView(this);
addWidget(bookings);
bookings->setModel(reservationModel);
bookings->setSelectionBehavior(QAbstractItemView::SelectRows);
bookings->setSelectionMode(QAbstractItemView::SingleSelection);
bookings->verticalHeader()->hide();
bookings->hideColumn(0);
bookings->resizeColumnToContents(2);
bookings->resizeColumnToContents(3);
bookings->resizeColumnToContents(4);
bookings->resizeColumnToContents(5);
bookings->resizeColumnToContents(6);
bookings->resizeRowsToContents();

connect(bookings, SIGNAL(clicked(QModelIndex)), this, SLOT(showInformation(QModelIndex)));

QFont font = bookings->font();
font.setPointSize(8);
bookings->setFont(font);

QPushButton *btnMenu = new QPushButton(trUtf8("Menu"), this);

Expand Down
7 changes: 6 additions & 1 deletion pages/bookingspage.h
Expand Up @@ -4,17 +4,22 @@
#include <QtGui>

#include "page.h"
#include "reservationfilterproxy.h"

class BookingsPage : public Page
{
Q_OBJECT
public:
explicit BookingsPage(QWidget *parent = 0);
explicit BookingsPage(
ReservationFilterProxy *rmodel,
QWidget *parent = 0);

signals:

public slots:

private:
ReservationFilterProxy *reservationModel;
};

#endif // BOOKINGSPAGE_H
6 changes: 4 additions & 2 deletions projet.pro
Expand Up @@ -52,7 +52,8 @@ HEADERS += geoposition.h \
pages/mymessagespage.h \
pages/writecommentpage.h \
pages/infostationpage.h \
vehiculefilterproxy.h
vehiculefilterproxy.h \
reservationfilterproxy.h
FORMS += mainwindow.ui \
cartewidget.ui \
userinterface.ui
Expand Down Expand Up @@ -93,7 +94,8 @@ SOURCES += geoposition.cpp \
pages/mymessagespage.cpp \
pages/writecommentpage.cpp \
pages/infostationpage.cpp \
vehiculefilterproxy.cpp
vehiculefilterproxy.cpp \
reservationfilterproxy.cpp

RESOURCES += \
icones.qrc
Expand Down
38 changes: 38 additions & 0 deletions reservationfilterproxy.cpp
@@ -0,0 +1,38 @@
#include "reservationfilterproxy.h"
#include "reservation.h"

#include <QDebug>

ReservationFilterProxy::ReservationFilterProxy(ReservationModel *rmodel, Reservation *reservation, Usager *user, QObject *parent) :
QSortFilterProxyModel(parent),
reservationModel(rmodel),
reservation(reservation),
user(user)
{
}


bool ReservationFilterProxy::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const {
return source_column == Reservation::COL_ID
|| source_column == Reservation::COL_DEBUT
|| source_column == Reservation::COL_FIN
|| source_column == Reservation::COL_VEHICULE
|| source_column == Reservation::COL_USAGER
|| source_column == Reservation::COL_STATION
|| source_column == Reservation::COL_PERSO;
}


bool ReservationFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
QModelIndex index = sourceModel()->index(source_row, Reservation::COL_ID);
qint64 reservationId = index.data().toInt();

foreach (Reservation *res, reservationModel->getReservations()) {
qDebug() << "res user: " << res->getUsager();
qDebug() << "user id: " << user->getId();
qDebug() << "user name: " << user->getNom();
if (res->getUsager() == user->getId())
return true;
}
return false;
}
31 changes: 31 additions & 0 deletions reservationfilterproxy.h
@@ -0,0 +1,31 @@
#ifndef RESERVATIONFILTERPROXY_H
#define RESERVATIONFILTERPROXY_H

#include <QSortFilterProxyModel>

#include "reservation.h"
#include "reservationmodel.h"
#include "usager.h"

class ReservationFilterProxy : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit ReservationFilterProxy(ReservationModel *rmodel, Reservation *reservation, Usager *user, QObject *parent = 0);

protected:
bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;

private:
ReservationModel *reservationModel;
Reservation *reservation;
Usager *user;

signals:

public slots:

};

#endif // RESERVATIONFILTERPROXY_H
9 changes: 7 additions & 2 deletions userinterface.cpp
Expand Up @@ -19,7 +19,8 @@
#include "station.h"
#include "stationmodel.h"
#include "stationsortproxy.h"
#include "reservationproxymodel.h"
#include "reservation.h"
#include "reservationfilterproxy.h"

#include <QDebug>

Expand Down Expand Up @@ -55,6 +56,10 @@ UserInterface::UserInterface(
vehiculeProxy = new VehiculeFilterProxy(rmodel, reservation, this);
vehiculeProxy->setSourceModel(vehiculeModel);
vehiculeProxy->setDynamicSortFilter(true);

reservationProxy = new ReservationFilterProxy(rmodel, reservation, user, this);
reservationProxy->setSourceModel(reservationModel);
reservationProxy->setDynamicSortFilter(true);
}

void UserInterface::createPages() {
Expand All @@ -66,7 +71,7 @@ void UserInterface::createPages() {
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_Bookings, new BookingsPage(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));
Expand Down
3 changes: 2 additions & 1 deletion userinterface.h
Expand Up @@ -15,6 +15,7 @@
#include "vehiculefilterproxy.h"
#include "reservation.h"
#include "reservationmodel.h"
#include "reservationfilterproxy.h"
#include "geoposition.h"

enum PageName { Page_MainMenu,
Expand Down Expand Up @@ -51,7 +52,7 @@ class UserInterface : public QMainWindow
VehiculeFilterProxy *vehiculeProxy;
UsagerModel *usagerModel;
ReservationModel *reservationModel;
ReservationProxyModel *reservationProxy;
ReservationFilterProxy *reservationProxy;
GeoPosition *currentPosition;
Reservation *reservation;

Expand Down

0 comments on commit a88c343

Please sign in to comment.