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 RELATIONMODEL_H |
21 | #define RELATIONMODEL_H |
22 | |
23 | #include "kptitemmodelbase.h" |
24 | #include "kptschedule.h" |
25 | |
26 | |
27 | class QMimeData; |
28 | class QModelIndex; |
29 | class KUndo2Command; |
30 | |
31 | namespace KPlato |
32 | { |
33 | |
34 | class Project; |
35 | class Node; |
36 | class Relation; |
37 | |
38 | class KPLATOMODELS_EXPORT RelationModel : public QObject |
39 | { |
40 | Q_OBJECT |
41 | public: |
42 | RelationModel() |
43 | : QObject() |
44 | {} |
45 | ~RelationModel() {} |
46 | |
47 | QVariant data( const Relation *relation, int property, int role = Qt::DisplayRole ) const; |
48 | |
49 | static QVariant ( int section, int role = Qt::DisplayRole ); |
50 | |
51 | static int propertyCount(); |
52 | |
53 | QVariant parentName( const Relation *r, int role ) const; |
54 | QVariant childName( const Relation *r, int role ) const; |
55 | QVariant type( const Relation *r, int role ) const; |
56 | QVariant lag( const Relation *r, int role ) const; |
57 | |
58 | }; |
59 | |
60 | class KPLATOMODELS_EXPORT RelationItemModel : public ItemModelBase |
61 | { |
62 | Q_OBJECT |
63 | public: |
64 | explicit RelationItemModel( QObject *parent = 0 ); |
65 | ~RelationItemModel(); |
66 | |
67 | virtual void setProject( Project *project ); |
68 | virtual void setNode( Node *node ); |
69 | |
70 | virtual Qt::ItemFlags flags( const QModelIndex & index ) const; |
71 | |
72 | virtual QModelIndex parent( const QModelIndex & index ) const; |
73 | virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
74 | |
75 | virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; |
76 | virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; |
77 | |
78 | virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; |
79 | virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
80 | |
81 | |
82 | virtual QVariant ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
83 | |
84 | Relation *relation( const QModelIndex &index ) const; |
85 | QAbstractItemDelegate *createDelegate( int column, QWidget *parent ) const; |
86 | |
87 | signals: |
88 | void executeCommand( KUndo2Command* ); |
89 | |
90 | protected slots: |
91 | void slotNodeChanged( Node* ); |
92 | void slotNodeToBeRemoved( Node *node ); |
93 | void slotNodeRemoved( Node *node ); |
94 | void slotRelationToBeRemoved( Relation *r ); |
95 | void slotRelationRemoved( Relation *r ); |
96 | void slotRelationToBeAdded( Relation *r, int, int ); |
97 | void slotRelationAdded( Relation *r ); |
98 | void slotRelationModified( Relation *r ); |
99 | |
100 | void slotLayoutChanged(); |
101 | |
102 | protected: |
103 | bool setType( Relation *r, const QVariant &value, int role ); |
104 | bool setLag( Relation *r, const QVariant &value, int role ); |
105 | |
106 | private: |
107 | Node *m_node; |
108 | RelationModel m_relationmodel; |
109 | |
110 | Relation *m_removedRelation; // to control endRemoveRows() |
111 | }; |
112 | |
113 | } //namespace KPlato |
114 | |
115 | #endif |
116 | |