kplato
kpttaskappointmentsview.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kpttaskappointmentsview.h"
00021
00022 #include "kptappointment.h"
00023 #include "kpttask.h"
00024
00025 #include <qapplication.h>
00026 #include <kcalendarsystem.h>
00027 #include <kglobal.h>
00028 #include <klocale.h>
00029
00030 #include <qheader.h>
00031
00032 namespace KPlato
00033 {
00034
00035 TaskAppointmentsView::ResourceItem::ResourceItem(Resource *r, QListView *parent, bool highlight)
00036 : DoubleListViewBase::MasterListItem(parent, r->name(), highlight),
00037 resource(r) {
00038
00039 setFormat(0, 'f', 1);
00040
00041 }
00042 TaskAppointmentsView::ResourceItem::ResourceItem(Resource *r, QListViewItem *p, bool highlight)
00043 : DoubleListViewBase::MasterListItem(p, r->name(), highlight),
00044 resource(r) {
00045
00046 setFormat(0, 'f', 1);
00047
00048 }
00049
00050 TaskAppointmentsView::ResourceItem::ResourceItem(QString text, QListViewItem *parent, bool highlight)
00051 : DoubleListViewBase::MasterListItem(parent, text, highlight),
00052 resource(0) {
00053
00054 setFormat(0, 'f', 1);
00055
00056 }
00057
00058
00059 TaskAppointmentsView::TaskAppointmentsView(QWidget *parent)
00060 : DoubleListViewBase(parent),
00061 m_task(0) {
00062
00063 setNameHeader(i18n("Resource"));
00064
00065
00066 QValueList<int> list = sizes();
00067 int tot = list[0] + list[1];
00068 list[0] = QMIN(35, tot);
00069 list[1] = tot-list[0];
00070 setSizes(list);
00071 }
00072
00073 void TaskAppointmentsView::zoom(double zoom) {
00074 Q_UNUSED(zoom);
00075 }
00076
00077
00078 void TaskAppointmentsView::draw(Task *task) {
00079 m_task = task;
00080 draw();
00081 }
00082
00083 void TaskAppointmentsView::draw() {
00084
00085 clearLists();
00086 if (!m_task)
00087 return;
00088
00089 QPtrList<Appointment> lst = m_task->appointments();
00090 QPtrListIterator<Appointment> it(lst);
00091 for (; it.current(); ++it) {
00092 Resource *r = it.current()->resource()->resource();
00093 TaskAppointmentsView::ResourceItem *item = new TaskAppointmentsView::ResourceItem(r, masterListView());
00094
00095 item->effortMap = it.current()->plannedPrDay(m_task->startTime().date(), m_task->endTime().date());
00096 }
00097 slotUpdate();
00098 }
00099
00100 void TaskAppointmentsView::drawContents(QPainter* painter)
00101 {
00102 this->DoubleListViewBase::drawContents(painter);
00103 }
00104
00105 void TaskAppointmentsView::slotUpdate() {
00106
00107 if (!m_task)
00108 return;
00109 QApplication::setOverrideCursor(Qt::waitCursor);
00110 createSlaveItems();
00111 KLocale *locale = KGlobal::locale();
00112 const KCalendarSystem *cal = locale->calendar();
00113
00114
00115 QDate start = m_task->startTime().date();
00116 QDate end = m_task->endTime().date();
00117
00118 int c=0;
00119 for (QDate dt = start; dt <= end; dt = cal->addDays(dt, 1), ++c) {
00120 QString df = locale->formatDate(dt, true);
00121 addSlaveColumn(df);
00122 }
00123 QListViewItemIterator it(masterListView());
00124 for (;it.current(); ++it) {
00125 TaskAppointmentsView::ResourceItem *item = static_cast<TaskAppointmentsView::ResourceItem*>(it.current());
00126 if (!item) {
00127 continue;
00128 }
00129 double eff;
00130 int col=0;
00131 for (QDate d=start; d <= end; d = cal->addDays(d, 1), ++col) {
00132 eff = (double)(item->effortMap.effortOnDate(d).minutes())/60.0;
00133 item->setSlaveItem(col, eff);
00134 item->addToTotal(eff);
00135 }
00136 }
00137 calculate();
00138 QApplication::restoreOverrideCursor();
00139 }
00140
00141
00142 void TaskAppointmentsView::print(KPrinter &) {
00143 kdDebug()<<k_funcinfo<<endl;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 void TaskAppointmentsView::clear() {
00172 clearLists();
00173 }
00174
00175 void TaskAppointmentsView::createSlaveItems() {
00176 DoubleListViewBase::createSlaveItems();
00177 setSlaveFormat(0, 'f', 1);
00178 }
00179
00180 }
00181
00182 #include "kpttaskappointmentsview.moc"
|