F:/KPlato/koffice/kplato/kpttaskappointmentsview.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 "kpttaskappointmentsview.h"
00021 
00022 #include "kptappointment.h"
00023 #include "kpttask.h"
00024 
00025 #include <QApplication>
00026 #include <QList>
00027 
00028 #include <kcalendarsystem.h>
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 
00032 namespace KPlato
00033 {
00034 
00035 TaskAppointmentsView::ResourceItem::ResourceItem( Resource *r, QTreeWidget *parent, bool highlight )
00036         : DoubleListViewBase::MasterListItem( parent, r->name(), highlight ),
00037         resource( r )
00038 {
00039 
00040     setFormat( 0, 'f', 1 );
00041     //kDebug()<<k_funcinfo<<endl;
00042 }
00043 TaskAppointmentsView::ResourceItem::ResourceItem( Resource *r, QTreeWidgetItem *p, bool highlight )
00044         : DoubleListViewBase::MasterListItem( p, r->name(), highlight ),
00045         resource( r )
00046 {
00047 
00048     setFormat( 0, 'f', 1 );
00049     //kDebug()<<k_funcinfo<<endl;
00050 }
00051 
00052 TaskAppointmentsView::ResourceItem::ResourceItem( QString text, QTreeWidgetItem *parent, bool highlight )
00053         : DoubleListViewBase::MasterListItem( parent, text, highlight ),
00054         resource( 0 )
00055 {
00056 
00057     setFormat( 0, 'f', 1 );
00058     //kDebug()<<k_funcinfo<<endl;
00059 }
00060 
00061 //-------------------------------------------
00062 TaskAppointmentsView::TaskAppointmentsView( QWidget *parent )
00063         : DoubleListViewBase( parent ),
00064         m_task( 0 )
00065 {
00066 
00067     setNameHeader( i18n( "Resource" ) );
00068 
00069 
00070     QList<int> list = sizes();
00071     int tot = list[ 0 ] + list[ 1 ];
00072     list[ 0 ] = qMin( 35, tot );
00073     list[ 1 ] = tot - list[ 0 ];
00074     setSizes( list );
00075 }
00076 
00077 void TaskAppointmentsView::setZoom( double zoom )
00078 {
00079     Q_UNUSED( zoom );
00080 }
00081 
00082 
00083 void TaskAppointmentsView::draw( Task *task )
00084 {
00085     m_task = task;
00086     draw();
00087 }
00088 
00089 void TaskAppointmentsView::draw()
00090 {
00091     //kDebug()<<k_funcinfo<<endl;
00092     clearLists();
00093     if ( !m_task )
00094         return ;
00095 
00096     QList<Appointment*> lst = m_task->appointments();
00097     QListIterator<Appointment*> it( lst );
00098     while ( it.hasNext() ) {
00099         Appointment * a = it.next();
00100         Resource *r = a->resource() ->resource();
00101         TaskAppointmentsView::ResourceItem *item = new TaskAppointmentsView::ResourceItem( r, masterListView() );
00102 
00103         item->effortMap = a->plannedPrDay( m_task->startTime().date(), m_task->endTime().date() );
00104     }
00105     slotUpdate();
00106 }
00107 
00108 void TaskAppointmentsView::slotUpdate()
00109 {
00110     //kDebug()<<k_funcinfo<<endl;
00111     if ( !m_task )
00112         return ;
00113     QApplication::setOverrideCursor( Qt::WaitCursor );
00114     createSlaveItems();
00115     KLocale *locale = KGlobal::locale();
00116     const KCalendarSystem *cal = locale->calendar();
00117 
00118     // Add columns for selected period/periods
00119     QDate start = m_task->startTime().date();
00120     QDate end = m_task->endTime().date();
00121     //kDebug()<<k_funcinfo<<start.toString()<<" - "<<end.toString()<<endl;
00122     QStringList df;
00123     for ( QDate dt = start; dt <= end; dt = cal->addDays( dt, 1 ) ) {
00124         df << locale->formatDate( dt, true );
00125     }
00126     setSlaveLabels( df );
00127     foreach ( QTreeWidgetItem * i, masterItems() ) {
00128         TaskAppointmentsView::ResourceItem * item = static_cast<TaskAppointmentsView::ResourceItem*>( i );
00129         if ( !item ) {
00130             continue;
00131         }
00132         double eff;
00133         int col = 0;
00134         for ( QDate d = start; d <= end; d = cal->addDays( d, 1 ), ++col ) {
00135             eff = ( double ) ( item->effortMap.effortOnDate( d ).minutes() ) / 60.0;
00136             item->setSlaveItem( col, eff );
00137             item->addToTotal( eff );
00138         }
00139     }
00140     calculate();
00141     QApplication::restoreOverrideCursor();
00142 }
00143 
00144 
00145 void TaskAppointmentsView::print( KPrinter & /*printer*/ )
00146 {
00147     kDebug() << k_funcinfo << endl;
00148 }
00149 
00150 // bool TaskAppointmentsView::setContext(Context::TaskAppointmentsView &context) {
00151 //     //kDebug()<<k_funcinfo<<endl;
00152 //
00153 //     QValueList<int> list;
00154 //     list << context.accountsviewsize << context.periodviewsize;
00155 //     m_dlv->setSizes(list);
00156 //     m_date = context.date;
00157 //     if (!m_date.isValid())
00158 //         m_date = QDate::currentDate();
00159 //     m_period = context.period;
00160 //     m_cumulative = context.cumulative;
00161 //
00162 //     return true;
00163 // }
00164 //
00165 // void TaskAppointmentsView::getContext(Context::TaskAppointmentsView &context) const {
00166 //     //kDebug()<<k_funcinfo<<endl;
00167 //     context.accountsviewsize = m_dlv->sizes()[0];
00168 //     context.periodviewsize = m_dlv->sizes()[1];
00169 //     context.date = m_date;
00170 //     context.period = m_period;
00171 //     context.cumulative = m_cumulative;
00172 //     //kDebug()<<k_funcinfo<<"sizes="<<sizes()[0]<<","<<sizes()[1]<<endl;
00173 // }
00174 
00175 void TaskAppointmentsView::clear()
00176 {
00177     clearLists();
00178 }
00179 
00180 void TaskAppointmentsView::createSlaveItems()
00181 {
00182     DoubleListViewBase::createSlaveItems();
00183     setSlaveFormat( 0, 'f', 1 );
00184 }
00185 
00186 }  //KPlato namespace
00187 
00188 #include "kpttaskappointmentsview.moc"

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