Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (83 sloc) 2.874 kB
5d8d1f4 @Gabriano working on res filters
Gabriano authored
1 #include <QDateTime>
a88c343 @Gabriano Creating reservation view
Gabriano authored
2 #include "reservationfilterproxy.h"
3 #include "reservation.h"
fa539b8 @Gabriano Fucking filter
Gabriano authored
4 #include "stationmodel.h"
5 #include "vehiculemodel.h"
a88c343 @Gabriano Creating reservation view
Gabriano authored
6
7 #include <QDebug>
8
fa539b8 @Gabriano Fucking filter
Gabriano authored
9 ReservationFilterProxy::ReservationFilterProxy(
10 StationModel *smodel,
11 VehiculeModel *vmodel,
12 QObject *parent) :
13 QSortFilterProxyModel(parent),
14 stationModel(smodel),
15 vehiculeModel(vmodel)
a88c343 @Gabriano Creating reservation view
Gabriano authored
16 {
f874f47 @Gabriano working on bookingsPage
Gabriano authored
17 user = 0;
1632f72 @Gabriano finished res display
Gabriano authored
18 pastResIncluded = true;
19 currentResIncluded = true;
20 futurResIncluded = true;
a88c343 @Gabriano Creating reservation view
Gabriano authored
21 }
22
23
24 bool ReservationFilterProxy::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const {
fa539b8 @Gabriano Fucking filter
Gabriano authored
25 return true;
26 }
27
28 QVariant ReservationFilterProxy::data(const QModelIndex &index, int role) const {
29 if (!index.isValid() || role != Qt::DisplayRole)
30 return QVariant();
31
32 qint64 vid, sid;
33
34 QVariant data = sourceModel()->data(index);
35
36 switch (index.column()) {
37 case Reservation::COL_DEBUT:
38 return data.toDateTime().toString("dd MMM yyyy hh:mm");
39
40 case Reservation::COL_STATION:
41 sid = data.toInt();
42 return stationModel->getStation(sid)->getNom();
43
44 case Reservation::COL_VEHICULE:
45 vid = data.toInt();
46 return vehiculeModel->getVehicule(vid)->getName();
47
48 default:
49 return QVariant();
50 }
51 }
52
53
54 QVariant ReservationFilterProxy::headerData(int section, Qt::Orientation orientation, int role) const {
55 return sourceModel()->headerData(section, orientation, role);
56 }
57
58 Qt::ItemFlags ReservationFilterProxy::flags(const QModelIndex &index) const {
59 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
a88c343 @Gabriano Creating reservation view
Gabriano authored
60 }
61
62
63 bool ReservationFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
f874f47 @Gabriano working on bookingsPage
Gabriano authored
64 if (user == 0)
65 return false;
a88c343 @Gabriano Creating reservation view
Gabriano authored
66
9d6e217 @gnuvince Added comments widgets
authored
67 QModelIndex index = sourceModel()->index(source_row, Reservation::COL_ID);
68 qint64 reservationId = index.data().toInt();
69 Reservation *reservation = dynamic_cast<ReservationModel*>(sourceModel())->getReservation(reservationId);
5d8d1f4 @Gabriano working on res filters
Gabriano authored
70
9d6e217 @gnuvince Added comments widgets
authored
71 if (reservation->getUsager() == user->getId()) {
5d8d1f4 @Gabriano working on res filters
Gabriano authored
72 QDateTime now = QDateTime::currentDateTime();
9d6e217 @gnuvince Added comments widgets
authored
73 QDateTime resStart = reservation->getDebut();
74 QDateTime resEnd = reservation->getFin();
5d8d1f4 @Gabriano working on res filters
Gabriano authored
75
76 if (currentResIncluded && (now > resStart) && (now < resEnd)) {
77 return true;
78 }
79 if (futurResIncluded && (now < resStart)) {
a88c343 @Gabriano Creating reservation view
Gabriano authored
80 return true;
5d8d1f4 @Gabriano working on res filters
Gabriano authored
81 }
82 if (pastResIncluded && (now > resEnd)) {
83 return true;
84 }
a88c343 @Gabriano Creating reservation view
Gabriano authored
85 }
86 return false;
87 }
f874f47 @Gabriano working on bookingsPage
Gabriano authored
88
89 void ReservationFilterProxy::setUser(Usager *user) {
90 this->user = user;
91 }
5d8d1f4 @Gabriano working on res filters
Gabriano authored
92
93 void ReservationFilterProxy::includePastRes(bool p) {
94 this->pastResIncluded = p;
9d6e217 @gnuvince Added comments widgets
authored
95 invalidate();
5d8d1f4 @Gabriano working on res filters
Gabriano authored
96 }
97
98 void ReservationFilterProxy::includeCurrentRes(bool p) {
99 this->currentResIncluded = p;
9d6e217 @gnuvince Added comments widgets
authored
100 invalidate();
5d8d1f4 @Gabriano working on res filters
Gabriano authored
101 }
102
103 void ReservationFilterProxy::includeFuturRes(bool p) {
104 this->futurResIncluded = p;
9d6e217 @gnuvince Added comments widgets
authored
105 invalidate();
5d8d1f4 @Gabriano working on res filters
Gabriano authored
106 }
Something went wrong with that request. Please try again.