You can use the model editor to create Universal Modeling Language (UML) style models with structured and behavioral diagrams that provide different views of your system. However, the editor uses a variant of UML and only a subset of properties are provided for specifying the appearance of model elements.
Structural diagrams represent the static aspect of the system and are therefore stable, whereas behavioral diagrams have both static and dynamic aspects.
You can create the following types of structural diagrams:
You can create the following types of behavioral diagrams:
You can create models that contain several different structural or behavioral diagrams. You can add elements to the diagrams and specify properties for them. You can either use standard model elements or add your own elements with custom icons.
You can add model elements to diagrams in the following ways:
You can group elements by surrounding them with a boundary. When you move the boundary, all elements within it are moved together. Similary, drag a swimlane to the diagram. When you move the swimlane, all elements right to the swimlane (for vertical swimlanes) or below it (for horizontal swimlanes) will be moved together. A vertical swimlane is created when you drop the swimlane icon on the top border of the diagram and a horizontal swimlane is created when you drop the icon near the left border.
Classes or other objects that you lay on packages are moved with the packages. You can move individual elements and modify their properties (5) by selecting them. You can also use multiselection to group elements temporarily.
To align elements in the editor, select several elements and right-click to open a context menu. Select actions in the Align Objects menu to align elements horizontally or vertically or to adjust their width and height.
Drag the mouse over elements to select them and apply actions such as changing their stereotype or color. A stereotype is a classifier for elements, such as entity , control , interface ,或 boundary . An entity is usually a class that is used to store data. For some stereotypes, a custom icon is defined. You can assign several comma-separated stereotypes to one element.
To add related elements to a diagram, select an element in the editor, and then select Add Related Elements 在上下文菜单。
By default, when you select an element in a diagram, it is highlighted also in the
Structure
view. To change this behavior so that selecting an element in the
Structure
makes it highlighted also in the diagram, click and hold the
button, and then select
Synchronize Diagram with Structure
. To keep the selections in the diagram and the
Structure
view synchronized, select
Keep Synchronized
.
To zoom into diagrams, select the Zoom In toolbar button, press Ctrl++ , or press Ctrl and roll the mouse wheel up. To zoom out of diagrams, select Zoom Out , press Ctrl+- , or press Ctrl and roll the mouse wheel down. To reset the diagram size to 100%, select Reset Zoom or press Ctrl+0 .
To print diagrams, press Ctrl+C when no elements are selected in the editor to copy all elements to the clipboard by using 300 dpi. Then paste the diagram to an application that can print images.
If you copy a selection of elements in the editor, only those elements and their relations will be copied to the clipboard as an image.
To save diagrams as images, select File > Export Diagram . To save only the selected parts of a diagram, select Export Selected Elements .
You can use wizards to create models and scratch models . A scratch model can be used to quickly put a temporary diagram together. The wizard creates the model file in a temporary folder without any input from you. Therefore, you can assign a keyboard shortcut to the wizard and use it to create and open models with empty diagrams.
To create models:
If possible, the end point of a relation is moved automatically to draw the line to the next sampling point either vertically or horizontally.
You can add nested package elements to a package diagram. The depth of the elements in the diagram corresponds to the depth of the structured model. Elements stacked on other elements of the same type are automatically drawn in a darker shade of the selected color.
Right-click a package to open a context menu, where you can select Create Diagram to create a new package diagram within the model. You can drag and drop items from the element tree to the diagram.
To update the include dependencies of the package, select Update Include Dependencies .
To create class diagrams:
To navigate from a class in a diagram to the source code, double-click the class in the editor or select Show Definition 在上下文菜单。
Elements in class diagrams can have the following types of relations: inheritance, association, and dependency. The end points of association relations can have the following properties: role, cardinality, navigable, and relationship.
To create self-relations, start creating a new association and press Shift to create a new sampling point while dragging the association. Create another sampling point and drop the association at the same class.
To add more points, press Shift and click a relation. To delete a point, press Ctrl and click a point.
To specify members for the class, enter each member on a separate line using a C++ like syntax. For example, the following lines define the method
m
that is private, virtual, and constant:
private: virtual int m(string a) const;
You may group members:
You may add stereotypes to members:
<<setter>> setPosition(const QPointF &pos);
There are some limitations of the parser:
void setSize(int width, int height);
throw()
and
noexpect()
specifiers are not ignored but will make the declaration a method.
You can add source code components, such as libraries, databases, programs, and architectural layers to a component diagram. To add components to component diagrams, drag and drop source code from Projects to the editor, and select Add Component .
To navigate from a component in a diagram to the source code, double-click the component in the editor or select Show Definition 在上下文菜单。
The model editor provides the following built-in element types: package, component, class, and item. For package, component, and class elements, you can specify custom icons. The color, size, and form of the icon are determined by a stereotype. If you attach the stereotype to an element, the element icon is replaced by the custom icon. For example, you can attach the entity and interface stereotypes to classes and the database stereotype to components.
The use case and activity diagrams are examples of using the built-in item element type to add custom elements. The item element has the form of a simple rectangle. The use case illustrates how to use a custom icon for an item. The attached stereotype is called usecase but it is hidden. Therefore, if you drag the use case to the diagram, it is shown as a use case but no stereotype appears to be defined and you can attach an additional stereotype to the use case.
Color and icons are attached to elements in use case and activity diagrams by using a simple definition file format. For example, the following code adds the
UseCase
custom element:
Icon {
id: UseCase
title: "Use-Case"
elements: item
stereotype: 'usecase'
display: icon
width: 40
height: 20
baseColor: #5fb4f0
Shape {
Ellipse { x: 20, y: 10, radiusX: 20, radiusY: 10 }
}
}
For more information about the available options, see standard.def 在 share/qtcreator/modeleditor directory in the Qt Creator installation directory. It describes also how to define custom relation types and templates for existing types (such as a composition relation that can be drawn between classes).
You can add your own definition file and save it with the file extension .def to add custom colors and icons for stereotypes, elements, or tool bars. Either store this file in the the same directory as the standard.def file or select the root element of a model and apply your .def file to the property Config path .