F:/KPlato/koffice/kplato/kptresourceappointmentsview.cc

Aller à la documentation de ce fichier.
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; either
00007    version 2 of the License, or (at your option) any later version.
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 #include "kptresourceappointmentsview.h"
00021 
00022 #include "kptappointment.h"
00023 #include "kptcalendar.h"
00024 #include "kptnode.h"
00025 #include "kptresource.h"
00026 #include "kptview.h"
00027 
00028 #include <QApplication>
00029 #include <QDateTime>
00030 #include <QList>
00031 
00032 #include <kcalendarsystem.h>
00033 #include <kglobal.h>
00034 #include <klocale.h>
00035 
00036 namespace KPlato
00037 {
00038 
00039 ResourceAppointmentsView::NodeItem::NodeItem(Node *t, QTreeWidget *parent, bool highlight)
00040     : DoubleListViewBase::MasterListItem(parent, t->name(), highlight),
00041       node(t) {
00042       
00043       setFormat(0, 'f', 1);
00044     //kDebug()<<k_funcinfo<<endl;
00045 }
00046 ResourceAppointmentsView::NodeItem::NodeItem(Node *t, QTreeWidgetItem *p, bool highlight)
00047     : DoubleListViewBase::MasterListItem(p, t->name(), highlight),
00048       node(t) {
00049       
00050       setFormat(0, 'f', 1);
00051     //kDebug()<<k_funcinfo<<endl;
00052 }
00053 
00054 ResourceAppointmentsView::NodeItem::NodeItem(QString text, QTreeWidgetItem *parent, bool highlight)
00055     : DoubleListViewBase::MasterListItem(parent, text, highlight),
00056       node(0) {
00057       
00058       setFormat(0, 'f', 1);
00059     //kDebug()<<k_funcinfo<<endl;
00060 }
00061 
00062 ResourceAppointmentsView::NodeItem::NodeItem(QString text, QTreeWidget *parent, bool highlight)
00063     : DoubleListViewBase::MasterListItem(parent, text, highlight),
00064       node(0) {
00065       
00066       setFormat(0, 'f', 1);
00067     //kDebug()<<k_funcinfo<<endl;
00068 }
00069 
00070 //-------------------------------------------
00071 ResourceAppointmentsView::ResourceAppointmentsView(View *view, QWidget *parent)
00072     : DoubleListViewBase(parent),
00073       m_mainview(view),
00074       m_resource(0),
00075       m_availItem(0),
00076       m_totalItem(0) {
00077     
00078     setNameHeader(i18n("Task"));
00079     
00080     
00081     QList<int> list = sizes();
00082     int tot = list[0] + list[1];
00083     list[0] = qMin(35, tot);
00084     list[1] = tot-list[0];
00085     setSizes(list);
00086 }
00087 
00088 void ResourceAppointmentsView::zoom(double zoom) {
00089     Q_UNUSED(zoom);
00090 }
00091 
00092 
00093 void ResourceAppointmentsView::draw(Resource *resource, const QDate &start, const QDate &end) {
00094     m_resource = resource;
00095     m_start = start;
00096     m_end = end;
00097     draw();
00098 }
00099 
00100 void ResourceAppointmentsView::draw() {
00101     //kDebug()<<k_funcinfo<<m_resource->name()<<": "<<m_start<< " - "<<m_end<<endl;
00102     clear();
00103     if (!m_resource)
00104         return;
00105     
00106     m_totalItem = new ResourceAppointmentsView::NodeItem(i18n("Total"), masterListView());
00107 //    m_totalItem->setExpandable(true);
00108 //    m_totalItem->setOpen(true);
00109     m_availItem = new ResourceAppointmentsView::NodeItem(i18n("Available"), masterListView());
00110     QList<Appointment*> lst = m_resource->appointments();
00111     //kDebug()<<k_funcinfo<<lst.count()<<endl;
00112     foreach (Appointment* a, lst) {
00113         //kDebug()<<k_funcinfo<<endl;
00114         Node *n = a->node()->node();
00115         ResourceAppointmentsView::NodeItem *item = new ResourceAppointmentsView::NodeItem(n, m_totalItem);
00116         
00117         item->effortMap = a->plannedPrDay(m_start, m_end);
00118     }
00119     slotUpdate();
00120 }
00121 
00122 void ResourceAppointmentsView::slotUpdate() {
00123     //kDebug()<<k_funcinfo<<endl;
00124     if (!m_resource)
00125         return;
00126     QApplication::setOverrideCursor(Qt::WaitCursor);
00127     createSlaveItems();
00128     KLocale *locale = KGlobal::locale();
00129     const KCalendarSystem *cal = locale->calendar();
00130     const Calendar *resCal = m_resource->calendar();
00131     const QDateTime availFrom = m_resource->availableFrom();
00132     const QDateTime availUntil = m_resource->availableUntil();
00133     // Add columns for selected period/periods
00134     //kDebug()<<k_funcinfo<<start<<" - "<<end<<endl;
00135     QStringList df;
00136     for (QDate dt = m_start; dt <= m_end; dt = cal->addDays(dt, 1)) {
00137         df << locale->formatDate(dt, true);
00138     }
00139     setSlaveLabels(df);
00140     if (m_totalItem) {
00141         m_totalItem->setHighlight(true);
00142         m_totalItem->setSlaveHighlight(true);
00143     }
00144     foreach (QTreeWidgetItem *i, masterItems()) {
00145         ResourceAppointmentsView::NodeItem *item = static_cast<ResourceAppointmentsView::NodeItem*>(i);
00146         if (!item || item->child(0)) {
00147             continue;
00148         }
00149         double eff;
00150         double avail;
00151         int col=0;
00152         for (QDate d=m_start; d <= m_end; d = cal->addDays(d, 1), ++col) {
00153             if (item == m_availItem && resCal) {
00154                 QDateTime f(d);
00155                 QDateTime u(d, QTime(23, 59, 59, 999));
00156                 if (f >= availUntil || u <= availFrom) {
00157                     avail = 0.0;
00158                 } else {
00159                     if (availFrom > f) {
00160                         f = availFrom;
00161                     }
00162                     if (availUntil < u) {
00163                         u = availUntil;
00164                     }
00165                     avail = ((double)(resCal->effort(f.date(), f.time(), u.time())*(double)(m_resource->units())/100.0).minutes()/60.0);
00166                 }
00167                 m_availItem->setSlaveItem(col, avail);
00168                 m_availItem->addToTotal(avail);
00169                 if (m_totalItem) {
00170                     m_totalItem->setSlaveLimit(col, avail);
00171                 }
00172             }
00173             if (item != m_availItem) {
00174                 eff = (double)(item->effortMap.effortOnDate(d).minutes())/60.0;
00175                 item->setSlaveItem(col, eff);
00176                 item->addToTotal(eff);
00177             }
00178         }
00179     }
00180     if (m_totalItem && m_availItem) {
00181         m_totalItem->setLimit(m_availItem->value());
00182         //kDebug()<<k_funcinfo<<"avail="<<m_availItem->value()<<endl;
00183     }
00184     calculate();
00185     QApplication::restoreOverrideCursor();
00186 }
00187 
00188 
00189 void ResourceAppointmentsView::print(KPrinter &/*printer*/) {
00190     kDebug()<<k_funcinfo<<endl;
00191 }
00192 
00193 // bool ResourceAppointmentsView::setContext(Context::ResourceAppointmentsView &context) {
00194 //     //kDebug()<<k_funcinfo<<endl;
00195 //     
00196 //     QValueList<int> list;
00197 //     list << context.accountsviewsize << context.periodviewsize;
00198 //     m_dlv->setSizes(list);
00199 //     m_date = context.date;
00200 //     if (!m_date.isValid())
00201 //         m_date = QDate::currentDate();
00202 //     m_period = context.period;
00203 //     m_cumulative = context.cumulative;
00204 //     
00205 //     return true;
00206 // }
00207 // 
00208 // void ResourceAppointmentsView::getContext(Context::ResourceAppointmentsView &context) const {
00209 //     //kDebug()<<k_funcinfo<<endl;
00210 //     context.accountsviewsize = m_dlv->sizes()[0];
00211 //     context.periodviewsize = m_dlv->sizes()[1];
00212 //     context.date = m_date;
00213 //     context.period = m_period;
00214 //     context.cumulative = m_cumulative;
00215 //     //kDebug()<<k_funcinfo<<"sizes="<<sizes()[0]<<","<<sizes()[1]<<endl;
00216 // }
00217 
00218 void ResourceAppointmentsView::clear() {
00219     clearLists();
00220     m_availItem = 0;
00221     m_totalItem = 0;
00222 }
00223 
00224 void ResourceAppointmentsView::createSlaveItems() {
00225     DoubleListViewBase::createSlaveItems();
00226     setSlaveFormat(0, 'f', 1);
00227 }
00228 
00229 }  //KPlato namespace
00230 
00231 #include "kptresourceappointmentsview.moc"

Généré le Wed Nov 22 23:40:57 2006 pour KPlato par  doxygen 1.5.1-p1