kplato

kptappointment.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KPTAPPOINTMENT_H
00021 #define KPTAPPOINTMENT_H
00022 
00023 #include "kptduration.h"
00024 #include "kptdatetime.h"
00025 
00026 #include <qdom.h>
00027 #include <qintdict.h>
00028 #include <qstring.h>
00029 #include <qptrlist.h>
00030 
00031 #include <kdebug.h>
00032 
00033 class QTime;
00034 
00035 namespace KPlato
00036 {
00037 
00038 class Risk;
00039 class Effort;
00040 class Appointment;
00041 class Task;
00042 class Node;
00043 class Project;
00044 class Resource;
00045 class ResourceRequest;
00046 class ResourceGroupRequest;
00047 class Calendar;
00048 class ResourceRequestCollection;
00049 class EffortCostMap;
00050 class Schedule;
00051 
00052 
00053 
00054 class AppointmentInterval {
00055 public:
00056     AppointmentInterval();
00057     AppointmentInterval(const AppointmentInterval &AppointmentInterval);
00058     AppointmentInterval(const DateTime &start, const DateTime end, double load=100);
00059     ~AppointmentInterval();
00060     
00061     void set(DateTime &start, DateTime &end, double load=100);
00062     void set(DateTime &start, Duration &duration, double load=100);
00063     
00064     Duration effort() const { return (m_end - m_start) * m_load / 100; }
00065     Duration effort(const DateTime &start, const DateTime end) const;
00066     Duration effort(const DateTime &time, bool upto) const;
00067     
00068     bool loadXML(QDomElement &element);
00069     void saveXML(QDomElement &element) const;
00070     
00071     const DateTime &startTime() const { return m_start; }
00072     void setStartTime(const DateTime &time) { m_start = time; }
00073     const DateTime &endTime() const { return m_end; }
00074     void setEndTime(const DateTime &time) { m_end = time; }
00075     double load() const { return m_load; }
00076     void setLoad(double load) { m_load = load; }
00077     
00078     bool isValid() const;
00079     AppointmentInterval firstInterval(const AppointmentInterval &interval, const DateTime &from) const;
00080 
00081 private:
00082     DateTime m_start;
00083     DateTime m_end;
00084     double m_load; //percent
00085 };
00086 
00087 
00093 class AppointmentIntervalList : public QPtrList<AppointmentInterval> {
00094 protected:
00095     int compareItems(QPtrCollection::Item item1, QPtrCollection::Item item2) {
00096         AppointmentInterval *i1 = static_cast<AppointmentInterval*>(item1);
00097         AppointmentInterval *i2 = static_cast<AppointmentInterval*>(item2);
00098         if (i1->startTime() < i2->startTime()) {
00099             return -1;
00100         }
00101         if (i1->startTime() > i2->startTime()) {
00102             return 1;
00103         }
00104         if (i1->endTime() < i2->endTime()) {
00105             return -1;
00106         }
00107         if (i1->endTime() > i2->endTime()) {
00108             return 1;
00109         }
00110         return 0;
00111     }
00112 };
00113 typedef QPtrListIterator<AppointmentInterval> AppointmentIntervalListIterator;
00114 
00126 class Appointment {
00127 public:
00128     Appointment();
00129     Appointment(Schedule *resource, Schedule *node, DateTime start, DateTime end, double load);
00130     Appointment(Schedule *resource, Schedule *node, DateTime start, Duration duration, double load);
00131     ~Appointment();
00132 
00133     // get/set member values.
00134     Schedule *node() const { return m_node; }
00135     void setNode(Schedule *n) { m_node = n; }
00136 
00137     Schedule *resource() const { return m_resource; }
00138     void setResource(Schedule *r) { m_resource = r; }
00139 
00140     DateTime startTime() const;
00141     DateTime endTime() const;
00142     double maxLoad() const;
00143     
00144     const Duration &repeatInterval() const {return m_repeatInterval;}
00145     void setRepeatInterval(Duration ri) {m_repeatInterval=ri;}
00146 
00147     int repeatCount() const { return m_repeatCount; }
00148     void setRepeatCount(int rc) { m_repeatCount=rc; }
00149 
00150     void deleteAppointmentFromRepeatList(DateTime time);
00151     void addAppointmentToRepeatList(DateTime time);
00152 
00153     bool isBusy(const DateTime &start, const DateTime &end);
00154 
00156     bool attach();
00158     void detach();
00159     
00160     void addInterval(AppointmentInterval *a);
00161     void addInterval(AppointmentInterval &a) 
00162         { addInterval(new AppointmentInterval(a)); }
00163     void addInterval(const DateTime &start, const DateTime &end, double load=100);
00164     void addInterval(const DateTime &start, const Duration &duration, double load=100);
00165     
00166     const AppointmentIntervalList &intervals() const { return m_intervals; }
00167 
00168     bool loadXML(QDomElement &element, Project &project, Schedule &sch);
00169     void saveXML(QDomElement &element) const;
00170 
00175     EffortCostMap plannedPrDay(const QDate& start, const QDate& end) const;
00176     
00178     Duration effort(const DateTime &start, const DateTime &end) const;
00180     Duration effort(const DateTime &start, const Duration &duration) const;
00182     Duration effortFrom(const DateTime &time) const;
00183     
00185     Duration plannedEffort() const;
00187     Duration plannedEffort(const QDate &date) const;
00189     Duration plannedEffortTo(const QDate &date) const;
00190 
00192     Duration actualEffort() const;
00194     Duration actualEffort(const QDate &date) const;
00196     Duration actualEffortTo(const QDate &date) const;
00197 
00199     double plannedCost();
00201     double plannedCost(const QDate &date);
00203     double plannedCostTo(const QDate &date);
00204 
00206     double actualCost();
00208     double actualCost(const QDate &date);
00210     double actualCostTo(const QDate &date);
00211 
00212     Appointment &operator=(const Appointment &app);
00213     Appointment &operator+=(const Appointment &app);
00214     Appointment operator+(const Appointment &app);
00215     
00216     void addActualEffort(QDate date, Duration effort, bool overtime=false);
00217     
00218 private:
00219     Schedule *m_node;
00220     Schedule *m_resource;
00221     
00222     Duration m_repeatInterval;
00223     int m_repeatCount;
00224     QPtrList<Duration> m_extraRepeats;
00225     QPtrList<Duration> m_skipRepeats;
00226 
00227     AppointmentIntervalList m_intervals;
00228     
00229     class UsedEffortItem {
00230     public:
00231         UsedEffortItem(QDate date, Duration effort, bool overtime=false);
00232         QDate date();
00233         Duration effort();
00234         bool isOvertime();
00235     private:
00236         QDate m_date;
00237         Duration m_effort;
00238         bool m_overtime;
00239     };
00240     class UsedEffort : QPtrList<UsedEffortItem> {
00241     public:
00242         UsedEffort();
00243         ~UsedEffort() {}
00244         void inSort(QDate date, Duration effort, bool overtime=false);
00245         Duration usedEffort(bool includeOvertime=true) const;
00246         Duration usedEffort(const QDate &date, bool includeOvertime=true) const;
00247         Duration usedEffortTo(const QDate &date, bool includeOvertime=true) const;
00248         Duration usedOvertime() const;
00249         Duration usedOvertime(const QDate &date) const;
00250         Duration usedOvertimeTo(const QDate &date) const;
00251         bool load(QDomElement &element);
00252         void save(QDomElement &element) const;
00253     
00254     protected:
00255         int compareItems(QPtrCollection::Item item1, QPtrCollection::Item item2);
00256     };
00257     
00258     UsedEffort m_actualEffort;
00259 
00260 #ifndef NDEBUG
00261 public:
00262         void printDebug(QString ident);
00263 #endif
00264 };
00265 
00266 
00267 }  //KPlato namespace
00268 
00269 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys