You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
7.5 KiB
234 lines
7.5 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
|
||
|
|
||
|
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"
|
||
|
|
||
14 years ago
|
#include <tqapplication.h>
|
||
15 years ago
|
#include <kcalendarsystem.h>
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqdatetime.h>
|
||
|
#include <tqheader.h>
|
||
15 years ago
|
|
||
|
namespace KPlato
|
||
|
{
|
||
|
|
||
14 years ago
|
ResourceAppointmentsView::NodeItem::NodeItem(Node *t, TQListView *parent, bool highlight)
|
||
|
: DoubleListViewBase::MasterListItem(parent, t->name(), highlight),
|
||
15 years ago
|
node(t) {
|
||
|
|
||
|
setFormat(0, 'f', 1);
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
}
|
||
14 years ago
|
ResourceAppointmentsView::NodeItem::NodeItem(Node *t, TQListViewItem *p, bool highlight)
|
||
15 years ago
|
: DoubleListViewBase::MasterListItem(p, t->name(), highlight),
|
||
|
node(t) {
|
||
|
|
||
|
setFormat(0, 'f', 1);
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
ResourceAppointmentsView::NodeItem::NodeItem(TQString text, TQListViewItem *parent, bool highlight)
|
||
|
: DoubleListViewBase::MasterListItem(parent, text, highlight),
|
||
15 years ago
|
node(0) {
|
||
|
|
||
|
setFormat(0, 'f', 1);
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
ResourceAppointmentsView::NodeItem::NodeItem(TQString text, TQListView *parent, bool highlight)
|
||
|
: DoubleListViewBase::MasterListItem(parent, text, highlight),
|
||
15 years ago
|
node(0) {
|
||
|
|
||
|
setFormat(0, 'f', 1);
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
}
|
||
|
|
||
|
//-------------------------------------------
|
||
14 years ago
|
ResourceAppointmentsView::ResourceAppointmentsView(View *view, TQWidget *parent)
|
||
|
: DoubleListViewBase(parent),
|
||
15 years ago
|
m_mainview(view),
|
||
|
m_resource(0),
|
||
|
m_availItem(0),
|
||
|
m_totalItem(0) {
|
||
|
|
||
|
setNameHeader(i18n("Task"));
|
||
|
|
||
|
|
||
14 years ago
|
TQValueList<int> list = sizes();
|
||
15 years ago
|
int tot = list[0] + list[1];
|
||
14 years ago
|
list[0] = TQMIN(35, tot);
|
||
15 years ago
|
list[1] = tot-list[0];
|
||
|
setSizes(list);
|
||
|
}
|
||
|
|
||
|
void ResourceAppointmentsView::zoom(double zoom) {
|
||
|
Q_UNUSED(zoom);
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void ResourceAppointmentsView::draw(Resource *resource, const TQDate &start, const TQDate &end) {
|
||
15 years ago
|
m_resource = resource;
|
||
|
m_start = start;
|
||
|
m_end = end;
|
||
|
draw();
|
||
|
}
|
||
|
|
||
|
void ResourceAppointmentsView::draw() {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
clear();
|
||
|
if (!m_resource)
|
||
|
return;
|
||
|
|
||
|
m_totalItem = new ResourceAppointmentsView::NodeItem(i18n("Total"), masterListView());
|
||
|
m_totalItem->setExpandable(true);
|
||
|
m_totalItem->setOpen(true);
|
||
|
m_availItem = new ResourceAppointmentsView::NodeItem(i18n("Available"), masterListView());
|
||
14 years ago
|
TQPtrList<Appointment> lst = m_resource->appointments();
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<lst.count()<<endl;
|
||
14 years ago
|
TQPtrListIterator<Appointment> it(lst);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
Node *n = it.current()->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()<<k_funcinfo<<endl;
|
||
|
if (!m_resource)
|
||
|
return;
|
||
14 years ago
|
TQApplication::setOverrideCursor(TQt::waitCursor);
|
||
15 years ago
|
createSlaveItems();
|
||
12 years ago
|
TDELocale *locale = TDEGlobal::locale();
|
||
15 years ago
|
const KCalendarSystem *cal = locale->calendar();
|
||
|
const Calendar *resCal = m_resource->calendar();
|
||
14 years ago
|
const TQDateTime availFrom = m_resource->availableFrom();
|
||
|
const TQDateTime availUntil = m_resource->availableUntil();
|
||
15 years ago
|
// Add columns for selected period/periods
|
||
|
//kdDebug()<<k_funcinfo<<start.toString()<<" - "<<end.toString()<<endl;
|
||
|
int c=0;
|
||
14 years ago
|
for (TQDate dt = m_start; dt <= m_end; dt = cal->addDays(dt, 1), ++c) {
|
||
|
TQString df = locale->formatDate(dt, true);
|
||
15 years ago
|
addSlaveColumn(df);
|
||
|
}
|
||
|
if (m_totalItem) {
|
||
|
m_totalItem->setHighlight(true);
|
||
|
m_totalItem->setSlaveHighlight(true);
|
||
|
}
|
||
14 years ago
|
TQListViewItemIterator it(masterListView());
|
||
15 years ago
|
for (;it.current(); ++it) {
|
||
|
ResourceAppointmentsView::NodeItem *item = static_cast<ResourceAppointmentsView::NodeItem*>(it.current());
|
||
|
if (!item || item->firstChild()) {
|
||
|
continue;
|
||
|
}
|
||
|
double eff;
|
||
|
double avail;
|
||
|
int col=0;
|
||
14 years ago
|
for (TQDate d=m_start; d <= m_end; d = cal->addDays(d, 1), ++col) {
|
||
15 years ago
|
if (item == m_availItem && resCal) {
|
||
14 years ago
|
TQDateTime f(d);
|
||
|
TQDateTime u(d, TQTime(23, 59, 59, 999));
|
||
15 years ago
|
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()<<k_funcinfo<<"avail="<<m_availItem->value()<<endl;
|
||
|
}
|
||
|
calculate();
|
||
14 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void ResourceAppointmentsView::print(KPrinter &/*printer*/) {
|
||
|
kdDebug()<<k_funcinfo<<endl;
|
||
|
}
|
||
|
|
||
|
// bool ResourceAppointmentsView::setContext(Context::ResourceAppointmentsView &context) {
|
||
|
// //kdDebug()<<k_funcinfo<<endl;
|
||
|
//
|
||
14 years ago
|
// TQValueList<int> list;
|
||
15 years ago
|
// list << context.accountsviewsize << context.periodviewsize;
|
||
|
// m_dlv->setSizes(list);
|
||
|
// m_date = context.date;
|
||
|
// if (!m_date.isValid())
|
||
13 years ago
|
// m_date = TQDate::currentDate();
|
||
15 years ago
|
// m_period = context.period;
|
||
|
// m_cumulative = context.cumulative;
|
||
|
//
|
||
|
// return true;
|
||
|
// }
|
||
|
//
|
||
|
// void ResourceAppointmentsView::getContext(Context::ResourceAppointmentsView &context) const {
|
||
|
// //kdDebug()<<k_funcinfo<<endl;
|
||
|
// context.accountsviewsize = m_dlv->sizes()[0];
|
||
|
// context.periodviewsize = m_dlv->sizes()[1];
|
||
|
// context.date = m_date;
|
||
|
// context.period = m_period;
|
||
|
// context.cumulative = m_cumulative;
|
||
|
// //kdDebug()<<k_funcinfo<<"sizes="<<sizes()[0]<<","<<sizes()[1]<<endl;
|
||
|
// }
|
||
|
|
||
|
void ResourceAppointmentsView::clear() {
|
||
|
clearLists();
|
||
|
m_availItem = 0;
|
||
|
m_totalItem = 0;
|
||
|
}
|
||
|
|
||
|
void ResourceAppointmentsView::createSlaveItems() {
|
||
|
DoubleListViewBase::createSlaveItems();
|
||
|
setSlaveFormat(0, 'f', 1);
|
||
|
}
|
||
|
|
||
|
} //KPlato namespace
|
||
|
|
||
|
#include "kptresourceappointmentsview.moc"
|