Permalink
Browse files

Vehicule filtering

  • Loading branch information...
gnuvince committed Apr 27, 2011
1 parent 3061d31 commit 5741bf88c450b13accc3428bb1774e51f2c77341
Showing with 38 additions and 25 deletions.
  1. +5 −3 pages/confirmpage.cpp
  2. +2 −2 pages/confirmpage.h
  3. +12 −0 reservationmodel.cpp
  4. +1 −0 reservationmodel.h
  5. +5 −9 userinterface.cpp
  6. +11 −10 vehiculefilterproxy.cpp
  7. +2 −1 vehiculefilterproxy.h
View
@@ -4,13 +4,11 @@
#include "confirmpage.h"
#include "vehicule.h"
-ConfirmPage::ConfirmPage(Reservation *reservation,
- UsagerModel *umodel,
+ConfirmPage::ConfirmPage(UsagerModel *umodel,
VehiculeModel *vmodel,
StationModel *smodel,
QWidget *parent) :
Page(parent),
- reservation(reservation),
umodel(umodel),
vmodel(vmodel),
smodel(smodel)
@@ -58,3 +56,7 @@ void ConfirmPage::setEditorText() {
.arg(reservation->getFin().toString("dd MMM yyyy hh:mm"))
);
}
+
+void ConfirmPage::setReservation(Reservation *res) {
+ reservation = res;
+}
View
@@ -14,11 +14,11 @@ class ConfirmPage : public Page
{
Q_OBJECT
public:
- explicit ConfirmPage(Reservation *reservation,
- UsagerModel *umodel,
+ explicit ConfirmPage(UsagerModel *umodel,
VehiculeModel *vmodel,
StationModel *smodel,
QWidget *parent = 0);
+ void setReservation(Reservation *res);
private:
Reservation *reservation;
View
@@ -232,3 +232,15 @@ qint64 ReservationModel::getVehiculeStation(qint64 vehiculeId) {
}
return -1;
}
+
+bool ReservationModel::vehiculeAvailable(qint64 vehiculeId, qint64 stationId, QDateTime start, QDateTime end) {
+ foreach (Reservation *res, reservations) {
+ if (res->getVehicule() == vehiculeId) {
+ if (stationId != res->getStation() ||
+ compareIntervalles(res->getDebut(), res->getFin(), start, end) == 0) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
View
@@ -57,6 +57,7 @@ class ReservationModel : public QAbstractTableModel
static const quint32 MAGIC_NUMBER = 0x182f3a41;
qint64 getVehiculeStation(qint64 vehiculeId);
+ bool vehiculeAvailable(qint64 vehiculeId, qint64 stationId, QDateTime start, QDateTime end);
private:
QVariant fieldAt(const QModelIndex &index, int role) const;
View
@@ -42,15 +42,14 @@ UserInterface::UserInterface(
pages = new QMap<PageName, Page*>;
- reservation = new Reservation(QDateTime::currentDateTime(), QDateTime::currentDateTime(), 0, 0, 0, this);
currentPosition = new GeoPosition(0, 0);
stationProxy = new StationSortProxy(this);
stationProxy->setSourceModel(stationModel);
stationProxy->setDynamicSortFilter(true);
stationProxy->sort(1);
- vehiculeProxy = new VehiculeFilterProxy(rmodel, reservation, this);
+ vehiculeProxy = new VehiculeFilterProxy(rmodel, this);
vehiculeProxy->setSourceModel(vehiculeModel);
vehiculeProxy->setDynamicSortFilter(true);
}
@@ -63,8 +62,7 @@ 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(reservation,
- usagerModel,
+ pages->insert(Page_Confirm, new ConfirmPage(usagerModel,
vehiculeModel,
stationModel,
this));
@@ -262,11 +260,9 @@ void UserInterface::setCarId(qint64 carId) {
void UserInterface::resetReservation() {
- reservation->setDebut(QDateTime::currentDateTime());
- reservation->setFin(QDateTime::currentDateTime());
- reservation->setStation(0);
- reservation->setVehicule(0);
- reservation->setUsager(user->getId());
+ reservation = new Reservation(QDateTime(), QDateTime(), 0, user->getId(), 0, this);
+ vehiculeProxy->setReservation(reservation);
+ dynamic_cast<ConfirmPage*>(getPage(Page_Confirm))->setReservation(reservation);
}
View
@@ -3,11 +3,11 @@
#include <QDebug>
-VehiculeFilterProxy::VehiculeFilterProxy(ReservationModel *rmodel, Reservation *reservation, QObject *parent) :
+VehiculeFilterProxy::VehiculeFilterProxy(ReservationModel *rmodel, QObject *parent) :
QSortFilterProxyModel(parent),
- reservationModel(rmodel),
- reservation(reservation)
+ reservationModel(rmodel)
{
+ reservation = 0;
}
@@ -21,13 +21,14 @@ bool VehiculeFilterProxy::filterAcceptsColumn(int source_column, const QModelInd
bool VehiculeFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
+ if (reservation == 0)
+ return false;
+
QModelIndex index = sourceModel()->index(source_row, Vehicule::COL_ID);
qint64 vehiculeId = index.data().toInt();
- foreach (Reservation *res, reservationModel->getReservations()) {
- if (res->getVehicule() == vehiculeId && res->getStation() == reservation->getStation()
- && reservationModel->testReservation(reservation)) {
- return true;
- }
- }
- return false;
+ return reservationModel->vehiculeAvailable(vehiculeId, reservation->getStation(), reservation->getDebut(), reservation->getFin());
+}
+
+void VehiculeFilterProxy::setReservation(Reservation *res) {
+ reservation = res;
}
View
@@ -10,7 +10,8 @@ class VehiculeFilterProxy : public QSortFilterProxyModel
{
Q_OBJECT
public:
- explicit VehiculeFilterProxy(ReservationModel *rmodel, Reservation *reservation, QObject *parent = 0);
+ explicit VehiculeFilterProxy(ReservationModel *rmodel, QObject *parent = 0);
+ void setReservation(Reservation *res);
protected:
bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const;

0 comments on commit 5741bf8

Please sign in to comment.