1/* This file is part of the KDE project
2 Copyright (C) 2007 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 KPTPERTCPMMODEL_H
21#define KPTPERTCPMMODEL_H
22
23#include "kplatomodels_export.h"
24
25#include <kptitemmodelbase.h>
26#include <kptnodeitemmodel.h>
27
28
29/// The main namespace
30namespace KPlato
31{
32
33class DateTime;
34class Duration;
35class Estimate;
36class Node;
37class Project;
38class ScheduleManager;
39class Task;
40class View;
41
42typedef QList<Node*> NodeList;
43
44class KPLATOMODELS_EXPORT CriticalPathItemModel : public ItemModelBase
45{
46 Q_OBJECT
47public:
48 explicit CriticalPathItemModel( QObject *parent = 0 );
49 ~CriticalPathItemModel();
50
51 const QMetaEnum columnMap() const { return m_nodemodel.columnMap(); }
52
53 virtual void setProject( Project *project );
54
55 virtual QModelIndex parent( const QModelIndex & index ) const;
56 virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
57
58 virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
59 virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
60
61 virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
62
63 virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
64
65 Node *node( const QModelIndex &index ) const;
66 void setManager( ScheduleManager *sm );
67 ScheduleManager *manager() const { return m_manager; }
68
69 /// Select a proper unit for total path values, dependent on @p duration
70 Duration::Unit presentationUnit( const Duration &duration ) const;
71
72protected slots:
73 void slotNodeChanged( Node* );
74 void slotNodeToBeInserted( Node *node, int row );
75 void slotNodeInserted( Node *node );
76 void slotNodeToBeRemoved( Node *node );
77 void slotNodeRemoved( Node *node );
78
79public:
80 QVariant alignment( int column ) const;
81
82 QVariant name( int role ) const;
83 QVariant duration( int role ) const;
84 QVariant variance( int role ) const;
85
86 QVariant notUsed( int role ) const;
87
88private:
89 ScheduleManager *m_manager;
90 QList<Node*> m_path;
91 NodeModel m_nodemodel;
92};
93
94//--------------------
95
96/**
97 This model displays results from project scheduling.
98*/
99class KPLATOMODELS_EXPORT PertResultItemModel : public ItemModelBase
100{
101 Q_OBJECT
102public:
103 explicit PertResultItemModel( QObject *parent = 0 );
104 ~PertResultItemModel();
105
106 const QMetaEnum columnMap() const { return m_nodemodel.columnMap(); }
107
108 virtual void setProject( Project *project );
109
110 virtual Qt::ItemFlags flags( const QModelIndex & index ) const;
111
112 virtual QModelIndex parent( const QModelIndex & index ) const;
113 virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
114// virtual QModelIndex index( const Node *node ) const;
115 virtual QModelIndex index( const NodeList *lst ) const;
116
117 virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
118 virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
119
120 virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
121
122 virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
123
124 virtual QMimeData * mimeData( const QModelIndexList & indexes ) const;
125 virtual QStringList mimeTypes () const;
126 virtual Qt::DropActions supportedDropActions() const;
127 virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
128
129 NodeList *list( const QModelIndex &index ) const;
130 Node *node( const QModelIndex &index ) const;
131 QAbstractItemDelegate *createDelegate( int column, QWidget *parent ) const;
132
133 NodeList nodeList( QDataStream &stream );
134 using ItemModelBase::dropAllowed;
135 bool dropAllowed( Node *on, const QMimeData *data );
136
137 void clear();
138 void refresh();
139
140 void setManager( ScheduleManager *sm );
141 ScheduleManager *manager() const { return m_manager; }
142
143protected slots:
144 void slotAboutToBeReset();
145 void slotReset();
146
147 void slotNodeChanged( Node* );
148 void slotNodeToBeInserted( Node *node, int row );
149 void slotNodeInserted( Node *node );
150 void slotNodeToBeRemoved( Node *node );
151 void slotNodeRemoved( Node *node );
152
153protected:
154 QVariant alignment( int column ) const;
155
156 QVariant name( int row, int role ) const;
157 QVariant name( const Node *node, int role ) const;
158 QVariant earlyStart( const Task *node, int role ) const;
159 QVariant earlyFinish( const Task *node, int role ) const;
160 QVariant lateStart( const Task *node, int role ) const;
161 QVariant lateFinish( const Task *node, int role ) const;
162 QVariant positiveFloat( const Task *node, int role ) const;
163 QVariant freeFloat( const Task *node, int role ) const;
164 QVariant negativeFloat( const Task *node, int role ) const;
165 QVariant startFloat( const Task *node, int role ) const;
166 QVariant finishFloat( const Task *node, int role ) const;
167
168private:
169 QStringList m_topNames;
170 QList<NodeList*> m_top;
171 NodeList m_cp;
172 NodeList m_critical;
173 NodeList m_noncritical;
174 NodeList m_dummyList;
175
176 ScheduleManager *m_manager;
177 NodeModel m_nodemodel;
178};
179
180} //KPlato namespace
181
182#endif
183