00001 #include "resourcereservationmodel.h"
00002 
00003 #include <domain/resource.h>
00004 #include <domain/user.h>
00005 #include <domain/duration.h>
00006 #include <domain/reservation.h>
00007 
00008 using namespace control;
00009 
00010 ResourceReservationModel::ResourceReservationModel (const domain::Resource* resource)
00011 {
00012     reservations = resource->reservations();
00013 }
00014 
00015 int ResourceReservationModel::columnCount (const QModelIndex& parent) const
00016 {
00017     if (!parent.isValid())
00018         return LastColumn;
00019 
00020     return 0;
00021 }
00022 
00023 int ResourceReservationModel::rowCount (const QModelIndex& parent) const
00024 {
00025     if (!parent.isValid())
00026         return reservations.size();
00027 
00028     return 0;
00029 }
00030 
00031 QVariant ResourceReservationModel::data (const QModelIndex& index, int role) const
00032 {
00033     const domain::Reservation* reservation = reservationForIndex(index);
00034 
00035     if (role == Qt::DisplayRole)
00036     {
00037         switch (index.column())
00038         {
00039             case Task:          return reservation->task()->id();
00040             case Time:          return reservation->time();
00041             case Duration:      return reservation->duration().toString();
00042 
00043             default:            return QVariant();
00044         }
00045     }
00046     else
00047         return QVariant();
00048 }
00049 
00050 QVariant ResourceReservationModel::headerData (int section,
00051                                     Qt::Orientation orientation, int role) const
00052 {
00053     if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00054     {
00055         switch (section)
00056         {
00057             case Task:          return "Task";
00058             case Time:          return "Time";
00059             case Duration:      return "Duration";
00060 
00061             default:            return QVariant();
00062         }
00063     }
00064     else
00065         return QVariant();
00066 }
00067 
00068 const domain::Reservation* ResourceReservationModel::reservationForIndex
00069                                                 (const QModelIndex& index) const
00070 {
00071     return reservations[index.row()];
00072 }
00073