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-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org> 6 */ 7 8 #ifndef CODEGENERATIONPOLICY_H 9 #define CODEGENERATIONPOLICY_H 10 11 #include "basictypes.h" 12 13 #include <QDir> 14 #include <QObject> 15 16 class QWidget; 17 class CodeGenerationPolicyPage; 18 19 /** 20 * class CodeGenerationPolicy 21 * This class describes the code generation policy for this project. 22 * Note that as the code gen policy may be the 'default' policy, it may 23 * not be coupled with a code generator. 24 */ 25 class CodeGenerationPolicy : public QObject 26 { 27 Q_OBJECT 28 public: 29 30 /** 31 * OverwritePolicy can have the following values 32 * - Ok: if there is a file named the same as what you want to name your output file, 33 * you can overwrite the old file. 34 * - Ask:if there is a file named the same as what you want to name your output file, 35 * you should ask the User what to do, and give him the option to overwrite the file 36 * write the code to a different file, or to abort the generation of this class. 37 * - Never: you cannot overwrite any files. Generates a new file name like "fileName1.h", "fileName2.h" 38 * until you find an appropriate name. 39 * - Cancel: Do not output anything. This is only set if the user chooses Apply to All Remaining Files 40 * and clicks on Do not Output in the Ask dialog 41 */ 42 enum OverwritePolicy {Ok=0, Ask, Never, Cancel}; 43 enum ModifyNamePolicy {No=0, Underscore, Capitalise}; 44 enum NewLineType {UNIX=0, DOS, MAC}; 45 enum IndentationType {NONE=0, TAB, SPACE}; 46 enum CommentStyle { SingleLine=0, MultiLine }; 47 48 explicit CodeGenerationPolicy(CodeGenerationPolicy * clone); 49 CodeGenerationPolicy(); 50 51 virtual ~CodeGenerationPolicy(); 52 53 void setOverwritePolicy(OverwritePolicy new_var); 54 OverwritePolicy getOverwritePolicy() const; 55 56 void setCodeVerboseSectionComments(bool new_var); 57 bool getCodeVerboseSectionComments() const; 58 59 void setCodeVerboseDocumentComments(bool new_var); 60 bool getCodeVerboseDocumentComments() const; 61 62 void setHeadingFileDir(const QString & path); 63 QString getHeadingFileDir() const; 64 65 void setIncludeHeadings(bool new_var); 66 bool getIncludeHeadings() const; 67 68 void setOutputDirectory(QDir new_var); 69 QDir getOutputDirectory(); 70 71 void setLineEndingType(NewLineType type); 72 NewLineType getLineEndingType(); 73 74 QString getNewLineEndingChars() const; 75 76 void setIndentationType(IndentationType type); 77 IndentationType getIndentationType(); 78 79 void setIndentationAmount(int amount); 80 int getIndentationAmount(); 81 82 QString getIndentation() const; 83 84 void setModifyPolicy(ModifyNamePolicy new_var); 85 ModifyNamePolicy getModifyPolicy() const; 86 87 void setAutoGenerateConstructors(bool var); 88 bool getAutoGenerateConstructors(); 89 90 void setAttributeAccessorScope(Uml::Visibility::Enum var); 91 Uml::Visibility::Enum getAttributeAccessorScope(); 92 93 void setAssociationFieldScope(Uml::Visibility::Enum var); 94 Uml::Visibility::Enum getAssociationFieldScope(); 95 96 virtual CodeGenerationPolicyPage * createPage(QWidget *parent = 0, const char * name = 0); 97 98 QString getHeadingFile(const QString& str); 99 100 virtual void setDefaults(CodeGenerationPolicy * defaults, bool emitUpdateSignal = true); 101 virtual void setDefaults(bool emitUpdateSignal = true); 102 103 virtual void writeConfig(); 104 105 void emitModifiedCodeContentSig(); 106 107 void setCommentStyle(CommentStyle new_var); 108 CommentStyle getCommentStyle(); 109 110 signals: 111 112 void modifiedCodeContent(); 113 114 protected: 115 116 /* 117 // Policy of how to deal with overwriting existing files. Allowed values are "ask", "yes" and "no". 118 OverwritePolicy m_overwritePolicy; 119 120 // Whether or not verbose code commenting for sections is desired. 121 // If true, comments for sections will be written even if the section is empty. 122 bool m_codeVerboseSectionComments; 123 124 // Whether or not verbose code commenting for documentation is desired. 125 // If true, documentation for various code will be written even if no 126 //code would normally be created at that point in the file. 127 bool m_codeVerboseDocumentComments; 128 129 QDir m_headingFiles; // location of the header file template. 130 bool m_includeHeadings; 131 QDir m_outputDirectory; // location of where output files will go. 132 NewLineType m_lineEndingType; // What type of line ending characters to use. 133 IndentationType m_indentationType; // The amount and type of whitespace to indent with. 134 int m_indentationAmount; // The amount of units to indent with. 135 ModifyNamePolicy m_modifyPolicy; 136 bool m_autoGenerateConstructors; 137 CommentStyle m_commentStyle; 138 Uml::Visibility::Value m_attributeAccessorScope; 139 Uml::Visibility::Value m_associationFieldScope; 140 */ 141 142 // these 2 private fields 'cache' the string values of other fields we may frequently call for 143 QString m_lineEndingChars; 144 QString m_indentation; 145 146 void calculateIndentation(); 147 148 /* 149 protected: 150 151 void initFields(); 152 */ 153 }; 154 155 #endif // CODEGENERATIONPOLICY_H 156