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 KPTDOCUMENTS_H 21 #define KPTDOCUMENTS_H 22 23 #include "plankernel_export.h" 24 25 #include <KoXmlReaderForward.h> 26 27 #include <QList> 28 #include <QUrl> 29 30 class KoStore; 31 32 class QDomElement; 33 34 namespace KPlato 35 { 36 37 class XMLLoaderObject; 38 class Node; 39 class Documents; 40 41 class PLANKERNEL_EXPORT Document 42 { 43 public: 44 enum Type { Type_None, Type_Product, Type_Reference }; 45 enum SendAs { SendAs_None, SendAs_Copy, SendAs_Reference }; 46 47 Document(); 48 explicit Document(const QUrl &url, Type type = Type_Reference, SendAs sendAs = SendAs_Reference); 49 ~Document(); 50 51 bool operator==(const Document &doc) const; 52 bool operator!=(const Document &doc) const { return ! operator==(doc); } 53 name()54 QString name() const { return m_name; } 55 void setName(const QString &name); 56 type()57 Type type() const { return m_type; } 58 void setType(Type type); 59 static QStringList typeList(bool trans = false); 60 static QString typeToString(Type type, bool trans = false); 61 sendAs()62 SendAs sendAs() const { return m_sendAs; } 63 void setSendAs(SendAs snd); 64 static QStringList sendAsList(bool trans = false); 65 static QString sendAsToString(SendAs snd, bool trans = false); 66 url()67 QUrl url() const { return m_url; } 68 void setUrl(const QUrl &url); 69 bool isValid() const; 70 status()71 QString status() const { return m_status; } 72 void setStatus(const QString &sts); 73 74 bool load(KoXmlElement &element, XMLLoaderObject &status); 75 void save(QDomElement &element) const; 76 77 private: 78 Type m_type; 79 QUrl m_url; 80 QString m_status; 81 SendAs m_sendAs; 82 QString m_name; 83 84 friend class Documents; 85 Documents *parent; 86 }; 87 88 class PLANKERNEL_EXPORT Documents 89 { 90 public: 91 Documents(); 92 explicit Documents(const Documents &docs); 93 ~Documents(); 94 95 bool operator==(const Documents &docs) const; 96 bool operator!=(const Documents &docs) const { return ! operator==(docs); } 97 98 void deleteAll(); documents()99 QList<Document*> documents() const { return m_docs; } 100 void addDocument(Document *doc); 101 void addDocument(const QUrl &url, Document::Type = Document::Type_None); 102 Document *takeDocument(int index); 103 Document *takeDocument(Document *doc); 104 Document *findDocument(const Document *doc) const; 105 Document *findDocument(const QUrl &url) const; 106 // Document *document(int index) const; 107 contains(const Document * doc)108 bool contains(const Document *doc) const { return m_docs.contains(const_cast<Document*>(doc) ); } indexOf(const Document * doc)109 int indexOf(const Document *doc) const { return m_docs.indexOf(const_cast<Document*>(doc) ); } count()110 int count() const { return m_docs.count(); } at(int index)111 const Document *at(int index) const { return m_docs.at(index); } value(int index)112 Document *value(int index) const { return m_docs.value(index); } 113 114 bool load(KoXmlElement &element, XMLLoaderObject &status); 115 void save(QDomElement &element) const; 116 117 void saveToStore(KoStore *store) const; 118 119 void documentChanged(Document *doc); 120 121 protected: 122 QList<Document*> m_docs; 123 124 private: 125 friend class Node; 126 Node *node; // owner node 127 }; 128 129 } //namespace KPlato 130 131 #endif 132