1 /*
2     SPDX-FileCopyrightText: 2011 Andi Fischer <andi.fischer@hispeed.ch>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #ifndef BASICTYPES_H
7 #define BASICTYPES_H
8 
9 // qt includes
10 #include <QFont>
11 #include <QString>
12 
13 #include <string>
14 
15 /**
16  * This namespace contains all the enums used all over the code base.
17  * The enums are embedded into namespaces and useful functionality is added.
18  */
19 namespace Uml
20 {
21 
22     /**
23      * The model type enum is used to identify the folder the diagrams belong to.
24      */
25     namespace ModelType
26     {
27         enum Enum {
28             Logical,
29             UseCase,
30             Component,
31             Deployment,
32             EntityRelationship,
33             N_MODELTYPES   // must remain last
34         };
35         QString toString(Enum item);
36         Enum fromString(const QString& item);
37         Enum fromInt(int item);
38     }
39 
40     /**
41      * The visibility enum defines the visibility of attributes and operations.
42      */
43     namespace Visibility
44     {
45         enum Enum {
46             Public,
47             Private,
48             Protected,
49             Implementation, // objects marked with this are declared in the implementation file.
50             FromParent = 3,  // alias for Implementation, used by CodeGenerationPolicy
51             Unknown
52         };
53         QString toString(Enum item, bool mnemonic = false);
54         Enum fromString(const QString& item, bool checkUnknown = false);
55         Enum fromInt(int item);
56     }
57 
58     /**
59      * Supported diagram types.
60      */
61     namespace DiagramType
62     {
63         enum Enum {
64             //the values in this enum are saved out to the file
65             //for file compatibility, only add new values to the end
66             Undefined = 0,
67             Class,
68             UseCase,
69             Sequence,
70             Collaboration,
71             State,
72             Activity,
73             Component,
74             Deployment,
75             EntityRelationship,
76             Object,
77             N_DIAGRAMTYPES   // must remain last
78         };
79         QString toString(Enum item);
80         QString toStringI18n(Enum item);
81         Enum fromString(const QString& item);
82         Enum fromInt(int item);
83     }
84 
85     /**
86      * Association types.
87      */
88     namespace AssociationType
89     {
90         // only append entries to this type
91         // it is used as xmi file attribute
92         enum Enum {
93             Generalization  =  500,
94             Aggregation,
95             Dependency,
96             Association,
97             Association_Self,
98             Coll_Mesg_Async,
99             Seq_Message,
100             Coll_Mesg_Self,
101             Seq_Message_Self,
102             Containment,
103             Composition,
104             Realization,
105             UniAssociation,
106             Anchor,
107             State,
108             Activity,
109             Exception,
110             Category2Parent,
111             Child2Category,
112             Relationship,
113             Coll_Mesg_Sync,
114             // enter new entries before this line
115             Reserved,
116             Unknown  =  - 1
117         };
118         QString toString(Enum item);
119         QString toStringI18n(Enum item);
120         Enum fromString(const QString& item);
121         Enum fromInt(int item);
122         bool hasUMLRepresentation(Enum item);
123     }
124 
125     /**
126      * Layout types.
127      */
128     namespace LayoutType
129     {
130         enum Enum {
131             Undefined = 0,
132             Direct,
133             Orthogonal,
134             Polyline,
135             Spline,
136             N_LAYOUTTYPES   // must remain last
137         };
138         QString toString(Enum item);
139         Enum fromString(const QString& item);
140         Enum fromInt(int item);
141     }
142 
143     /**
144      * Diagram property controlling display of stereotypes.
145      */
146     namespace ShowStereoType
147     {
148         enum Enum {
149             None = 0,    ///< no display of stereotype
150             Name,        ///< stereotype name only
151             Tags         ///< stereotype name and tagged values
152         };
153     }
154 
155     /**
156      * Signature types.
157      */
158     namespace SignatureType
159     {
160         enum Enum {
161             NoSig  =  600,
162             ShowSig,
163             SigNoVis,
164             NoSigNoVis
165         };
166         QString toString(Enum item);
167         Enum fromString(const QString& item);
168         Enum fromInt(int item);
169     }
170 
171     /**
172      * TextRole types.
173      */
174     namespace TextRole
175     {
176         enum Enum {
177             Floating  =  700,   //text widget on diagrams
178             MultiA,             //Text for Multiple A
179             MultiB,             //Text for Multiple B
180             Name,               //middle text on most associations
181             Seq_Message,        //message on seq diagram between two objects
182             Seq_Message_Self,   //message to self on seq diagram - feature not implemented yet
183             Coll_Message,       //message between two objects on a collab diagram
184             Coll_Message_Self,  //message to object self on collab diagram
185             State,
186             RoleAName,          //RoleA text on associations
187             RoleBName,          //RoleB text on associations
188             ChangeA,            //Changeability A text on associations
189             ChangeB,            //Changeability B text on associations
190             Reserved            //Enter new entries before this line
191         };
192         QString toString(Enum item);
193         Enum fromString(const QString& item);
194         Enum fromInt(int item);
195     }
196 
197     /**
198      * Changeability types.
199      */
200     namespace Changeability
201     {
202         enum Enum {
203             Changeable = 900,
204             Frozen,
205             AddOnly
206         };
207         QString toString(Enum item);
208         Enum fromString(const QString& item);
209         Enum fromInt(int item);
210     }
211 
212     /**
213      * SequenceMessage type
214      */
215     namespace SequenceMessage
216     {
217         enum Enum {
218             //This is saved out to the file so only add new entries at the end
219             Synchronous = 1000,
220             Asynchronous,
221             Creation,
222             Lost,
223             Found,
224             Destroy,
225         };
226         QString toString(Enum item);
227         Enum fromString(const QString& item);
228         Enum fromInt(int item);
229     }
230 
231     /**
232      * Constants used for indexing the roles of associations.
233      */
234     namespace RoleType
235     {
236         enum Enum {
237             A,
238             B
239         };
240         QString toString(Enum item);
241         Enum fromString(const QString& item);
242         Enum fromInt(int item);
243     }
244 
245     /**
246      * Direction of operation parameters:
247      *   in = operation uses the parameter as an input value
248      *   out = operation fills the parameter as a return value
249      *   inout = operation both reads and writes the parameter
250      * The numeric values of this enum are not currently saved to file.
251      */
252     namespace ParameterDirection
253     {
254         enum Enum {
255             In,
256             InOut,
257             Out
258         };
259         QString toString(Enum item);
260         Enum fromString(const QString& item);
261         Enum fromInt(int item);
262     }
263 
264     /**
265      * UML primitive types
266      */
267     namespace PrimitiveTypes
268     {
269         enum Enum {
270             String,
271             Boolean,
272             UnlimitedNatural,
273             Integer,
274             Real,
275             Reserved
276         };
277 
278         const int n_types = int(Reserved);
279 
280         QString toString(Enum item);
281         QString toString(int item);
282         Enum fromString(const QString& item, bool strict = false);
283         Enum fromInt(int item);
284     }
285 
286     /**
287      * Supported programming languages.
288      */
289     namespace ProgrammingLanguage
290     {
291         enum Enum {
292             ActionScript,
293             Ada,
294             Cpp,
295             CSharp,
296             D,
297             IDL,
298             Java,
299             JavaScript,
300             MySQL,
301             Pascal,
302             Perl,
303             PHP,
304             PHP5,
305             PostgreSQL,
306             Python,
307             Ruby,
308             SQL,
309             Tcl,
310             Vala,
311             XMLSchema,
312             Reserved   // for UML Primitive Types (no code generator)
313         };
314         QString toString(Enum item);
315         Enum fromString(const QString& item);
316         Enum fromInt(int item);
317         QStringList toExtensions(Enum item);
318         QString toExtensionsDescription(Enum item);
319         bool isCaseSensitive(Enum item);
320         QString scopeSeparator(Enum item);
321     }
322 
323     /**
324      * Enumeration used for stating where a line is on a widget.
325      * @note Do not change this ordering, as we use these values in for loop.
326      * @note See also associationwidget.h.
327      */
328     namespace Region
329     {
330         enum Enum {
331             Error = 0,
332             West,
333             North,
334             East,
335             South,
336             NorthWest,
337             NorthEast,
338             SouthEast,
339             SouthWest,
340             Center
341         };
342         QString toString(Enum item);
343         Enum fromString(const QString& item);
344         Enum fromInt(int item);
345     }
346 
347     /**
348      * Corner class with special operators.
349      */
350     class Corner
351     {
352     public:
353         enum Enum {
354             TopLeft     = 0x1,
355             TopRight    = 0x2,
356             BottomRight = 0x4,
357             BottomLeft  = 0x8
358         };
359         static QString toString(Enum item);
360         static Enum fromString(const QString& item);
361         static Enum fromInt(int item);
362     };
Q_DECLARE_FLAGS(Corners,Corner::Enum)363     Q_DECLARE_FLAGS(Corners, Corner::Enum)
364     Q_DECLARE_OPERATORS_FOR_FLAGS(Corners)
365 
366     /**
367      * The data type used for unique IDs.
368      */
369     namespace ID
370     {
371         typedef std::string Type;
372 
373         const Type None     = "-1";   ///< special value for uninitialized ID
374         const Type Reserved = "0";    ///< special value for illegal ID
375 
376         QString toString(const ID::Type &id);
377         ID::Type fromString(const QString &id);
378         QDebug operator<<(QDebug out, ID::Type &type);
379     }
380 
381 QFont systemFont();
382 
383 }  // end namespace Uml
384 
toString(Uml::ProgrammingLanguage::Enum lang)385 static inline QString toString(Uml::ProgrammingLanguage::Enum lang)
386 {
387     return Uml::ProgrammingLanguage::toString(lang);
388 }
389 
toString(Uml::Visibility::Enum visibility)390 static inline QString toString(Uml::Visibility::Enum visibility)
391 {
392     return Uml::Visibility::toString(visibility);
393 }
394 
395 qreal toDoubleFromAnyLocale(const QString &s);
396 
397 #endif
398