Permalink
Browse files

working on res filters

  • Loading branch information...
1 parent f874f47 commit 5d8d1f4c53abdd87b00a5690457e30d93df6edf0 @Gabriano Gabriano committed Apr 27, 2011
Showing with 44 additions and 5 deletions.
  1. +4 −0 pages/bookingspage.cpp
  2. +3 −0 pages/bookingspage.h
  3. +28 −5 reservationfilterproxy.cpp
  4. +6 −0 reservationfilterproxy.h
  5. +3 −0 userinterface.cpp
View
@@ -1,5 +1,6 @@
#include <QtGui>
#include <QTableView>
+#include <QModelIndex>
#include "page.h"
#include "bookingspage.h"
@@ -51,4 +52,7 @@ BookingsPage::BookingsPage(
addBottomButtons(0, btnMenu, 0);
connect(btnMenu, SIGNAL(clicked()), SIGNAL(Menu()));
+ connect(past, SIGNAL(clicked(bool)), SIGNAL(includePastRes(bool)));
+ connect(current, SIGNAL(clicked(bool)), SIGNAL(includeCurrentRes(bool)));
+ connect(futur, SIGNAL(clicked(bool)), SIGNAL(includeFuturRes(bool)));
}
View
@@ -15,6 +15,9 @@ class BookingsPage : public Page
QWidget *parent = 0);
signals:
+ void includePastRes(bool);
+ void includeCurrentRes(bool);
+ void includeFuturRes(bool);
public slots:
View
@@ -1,3 +1,4 @@
+#include <QDateTime>
#include "reservationfilterproxy.h"
#include "reservation.h"
@@ -25,12 +26,22 @@ bool ReservationFilterProxy::filterAcceptsRow(int source_row, const QModelIndex
if (user == 0)
return false;
- 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())
+
+ QModelIndex indexUser = sourceModel()->index(source_row, Reservation::COL_USAGER);
+ if (user->getId() == indexUser.data().toInt()) {
+ QDateTime now = QDateTime::currentDateTime();
+ QDateTime resStart = sourceModel()->index(source_row, Reservation::COL_DEBUT).data().toDateTime();
+ QDateTime resEnd = sourceModel()->index(source_row, Reservation::COL_FIN).data().toDateTime();
+
+ if (currentResIncluded && (now > resStart) && (now < resEnd)) {
+ return true;
+ }
+ if (futurResIncluded && (now < resStart)) {
return true;
+ }
+ if (pastResIncluded && (now > resEnd)) {
+ return true;
+ }
}
return false;
}
@@ -39,3 +50,15 @@ void ReservationFilterProxy::setUser(Usager *user) {
qDebug() << "ReservationFilterProxy::setUser done";
this->user = user;
}
+
+void ReservationFilterProxy::includePastRes(bool p) {
+ this->pastResIncluded = p;
+}
+
+void ReservationFilterProxy::includeCurrentRes(bool p) {
+ this->currentResIncluded = p;
+}
+
+void ReservationFilterProxy::includeFuturRes(bool p) {
+ this->futurResIncluded = p;
+}
View
@@ -20,10 +20,16 @@ class ReservationFilterProxy : public QSortFilterProxyModel
private:
ReservationModel *reservationModel;
Usager *user;
+ bool pastResIncluded;
+ bool currentResIncluded;
+ bool futurResIncluded;
signals:
public slots:
+ void includePastRes(bool p);
+ void includeCurrentRes(bool p);
+ void includeFuturRes(bool p);
};
View
@@ -149,6 +149,9 @@ void UserInterface::createPages() {
// Connections for bookings
connect(getPage(Page_Bookings), SIGNAL(Menu()), this, SLOT(gotoMainMenu()));
+ connect(getPage(Page_Bookings), SIGNAL(includePastRes(bool)), reservationProxy, SLOT(includePastRes(bool)));
+ 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()));

0 comments on commit 5d8d1f4

Please sign in to comment.