1 | /* This file is part of the KDE project |
2 | Copyright (C) 2007 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 TASKSTATUSMODEL_H |
21 | #define TASKSTATUSMODEL_H |
22 | |
23 | #include "kplatomodels_export.h" |
24 | |
25 | #include "kptitemmodelbase.h" |
26 | #include "kptnodeitemmodel.h" |
27 | |
28 | class KAction; |
29 | |
30 | namespace KPlato |
31 | { |
32 | |
33 | class Project; |
34 | class Node; |
35 | class Task; |
36 | |
37 | typedef QMap<QString, Node*> NodeMap; |
38 | |
39 | class KPLATOMODELS_EXPORT TaskStatusItemModel : public ItemModelBase |
40 | { |
41 | Q_OBJECT |
42 | public: |
43 | explicit TaskStatusItemModel( QObject *parent = 0 ); |
44 | ~TaskStatusItemModel(); |
45 | |
46 | enum PeriodType { UseCurrentDate, UseWeekday }; |
47 | int periodType() const { return m_periodType; } |
48 | void setPeriodType( int type ) { m_periodType = type; } |
49 | |
50 | /// Returns a column number/- name map for this model |
51 | virtual const QMetaEnum columnMap() const { return m_nodemodel.columnMap(); } |
52 | |
53 | virtual void setProject( Project *project ); |
54 | |
55 | virtual Qt::ItemFlags flags( const QModelIndex & index ) const; |
56 | |
57 | virtual QModelIndex parent( const QModelIndex & index ) const; |
58 | virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
59 | virtual QModelIndex index( const Node *node ) const; |
60 | virtual QModelIndex index( const NodeMap *lst ) const; |
61 | |
62 | virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; |
63 | virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; |
64 | |
65 | virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; |
66 | virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
67 | |
68 | |
69 | virtual QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
70 | |
71 | virtual QMimeData * mimeData( const QModelIndexList & indexes ) const; |
72 | virtual QStringList mimeTypes () const; |
73 | virtual Qt::DropActions supportedDropActions() const; |
74 | virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ); |
75 | |
76 | NodeMap *list( const QModelIndex &index ) const; |
77 | Node *node( const QModelIndex &index ) const; |
78 | QAbstractItemDelegate *createDelegate( int column, QWidget *parent ) const; |
79 | |
80 | NodeMap nodeList( QDataStream &stream ); |
81 | using ItemModelBase::dropAllowed; |
82 | bool dropAllowed( Node *on, const QMimeData *data ); |
83 | |
84 | void clear(); |
85 | |
86 | void setNow(); |
87 | void setPeriod( int days ) { m_period = days; } |
88 | int period() const { return m_period; } |
89 | void setWeekday( int day ) { m_weekday = day; } |
90 | int weekday() const { return m_weekday; } |
91 | |
92 | /// Return the sortorder to be used for @p column |
93 | virtual int sortRole( int column ) const; |
94 | |
95 | public slots: |
96 | virtual void setScheduleManager( ScheduleManager *sm ); |
97 | virtual void refresh(); |
98 | |
99 | protected slots: |
100 | void slotAboutToBeReset(); |
101 | void slotReset(); |
102 | |
103 | void slotNodeChanged( Node* ); |
104 | void slotNodeToBeInserted( Node *node, int row ); |
105 | void slotNodeInserted( Node *node ); |
106 | void slotNodeToBeRemoved( Node *node ); |
107 | void slotNodeRemoved( Node *node ); |
108 | void slotNodeToBeMoved( Node *node, int pos, Node *newParent, int newPos ); |
109 | void slotNodeMoved( Node *node ); |
110 | |
111 | void slotWbsDefinitionChanged(); |
112 | void slotLayoutChanged(); |
113 | |
114 | protected: |
115 | |
116 | // keep in sync with order in m_top |
117 | enum TaskStatus { |
118 | TaskUnknownStatus = -1, |
119 | TaskNotStarted = 0, |
120 | TaskRunning = 1, |
121 | TaskFinished = 2, |
122 | TaskUpcoming = 3 |
123 | }; |
124 | |
125 | QVariant alignment( int column ) const; |
126 | |
127 | QVariant name( int row, int role ) const; |
128 | TaskStatusItemModel::TaskStatus taskStatus(const Task *task, const QDate &begin, const QDate &end); |
129 | |
130 | bool setCompletion( Node *node, const QVariant &value, int role ); |
131 | bool setRemainingEffort( Node *node, const QVariant &value, int role ); |
132 | bool setActualEffort( Node *node, const QVariant &value, int role ); |
133 | bool setStartedTime( Node *node, const QVariant &value, int role ); |
134 | bool setFinishedTime( Node *node, const QVariant &value, int role ); |
135 | |
136 | private: |
137 | NodeModel m_nodemodel; |
138 | QStringList m_topNames; |
139 | QStringList m_topTips; |
140 | QList<NodeMap*> m_top; |
141 | NodeMap m_notstarted; |
142 | NodeMap m_running; |
143 | NodeMap m_finished; |
144 | NodeMap m_upcoming; |
145 | |
146 | long m_id; // schedule id |
147 | int m_period; // days |
148 | int m_periodType; |
149 | int m_weekday; |
150 | |
151 | }; |
152 | |
153 | } //namespace KPlato |
154 | |
155 | |
156 | #endif |
157 | |