Browse files

Creating reservation view

  • Loading branch information...
1 parent 2f54672 commit a88c34357990ea68a59992df5ff005f9e7a70546 @Gabriano Gabriano committed Apr 27, 2011
Showing with 112 additions and 8 deletions.
  1. +24 −2 pages/bookingspage.cpp
  2. +6 −1 pages/bookingspage.h
  3. +4 −2 projet.pro
  4. +38 −0 reservationfilterproxy.cpp
  5. +31 −0 reservationfilterproxy.h
  6. +7 −2 userinterface.cpp
  7. +2 −1 userinterface.h
View
26 pages/bookingspage.cpp
@@ -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);
View
7 pages/bookingspage.h
@@ -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
View
6 projet.pro
@@ -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
@@ -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
View
38 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;
+}
View
31 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
View
9 userinterface.cpp
@@ -19,7 +19,8 @@
#include "station.h"
#include "stationmodel.h"
#include "stationsortproxy.h"
-#include "reservationproxymodel.h"
+#include "reservation.h"
+#include "reservationfilterproxy.h"
#include <QDebug>
@@ -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() {
@@ -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));
View
3 userinterface.h
@@ -15,6 +15,7 @@
#include "vehiculefilterproxy.h"
#include "reservation.h"
#include "reservationmodel.h"
+#include "reservationfilterproxy.h"
#include "geoposition.h"
enum PageName { Page_MainMenu,
@@ -51,7 +52,7 @@ class UserInterface : public QMainWindow
VehiculeFilterProxy *vehiculeProxy;
UsagerModel *usagerModel;
ReservationModel *reservationModel;
- ReservationProxyModel *reservationProxy;
+ ReservationFilterProxy *reservationProxy;
GeoPosition *currentPosition;
Reservation *reservation;

0 comments on commit a88c343

Please sign in to comment.