Permalink
Browse files

Fucking filter

  • Loading branch information...
1 parent 80db356 commit fa539b8539b503712d1be64d29e2b63df33615ac @Gabriano Gabriano committed Apr 29, 2011
Showing with 63 additions and 26 deletions.
  1. +2 −10 pages/bookingspage.cpp
  2. +4 −4 reservation.cpp
  3. +44 −7 reservationfilterproxy.cpp
  4. +12 −1 reservationfilterproxy.h
  5. +0 −3 robot.cpp
  6. +1 −1 userinterface.cpp
@@ -21,12 +21,8 @@ BookingsPage::BookingsPage(
bookings->setSelectionMode(QAbstractItemView::SingleSelection);
bookings->verticalHeader()->hide();
bookings->hideColumn(0);
- bookings->resizeColumnToContents(1);
- bookings->resizeColumnToContents(2);
- bookings->resizeColumnToContents(3);
- bookings->resizeColumnToContents(4);
- bookings->resizeColumnToContents(5);
- bookings->resizeColumnToContents(6);
+ bookings->hideColumn(2);
+ bookings->hideColumn(4);
bookings->resizeRowsToContents();
bookings->setAlternatingRowColors(true);
addWidget(bookings);
@@ -63,11 +59,7 @@ BookingsPage::BookingsPage(
}
void BookingsPage::resizeCols() {
- qDebug() << "resizingCols";
bookings->resizeColumnToContents(1);
- bookings->resizeColumnToContents(2);
bookings->resizeColumnToContents(3);
- bookings->resizeColumnToContents(4);
bookings->resizeColumnToContents(5);
- bookings->resizeColumnToContents(6);
}
View
@@ -33,11 +33,11 @@ qint64 Reservation::idCount = 0;
QStringList& Reservation::headers() {
static QStringList _headers = QStringList()
<< trUtf8("id")
- << trUtf8("debut")
- << trUtf8("fin")
- << trUtf8("vehicule")
+ << trUtf8("Début")
+ << trUtf8("Fin")
+ << trUtf8("Véhicule")
<< trUtf8("usager")
- << trUtf8("station");
+ << trUtf8("Station");
return _headers;
}
@@ -1,11 +1,18 @@
#include <QDateTime>
#include "reservationfilterproxy.h"
#include "reservation.h"
+#include "stationmodel.h"
+#include "vehiculemodel.h"
#include <QDebug>
-ReservationFilterProxy::ReservationFilterProxy(QObject *parent) :
- QSortFilterProxyModel(parent)
+ReservationFilterProxy::ReservationFilterProxy(
+ StationModel *smodel,
+ VehiculeModel *vmodel,
+ QObject *parent) :
+ QSortFilterProxyModel(parent),
+ stationModel(smodel),
+ vehiculeModel(vmodel)
{
user = 0;
pastResIncluded = true;
@@ -15,11 +22,41 @@ ReservationFilterProxy::ReservationFilterProxy(QObject *parent) :
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_STATION;
+ return true;
+}
+
+QVariant ReservationFilterProxy::data(const QModelIndex &index, int role) const {
+ if (!index.isValid() || role != Qt::DisplayRole)
+ return QVariant();
+
+ qint64 vid, sid;
+
+ QVariant data = sourceModel()->data(index);
+
+ switch (index.column()) {
+ case Reservation::COL_DEBUT:
+ return data.toDateTime().toString("dd MMM yyyy hh:mm");
+
+ case Reservation::COL_STATION:
+ sid = data.toInt();
+ return stationModel->getStation(sid)->getNom();
+
+ case Reservation::COL_VEHICULE:
+ vid = data.toInt();
+ return vehiculeModel->getVehicule(vid)->getName();
+
+ default:
+ return QVariant();
+ }
+}
+
+
+QVariant ReservationFilterProxy::headerData(int section, Qt::Orientation orientation, int role) const {
+ return sourceModel()->headerData(section, orientation, role);
+}
+
+Qt::ItemFlags ReservationFilterProxy::flags(const QModelIndex &index) const {
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
@@ -10,15 +10,26 @@ class ReservationFilterProxy : public QSortFilterProxyModel
{
Q_OBJECT
public:
- explicit ReservationFilterProxy(QObject *parent = 0);
+ explicit ReservationFilterProxy(
+ StationModel *smodel,
+ VehiculeModel *vmodel,
+ QObject *parent = 0);
void setUser(Usager *user);
+ QVariant data(const QModelIndex &index, int role) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+
protected:
bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+
private:
ReservationModel *reservationModel;
+ StationModel *stationModel;
+ VehiculeModel *vehiculeModel;
Usager *user;
bool pastResIncluded;
bool currentResIncluded;
View
@@ -56,7 +56,6 @@ bool Robot::tenteUneReservation(QDateTime debut,QDateTime fin,qint64 vId,qint64
QList<Reservation*> disponibles = proxy->getFilteredReservations();
if( disponibles.count()==0 ) {
- //qDebug()<<"Aucun vehicule disponible! (pas de vehicule du tout)";
return false;
}
@@ -245,7 +244,6 @@ void Robot::updateTime(QDateTime now)
if( (nb+1)%10==0 ) qApp->processEvents();
if( nb>10 ) break;
}
- qDebug() << "robot genere"<<nb<<"ajouteReservationAuHasard";
//
// Envoi d'une note d'un usager à un autre
@@ -256,7 +254,6 @@ void Robot::updateTime(QDateTime now)
if( (nb+1)%10==0 ) qApp->processEvents();
if( nb>10 ) break;
}
- qDebug() << "robot genere"<<nb<<"ajouteNotePersonnelleAuHasard";
// a la fin... se rappeller de l'heure
last=now;
View
@@ -58,7 +58,7 @@ UserInterface::UserInterface(
vehiculeProxy->setSourceModel(vehiculeModel);
vehiculeProxy->setDynamicSortFilter(true);
- reservationProxy = new ReservationFilterProxy(this);
+ reservationProxy = new ReservationFilterProxy(stationModel, vehiculeModel, this);
reservationProxy->setSourceModel(reservationModel);
reservationProxy->setDynamicSortFilter(true);
}

0 comments on commit fa539b8

Please sign in to comment.