1/* This file is part of the KDE project
2 Copyright (C) 2001 Thomas Zander zander@kde.org
3 Copyright (C) 2004 - 2007 Dag Andersen <danders@get2net.dk>
4 Copyright (C) 2007 Florian Piquemal <flotueur@yahoo.fr>
5 Copyright (C) 2007 Alexis Ménard <darktears31@gmail.com>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22
23#ifndef KPTTASK_H
24#define KPTTASK_H
25
26#include "kplatokernel_export.h"
27
28#include "kptnode.h"
29#include "kptglobal.h"
30#include "kptdatetime.h"
31#include "kptduration.h"
32#include "kptresource.h"
33
34#include <QList>
35#include <QMap>
36#include <QPair>
37
38/// The main namespace.
39namespace KPlato
40{
41
42class Completion;
43
44/**
45 * The Completion class holds information about the tasks progress.
46 */
47class KPLATOKERNEL_EXPORT Completion
48{
49
50public:
51 class KPLATOKERNEL_EXPORT UsedEffort
52 {
53 public:
54 class KPLATOKERNEL_EXPORT ActualEffort : public QPair<Duration, Duration>
55 {
56 public:
57 explicit ActualEffort( const Duration &ne = Duration::zeroDuration, const Duration oe = Duration::zeroDuration )
58 : QPair<Duration, Duration>( ne, oe )
59 {}
60 ActualEffort( const ActualEffort &e )
61 : QPair<Duration, Duration>( e.first, e.second )
62 {}
63 ~ActualEffort() {}
64 Duration normalEffort() const { return first; }
65 void setNormalEffort( const Duration &e ) { first = e; }
66 Duration overtimeEffort() const { return second; }
67 void setOvertimeEffort( const Duration &e ) { second = e; }
68 /// Returns the sum of normalEffort + overtimeEffort
69 Duration effort() const { return first + second; }
70 void setEffort( const Duration &ne, const Duration &oe = Duration::zeroDuration ) { first = ne; second = oe; }
71 };
72 UsedEffort();
73 UsedEffort( const UsedEffort &e );
74 ~UsedEffort();
75 bool operator==( const UsedEffort &e ) const;
76 bool operator!=( const UsedEffort &e ) const { return !operator==( e ); }
77 void mergeEffort( const UsedEffort &value );
78 void setEffort( const QDate &date, const ActualEffort &value );
79 /// Returns the total effort up to @p date
80 Duration effortTo( const QDate &date ) const;
81 /// Returns the total effort on @p date
82 ActualEffort effort( const QDate &date ) const { return m_actual.value( date ); }
83 ActualEffort takeEffort( const QDate &date ) { return m_actual.take( date ); }
84 /// Returns the total effort for all registered dates
85 Duration effort() const;
86 QMap<QDate, ActualEffort> actualEffortMap() const { return m_actual; }
87
88 /// Load from document
89 bool loadXML(KoXmlElement &element, XMLLoaderObject &status );
90 /// Save to document
91 void saveXML(QDomElement &element) const;
92 bool contains( const QDate &date ) const { return m_actual.contains( date ); }
93
94 private:
95 QMap<QDate, ActualEffort> m_actual;
96 };
97 typedef QMap<QDate, UsedEffort::ActualEffort> DateUsedEffortMap;
98
99 class KPLATOKERNEL_EXPORT Entry
100 {
101 public:
102 Entry()
103 : percentFinished( 0 ),
104 remainingEffort( Duration::zeroDuration ),
105 totalPerformed( Duration::zeroDuration )
106 {}
107 Entry( int percent, Duration remaining, Duration performed )
108 : percentFinished( percent ),
109 remainingEffort( remaining ),
110 totalPerformed( performed )
111 {}
112 Entry( const Entry &e ) { copy( e ); }
113 bool operator==( const Entry &e ) const {
114 return percentFinished == e.percentFinished
115 && remainingEffort == e.remainingEffort
116 && totalPerformed == e.totalPerformed
117 && note == e.note;
118 }
119 bool operator!=( const Entry &e ) const { return ! operator==( e ); }
120 Entry &operator=(const Entry &e ) { copy( e ); return *this; }
121
122 int percentFinished;
123 Duration remainingEffort;
124 Duration totalPerformed;
125 QString note;
126 protected:
127 void copy( const Entry &e ) {
128 percentFinished = e.percentFinished;
129 remainingEffort = e.remainingEffort;
130 totalPerformed = e.totalPerformed;
131 note = e.note;
132 }
133 };
134 typedef QMap<QDate, Entry*> EntryList;
135
136 typedef QMap<const Resource*, UsedEffort*> ResourceUsedEffortMap;
137
138 explicit Completion( Node *node = 0 ); // review * or &, or at all?
139 Completion( const Completion &copy );
140 virtual ~Completion();
141
142 bool operator==(const Completion &p);
143 bool operator!=(Completion &p) { return !(*this == p); }
144 Completion &operator=(const Completion &p);
145
146 /// Load from document
147 bool loadXML(KoXmlElement &element, XMLLoaderObject &status );
148 /// Save to document
149 void saveXML(QDomElement &element) const;
150
151 bool startIsValid() const { return m_started && m_startTime.isValid(); }
152 bool isStarted() const { return m_started; }
153 void setStarted( bool on );
154 bool finishIsValid() const { return m_finished && m_finishTime.isValid(); }
155 bool isFinished() const { return m_finished; }
156 void setFinished( bool on );
157 DateTime startTime() const { return m_startTime; }
158 void setStartTime( const DateTime &dt );
159 DateTime finishTime() const { return m_finishTime; }
160 void setFinishTime( const DateTime &dt );
161 void setPercentFinished( const QDate &date, int value );
162 void setRemainingEffort( const QDate &date, const Duration &value );
163 void setActualEffort( const QDate &date, const Duration &value );
164
165 /// Return a list of the resource that has done any work on this task
166 QList<const Resource*> resources() { return m_usedEffort.keys(); }
167
168 const EntryList &entries() const { return m_entries; }
169 void addEntry( const QDate &date, Entry *entry );
170 Entry *takeEntry( const QDate &date ) { return m_entries.take( date ); changed(); }
171 Entry *entry( const QDate &date ) const { return m_entries[ date ]; }
172
173 /// Returns the date of the latest entry
174 QDate entryDate() const;
175 /// Returns the percentFinished of the latest entry
176 int percentFinished() const;
177 /// Returns the percentFinished on @p date
178 int percentFinished( const QDate &date ) const;
179 /// Returns the estimated remaining effort
180 Duration remainingEffort() const;
181 /// Returns the estimated remaining effort on @p date
182 Duration remainingEffort( const QDate &date ) const;
183 /// Returns the total actual effort
184 Duration actualEffort() const;
185 /// Returns the total actual effort on @p date
186 Duration actualEffort( const QDate &date ) const;
187 /// Returns the total actual effort upto and including @p date
188 Duration actualEffortTo( const QDate &date ) const;
189 /// Returns the actual effort for @p resource on @p date
190 Duration actualEffort( const Resource *resource, const QDate &date ) const;
191 /// TODO
192 QString note() const;
193 /// TODO
194 void setNote( const QString &str );
195
196 /// Returns the total actual cost
197 double actualCost() const;
198 /// Returns the actual cost for @p resource
199 double actualCost( const Resource *resource ) const;
200 /// Returns the actual cost on @p date
201 double actualCost( const QDate &date ) const;
202 /// Returns the total actual cost for @p resource on @p date
203 double actualCost( const Resource *resource, const QDate &date ) const;
204 /// Returns the total actual effort and cost upto and including @p date
205 EffortCost actualCostTo( long int id, const QDate &date ) const;
206
207 /**
208 * Returns a map of all actual effort and cost entered
209 */
210 virtual EffortCostMap actualEffortCost( long id, EffortCostCalculationType type = ECCT_All ) const;
211
212 void addUsedEffort( const Resource *resource, UsedEffort *value = 0 );
213 UsedEffort *takeUsedEffort( const Resource *r ) { return m_usedEffort.take( const_cast<Resource*>( r ) ); changed(); }
214 UsedEffort *usedEffort( const Resource *r ) const { return m_usedEffort.value( const_cast<Resource*>( r ) ); }
215 const ResourceUsedEffortMap &usedEffortMap() const { return m_usedEffort; }
216
217 void changed( int propert = -1 );
218 Node *node() const { return m_node; }
219 void setNode( Node *node ) { m_node = node; }
220
221 enum Entrymode { FollowPlan, EnterCompleted, EnterEffortPerTask, EnterEffortPerResource };
222 void setEntrymode( Entrymode mode ) { m_entrymode = mode; }
223 Entrymode entrymode() const { return m_entrymode; }
224 void setEntrymode( const QString &mode );
225 QString entryModeToString() const;
226 QStringList entrymodeList() const;
227
228 EffortCostMap effortCostPrDay(const QDate &start, const QDate &end, long id = -1 ) const;
229 /// Returns the actual effort and cost pr day used by @p resource
230 EffortCostMap effortCostPrDay(const Resource *resource, const QDate &start, const QDate &end, long id = CURRENTSCHEDULE ) const;
231
232protected:
233 void copy( const Completion &copy);
234 double averageCostPrHour( const QDate &date, long id ) const;
235 QPair<QDate, QDate> actualStartEndDates() const;
236
237private:
238 Node *m_node;
239 bool m_started, m_finished;
240 DateTime m_startTime, m_finishTime;
241 EntryList m_entries;
242 ResourceUsedEffortMap m_usedEffort;
243 Entrymode m_entrymode;
244
245#ifndef NDEBUG
246public:
247 void printDebug( const QByteArray &ident ) const;
248#endif
249};
250
251/**
252 * The WorkPackage class controls work flow for a task
253 */
254class KPLATOKERNEL_EXPORT WorkPackage
255{
256public:
257
258 /// @enum WPTransmitionStatus describes if this package was sent or received
259 enum WPTransmitionStatus {
260 TS_None, /// Not sent nor received
261 TS_Send, /// Package was sent to resource
262 TS_Receive /// Package was received from resource
263 };
264
265 explicit WorkPackage( Task *task = 0 );
266 explicit WorkPackage( const WorkPackage &wp );
267 virtual ~WorkPackage();
268
269 Task *parentTask() const { return m_task; }
270 void setParentTask( Task *task ) { m_task = task; }
271
272 /// Returns the transmission status of this package
273 WPTransmitionStatus transmitionStatus() const { return m_transmitionStatus; }
274 void setTransmitionStatus( WPTransmitionStatus sts ) { m_transmitionStatus = sts; }
275 static QString transmitionStatusToString( WPTransmitionStatus sts, bool trans = false );
276 static WPTransmitionStatus transmitionStatusFromString( const QString &sts );
277
278 /// Load from document
279 virtual bool loadXML(KoXmlElement &element, XMLLoaderObject &status );
280 /// Save the full workpackage
281 virtual void saveXML(QDomElement &element) const;
282
283 /// Load from document
284 virtual bool loadLoggedXML(KoXmlElement &element, XMLLoaderObject &status );
285 /// Save the full workpackage
286 virtual void saveLoggedXML(QDomElement &element) const;
287
288 /// Set schedule manager
289 void setScheduleManager( ScheduleManager *sm );
290 /// Return schedule manager
291 ScheduleManager *scheduleManager() const { return m_manager; }
292 /// Return the schedule id, or NOTSCHEDULED if no schedule manager is set
293 long id() const { return m_manager ? m_manager->scheduleId() : NOTSCHEDULED; }
294
295 Completion &completion();
296 const Completion &completion() const;
297
298 void addLogEntry( DateTime &dt, const QString &str );
299 QMap<DateTime, QString> log() const;
300 QStringList log();
301
302 /// Return a list of resources fetched from the appointements or requests
303 /// merged with resources added to completion
304 QList<Resource*> fetchResources();
305
306 /// Return a list of resources fetched from the appointements or requests
307 /// merged with resources added to completion
308 QList<Resource*> fetchResources( long id );
309
310 /// Returns id of the resource that owns this package. If empty, task leader owns it.
311 QString ownerId() const { return m_ownerId; }
312 /// Set the resource that owns this package to @p owner. If empty, task leader owns it.
313 void setOwnerId( const QString &id ) { m_ownerId = id; }
314
315 /// Returns the name of the resource that owns this package.
316 QString ownerName() const { return m_ownerName; }
317 /// Set the name of the resource that owns this package.
318 void setOwnerName( const QString &name ) { m_ownerName = name; }
319
320 DateTime transmitionTime() const { return m_transmitionTime; }
321 void setTransmitionTime( const DateTime &dt ) { m_transmitionTime = dt; }
322
323 /// Clear workpackage data
324 void clear();
325
326private:
327 Task *m_task;
328 ScheduleManager *m_manager;
329 Completion m_completion;
330 QString m_ownerName;
331 QString m_ownerId;
332 WPTransmitionStatus m_transmitionStatus;
333 DateTime m_transmitionTime;
334
335 QMap<DateTime, QString> m_log;
336};
337
338class KPLATOKERNEL_EXPORT WorkPackageSettings
339{
340public:
341 WorkPackageSettings();
342 bool loadXML( const KoXmlElement &element );
343 void saveXML( QDomElement &element) const;
344 bool operator==( const WorkPackageSettings &settings ) const;
345 bool operator!=( const WorkPackageSettings &settings ) const;
346 bool usedEffort;
347 bool progress;
348 bool documents;
349};
350
351/**
352 * A task in the scheduling software is represented by this class. A task
353 * can be anything from 'build house' to 'drill hole' It will always mean
354 * an activity.
355 */
356class KPLATOKERNEL_EXPORT Task : public Node {
357 Q_OBJECT
358public:
359 explicit Task(Node *parent = 0);
360 explicit Task(const Task &task, Node *parent = 0);
361 ~Task();
362
363 /// Return task type. Can be Type_Task, Type_Summarytask ot Type_Milestone.
364 virtual int type() const;
365
366 /**
367 * Instead of using the expected duration, generate a random value using
368 * the Distribution of each Task. This can be used for Monte-Carlo
369 * estimation of Project duration.
370 */
371 Duration *getRandomDuration();
372
373 /**
374 * Return the resource request made to group
375 * (There should be only one)
376 */
377 ResourceGroupRequest *resourceGroupRequest(const ResourceGroup *group) const;
378 void clearResourceRequests();
379 void addRequest(ResourceGroup *group, int numResources);
380 void addRequest(ResourceGroupRequest *request);
381 void takeRequest(ResourceGroupRequest *request);
382 void makeAppointments();
383 virtual QStringList requestNameList() const;
384 virtual QList<Resource*> requestedResources() const;
385 virtual bool containsRequest( const QString &/*identity*/ ) const;
386 virtual ResourceRequest *resourceRequest( const QString &/*name*/ ) const;
387
388 /// Return the list of resources assigned to this task
389 virtual QStringList assignedNameList( long id = CURRENTSCHEDULE ) const;
390
391 /**
392 * Calculates if the assigned resource is overbooked
393 * within the duration of this task
394 */
395 void calcResourceOverbooked();
396
397 /// Load from document
398 virtual bool load(KoXmlElement &element, XMLLoaderObject &status );
399 /// Save to document
400 virtual void save(QDomElement &element) const;
401 /// Save appointments for schedule with id
402 virtual void saveAppointments(QDomElement &element, long id) const;
403
404 /// Save a workpackage document with schedule identity @p id
405 void saveWorkPackageXML( QDomElement &element, long id ) const;
406
407 /**
408 * Returns a list of planned effort and cost for this task
409 * for the interval start, end inclusive
410 */
411 virtual EffortCostMap plannedEffortCostPrDay(const QDate &start, const QDate &end, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
412 /**
413 * Returns a list of planned effort and cost for the @p resource
414 * for the interval @p start, @p end inclusive, useing schedule with identity @p id
415 */
416 virtual EffortCostMap plannedEffortCostPrDay(const Resource *resource, const QDate &start, const QDate &end, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
417
418 /// Returns the total planned effort for @p reosurce on this task (or subtasks)
419 virtual Duration plannedEffort( const Resource *resource, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
420 /// Returns the total planned effort for this task (or subtasks)
421 virtual Duration plannedEffort( long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
422 /// Returns the total planned effort for this task (or subtasks) on date
423 virtual Duration plannedEffort(const QDate &date, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
424 /// Returns the total planned effort for @p resource on this task (or subtasks) on date
425 virtual Duration plannedEffort( const Resource *resource, const QDate &date, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
426 /// Returns the planned effort up to and including date
427 virtual Duration plannedEffortTo(const QDate &date, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
428 /// Returns the planned effort for @p resource up to and including date
429 virtual Duration plannedEffortTo( const Resource *resource, const QDate &date, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
430
431 /// Returns the total actual effort for this task (or subtasks)
432 virtual Duration actualEffort() const;
433 /// Returns the total actual effort for this task (or subtasks) on date
434 virtual Duration actualEffort(const QDate &date ) const;
435 /// Returns the actual effort up to and including date
436 virtual Duration actualEffortTo(const QDate &date ) const;
437
438 /**
439 * Returns the total planned cost for this task (or subtasks)
440 */
441 virtual EffortCost plannedCost( long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
442 /// Planned cost up to and including date
443 virtual double plannedCostTo(const QDate &/*date*/, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
444
445 /// Returns actual effort and cost up to and including @p date
446 virtual EffortCost actualCostTo( long int id, const QDate &date ) const;
447
448 /**
449 * Returns a list of actual effort and cost for this task
450 * for the interval start, end inclusive
451 */
452 virtual EffortCostMap actualEffortCostPrDay( const QDate &start, const QDate &end, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
453 /// Returns the actual effort and cost pr day used by @p resource
454 virtual EffortCostMap actualEffortCostPrDay( const Resource *resource, const QDate &start, const QDate &end, long id = CURRENTSCHEDULE, EffortCostCalculationType = ECCT_All ) const;
455
456 /// Returns the effort planned to be used to reach the actual percent finished
457 virtual Duration budgetedWorkPerformed( const QDate &date, long id = CURRENTSCHEDULE ) const;
458
459 /// Returns the cost planned to be used to reach the actual percent finished
460 virtual double budgetedCostPerformed( const QDate &date, long id = CURRENTSCHEDULE ) const;
461
462 using Node::bcwsPrDay;
463 /// Return map of Budgeted Cost of Work Scheduled pr day
464 virtual EffortCostMap bcwsPrDay( long id = CURRENTSCHEDULE, EffortCostCalculationType type = ECCT_All );
465
466 /// Budgeted Cost of Work Scheduled
467 virtual double bcws( const QDate &date, long id = CURRENTSCHEDULE ) const;
468
469 using Node::bcwpPrDay;
470 /// Return map of Budgeted Cost of Work Performed pr day (also includes bcwsPrDay)
471 virtual EffortCostMap bcwpPrDay( long id = CURRENTSCHEDULE, EffortCostCalculationType type = ECCT_All );
472 /// Budgeted Cost of Work Performed
473 virtual double bcwp( long id = CURRENTSCHEDULE ) const;
474 /// Budgeted Cost of Work Performed ( up to @p date )
475 virtual double bcwp( const QDate &date, long id = CURRENTSCHEDULE ) const;
476
477 using Node::acwp;
478 /// Map of Actual Cost of Work Performed
479 virtual EffortCostMap acwp( long id = CURRENTSCHEDULE, EffortCostCalculationType type = ECCT_All );
480 /// Actual Cost of Work Performed up to dat
481 virtual EffortCost acwp( const QDate &date, long id = CURRENTSCHEDULE ) const;
482
483 /// Effort based performance index
484 virtual double effortPerformanceIndex( const QDate &date, long id = CURRENTSCHEDULE ) const;
485
486 /// Schedule performance index
487 virtual double schedulePerformanceIndex( const QDate &date, long id = CURRENTSCHEDULE ) const;
488 /// Cost performance index
489 virtual double costPerformanceIndex( long int id, const QDate &date, bool *error=0 ) const;
490
491 /**
492 * Return the duration that an activity's start can be delayed
493 * without affecting the project completion date.
494 * An activity with positive float is not on the critical path.
495 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
496 */
497 Duration positiveFloat( long id = CURRENTSCHEDULE ) const;
498 void setPositiveFloat( const Duration &fl, long id = CURRENTSCHEDULE ) const;
499 /**
500 * Return the duration by which the duration of an activity or path
501 * has to be reduced in order to fullfil a timing- or dependency constraint.
502 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
503 */
504 Duration negativeFloat( long id = CURRENTSCHEDULE ) const;
505 void setNegativeFloat( const Duration &fl, long id = CURRENTSCHEDULE ) const;
506 /**
507 * Return the duration by which an activity can be delayed or extended
508 * without affecting the start of any succeeding activity.
509 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
510 */
511 Duration freeFloat( long id = CURRENTSCHEDULE ) const;
512 void setFreeFloat( const Duration &fl, long id = CURRENTSCHEDULE ) const;
513 /**
514 * Return the duration from Early Start to Late Start.
515 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
516 */
517 Duration startFloat( long id = CURRENTSCHEDULE ) const;
518 /**
519 * Return the duration from Early Finish to Late Finish.
520 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
521 */
522 Duration finishFloat( long id = CURRENTSCHEDULE ) const;
523
524 /**
525 * A task is critical if positive float equals 0
526 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
527 */
528 virtual bool isCritical( long id = CURRENTSCHEDULE ) const;
529
530 /**
531 * Set current schedule to schedule with identity id, for me and my children.
532 * @param id Schedule identity
533 */
534 virtual void setCurrentSchedule(long id);
535
536 /**
537 * The assigned resources can not fullfil the estimated effort.
538 * @param id Schedule identity. If id is CURRENTSCHEDULE, use current schedule.
539 */
540 virtual bool effortMetError( long id = CURRENTSCHEDULE ) const;
541
542 Completion &completion() { return m_workPackage.completion(); }
543 const Completion &completion() const { return m_workPackage.completion(); }
544
545 WorkPackage &workPackage() { return m_workPackage; }
546 const WorkPackage &workPackage() const { return m_workPackage; }
547
548 int workPackageLogCount() const { return m_packageLog.count(); }
549 QList<WorkPackage*> workPackageLog() const { return m_packageLog; }
550 void addWorkPackage( WorkPackage *wp );
551 void removeWorkPackage( WorkPackage *wp );
552 WorkPackage *workPackageAt( int index ) const;
553
554 QString wpOwnerName() const;
555 WorkPackage::WPTransmitionStatus wpTransmitionStatus() const;
556 DateTime wpTransmitionTime() const;
557
558 /**
559 * Returns the state of the task
560 * @param id The identity of the schedule used when calculating the state
561 */
562 virtual uint state( long id = CURRENTSCHEDULE ) const;
563
564 /// Check if this node has any dependent child nodes
565 virtual bool isEndNode() const;
566 /// Check if this node has any dependent parent nodes
567 virtual bool isStartNode() const;
568
569 QList<Relation*> parentProxyRelations() const { return m_parentProxyRelations; }
570 QList<Relation*> childProxyRelations() const { return m_childProxyRelations; }
571
572 /**
573 * Calculates and returns the duration of the node.
574 * Uses the correct expected-, optimistic- or pessimistic effort
575 * dependent on @p use.
576 * @param time Where to start calculation.
577 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
578 * @param backward If true, time specifies when the task should end.
579 */
580 virtual Duration duration(const DateTime &time, int use, bool backward);
581
582 /**
583 * Return the duration calculated on bases of the estimates calendar
584 */
585 Duration length(const DateTime &time, const Duration &duration, bool backward);
586 Duration length(const DateTime &time, const Duration &duration, Schedule *sch, bool backward);
587
588 /// Copy info from parent schedule
589 void copySchedule();
590 /// Copy intervals from parent schedule
591 void copyAppointments();
592 /// Copy intervals from parent schedule in the range @p start, @p end
593 void copyAppointments( const DateTime &start, const DateTime &end = DateTime() );
594
595signals:
596 void workPackageToBeAdded( Node *node, int row );
597 void workPackageAdded( Node *node );
598 void workPackageToBeRemoved( Node *node, int row );
599 void workPackageRemoved( Node *node );
600
601public:
602 virtual void initiateCalculation(MainSchedule &sch);
603 /**
604 * Sets up the lists used for calculation.
605 * This includes adding summarytasks relations to subtasks
606 * and lists for start- and endnodes.
607 */
608 virtual void initiateCalculationLists(MainSchedule &sch);
609 /**
610 * Calculates early start and early finish, first for all predeccessors,
611 * then for this task.
612 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
613 */
614 virtual DateTime calculateForward(int use);
615 /**
616 * Calculates ref m_durationForward from ref earliestStart and
617 * returns the resulting end time (early finish),
618 * which will be used as the successors ref earliestStart.
619 *
620 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
621 */
622 virtual DateTime calculateEarlyFinish(int use);
623 /**
624 * Calculates late start and late finish, first for all successors,
625 * then for this task.
626 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
627 */
628 virtual DateTime calculateBackward(int use);
629 /**
630 * Calculates ref m_durationBackward from ref latestFinish and
631 * returns the resulting start time (late start),
632 * which will be used as the predecessors ref latestFinish.
633 *
634 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
635 */
636 virtual DateTime calculateLateStart(int use);
637 /**
638 * Schedules the task within the limits of earliestStart and latestFinish.
639 * Calculates ref m_startTime, ref m_endTime and ref m_duration,
640 * Assumes ref calculateForward() and ref calculateBackward() has been run.
641 *
642 * @param earliest The task is not scheduled to start earlier than this
643 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
644 * @return The tasks endtime which can be used for scheduling the successor.
645 */
646 virtual DateTime scheduleForward(const DateTime &earliest, int use);
647 /**
648 * Schedules the task within the limits of start time and latestFinish,
649 * Calculates end time and duration.
650 * Assumes ref calculateForward() and ref calculateBackward() has been run.
651 *
652 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
653 * @return The tasks endtime which can be used for scheduling the successor.
654 */
655 virtual DateTime scheduleFromStartTime(int use);
656 /**
657 * Schedules the task within the limits of earliestStart and latestFinish.
658 * Calculates ref m_startTime, ref m_endTime and ref m_duration,
659 * Assumes ref calculateForward() and ref calculateBackward() has been run.
660 *
661 * @param latest The task is not scheduled to end later than this
662 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
663 * @return The tasks starttime which can be used for scheduling the predeccessor.
664 */
665 virtual DateTime scheduleBackward(const DateTime &latest, int use);
666 /**
667 * Schedules the task within the limits of end time and latestFinish.
668 * Calculates endTime and duration.
669 * Assumes ref calculateForward() and ref calculateBackward() has been run.
670 *
671 * @param latest The task is not scheduled to end later than this
672 * @param use Calculate using expected-, optimistic- or pessimistic estimate.
673 * @return The tasks starttime which can be used for scheduling the predeccessor.
674 */
675 virtual DateTime scheduleFromEndTime(int use);
676
677 /**
678 * Summarytasks (with milestones) need special treatment because
679 * milestones are always 'glued' to their predecessors.
680 */
681 virtual void adjustSummarytask();
682
683 /// Calculate the critical path
684 virtual bool calcCriticalPath(bool fromEnd);
685 virtual void calcFreeFloat();
686
687 // Proxy relations are relations to/from summarytasks.
688 // These relations are distributed to the child tasks before calculation.
689 virtual void clearProxyRelations();
690 virtual void addParentProxyRelations( const QList<Relation*> & );
691 virtual void addChildProxyRelations( const QList<Relation*> & );
692 virtual void addParentProxyRelation(Node *, const Relation *);
693 virtual void addChildProxyRelation(Node *, const Relation *);
694
695public:
696 DateTime earlyStartDate();
697 void setEarlyStartDate(DateTime value);
698
699 DateTime earlyFinishDate();
700 void setEarlyFinishDate(DateTime value);
701
702 DateTime lateStartDate();
703 void setLateStartDate(DateTime value);
704
705 DateTime lateFinishDate();
706 void setLateFinishDate(DateTime value);
707
708 int activitySlack();
709 void setActivitySlack(int value);
710
711 int activityFreeMargin();
712 void setActivityFreeMargin(int value);
713
714protected:
715 /**
716 * Return the duration calculated on bases of the requested resources
717 */
718 Duration calcDuration(const DateTime &time, const Duration &effort, bool backward);
719
720private:
721 DateTime calculateSuccessors(const QList<Relation*> &list, int use);
722 DateTime calculatePredeccessors(const QList<Relation*> &list, int use);
723 DateTime scheduleSuccessors(const QList<Relation*> &list, int use);
724 DateTime schedulePredeccessors(const QList<Relation*> &list, int use);
725
726 /// Fixed duration: Returns @p dt
727 /// Duration with calendar: Returns first available after @p dt
728 /// Has working resource(s) allocated: Returns the earliest time a resource can start work after @p dt, and checks appointments if @p sch is not null.
729 DateTime workTimeAfter(const DateTime &dt, Schedule *sch = 0) const;
730 /// Fixed duration: Returns @p dt
731 /// Duration with calendar: Returns first available before @p dt
732 /// Has working resource(s) allocated: Returns the latest time a resource can finish work, and checks appointments if @p sch is not null.
733 DateTime workTimeBefore(const DateTime &dt, Schedule *sch = 0) const;
734
735private:
736 QList<ResourceGroup*> m_resource;
737
738 QList<Relation*> m_parentProxyRelations;
739 QList<Relation*> m_childProxyRelations;
740
741 // This list store pointers to linked task
742 QList<Node*> m_requiredTasks;
743
744 WorkPackage m_workPackage;
745 QList<WorkPackage*> m_packageLog;
746
747 bool m_calculateForwardRun;
748 bool m_calculateBackwardRun;
749 bool m_scheduleForwardRun;
750 bool m_scheduleBackwardRun;
751};
752
753} //KPlato namespace
754
755Q_DECLARE_METATYPE( KPlato::Completion::UsedEffort::ActualEffort )
756
757#ifndef QT_NO_DEBUG_STREAM
758KPLATOKERNEL_EXPORT QDebug operator<<( QDebug dbg, const KPlato::Completion::UsedEffort::ActualEffort &ae );
759#endif
760
761#endif
762