-
-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathrelationshipview.h
More file actions
240 lines (173 loc) · 8.57 KB
/
relationshipview.h
File metadata and controls
240 lines (173 loc) · 8.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
# PostgreSQL Database Modeler (pgModeler)
#
# Copyright 2006-2025 - Raphael Araújo e Silva <raphael@pgmodeler.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The complete text of GPLv3 is at LICENSE file on source code root directory.
# Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
*/
/**
\ingroup libcanvas
\class RelationshipView
\brief Implements the graphical representation for relationships
*/
#ifndef RELATIONSHIP_VIEW_H
#define RELATIONSHIP_VIEW_H
#include "textboxview.h"
#include "baserelationship.h"
#include "basetableview.h"
#include "beziercurveitem.h"
class __libcanvas RelationshipView: public BaseObjectView {
Q_OBJECT
public:
enum LineConnectionMode: unsigned {
ConnectCenterPoints,
ConnectFkToPk,
ConnectTableEdges
};
private:
//! \brief Graphical point radius
static constexpr double GraphicPointRadius=6.0;
/*! \brief The width of the path stroke used to select relationship line
* as well as add points to it */
static constexpr double LineSelStrokeWidth=15;
//! \brief Length of the lines linked to fk/pk columns
static constexpr double ConnLineLength=20.0;
//! \brief Indicates that the relationship labels must be hidden
static bool hide_name_label;
//! \brief Indicates that the relationship lines should be curved
static bool use_curved_lines;
//! \brief Indicates that the relationship should be drawn in Crow's foot notation
static bool use_crows_foot;
/*! \brief Specify the type of connection used by the lines. The first (classical)
is to connect the line to tables through their central points. The second (better semantics)
makes the line start from the fk columns on receiver table and connecting to the pk columns on reference table */
static LineConnectionMode line_conn_mode;
/*! \brief Indicate that the line is being configured/updated. This flag is used to evict
that the configureLine() method is exceedingly called during the table moving. */
bool configuring_line,
//! \brief Indicates if the instance is configured to use placeholders
using_placeholders;
//! \brief Stores the graphical representation for labels
TextboxView *labels[3];
//! \brief Stores the graphical representation for the participant tables
BaseTableView *tables[2];
QString tab_hashes[2];
/*! \brief Stores the points on tables where the relationship line is connected.
This attribute is updated every time the configureLine() method is called.
When the relationship uses the classical link mode (center points) this attribute
contains the table's center points. Now, when the new line mode is used this
attribute stores the middle point between the connection points of each table */
QPointF conn_points[2];
//! \brief Graphical representation for the user added points
std::vector<QGraphicsPolygonItem *> graph_points;
//! \brief Lines that represent the relationship
std::vector<QGraphicsLineItem *> lines,
//! \brief Lines that are connected to the reference table (only on CONNECT_FK_TO_PK mode)
pk_lines,
//! \brief Lines that are connected to the receiver table (only on CONNECT_FK_TO_PK mode)
fk_lines;
//! \brief Stores the graphical representation for relationship attributes
std::vector<QGraphicsItemGroup *> attributes;
//! \brief Relationship descriptor (lozenge -> (1,n)-(1,n) relationship, triangle -> inheritance)
QGraphicsPolygonItem *descriptor;
//! \brief Stores the current hovered child object
QGraphicsItem *sel_object;
//! \brief Stores the initial (default) labels position
QPointF labels_ini_pos[3];
QGraphicsEllipseItem *line_circles[2];
//! \brief Stores the curved lines representing the relationship
std::vector<BezierCurveItem *> curves;
//! \brief Stores the crow's foot notation descriptors
QGraphicsItemGroup * cf_descriptors[2];
std::vector<QGraphicsLineItem *> src_cf_lines, dst_cf_lines;
QGraphicsEllipseItem *round_cf_descriptors[2];
//! \brief Stores the selected child object index
int sel_object_idx;
//! \brief Configures the labels positioning
void configureLabels();
//! \brief Configures the relationship tooltip
void configureToolTip();
//! \brief Configures the descriptor form and positioning
void configureDescriptor();
//! \brief Configures the crow's feet descriptors form and positioning
void configureCrowsFootDescriptors();
//! \brief Configures the attributes positioning
void configureAttributes();
//! \brief Configures the position info object
void configurePositionInfo();
//! \brief Configures the specified label's position based as well some styles for it
void configureLabelPosition(BaseRelationship::LabelId label_id, double x, double y);
/*! \brief Returns the default pen width size taking into account the screen dpi and the
* whether the relationship is identifier or not */
double getDefaultPenWidth();
QPainterPath rel_shape;
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
/*! \brief (Re)connects the tables to the relationship changing the signals captured.
This method is called whenever the placeholder usage is toggled. If the placeholders are on
the the table's signal s_relUpdateRequested() is used otherwise the s_objectMoved() is used */
void connectTables();
//! \brief Disconnects the signal handled by the relationship which senders are the tables
void disconnectTables();
public:
RelationshipView(BaseRelationship *rel);
virtual ~RelationshipView();
virtual QPainterPath shape() const override;
//! \brief Calculates the relationship bounding rect considering all the children objects dimension
void configureBoundingRect();
//! \brief Returns the relationship that generates the graphical representation
BaseRelationship *getUnderlyingObject();
//! \brief Hides the relationship's name label. This applies to all relationship instances
static void setHideNameLabel(bool value);
//! \brief Returns the current visibility state of name label
static bool isNameLabelHidden();
//! \brief Enables the usage of curved lines for all relationships
static void setCurvedLines(bool value);
//! \brief Returns the current state of curved lines usage
static bool isCurvedLines();
//! \brief Enables the usage of Crow's foot notation for all relationships
static void setCrowsFoot(bool value);
//! \brief Returns the current state of Crow's foot notation usage
static bool isCrowsFoot();
/*! \brief Configures the mode in which the lines are connected on tables.
The first one is the CONNECT_CENTER_PNTS (the classical one) which connects the
two tables through the center points. The CONNECT_FK_TO_PK is the one with a better
semantics and connects the fk columns of receiver table to pk columns on reference table */
static void setLineConnectionMode(LineConnectionMode mode);
//! \brief Returns the line connection mode used for the relationships
static unsigned getLineConnectinMode();
/*! \brief Returns the connection point for the specified table. The connection point is
where the relationship is connected on envolved tables. The point returned deffers depending on the
line connection mode used. */
QPointF getConnectionPoint(BaseRelationship::TableId table_idx);
//! \brief Returns the label through its index
TextboxView *getLabel(BaseRelationship::LabelId lab_idx);
//! \brief Returns the current visibility state of the tables in that are linked by the relationship
bool isTableVisible(BaseRelationship::TableId table_idx);
void configureObjectShadow(void) = delete;
void configureObjectSelection(void) = delete;
public slots:
//! \brief Configures the relationship line
void configureLine();
private slots:
//! \brief Makes the comple relationship configuration
virtual void configureObject() override;
signals:
void s_relationshipModified(BaseGraphicObject *rel);
friend class ObjectsScene;
};
#endif