/* This file is part of the KDE project Copyright (C) 2005 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kptresourceappointmentsview.h" #include "kptappointment.h" #include "kptcalendar.h" #include "kptnode.h" #include "kptresource.h" #include "kptview.h" #include #include #include #include #include #include namespace KPlato { ResourceAppointmentsView::NodeItem::NodeItem(Node *t, QListView *parent, bool highlight) : DoubleListViewBase::MasterListItem(parent, t->name(), highlight), node(t) { setFormat(0, 'f', 1); //kdDebug()<name(), highlight), node(t) { setFormat(0, 'f', 1); //kdDebug()< list = sizes(); int tot = list[0] + list[1]; list[0] = QMIN(35, tot); list[1] = tot-list[0]; setSizes(list); } void ResourceAppointmentsView::zoom(double zoom) { Q_UNUSED(zoom); } void ResourceAppointmentsView::draw(Resource *resource, const QDate &start, const QDate &end) { m_resource = resource; m_start = start; m_end = end; draw(); } void ResourceAppointmentsView::draw() { //kdDebug()<setExpandable(true); m_totalItem->setOpen(true); m_availItem = new ResourceAppointmentsView::NodeItem(i18n("Available"), masterListView()); QPtrList lst = m_resource->appointments(); //kdDebug()< it(lst); for (; it.current(); ++it) { //kdDebug()<node()->node(); ResourceAppointmentsView::NodeItem *item = new ResourceAppointmentsView::NodeItem(n, m_totalItem); item->effortMap = it.current()->plannedPrDay(m_start, m_end); } slotUpdate(); } void ResourceAppointmentsView::slotUpdate() { //kdDebug()<calendar(); const Calendar *resCal = m_resource->calendar(); const QDateTime availFrom = m_resource->availableFrom(); const QDateTime availUntil = m_resource->availableUntil(); // Add columns for selected period/periods //kdDebug()<addDays(dt, 1), ++c) { QString df = locale->formatDate(dt, true); addSlaveColumn(df); } if (m_totalItem) { m_totalItem->setHighlight(true); m_totalItem->setSlaveHighlight(true); } QListViewItemIterator it(masterListView()); for (;it.current(); ++it) { ResourceAppointmentsView::NodeItem *item = static_cast(it.current()); if (!item || item->firstChild()) { continue; } double eff; double avail; int col=0; for (QDate d=m_start; d <= m_end; d = cal->addDays(d, 1), ++col) { if (item == m_availItem && resCal) { QDateTime f(d); QDateTime u(d, QTime(23, 59, 59, 999)); if (f >= availUntil || u <= availFrom) { avail = 0.0; } else { if (availFrom > f) { f = availFrom; } if (availUntil < u) { u = availUntil; } avail = ((double)(resCal->effort(f.date(), f.time(), u.time())*(double)(m_resource->units())/100.0).minutes()/60.0); } m_availItem->setSlaveItem(col, avail); m_availItem->addToTotal(avail); if (m_totalItem) { m_totalItem->setSlaveLimit(col, avail); } } if (item != m_availItem) { eff = (double)(item->effortMap.effortOnDate(d).minutes())/60.0; item->setSlaveItem(col, eff); item->addToTotal(eff); } } } if (m_totalItem && m_availItem) { m_totalItem->setLimit(m_availItem->value()); //kdDebug()<value()< list; // list << context.accountsviewsize << context.periodviewsize; // m_dlv->setSizes(list); // m_date = context.date; // if (!m_date.isValid()) // m_date = QDate::currentDate(); // m_period = context.period; // m_cumulative = context.cumulative; // // return true; // } // // void ResourceAppointmentsView::getContext(Context::ResourceAppointmentsView &context) const { // //kdDebug()<sizes()[0]; // context.periodviewsize = m_dlv->sizes()[1]; // context.date = m_date; // context.period = m_period; // context.cumulative = m_cumulative; // //kdDebug()<