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 KPTDOCUMENTMODEL_H
21#define KPTDOCUMENTMODEL_H
22
23#include "kptitemmodelbase.h"
24
25namespace KPlato
26{
27
28class Document;
29class Documents;
30
31class KPLATOMODELS_EXPORT DocumentModel : public QObject
32{
33 Q_OBJECT
34public:
35 enum Properties {
36 Property_Url = 0,
37 Property_Name,
38 Property_Type,
39 Property_SendAs,
40 Property_Status
41 };
42
43 DocumentModel()
44 : QObject()
45 {}
46 ~DocumentModel() {}
47
48 QVariant data( const Document *doc, int property, int role = Qt::DisplayRole ) const;
49 static bool setData( Document *doc, int property, const QVariant & value, int role = Qt::EditRole );
50
51 static QVariant headerData( int section, int role = Qt::DisplayRole );
52
53 static int propertyCount();
54
55 QVariant url( const Document *doc, int role ) const;
56 QVariant name( const Document *doc, int role ) const;
57 bool setName( Document *doc, const QVariant &value, int role );
58 QVariant type( const Document *doc, int role ) const;
59 bool setType( Document *doc, const QVariant &value, int role );
60 QVariant status( const Document *doc, int role ) const;
61 QVariant sendAs( const Document *doc, int role ) const;
62 bool setSendAs( Document *doc, const QVariant &value, int role );
63};
64
65class KPLATOMODELS_EXPORT DocumentItemModel : public ItemModelBase
66{
67 Q_OBJECT
68public:
69 explicit DocumentItemModel( QObject *parent = 0 );
70 ~DocumentItemModel();
71
72 virtual void setDocuments( Documents *docs );
73 Documents *documents() const;
74
75 virtual Qt::ItemFlags flags( const QModelIndex & index ) const;
76
77 virtual QModelIndex parent( const QModelIndex & index ) const;
78 virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
79 virtual QModelIndex index( const Document *doc ) const;
80
81 virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
82 virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
83
84 virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
85 virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
86
87
88 virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
89
90 virtual QMimeData * mimeData( const QModelIndexList & indexes ) const;
91 virtual QStringList mimeTypes () const;
92 virtual Qt::DropActions supportedDropActions() const;
93 virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
94
95 Document *document( const QModelIndex &index ) const;
96
97 QAbstractItemDelegate *createDelegate( int column, QWidget *parent ) const;
98
99 QModelIndex insertDocument( Document *doc, Document *after );
100
101 bool dropAllowed( Document *on, const QMimeData *data );
102
103 virtual bool dropAllowed( const QModelIndex &index, int dropIndicatorPosition, const QMimeData *data );
104
105protected slots:
106 void slotDocumentChanged( Document* );
107 void slotDocumentToBeInserted( Documents*, int row );
108 void slotDocumentInserted( Document* );
109 void slotDocumentToBeRemoved( Document* );
110 void slotDocumentRemoved( Document* );
111
112protected:
113 bool setUrl( Document *doc, const QVariant &value, int role );
114 bool setName( Document *doc, const QVariant &value, int role );
115 bool setType( Document *doc, const QVariant &value, int role );
116 bool setSendAs( Document *doc, const QVariant &value, int role );
117
118private:
119 Documents *m_documents;
120 DocumentModel m_model;
121};
122
123
124} //namespace KPlato
125
126#endif
127