1/* This file is KoDocument of the KDE project
2 Copyright (C) 2007 Dag Andersen <danders@get2net.dk>
3 Copyright (C) 2011 Dag Andersen <danders@get2net.dk>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18* Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KPTACCOUNTSMODEL_H
22#define KPTACCOUNTSMODEL_H
23
24#include "kplatomodels_export.h"
25
26#include <kptitemmodelbase.h>
27#include "kpteffortcostmap.h"
28
29namespace KPlato
30{
31
32class Project;
33class Account;
34class ScheduleManager;
35class Node;
36class AccountItemModel;
37
38class KPLATOMODELS_EXPORT AccountModel : public QObject
39{
40 Q_OBJECT
41 Q_ENUMS( Properties )
42public:
43 AccountModel();
44 ~AccountModel() {}
45
46 enum Properties {
47 Name = 0,
48 Description
49 };
50 const QMetaEnum columnMap() const;
51 int propertyCount() const;
52
53 virtual QVariant data( const Account *a, int property, int role = Qt::DisplayRole ) const;
54 virtual QVariant headerData( int property, int role = Qt::DisplayRole ) const;
55
56protected:
57 QVariant name( const Account *account, int role ) const;
58 QVariant description( const Account *account, int role ) const;
59
60private:
61 friend class AccountItemModel;
62 Project *m_project;
63};
64
65class KPLATOMODELS_EXPORT AccountItemModel : public ItemModelBase
66{
67 Q_OBJECT
68public:
69 explicit AccountItemModel( QObject *parent = 0 );
70 ~AccountItemModel();
71
72 const QMetaEnum columnMap() const;
73 virtual void setProject( Project *project );
74
75 virtual Qt::ItemFlags flags( const QModelIndex & index ) const;
76
77 virtual QModelIndex parent( const QModelIndex & index ) const;
78 virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
79 QModelIndex index( const Account* account, int column = 0 ) const;
80
81 virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
82 virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
83
84 virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
85 virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
86
87
88 virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
89
90 Account *account( const QModelIndex &index ) const;
91 QModelIndex insertAccount( Account *account, Account *parent = 0, int index = -1 );
92 void removeAccounts( QList<Account*> lst );
93
94protected slots:
95 void slotAccountChanged( Account* );
96 void slotAccountToBeInserted( const Account *parent, int row );
97 void slotAccountInserted( const Account *account );
98 void slotAccountToBeRemoved( const Account *account );
99 void slotAccountRemoved( const Account *account );
100
101protected:
102 bool setName( Account *account, const QVariant &value, int role );
103
104 bool setDescription( Account *account, const QVariant &value, int role );
105
106private:
107 AccountModel m_model;
108 Account *m_account; // test for sane operation
109};
110
111//---------------
112class KPLATOMODELS_EXPORT CostBreakdownItemModel : public ItemModelBase
113{
114 Q_OBJECT
115public:
116 enum PeriodType { Period_Day = 0, Period_Week = 1, Period_Month = 2 };
117 enum StartMode { StartMode_Project = 0, StartMode_Date = 1 };
118 enum EndMode { EndMode_Project = 0, EndMode_Date = 1, EndMode_CurrentDate = 2 };
119 enum ShowMode { ShowMode_Actual = 0, ShowMode_Planned = 1, ShowMode_Both = 2, ShowMode_Deviation = 3 };
120
121 explicit CostBreakdownItemModel( QObject *parent = 0 );
122 ~CostBreakdownItemModel();
123
124 virtual void setProject( Project *project );
125 virtual void setScheduleManager( ScheduleManager *sm );
126 long id() const;
127
128 virtual QModelIndex parent( const QModelIndex & index ) const;
129 virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
130 QModelIndex index( const Account* account ) const;
131
132 virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
133 virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
134
135 virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
136
137 virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
138
139 Account *account( const QModelIndex &index ) const;
140
141 bool cumulative() const;
142 void setCumulative( bool on );
143 int periodType() const;
144 void setPeriodType( int period );
145 int startMode() const;
146 void setStartMode( int mode );
147 int endMode() const;
148 void setEndMode( int mode );
149 QDate startDate() const;
150 void setStartDate( const QDate &date );
151 QDate endDate() const;
152 void setEndDate( const QDate &date );
153 int showMode() const;
154 void setShowMode( int show );
155
156 QString formatMoney( double plannedCost, double actualCost ) const;
157 QString format() const { return m_format; }
158 void setFormat( const QString &f ) { m_format = f; }
159
160protected:
161 void fetchData();
162 EffortCostMap fetchPlannedCost( Account *account );
163 EffortCostMap fetchActualCost( Account *account );
164
165 QVariant cost( const Account *a, int offset, int role ) const;
166
167protected slots:
168 void slotAccountChanged( Account* );
169 void slotAccountToBeInserted( const Account *parent, int row );
170 void slotAccountInserted( const Account *account );
171 void slotAccountToBeRemoved( const Account *account );
172 void slotAccountRemoved( const Account *account );
173
174 void slotDataChanged();
175
176private:
177 ScheduleManager *m_manager;
178
179 bool m_cumulative;
180 int m_periodtype;
181 int m_startmode;
182 int m_endmode;
183 QDate m_start;
184 QDate m_end;
185 int m_showmode;
186 QMap<Account*, EffortCostMap> m_plannedCostMap;
187 QDate m_plannedStart, m_plannedEnd;
188 QMap<Account*, EffortCostMap> m_actualCostMap;
189 QDate m_actualStart, m_actualEnd;
190 QString m_format;
191
192};
193
194
195} //KPlato namespace
196
197#endif
198