1 | /* This file is part of the Calligra project |
2 | * Copyright (c) 2008 Dag Andersen <danders@get2net.dk> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KPTNODECHARTMODEL_H |
21 | #define KPTNODECHARTMODEL_H |
22 | |
23 | #include "kplatomodels_export.h" |
24 | |
25 | #include "kptitemmodelbase.h" |
26 | |
27 | #include "kpteffortcostmap.h" |
28 | |
29 | #include <QSortFilterProxyModel> |
30 | |
31 | #include "kptdebug.h" |
32 | |
33 | #include "KDChartGlobal" |
34 | |
35 | namespace KPlato |
36 | { |
37 | |
38 | class Resource; |
39 | class Project; |
40 | class ScheduleManager; |
41 | class Node; |
42 | |
43 | class KPLATOMODELS_EXPORT ChartProxyModel : public QSortFilterProxyModel |
44 | { |
45 | Q_OBJECT |
46 | public: |
47 | explicit ChartProxyModel(QObject *parent = 0) : QSortFilterProxyModel( parent ) {} |
48 | |
49 | QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const { |
50 | //if ( role == Qt::DisplayRole && orientation == Qt::Vertical ) kDebug()<<"fetch:"<<orientation<<section<<mapToSource( index(0, section) ).column()<<m_rejects; |
51 | return QSortFilterProxyModel::headerData( section, orientation, role ); |
52 | } |
53 | |
54 | QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const { |
55 | if ( role == Qt::DisplayRole && ! m_zerocolumns.isEmpty() ) { |
56 | int column = mapToSource( index ).column(); |
57 | if ( m_zerocolumns.contains( column ) ) { |
58 | //kDebug()<<"zero:"<<index.column()<<mapToSource( index ).column(); |
59 | return QVariant(); |
60 | } |
61 | } |
62 | //if ( role == Qt::DisplayRole ) kDebug()<<"fetch:"<<index.column()<<mapToSource( index ).column()<<m_rejects; |
63 | QVariant v = QSortFilterProxyModel::data( index, role ); |
64 | //if ( role == Qt::DisplayRole ) kDebug(planDbg())<<index.row()<<","<<index.column()<<"("<<columnCount()<<")"<<v; |
65 | return v; |
66 | } |
67 | void setRejectColumns( const QList<int> &columns ) { m_rejects = columns; invalidateFilter(); } |
68 | QList<int> rejectColumns() const { return m_rejects; } |
69 | void setZeroColumns( const QList<int> &columns ) { m_zerocolumns = columns; } |
70 | QList<int> zeroColumns() const { return m_zerocolumns; } |
71 | |
72 | void reset() { QSortFilterProxyModel::reset(); } |
73 | |
74 | protected: |
75 | bool filterAcceptsColumn ( int source_column, const QModelIndex &/*source_parent */) const { |
76 | //kDebug()<<this<<source_column<<m_rejects<<(! m_rejects.contains( source_column )); |
77 | return ! m_rejects.contains( source_column ); |
78 | } |
79 | |
80 | private: |
81 | QList<int> m_rejects; |
82 | QList<int> m_zerocolumns; |
83 | }; |
84 | |
85 | class KPLATOMODELS_EXPORT ChartItemModel : public ItemModelBase |
86 | { |
87 | Q_OBJECT |
88 | Q_ENUMS( Properties ) |
89 | public: |
90 | enum Properties { |
91 | BCWSCost, |
92 | BCWPCost, |
93 | ACWPCost, |
94 | BCWSEffort, |
95 | BCWPEffort, |
96 | ACWPEffort, |
97 | SPICost, |
98 | CPICost, |
99 | SPIEffort, |
100 | CPIEffort |
101 | }; |
102 | const QMetaEnum columnMap() const; |
103 | |
104 | explicit ChartItemModel(QObject *parent = 0); |
105 | |
106 | |
107 | // virtual Qt::ItemFlags flags( const QModelIndex & index ) const; |
108 | |
109 | virtual QModelIndex parent( const QModelIndex & index ) const; |
110 | virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
111 | |
112 | virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; |
113 | virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; |
114 | |
115 | virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; |
116 | |
117 | virtual QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
118 | |
119 | |
120 | const EffortCostMap &bcwp() const { return m_bcws; } |
121 | const EffortCostMap &acwp() const { return m_acwp; } |
122 | |
123 | void setProject( Project *project ); |
124 | |
125 | void setNodes( const QList<Node*> &nodes ); |
126 | void addNode( Node *node ); |
127 | void clearNodes(); |
128 | QDate startDate() const; |
129 | QDate endDate() const; |
130 | void calculate(); |
131 | |
132 | void setLocalizeValues( bool on ); |
133 | |
134 | public slots: |
135 | void setScheduleManager( ScheduleManager *sm ); |
136 | void slotNodeRemoved( Node *node ); |
137 | void slotNodeChanged( Node *node ); |
138 | void slotResourceChanged( Resource *resource ); |
139 | void slotResourceChanged( const Resource *resource ); |
140 | |
141 | protected: |
142 | double bcwsEffort( int day ) const; |
143 | double bcwpEffort( int day ) const; |
144 | double acwpEffort( int day ) const; |
145 | double bcwsCost( int day ) const; |
146 | double bcwpCost( int day ) const; |
147 | double acwpCost( int day ) const; |
148 | double spiEffort( int day ) const; |
149 | double cpiEffort( int day ) const; |
150 | double spiCost( int day ) const; |
151 | double cpiCost( int day ) const; |
152 | |
153 | protected: |
154 | QList<Node*> m_nodes; |
155 | EffortCostMap m_bcws; |
156 | EffortCostMap m_acwp; |
157 | bool m_localizeValues; |
158 | }; |
159 | |
160 | class KPLATOMODELS_EXPORT PerformanceDataCurrentDateModel : public ChartItemModel |
161 | { |
162 | Q_OBJECT |
163 | public: |
164 | explicit PerformanceDataCurrentDateModel(QObject *parent); |
165 | |
166 | int rowCount( const QModelIndex &parent = QModelIndex() ) const; |
167 | int columnCount( const QModelIndex &parent = QModelIndex() ) const; |
168 | QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; |
169 | QVariant data( const QModelIndex &proxyIndex, int role = Qt::DisplayRole ) const; |
170 | QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
171 | |
172 | QModelIndex mapIndex( const QModelIndex &idx ) const; |
173 | }; |
174 | |
175 | } //namespace KPlato |
176 | |
177 | #endif |
178 | |