diff --git a/plan/libs/models/kptnodechartmodel.cpp b/plan/libs/models/kptnodechartmodel.cpp index 2824c5c7836..d22fa79e4e1 100644 --- a/plan/libs/models/kptnodechartmodel.cpp +++ b/plan/libs/models/kptnodechartmodel.cpp @@ -1,540 +1,540 @@ /* This file is part of the Calligra project * Copyright (c) 2008, 2012 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kptnodechartmodel.h" #include "kptlocale.h" #include "kptnode.h" #include "kptproject.h" #include "kptschedule.h" #include "kptresource.h" #include "kptdebug.h" #include #include #include #include #include namespace KPlato { ChartItemModel::ChartItemModel( QObject *parent ) : ItemModelBase( parent ), m_localizeValues( false ) { } QModelIndex ChartItemModel::parent( const QModelIndex &index ) const { Q_UNUSED(index); return QModelIndex(); } const QMetaEnum ChartItemModel::columnMap() const { return metaObject()->enumerator( metaObject()->indexOfEnumerator("Properties") ); } int ChartItemModel::columnCount( const QModelIndex &/*parent*/ ) const { return columnMap().keyCount(); } int ChartItemModel::rowCount( const QModelIndex &/*parent */) const { return startDate().daysTo( endDate() ) + 1; } QModelIndex ChartItemModel::index( int row, int column, const QModelIndex &parent ) const { if ( m_project == 0 || row < 0 || column < 0 ) { //debugPlan<<"No project"< m_bcws.endDate() ) { res = m_bcws.bcwpEffort( date ); } return res; } double ChartItemModel::acwpEffort( int day ) const { return m_acwp.hoursTo( startDate().addDays( day ) ); } double ChartItemModel::bcwsCost( int day ) const { return m_bcws.costTo( startDate().addDays( day ) ); } double ChartItemModel::bcwpCost( int day ) const { double res = 0.0; QDate date = startDate().addDays( day ); if ( m_bcws.days().contains( date ) ) { res = m_bcws.bcwpCost( date ); } else if ( date > m_bcws.endDate() ) { res = m_bcws.bcwpCost( m_bcws.endDate() ); } return res; } double ChartItemModel::acwpCost( int day ) const { return m_acwp.costTo( startDate().addDays( day ) ); } double ChartItemModel::spiEffort( int day ) const { double p = bcwpEffort( day ); double s = bcwsEffort( day ); return s == 0.0 ? 0.0 : p / s; } double ChartItemModel::spiCost( int day ) const { double p = bcwpCost( day ); double s = bcwsCost( day ); return s == 0.0 ? 0.0 : p / s; } double ChartItemModel::cpiEffort( int day ) const { double p = bcwpEffort( day ); double a = acwpEffort( day ); return a == 0.0 ? 0.0 : p / a; } double ChartItemModel::cpiCost( int day ) const { double p = bcwpCost( day ); double a = acwpCost( day ); return a == 0.0 ? 0.0 : p / a; } QVariant ChartItemModel::data( const QModelIndex &index, int role ) const { QVariant result; if ( role == Qt::DisplayRole ) { if ( ! m_localizeValues ) { return data( index, Qt::EditRole ); } else { QLocale locale; // TODO: temporary workaround while KLocale/money logic still used Locale *planLocale; Locale *tmpPlanLocale = 0; if (project()) { planLocale = project()->locale(); } else { tmpPlanLocale = new Locale(); planLocale = tmpPlanLocale; } switch ( index.column() ) { case BCWSCost: result = planLocale->formatMoney( bcwsCost( index.row() ), QString(), 0 ); break; case BCWPCost: result = planLocale->formatMoney( bcwpCost( index.row() ), QString(), 0 ); break; case ACWPCost: result = planLocale->formatMoney( acwpCost( index.row() ), QString(), 0 ); break; case BCWSEffort: result = locale.toString( bcwsEffort( index.row() ), 'f', 0 ); break; case BCWPEffort: result = locale.toString( bcwpEffort( index.row() ), 'f', 0 ); break; case ACWPEffort: result = locale.toString( acwpEffort( index.row() ), 'f', 0 ); break; case SPICost: result = locale.toString( spiCost( index.row() ), 'f', 2 ); break; case CPICost: result = locale.toString( cpiCost( index.row() ), 'f', 2 ); break; case SPIEffort: result = locale.toString( spiEffort( index.row() ), 'f', 2 ); break; case CPIEffort: result = locale.toString( cpiEffort( index.row() ), 'f', 2 ); break; default: break; } delete tmpPlanLocale; } //debugPlan< 0.0 && v < 1.0 ) { result = QBrush( Qt::red ); } return result; } else if ( role == KChart::DatasetBrushRole ) { return headerData( index.column(), Qt::Horizontal, role ); } else if ( role == KChart::DatasetPenRole ) { return headerData( index.column(), Qt::Horizontal, role ); } //debugPlan<() ); result = p; //debugPlan< &nodes ) { debugPlan<isChildOf( n ) ) { calculate(); reset(); return; } } } void ChartItemModel::slotResourceChanged( Resource* ) { calculate(); reset(); } void ChartItemModel::slotResourceChanged( const Resource* ) { calculate(); reset(); } QDate ChartItemModel::startDate() const { QDate d = m_bcws.startDate(); if ( m_acwp.startDate().isValid() ) { if ( ! d.isValid() || d > m_acwp.startDate() ) { d = m_acwp.startDate(); } } return d; } QDate ChartItemModel::endDate() const { return qMax( m_bcws.endDate(), m_acwp.endDate() ); } void ChartItemModel::calculate() { //debugPlan<isChildOf( p ) ) { skip = true; break; } } if ( ! skip ) { m_bcws += n->bcwpPrDay( m_manager->scheduleId(), ECCT_EffortWork ); m_acwp += n->acwp( m_manager->scheduleId() ); } } } } //debugPlan<<"bcwp"<