1 | /* This file is part of the KDE project |
2 | Copyright (C) 2009 Dag Andersen <danders@get2net> |
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 KPTRESOURCEALLOCATIONMODEL_H |
21 | #define KPTRESOURCEALLOCATIONMODEL_H |
22 | |
23 | #include "kplatomodels_export.h" |
24 | |
25 | #include <kptitemmodelbase.h> |
26 | |
27 | #include <QMetaEnum> |
28 | #include <QMap> |
29 | |
30 | class QPoint; |
31 | |
32 | |
33 | namespace KPlato |
34 | { |
35 | |
36 | class Project; |
37 | class Task; |
38 | class Resource; |
39 | class ResourceGroup; |
40 | class ResourceRequest; |
41 | class ResourceGroupRequest; |
42 | |
43 | /** |
44 | The ResourceAllocationModel gives access to resource requests |
45 | */ |
46 | |
47 | class KPLATOMODELS_EXPORT ResourceAllocationModel : public QObject |
48 | { |
49 | Q_OBJECT |
50 | Q_ENUMS( Properties ) |
51 | public: |
52 | explicit ResourceAllocationModel( QObject *parent = 0 ); |
53 | ~ResourceAllocationModel(); |
54 | |
55 | enum Properties { |
56 | RequestName = 0, |
57 | RequestType, |
58 | RequestAllocation, |
59 | RequestMaximum, |
60 | RequestRequired |
61 | }; |
62 | |
63 | const QMetaEnum columnMap() const; |
64 | void setProject( Project *project ); |
65 | Task *task() const { return m_task; } |
66 | void setTask( Task *task ); |
67 | int propertyCount() const; |
68 | QVariant data( const ResourceGroup *group, const Resource *resource, int property, int role = Qt::DisplayRole ) const; |
69 | QVariant data( const ResourceGroup *group, int property, int role = Qt::DisplayRole ) const; |
70 | static QVariant ( int section, int role = Qt::DisplayRole ); |
71 | |
72 | QVariant name( const Resource *res, int role ) const; |
73 | QVariant type( const Resource *res, int role ) const; |
74 | QVariant allocation( const ResourceGroup *group, const Resource *res, int role ) const; |
75 | QVariant maximum( const Resource *res, int role ) const; |
76 | QVariant required( const Resource *res, int role ) const; |
77 | |
78 | QVariant name( const ResourceGroup *res, int role ) const; |
79 | QVariant type( const ResourceGroup *res, int role ) const; |
80 | QVariant allocation( const ResourceGroup *res, int role ) const; |
81 | QVariant maximum( const ResourceGroup *res, int role ) const; |
82 | |
83 | private: |
84 | Project *m_project; |
85 | Task *m_task; |
86 | }; |
87 | |
88 | /** |
89 | The ResourceAllocationItemModel facilitates viewing and modifying |
90 | resource allocations for a task. |
91 | */ |
92 | |
93 | class KPLATOMODELS_EXPORT ResourceAllocationItemModel : public ItemModelBase |
94 | { |
95 | Q_OBJECT |
96 | public: |
97 | explicit ResourceAllocationItemModel( QObject *parent = 0 ); |
98 | ~ResourceAllocationItemModel(); |
99 | |
100 | virtual const QMetaEnum columnMap() const { return m_model.columnMap(); } |
101 | |
102 | virtual void setProject( Project *project ); |
103 | Task *task() const { return m_model.task(); } |
104 | |
105 | virtual Qt::ItemFlags flags( const QModelIndex & index ) const; |
106 | |
107 | virtual QModelIndex parent( const QModelIndex & index ) const; |
108 | virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
109 | QModelIndex index( const ResourceGroup *group ) const; |
110 | QModelIndex index( const Resource *resource ) 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 | virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
117 | |
118 | |
119 | virtual QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
120 | |
121 | QAbstractItemDelegate *createDelegate( int col, QWidget *parent ) const; |
122 | |
123 | QObject *object( const QModelIndex &index ) const; |
124 | |
125 | const QMap<const Resource*, ResourceRequest*> &resourceCache() const { return m_resourceCache; } |
126 | const QMap<const ResourceGroup*, ResourceGroupRequest*> &groupCache() const { return m_groupCache; } |
127 | |
128 | Resource *resource( const QModelIndex &idx ) const; |
129 | void setRequired( const QModelIndex &idx, const QList<Resource*> &lst ); |
130 | QList<Resource*> required( const QModelIndex &idx ) const; |
131 | |
132 | public slots: |
133 | void setTask( Task *task ); |
134 | |
135 | protected slots: |
136 | void slotResourceChanged( Resource* ); |
137 | void slotResourceGroupChanged( ResourceGroup * ); |
138 | void slotResourceGroupToBeInserted( const ResourceGroup *group, int row ); |
139 | void slotResourceGroupInserted( const ResourceGroup *group ); |
140 | void slotResourceGroupToBeRemoved( const ResourceGroup *group ); |
141 | void slotResourceGroupRemoved( const ResourceGroup *group ); |
142 | void slotResourceToBeInserted( const ResourceGroup *group, int row ); |
143 | void slotResourceInserted( const Resource *resource ); |
144 | void slotResourceToBeRemoved( const Resource *resource ); |
145 | void slotResourceRemoved( const Resource *resource ); |
146 | |
147 | protected: |
148 | void filldata( Task *task ); |
149 | |
150 | QVariant notUsed( const ResourceGroup *res, int role ) const; |
151 | |
152 | QVariant allocation( const ResourceGroup *group, const Resource *res, int role ) const; |
153 | QVariant allocation( const ResourceGroup *res, int role ) const; |
154 | bool setAllocation( ResourceGroup *res, const QVariant &value, int role ); |
155 | bool setAllocation( Resource *res, const QVariant &value, int role ); |
156 | |
157 | QVariant maximum( const ResourceGroup *res, int role ) const; |
158 | |
159 | bool setRequired( const QModelIndex &idx, const QVariant &value, int role ); |
160 | QVariant required( const QModelIndex &idx, int role ) const; |
161 | |
162 | private: |
163 | int requestedResources( const ResourceGroup *res ) const; |
164 | bool hasMaterialResources() const; |
165 | |
166 | private: |
167 | ResourceAllocationModel m_model; |
168 | |
169 | QMap<const Resource*, ResourceRequest*> m_resourceCache; |
170 | QMap<const Resource*, int> m_requiredChecked; |
171 | QMap<const ResourceGroup*, ResourceGroupRequest*> m_groupCache; |
172 | }; |
173 | |
174 | |
175 | } //KPlato namespace |
176 | |
177 | #endif |
178 | |