1/* This file is part of the KDE project
2 Copyright (C) 2007, 2012 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 WORKPACKAGEMODEL_H
21#define WORKPACKAGEMODEL_H
22
23#include "kplatomodels_export.h"
24
25#include <QSortFilterProxyModel>
26
27class QModelIndex;
28class QVariant;
29
30/// The main namespace
31namespace KPlato
32{
33
34class WorkPackage;
35class Node;
36class Task;
37class Project;
38class ScheduleManager;
39class NodeItemModel;
40
41class KPLATOMODELS_EXPORT WorkPackageModel : public QObject
42{
43 Q_OBJECT
44 Q_ENUMS( Properties )
45public:
46 explicit WorkPackageModel( QObject *parent = 0 )
47 : QObject( parent )
48 {}
49 ~WorkPackageModel() {}
50
51 QVariant data( const WorkPackage *wp, int column, int role = Qt::DisplayRole ) const;
52
53protected:
54 QVariant nodeName(const WorkPackage *wp, int role ) const;
55 QVariant ownerName(const WorkPackage *wp, int role ) const;
56 QVariant transmitionStatus(const WorkPackage *wp, int role ) const;
57 QVariant transmitionTime(const WorkPackage *wp, int role ) const;
58
59 QVariant completion( const WorkPackage *wp, int role ) const;
60};
61
62/**
63 The WPSortFilterProxyModel only accepts scheduled tasks.
64*/
65class WPSortFilterProxyModel : public QSortFilterProxyModel
66{
67 Q_OBJECT
68public:
69 explicit WPSortFilterProxyModel(QObject *parent = 0) : QSortFilterProxyModel( parent ) {}
70protected:
71 /// Only accept scheduled tasks
72 bool filterAcceptsRow(int source_row, const QModelIndex &sourceParent) const;
73};
74
75/**
76 The WorkPackageProxyModel offers a flat list of tasks with workpackage log entries as children.
77
78 The tasks is fetched from the WPSortFilterProxyModel, the work packages is added by this model.
79
80 It uses the NodeItemModel to get the tasks, the FlatProxyModel to convert to a flat list,
81 and the WPSortFilterProxyModel to accept only scheduled tasks.
82 It depends on the fact that the WPSortFilterProxyModel holds a flat list.
83*/
84class KPLATOMODELS_EXPORT WorkPackageProxyModel : public QAbstractProxyModel
85{
86 Q_OBJECT
87public:
88 explicit WorkPackageProxyModel(QObject *parent = 0);
89
90 Qt::ItemFlags flags(const QModelIndex &index) const;
91 void setSourceModel( QAbstractItemModel *sourceModel );
92 bool hasChildren(const QModelIndex &parent) const;
93 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
94 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
95 QModelIndex parent( const QModelIndex &child ) const;
96 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
97 QVariant data( const QModelIndex &idx, int role = Qt::DisplayRole ) const;
98
99 NodeItemModel *baseModel() const;
100
101 QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
102 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
103
104 Task *taskFromIndex( const QModelIndex &idx ) const;
105 QModelIndex indexFromTask( const Node *node ) const;
106
107public slots:
108 void setProject( Project *project );
109 void setScheduleManager( ScheduleManager *sm );
110
111protected slots:
112 void sourceDataChanged(const QModelIndex& start, const QModelIndex& end);
113 void sourceModelAboutToBeReset();
114 void sourceModelReset();
115 void sourceRowsAboutToBeInserted(const QModelIndex&, int, int );
116 void sourceRowsInserted(const QModelIndex&, int, int end);
117 void sourceRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
118 void sourceRowsRemoved(const QModelIndex& parent, int start, int);
119 void sourceRowsAboutToBeMoved( const QModelIndex&, int sourceStart, int sourceEnd, const QModelIndex&, int destStart );
120 void sourceRowsMoved( const QModelIndex&, int , int , const QModelIndex&, int );
121 void workPackageToBeAdded(Node*, int);
122 void workPackageAdded(Node*);
123 void workPackageToBeRemoved(Node*, int);
124 void workPackageRemoved(Node*);
125
126protected:
127 QModelIndex mapFromBaseModel( const QModelIndex &idx ) const;
128 void detachTasks( Task *task = 0 );
129 void attachTasks( Task *task = 0 );
130
131 inline bool isTaskIndex( const QModelIndex &idx ) const {
132 return idx.isValid() && ! idx.internalPointer();
133 }
134 inline bool isWorkPackageIndex( const QModelIndex &idx ) const {
135 return idx.isValid() && idx.internalPointer();
136 }
137
138private:
139 WorkPackageModel m_model;
140 NodeItemModel *m_nodemodel;
141 QList<QAbstractProxyModel*> m_proxies;
142};
143
144} //namespace KPlato
145
146#endif //WORKPACKAGEMODEL_H
147