1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/* This file is part of the KDE project
Copyright (C) 2005 Dag Andersen <[email protected]>
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 <tqapplication.h>
#include <kcalendarsystem.h>
#include <kglobal.h>
#include <klocale.h>
#include <tqdatetime.h>
#include <tqheader.h>
namespace KPlato
{
ResourceAppointmentsView::NodeItem::NodeItem(Node *t, TQListView *parent, bool highlight)
: DoubleListViewBase::MasterListItem(parent, t->name(), highlight),
node(t) {
setFormat(0, 'f', 1);
//kdDebug()<<k_funcinfo<<endl;
}
ResourceAppointmentsView::NodeItem::NodeItem(Node *t, TQListViewItem *p, bool highlight)
: DoubleListViewBase::MasterListItem(p, t->name(), highlight),
node(t) {
setFormat(0, 'f', 1);
//kdDebug()<<k_funcinfo<<endl;
}
ResourceAppointmentsView::NodeItem::NodeItem(TQString text, TQListViewItem *parent, bool highlight)
: DoubleListViewBase::MasterListItem(parent, text, highlight),
node(0) {
setFormat(0, 'f', 1);
//kdDebug()<<k_funcinfo<<endl;
}
ResourceAppointmentsView::NodeItem::NodeItem(TQString text, TQListView *parent, bool highlight)
: DoubleListViewBase::MasterListItem(parent, text, highlight),
node(0) {
setFormat(0, 'f', 1);
//kdDebug()<<k_funcinfo<<endl;
}
//-------------------------------------------
ResourceAppointmentsView::ResourceAppointmentsView(View *view, TQWidget *parent)
: DoubleListViewBase(parent),
m_mainview(view),
m_resource(0),
m_availItem(0),
m_totalItem(0) {
setNameHeader(i18n("Task"));
TQValueList<int> list = sizes();
int tot = list[0] + list[1];
list[0] = TQMIN(35, tot);
list[1] = tot-list[0];
setSizes(list);
}
void ResourceAppointmentsView::zoom(double zoom) {
Q_UNUSED(zoom);
}
void ResourceAppointmentsView::draw(Resource *resource, const TQDate &start, const TQDate &end) {
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());
TQPtrList<Appointment> lst = m_resource->appointments();
//kdDebug()<<k_funcinfo<<lst.count()<<endl;
TQPtrListIterator<Appointment> it(lst);
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;
TQApplication::setOverrideCursor(TQt::waitCursor);
createSlaveItems();
KLocale *locale = TDEGlobal::locale();
const KCalendarSystem *cal = locale->calendar();
const Calendar *resCal = m_resource->calendar();
const TQDateTime availFrom = m_resource->availableFrom();
const TQDateTime availUntil = m_resource->availableUntil();
// Add columns for selected period/periods
//kdDebug()<<k_funcinfo<<start.toString()<<" - "<<end.toString()<<endl;
int c=0;
for (TQDate dt = m_start; dt <= m_end; dt = cal->addDays(dt, 1), ++c) {
TQString df = locale->formatDate(dt, true);
addSlaveColumn(df);
}
if (m_totalItem) {
m_totalItem->setHighlight(true);
m_totalItem->setSlaveHighlight(true);
}
TQListViewItemIterator it(masterListView());
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;
for (TQDate d=m_start; d <= m_end; d = cal->addDays(d, 1), ++col) {
if (item == m_availItem && resCal) {
TQDateTime f(d);
TQDateTime u(d, TQTime(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()<<k_funcinfo<<"avail="<<m_availItem->value()<<endl;
}
calculate();
TQApplication::restoreOverrideCursor();
}
void ResourceAppointmentsView::print(KPrinter &/*printer*/) {
kdDebug()<<k_funcinfo<<endl;
}
// bool ResourceAppointmentsView::setContext(Context::ResourceAppointmentsView &context) {
// //kdDebug()<<k_funcinfo<<endl;
//
// TQValueList<int> list;
// list << context.accountsviewsize << context.periodviewsize;
// m_dlv->setSizes(list);
// m_date = context.date;
// if (!m_date.isValid())
// m_date = TQDate::currentDate();
// 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"
|