00001 #include "reservationmodel.h"
00002
00003 #include <domain/taskmanagerdata.h>
00004 #include <domain/reservation.h>
00005 #include <domain/duration.h>
00006 #include <domain/resource.h>
00007 #include <domain/user.h>
00008
00009 #include <QDateTime>
00010
00011 using namespace control;
00012
00013 ReservationModel::ReservationModel(domain::TaskManagerData* data) :
00014 DomainModel(data)
00015 {
00016 connect(data, SIGNAL(reservationsChanged()), this, SLOT(emitDataChange()));
00017 }
00018
00019 int ReservationModel::columnCount(const QModelIndex& parent) const
00020 {
00021 if (!parent.isValid())
00022 return LastColumn;
00023
00024 return 0;
00025 }
00026
00027 int ReservationModel::rowCount(const QModelIndex& parent) const
00028 {
00029 if (!parent.isValid())
00030 return domainData->reservations().size();
00031
00032 return 0;
00033 }
00034
00035 QVariant ReservationModel::headerData(int section, Qt::Orientation orientation,
00036 int role) const
00037 {
00038 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00039 {
00040 switch (section)
00041 {
00042 case Resource: return "Resource";
00043 case Task: return "Task";
00044 case Time: return "Time";
00045 case Duration: return "Duration";
00046
00047 default: return QVariant();
00048 }
00049 }
00050
00051 return QVariant();
00052 }
00053
00054 QVariant ReservationModel::data(const QModelIndex& index, int role) const
00055 {
00056 const domain::Reservation* reservation =
00057 domainData->reservations()[index.row()];
00058
00059 if (role == Qt::DisplayRole)
00060 {
00061 switch (index.column())
00062 {
00063 case Resource: return reservation->resource()->description();
00064 case Task: return (int)reservation->task();
00065 case Time: return reservation->time();
00066 case Duration: return reservation->duration().toString();
00067
00068 default: return QVariant();
00069 }
00070 }
00071 else if (role == Qt::ToolTipRole)
00072 {
00073 QString toolTip("Reservation of resource %1 for task %2\n"
00074 "Starting %3 for a period of %4");
00075
00076 return toolTip.arg(reservation->resource()->description())
00077 .arg(reservation->task()->id())
00078 .arg(reservation->time().toString())
00079 .arg(reservation->duration().toString());
00080 }
00081 else
00082 return QVariant();
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108