1 | /* This file is part of the KDE project |
2 | Copyright (C) 2007, 2008 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 KPTSCHEDULEMODEL_H |
22 | #define KPTSCHEDULEMODEL_H |
23 | |
24 | #include "kplatomodels_export.h" |
25 | |
26 | #include "kptitemmodelbase.h" |
27 | #include "kptschedule.h" |
28 | |
29 | #include <QStandardItemModel> |
30 | #include <QSortFilterProxyModel> |
31 | |
32 | namespace KPlato |
33 | { |
34 | |
35 | class View; |
36 | class Project; |
37 | class ScheduleManager; |
38 | class MainSchedule; |
39 | class Schedule; |
40 | class Node; |
41 | class Resource; |
42 | |
43 | class KPLATOMODELS_EXPORT ScheduleModel : public QObject |
44 | { |
45 | Q_OBJECT |
46 | Q_ENUMS( Properties ) |
47 | public: |
48 | explicit ScheduleModel( QObject *parent = 0 ); |
49 | ~ScheduleModel(); |
50 | |
51 | enum Properties { |
52 | ScheduleName = 0, |
53 | ScheduleState, |
54 | ScheduleDirection, |
55 | ScheduleOverbooking, |
56 | ScheduleDistribution, |
57 | SchedulePlannedStart, |
58 | SchedulePlannedFinish, |
59 | ScheduleScheduler, |
60 | ScheduleGranularity, |
61 | ScheduleScheduled |
62 | }; |
63 | const QMetaEnum columnMap() const; |
64 | |
65 | int propertyCount() const; |
66 | }; |
67 | |
68 | class KPLATOMODELS_EXPORT ScheduleItemModel : public ItemModelBase |
69 | { |
70 | Q_OBJECT |
71 | public: |
72 | explicit ScheduleItemModel( QObject *parent = 0 ); |
73 | ~ScheduleItemModel(); |
74 | |
75 | const QMetaEnum columnMap() const { return m_model.columnMap(); } |
76 | |
77 | virtual void setProject( Project *project ); |
78 | |
79 | virtual Qt::ItemFlags flags( const QModelIndex & index ) const; |
80 | |
81 | virtual QModelIndex parent( const QModelIndex & index ) const; |
82 | virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
83 | QModelIndex index( const ScheduleManager *manager ) const; |
84 | |
85 | virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; |
86 | virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; |
87 | |
88 | virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; |
89 | virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
90 | |
91 | virtual QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
92 | |
93 | QAbstractItemDelegate *createDelegate( int column, QWidget *parent ) const; |
94 | |
95 | virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ); |
96 | |
97 | virtual QMimeData * mimeData( const QModelIndexList & indexes ) const; |
98 | virtual QStringList mimeTypes () const; |
99 | |
100 | ScheduleManager *manager( const QModelIndex &index ) const; |
101 | |
102 | void setFlat( bool flat ); |
103 | |
104 | signals: |
105 | void scheduleManagerAdded( ScheduleManager* ); |
106 | |
107 | protected slots: |
108 | void slotManagerChanged( ScheduleManager *sch ); |
109 | void slotScheduleChanged( MainSchedule *sch ); |
110 | |
111 | void slotScheduleManagerToBeInserted( const ScheduleManager *manager, int row ); |
112 | void slotScheduleManagerInserted( const ScheduleManager *manager ); |
113 | void slotScheduleManagerToBeRemoved( const ScheduleManager *manager ); |
114 | void slotScheduleManagerRemoved( const ScheduleManager *manager ); |
115 | void slotScheduleManagerToBeMoved( const ScheduleManager *manager ); |
116 | void slotScheduleManagerMoved( const ScheduleManager *manager, int index ); |
117 | void slotScheduleToBeInserted( const ScheduleManager *manager, int row ); |
118 | void slotScheduleInserted( const MainSchedule *schedule ); |
119 | void slotScheduleToBeRemoved( const MainSchedule *schedule ); |
120 | void slotScheduleRemoved( const MainSchedule *schedule ); |
121 | |
122 | protected: |
123 | int row( const Schedule *sch ) const; |
124 | |
125 | QVariant name( const QModelIndex &index, int role ) const; |
126 | bool setName( const QModelIndex &index, const QVariant &value, int role ); |
127 | |
128 | QVariant state( const QModelIndex &index, int role ) const; |
129 | bool setState( const QModelIndex &index, const QVariant &value, int role ); |
130 | |
131 | QVariant allowOverbooking( const QModelIndex &index, int role ) const; |
132 | bool setAllowOverbooking( const QModelIndex &index, const QVariant &value, int role ); |
133 | |
134 | QVariant usePert( const QModelIndex &index, int role ) const; |
135 | bool setUsePert( const QModelIndex &index, const QVariant &value, int role ); |
136 | |
137 | QVariant projectStart( const QModelIndex &index, int role ) const; |
138 | QVariant projectEnd( const QModelIndex &index, int role ) const; |
139 | |
140 | QVariant schedulingDirection( const QModelIndex &index, int role ) const; |
141 | bool setSchedulingDirection( const QModelIndex &index, const QVariant &value, int role ); |
142 | |
143 | QVariant schedulingStartTime( const QModelIndex &index, int role ) const; |
144 | bool setSchedulingStartTime( const QModelIndex &index, const QVariant &value, int role ); |
145 | |
146 | QVariant scheduler( const QModelIndex &index, int role ) const; |
147 | bool setScheduler( const QModelIndex &index, const QVariant &value, int role ); |
148 | |
149 | QVariant isScheduled( const QModelIndex &index, int role ) const; |
150 | |
151 | QVariant granularity( const QModelIndex &index, int role ) const; |
152 | bool setGranularity( const QModelIndex &index, const QVariant &value, int role ); |
153 | |
154 | private: |
155 | ScheduleManager *m_manager; // for sanety check |
156 | bool m_flat; |
157 | ScheduleModel m_model; |
158 | |
159 | QList<ScheduleManager*> m_managerlist; |
160 | |
161 | }; |
162 | |
163 | //---------------------------------------- |
164 | class KPLATOMODELS_EXPORT ScheduleSortFilterModel : public QSortFilterProxyModel |
165 | { |
166 | Q_OBJECT |
167 | public: |
168 | explicit ScheduleSortFilterModel( QObject *parent = 0 ); |
169 | ~ScheduleSortFilterModel(); |
170 | |
171 | ScheduleManager *manager( const QModelIndex &index ) const; |
172 | |
173 | }; |
174 | |
175 | //---------------------------------------- |
176 | class KPLATOMODELS_EXPORT ScheduleLogItemModel : public QStandardItemModel |
177 | { |
178 | Q_OBJECT |
179 | public: |
180 | enum DataRoles { SeverityRole = Qt::UserRole + 1, IdentityRole }; |
181 | |
182 | explicit ScheduleLogItemModel( QObject *parent = 0 ); |
183 | ~ScheduleLogItemModel(); |
184 | |
185 | void setProject( Project *project ); |
186 | Project *project() const { return m_project; } |
187 | void setManager( ScheduleManager *manager ); |
188 | ScheduleManager *manager() const { return m_manager; } |
189 | |
190 | virtual Qt::ItemFlags flags( const QModelIndex & index ) const; |
191 | |
192 | void refresh(); |
193 | |
194 | QString identity( const QModelIndex &idx ) const; |
195 | |
196 | protected slots: |
197 | void slotManagerChanged( ScheduleManager *sch ); |
198 | void slotScheduleChanged( MainSchedule *sch ); |
199 | |
200 | void slotScheduleManagerToBeRemoved( const ScheduleManager *manager ); |
201 | void slotScheduleManagerRemoved( const ScheduleManager *manager ); |
202 | void slotScheduleToBeInserted( const ScheduleManager *manager, int row ); |
203 | void slotScheduleInserted( const MainSchedule *schedule ); |
204 | void slotScheduleToBeRemoved( const MainSchedule *schedule ); |
205 | void slotScheduleRemoved( const MainSchedule *schedule ); |
206 | |
207 | void slotLogInserted( MainSchedule*, int firstrow, int lastrow ); |
208 | |
209 | protected: |
210 | void addLogEntry( const Schedule::Log &log, int row ); |
211 | |
212 | private: |
213 | Project *m_project; |
214 | ScheduleManager *m_manager; |
215 | MainSchedule *m_schedule; |
216 | |
217 | }; |
218 | |
219 | |
220 | } //KPlato namespace |
221 | |
222 | #endif |
223 | |