Please download the Source Code of the application to continue further
In this blog, I am going to briefly write the steps to generate a basic ER diagram using Qt & QML. You can use the same logic to create your own ER diagram.
Objectives
Generate the rectangle entities dynamically and connect the last created rectangle to the previous rectangle.
On deleting a rectangle, delete all its child rectangle entities and relations
On dragging a rectangle, the coordinates of front and back connecting lines should be updated
Steps to achieve the objectives
We will create 3 separate subcomponents for a RectangleEntity, LineEntity, and a DeleteEntity which will be called dynamically whenever a new entity creation command is applied. Apart from that, a Button component is called to fire the entity creation signal from the main file
To create a new entity dynamically, we need to use
Qt.createComponent()
andcreateObject()
.Save the dynamically generated component instances inside separate
Map()
to be accessed laterLines can be created using
QtQuick.Shapes
(canvas is not required). Bind one ends of a connecting line to the front and back coordinates of two nearby rectangles so that whenever a rectangle is moved, the coordinates of the line are updated as well.Bind the coordinates of the delete button to the left top of each rectangle
To move a rectangle, use
drag.target: entityRectangle
inside the MouseAreaLastly, when a rectangle entity coordinates are updated, fire a signal to update the new location of the rectangle using QML signals and slots
Top comments (0)