1 /* 2 SPDX-License-Identifier: GPL-2.0-or-later 3 4 SPDX-FileCopyrightText: 2003 Brian Thomas <thomas@mail630.gsfc.nasa.gov> 5 SPDX-FileCopyrightText: 2004-2021 Umbrello UML Modeller Authors <umbrello-devel@kde.org> 6 */ 7 8 #ifndef CODEDOCUMENT_H 9 #define CODEDOCUMENT_H 10 11 #include "codegenobjectwithtextblocks.h" 12 #include "hierarchicalcodeblock.h" 13 14 #include <QMap> 15 #include <QObject> 16 #include <QString> 17 18 class CodeBlockWithComments; 19 class CodeComment; 20 class QXmlStreamWriter; 21 class TextBlock; 22 class UMLPackage; 23 24 /** 25 * A document containing the code for one file. 26 * "friend" status is needed for HBlock so it may call addChildTagToMap which 27 * is protected. 28 */ 29 class CodeDocument : public QObject, public CodeGenObjectWithTextBlocks 30 { 31 friend class HierarchicalCodeBlock; 32 Q_OBJECT 33 public: 34 35 CodeDocument (); 36 virtual ~CodeDocument (); 37 38 void setFileExtension (const QString &new_var); 39 QString getFileExtension () const; 40 41 void setFileName (const QString &new_var); 42 QString getFileName () const; 43 44 void setPackage (UMLPackage *new_var); 45 QString getPackage () const; 46 47 virtual QString getPath () const; 48 49 void setID (const QString &new_id); 50 QString ID () const; 51 52 void setWriteOutCode (bool new_var); 53 bool getWriteOutCode () const; 54 55 void setHeader (CodeComment * comment); 56 CodeComment * getHeader () const; 57 58 bool insertTextBlock (TextBlock * newBlock, TextBlock * existingBlock, bool after = true); 59 60 TextBlock * findTextBlockByTag(const QString &tag, bool descendIntoChildren = false) const; 61 62 virtual QString toString () const; 63 64 virtual void saveToXMI1(QXmlStreamWriter& writer); 65 virtual void loadFromXMI1 (QDomElement & root); 66 67 virtual CodeBlock * newCodeBlock (); 68 virtual HierarchicalCodeBlock * newHierarchicalCodeBlock (); 69 virtual CodeBlockWithComments * newCodeBlockWithComments (); 70 71 virtual QString getUniqueTag(const QString& prefix = QString()); 72 73 QString cleanName (const QString &name); 74 75 virtual void synchronize(); 76 77 virtual void updateContent(); 78 79 friend QDebug operator<<(QDebug os, const CodeDocument& obj); 80 81 protected: 82 83 virtual void setAttributesOnNode (QXmlStreamWriter& writer); 84 85 virtual void setAttributesFromNode (QDomElement & element); 86 87 // these next 2 are needed by child hierarchical code blocks so 88 // that when they call getUniqueTag, we really get a unique tag 89 // Also, it allows 'findTextBlockByTag' To find any tagged text block 90 // anywhere in the document, whether directly owned by the document OR 91 // by some child hierarchical textblock 92 void addChildTagToMap (const QString &tag, TextBlock * tb); 93 void removeChildTagFromMap (const QString &tag); 94 95 void updateHeader (); 96 97 void resetTextBlocks(); 98 99 virtual TextBlock * findCodeClassFieldTextBlockByTag(const QString &tag); 100 101 private: 102 103 int m_lastTagIndex; 104 QString m_filename; 105 QString m_fileExtension; 106 QString m_ID; 107 QString m_pathName; 108 UMLPackage *m_package; 109 110 bool m_writeOutCode; // Whether or not to write out this code document 111 // and any codeblocks, etc that it owns. 112 113 CodeComment * m_header; 114 115 // for recording all of the textblocks held by child hierarchical codeblocks 116 QMap<QString, TextBlock *> m_childTextBlockTagMap; 117 118 }; 119 120 #endif // CODEDOCUMENT_H 121