kplato

kptappointment.h
1/* This file is part of the KDE project
2 Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KPTAPPOINTMENT_H
21#define KPTAPPOINTMENT_H
22
23#include "kptduration.h"
24#include "kptdatetime.h"
25
26#include <tqdom.h>
27#include <tqintdict.h>
28#include <tqstring.h>
29#include <tqptrlist.h>
30
31#include <kdebug.h>
32
33class TQTime;
34
35namespace KPlato
36{
37
38class Risk;
39class Effort;
40class Appointment;
41class Task;
42class Node;
43class Project;
44class Resource;
45class ResourceRequest;
46class ResourceGroupRequest;
47class Calendar;
48class ResourceRequestCollection;
49class EffortCostMap;
50class Schedule;
51
52
53
54class AppointmentInterval {
55public:
56 AppointmentInterval();
57 AppointmentInterval(const AppointmentInterval &AppointmentInterval);
58 AppointmentInterval(const DateTime &start, const DateTime end, double load=100);
59 ~AppointmentInterval();
60
61 void set(DateTime &start, DateTime &end, double load=100);
62 void set(DateTime &start, Duration &duration, double load=100);
63
64 Duration effort() const { return (m_end - m_start) * m_load / 100; }
65 Duration effort(const DateTime &start, const DateTime end) const;
66 Duration effort(const DateTime &time, bool upto) const;
67
68 bool loadXML(TQDomElement &element);
69 void saveXML(TQDomElement &element) const;
70
71 const DateTime &startTime() const { return m_start; }
72 void setStartTime(const DateTime &time) { m_start = time; }
73 const DateTime &endTime() const { return m_end; }
74 void setEndTime(const DateTime &time) { m_end = time; }
75 double load() const { return m_load; }
76 void setLoad(double load) { m_load = load; }
77
78 bool isValid() const;
79 AppointmentInterval firstInterval(const AppointmentInterval &interval, const DateTime &from) const;
80
81private:
82 DateTime m_start;
83 DateTime m_end;
84 double m_load; //percent
85};
86
87
93class AppointmentIntervalList : public TQPtrList<AppointmentInterval> {
94protected:
95 int compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2) {
96 AppointmentInterval *i1 = static_cast<AppointmentInterval*>(item1);
97 AppointmentInterval *i2 = static_cast<AppointmentInterval*>(item2);
98 if (i1->startTime() < i2->startTime()) {
99 return -1;
100 }
101 if (i1->startTime() > i2->startTime()) {
102 return 1;
103 }
104 if (i1->endTime() < i2->endTime()) {
105 return -1;
106 }
107 if (i1->endTime() > i2->endTime()) {
108 return 1;
109 }
110 return 0;
111 }
112};
113typedef TQPtrListIterator<AppointmentInterval> AppointmentIntervalListIterator;
114
127public:
128 Appointment();
129 Appointment(Schedule *resource, Schedule *node, DateTime start, DateTime end, double load);
130 Appointment(Schedule *resource, Schedule *node, DateTime start, Duration duration, double load);
131 ~Appointment();
132
133 // get/set member values.
134 Schedule *node() const { return m_node; }
135 void setNode(Schedule *n) { m_node = n; }
136
137 Schedule *resource() const { return m_resource; }
138 void setResource(Schedule *r) { m_resource = r; }
139
140 DateTime startTime() const;
141 DateTime endTime() const;
142 double maxLoad() const;
143
144 const Duration &repeatInterval() const {return m_repeatInterval;}
145 void setRepeatInterval(Duration ri) {m_repeatInterval=ri;}
146
147 int repeatCount() const { return m_repeatCount; }
148 void setRepeatCount(int rc) { m_repeatCount=rc; }
149
150 void deleteAppointmentFromRepeatList(DateTime time);
151 void addAppointmentToRepeatList(DateTime time);
152
153 bool isBusy(const DateTime &start, const DateTime &end);
154
156 bool attach();
158 void detach();
159
160 void addInterval(AppointmentInterval *a);
161 void addInterval(AppointmentInterval &a)
162 { addInterval(new AppointmentInterval(a)); }
163 void addInterval(const DateTime &start, const DateTime &end, double load=100);
164 void addInterval(const DateTime &start, const Duration &duration, double load=100);
165
166 const AppointmentIntervalList &intervals() const { return m_intervals; }
167
168 bool loadXML(TQDomElement &element, Project &project, Schedule &sch);
169 void saveXML(TQDomElement &element) const;
170
175 EffortCostMap plannedPrDay(const TQDate& start, const TQDate& end) const;
176
178 Duration effort(const DateTime &start, const DateTime &end) const;
180 Duration effort(const DateTime &start, const Duration &duration) const;
182 Duration effortFrom(const DateTime &time) const;
183
185 Duration plannedEffort() const;
187 Duration plannedEffort(const TQDate &date) const;
189 Duration plannedEffortTo(const TQDate &date) const;
190
192 Duration actualEffort() const;
194 Duration actualEffort(const TQDate &date) const;
196 Duration actualEffortTo(const TQDate &date) const;
197
199 double plannedCost();
201 double plannedCost(const TQDate &date);
203 double plannedCostTo(const TQDate &date);
204
206 double actualCost();
208 double actualCost(const TQDate &date);
210 double actualCostTo(const TQDate &date);
211
212 Appointment &operator=(const Appointment &app);
213 Appointment &operator+=(const Appointment &app);
214 Appointment operator+(const Appointment &app);
215
216 void addActualEffort(TQDate date, Duration effort, bool overtime=false);
217
218private:
219 Schedule *m_node;
220 Schedule *m_resource;
221
222 Duration m_repeatInterval;
223 int m_repeatCount;
224 TQPtrList<Duration> m_extraRepeats;
225 TQPtrList<Duration> m_skipRepeats;
226
227 AppointmentIntervalList m_intervals;
228
229 class UsedEffortItem {
230 public:
231 UsedEffortItem(TQDate date, Duration effort, bool overtime=false);
232 TQDate date();
233 Duration effort();
234 bool isOvertime();
235 private:
236 TQDate m_date;
237 Duration m_effort;
238 bool m_overtime;
239 };
240 class UsedEffort : TQPtrList<UsedEffortItem> {
241 public:
242 UsedEffort();
243 ~UsedEffort() {}
244 void inSort(TQDate date, Duration effort, bool overtime=false);
245 Duration usedEffort(bool includeOvertime=true) const;
246 Duration usedEffort(const TQDate &date, bool includeOvertime=true) const;
247 Duration usedEffortTo(const TQDate &date, bool includeOvertime=true) const;
248 Duration usedOvertime() const;
249 Duration usedOvertime(const TQDate &date) const;
250 Duration usedOvertimeTo(const TQDate &date) const;
251 bool load(TQDomElement &element);
252 void save(TQDomElement &element) const;
253
254 protected:
255 int compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2);
256 };
257
258 UsedEffort m_actualEffort;
259
260#ifndef NDEBUG
261public:
262 void printDebug(TQString ident);
263#endif
264};
265
266
267} //KPlato namespace
268
269#endif
This list is sorted after 1) startdatetime, 2) enddatetime.
A resource (Resource) can be scheduled to be used at any time, this is represented internally with Ap...
Duration effortFrom(const DateTime &time) const
Returns the planned effort from time onwards.
void detach()
detach appointment from resource and node
EffortCostMap plannedPrDay(const TQDate &start, const TQDate &end) const
Returns the planned effort and cost for the interval start to end (inclusive).
double plannedCost()
Calculates the total planned cost for this appointment.
double actualCost()
Calculates the total actual cost for this appointment.
double actualCostTo(const TQDate &date)
Calculates the actual cost upto and including date.
Duration plannedEffort() const
Returns the total planned effort for this appointment.
bool attach()
attach appointment to resource and node
Duration actualEffortTo(const TQDate &date) const
Returns the actual effort on the date.
Duration effort(const DateTime &start, const DateTime &end) const
Returns the planned effort from start to end.
Duration plannedEffortTo(const TQDate &date) const
Returns the planned effort upto and including date.
Duration actualEffort() const
Returns the total actual effort for this appointment.
double plannedCostTo(const TQDate &date)
Calculates the planned cost upto and including date.
DateTime is a TQDateTime which knows about Duration.
Definition kptdatetime.h:33
The duration class can be used to store a timespan in a convenient format.
Definition kptduration.h:34
Project is the main node in a project, it contains child nodes and possibly sub-projects.
Definition kptproject.h:52
The Schedule class holds data calculated during project calculation and scheduling,...
Definition kptschedule.h:55