DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbse::SchemaGraphicSegmentedArrow Class Reference

#include <SchemaGraphicSegmentedArrow.hpp>

Inheritance diagram for dbse::SchemaGraphicSegmentedArrow:
[legend]
Collaboration diagram for dbse::SchemaGraphicSegmentedArrow:
[legend]

Public Member Functions

 SchemaGraphicSegmentedArrow (SchemaGraphicObject *StartItem, SchemaGraphicObject *EndItem, int connection_count, bool IsInheritance, bool IsComposite, QString ArrowName, QString ArrowCardinality, QGraphicsItem *parent=nullptr)
 ~SchemaGraphicSegmentedArrow ()
QRectF boundingRect () const
QPainterPath shape () const
void UpdatePosition ()
SchemaGraphicObject * GetStartItem () const
SchemaGraphicObject * GetEndItem () const
bool GetInheritanceMode ()
void RemoveArrow ()

Protected Member Functions

void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
void hoverEnterEvent (QGraphicsSceneHoverEvent *ev)
void hoverLeaveEvent (QGraphicsSceneHoverEvent *ev)

Private Member Functions

QPointF p1 () const
QPointF p2 () const
qreal dx () const
qreal dy () const
QPolygonF make_arrow_head (qreal angle) const
QPolygonF make_rhombus (qreal angle) const

Private Attributes

SchemaGraphicObject * m_start_item
SchemaGraphicObject * m_end_item
int m_connection_count
QPolygonF m_marker
QRectF m_rel_label_br
QRectF m_rel_cardinality_br
bool m_inheritance
bool m_composite
QString m_name
QString m_cardinality
QColor m_default_color
QFont m_label_font
qreal m_arrow_size
double LastDegree
double LastRotation

Detailed Description

Definition at line 12 of file SchemaGraphicSegmentedArrow.hpp.

Constructor & Destructor Documentation

◆ SchemaGraphicSegmentedArrow()

dbse::SchemaGraphicSegmentedArrow::SchemaGraphicSegmentedArrow ( SchemaGraphicObject * StartItem,
SchemaGraphicObject * EndItem,
int connection_count,
bool IsInheritance,
bool IsComposite,
QString ArrowName,
QString ArrowCardinality,
QGraphicsItem * parent = nullptr )

Definition at line 18 of file SchemaGraphicSegmentedArrow.cpp.

26 : QGraphicsPathItem(parent)
27 , m_start_item(start_item)
28 , m_end_item(end_item)
29 , m_connection_count(connection_count)
30 , m_inheritance(is_inheritance)
31 , m_composite(is_composite)
32 , m_name(arrow_name)
33 , m_cardinality(arrow_cardinality)
34 , LastDegree(0)
35 , LastRotation(0)
36{
37 if (!is_inheritance) {
38 setAcceptHoverEvents(true);
39 }
40 // setPen(QPen(Qt::black,2,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
41 setFlag(ItemIsSelectable, true);
42 m_arrow_size = 20;
43}

◆ ~SchemaGraphicSegmentedArrow()

dbse::SchemaGraphicSegmentedArrow::~SchemaGraphicSegmentedArrow ( )

Definition at line 45 of file SchemaGraphicSegmentedArrow.cpp.

45{}

Member Function Documentation

◆ boundingRect()

QRectF dbse::SchemaGraphicSegmentedArrow::boundingRect ( ) const

Definition at line 67 of file SchemaGraphicSegmentedArrow.cpp.

68{
69 if (m_start_item->collidesWithItem(m_end_item)) {
70 return QRectF();
71 }
72
73 qreal extra = (pen().width() + 20) / 2.0 + 10;
74 auto br =
75 QRectF(p1(), QSizeF(p2().x() - p1().x(), p2().y() - p1().y())).normalized().adjusted(-extra, -extra, extra, extra);
76 br = br.united(m_rel_label_br);
77 br = br.united(m_rel_cardinality_br);
78 return br;
79}

◆ dx()

qreal dbse::SchemaGraphicSegmentedArrow::dx ( ) const
inlineprivate

Definition at line 40 of file SchemaGraphicSegmentedArrow.hpp.

40{ return p2().x() - p1().x(); }

◆ dy()

qreal dbse::SchemaGraphicSegmentedArrow::dy ( ) const
inlineprivate

Definition at line 41 of file SchemaGraphicSegmentedArrow.hpp.

41{ return p2().y() - p1().y(); }

◆ GetEndItem()

SchemaGraphicObject * dbse::SchemaGraphicSegmentedArrow::GetEndItem ( ) const

Definition at line 281 of file SchemaGraphicSegmentedArrow.cpp.

282{
283 return m_end_item;
284}

◆ GetInheritanceMode()

bool dbse::SchemaGraphicSegmentedArrow::GetInheritanceMode ( )

Definition at line 287 of file SchemaGraphicSegmentedArrow.cpp.

288{
289 return m_inheritance;
290}

◆ GetStartItem()

SchemaGraphicObject * dbse::SchemaGraphicSegmentedArrow::GetStartItem ( ) const

Definition at line 275 of file SchemaGraphicSegmentedArrow.cpp.

276{
277 return m_start_item;
278}

◆ hoverEnterEvent()

void dbse::SchemaGraphicSegmentedArrow::hoverEnterEvent ( QGraphicsSceneHoverEvent * ev)
protected

Definition at line 48 of file SchemaGraphicSegmentedArrow.cpp.

49{
50 if (!m_name.isEmpty()) {
51 auto info = m_start_item->GetClass();
52
53 auto rel = info->find_relationship(m_name.toStdString());
54
55 QToolTip::showText(he->screenPos(), QString::fromStdString(rel->get_description()));
56 }
57 he->ignore();
58}
dunedaq::oks::OksClass * GetClass() const

◆ hoverLeaveEvent()

void dbse::SchemaGraphicSegmentedArrow::hoverLeaveEvent ( QGraphicsSceneHoverEvent * ev)
protected

Definition at line 60 of file SchemaGraphicSegmentedArrow.cpp.

61{
62 QToolTip::hideText();
63 he->ignore();
64}

◆ make_arrow_head()

QPolygonF dbse::SchemaGraphicSegmentedArrow::make_arrow_head ( qreal angle) const
private

Definition at line 303 of file SchemaGraphicSegmentedArrow.cpp.

304{
305
306 float opening_angle = atan2(1, 0.5);
307 qreal size = m_arrow_size;
308 QPointF a1 = QPointF(sin(rotation + opening_angle) * size, cos(rotation + opening_angle) * size);
309 QPointF a2 = QPointF(sin(rotation + M_PI - opening_angle) * size, cos(rotation + M_PI - opening_angle) * size);
310
311 QPolygonF arrow;
312 arrow << QPointF(0, 0) << a1 << a2;
313 return arrow;
314}
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ make_rhombus()

QPolygonF dbse::SchemaGraphicSegmentedArrow::make_rhombus ( qreal angle) const
private

Definition at line 317 of file SchemaGraphicSegmentedArrow.cpp.

318{
319
320 float opening_angle = M_PI / 3;
321 qreal size = 0.6 * m_arrow_size;
322
323 QPointF a1 = QPointF(sin(rotation + opening_angle) * size, cos(rotation + opening_angle) * size);
324 QPointF a2 = QPointF(sin(rotation + M_PI - opening_angle) * size, cos(rotation + M_PI - opening_angle) * size);
325
326 QPointF m = QPointF((a1.x() + a2.x()) / 2, (a1.y() + a2.y()) / 2);
327 QPointF a3 = QPointF(2 * m.x(), 2 * m.y());
328
329 QPolygonF rhombus;
330 rhombus << QPointF(0, 0) << a1 << a3 << a2;
331 return rhombus;
332}

◆ p1()

QPointF dbse::SchemaGraphicSegmentedArrow::p1 ( ) const
inlineprivate

Definition at line 38 of file SchemaGraphicSegmentedArrow.hpp.

38{ return path().elementCount() > 0 ? path().elementAt(0) : QPointF(); }

◆ p2()

QPointF dbse::SchemaGraphicSegmentedArrow::p2 ( ) const
inlineprivate

Definition at line 39 of file SchemaGraphicSegmentedArrow.hpp.

39{ return path().elementCount() > 0 ? path().elementAt(path().elementCount() - 1) : QPointF(); }

◆ paint()

void dbse::SchemaGraphicSegmentedArrow::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget = 0 )
protected

Draw Rhombus

Draw Rhombus

Definition at line 335 of file SchemaGraphicSegmentedArrow.cpp.

336{
337 Q_UNUSED(option)
338 Q_UNUSED(widget)
339
340 if (m_start_item->collidesWithItem(m_end_item)) {
341 return;
342 }
343
344 const QPen line_pen = QPen(SchemaStyle::get_color("foreground", "line"), 1);
345 const QPen arrow_pen = QPen(SchemaStyle::get_color("foreground", "line"), 1);
346
347 painter->setFont(QFont(SchemaStyle::get_font("line")));
348 painter->setPen(line_pen);
349 painter->setBrush({});
350 painter->setRenderHint(QPainter::Antialiasing);
351
352 painter->drawPath(this->path());
353
354 painter->setPen(arrow_pen);
355 if (!m_inheritance) {
356 painter->drawText(m_rel_label_br, Qt::AlignTop | Qt::AlignLeft, QString(m_name));
357 painter->drawText(m_rel_cardinality_br, Qt::AlignTop | Qt::AlignLeft, QString(m_cardinality));
358 }
359
360 if (m_inheritance) {
361 painter->setBrush(Qt::white);
362 } else if (m_composite) {
364 painter->setBrush(SchemaStyle::get_color("foreground", "line"));
365
366 } else {
368 painter->setBrush(Qt::white);
369 }
370 painter->drawPolygon(m_marker);
371}
static QColor get_color(const QString &item, const QString &group)
static QFont get_font(const QString &group)

◆ RemoveArrow()

void dbse::SchemaGraphicSegmentedArrow::RemoveArrow ( )

Remove Super class

Remove relationship

Definition at line 293 of file SchemaGraphicSegmentedArrow.cpp.

294{
295 if (m_inheritance) {
297 } else {
299 }
300}

◆ shape()

QPainterPath dbse::SchemaGraphicSegmentedArrow::shape ( ) const

Definition at line 82 of file SchemaGraphicSegmentedArrow.cpp.

83{
84 QPainterPath path = QGraphicsPathItem::shape();
85 path.addRect(m_rel_label_br);
86 path.addRect(m_rel_cardinality_br);
87 path.addPolygon(m_marker);
88 // path.addText ( p2() + QPoint ( 10, 10 ), QFont ( "Helvetica [Cronyx]", 10 ),
89 // m_cardinality );
90 // path.addText ( p1() + QPoint ( -10, -10 ), QFont ( "Helvetica [Cronyx]", 10 ),
91 // m_cardinality );
92 return path;
93}

◆ UpdatePosition()

void dbse::SchemaGraphicSegmentedArrow::UpdatePosition ( )

Definition at line 96 of file SchemaGraphicSegmentedArrow.cpp.

97{
98 if (m_start_item->collidesWithItem(m_end_item)) {
99 // this->setPath(QPainterPath());
100 // m_marker = QPolygonF();
101 return;
102 }
103
104 std::vector<QLineF> norms = {
105 { 0., 0., 0., 1. }, // up
106 { 0., 0., 1., 0. }, // right
107 { 0., 0., 0, -1. }, // down
108 { 0., 0., -1., 0. }, // left
109 };
110
111 qreal xoffset;
112 qreal yoffset;
113 const qreal xfactor = 23.0;
114 const qreal yfactor = 17.0;
115 if (m_start_item->boundingRect().x() < m_end_item->boundingRect().x()) {
116 xoffset = m_connection_count * xfactor;
117 } else {
118 xoffset = m_connection_count * -xfactor;
119 }
120
121 if (m_start_item->boundingRect().y() > m_end_item->boundingRect().y()) {
122 yoffset = m_connection_count * yfactor;
123 } else {
124 yoffset = m_connection_count * -yfactor;
125 }
126
127 QPointF start_offset(xoffset, yoffset);
128 QPointF end_offset(0, 0);
129
130 QLineF center_line(m_start_item->mapToScene(m_start_item->boundingRect().center() + start_offset),
131 m_end_item->mapToScene(m_end_item->boundingRect().center() + end_offset));
132 QPolygonF start_polygon = QPolygonF(m_start_item->boundingRect());
133 QPolygonF end_polygon = QPolygonF(m_end_item->boundingRect());
134 QPointF intersect_point_start, intersect_point_end;
135 QLineF intersect_norm_start, intersect_norm_end;
136
137 // Iterate on the sides starting from top-left
138 QPointF p1 = end_polygon.first() + m_end_item->pos(), p2;
139 for (int i = 1; i < end_polygon.count(); ++i) {
140
141 p2 = end_polygon.at(i) + m_end_item->pos();
142 QLineF item_side = QLineF(p1, p2);
143 QLineF::IntersectType intersect_type = item_side.intersects(center_line, &intersect_point_end);
144
145 if (intersect_type == QLineF::BoundedIntersection) {
146 intersect_norm_end = norms[i - 1];
147 break;
148 }
149
150 p1 = p2;
151 }
152
153 p1 = start_polygon.first() + m_start_item->pos();
154 QPointF start_sp;
155 for (int i = 1; i < start_polygon.count(); ++i) {
156 p2 = start_polygon.at(i) + m_start_item->pos();
157 QLineF item_side = QLineF(p1, p2);
158 QLineF::IntersectType intersect_type = item_side.intersects(center_line, &intersect_point_start);
159 if (intersect_type == QLineF::BoundedIntersection) {
160 switch (i) {
161 case 1:
162 start_sp = QPointF{ m_start_item->pos().x() + (m_start_item->boundingRect().width() / 2) + xoffset,
163 intersect_point_start.y() };
164 break;
165 case 3:
166 start_sp = QPointF{ m_start_item->pos().x() + (m_start_item->boundingRect().width() / 2) - xoffset,
167 intersect_point_start.y() };
168 break;
169
170 case 2:
171 case 4:
172 start_sp = { intersect_point_start.x(),
173 m_start_item->pos().y() + m_start_item->boundingRect().height() / 2 + yoffset };
174 break;
175 }
176 intersect_norm_start = norms[i - 1];
177 break;
178 }
179
180 p1 = p2;
181 }
182
183 QLineF direct_line(start_sp, intersect_point_end);
184 auto font = QFont(SchemaStyle::get_font("line"));
185 auto label_br = QRectF(QFontMetrics(font).boundingRect(m_name));
186 // Center rectangle on origin
187 label_br.translate(-label_br.width() / 2, label_br.height() / 2);
188
189 auto cardinality_br = QRectF(QFontMetrics(font).boundingRect(m_cardinality));
190 // Center rectangle on origin
191 cardinality_br.translate(-cardinality_br.width() / 2, cardinality_br.height() / 2);
192
193 qreal label_x_padding = 2;
194 qreal label_y_padding = -2;
195 qreal card_x_padding = 2;
196 qreal card_y_padding = -2;
197
198 QPainterPath path(intersect_point_start);
199
200 if ((intersect_norm_start.dx() == 0) && (intersect_norm_end.dx() == 0)) {
201 // Three segments, starting and ending vertically
202 QPointF wp1 = QPointF(direct_line.x1(), direct_line.center().y() + yoffset);
203 QPointF wp2 = QPointF(direct_line.x2(), direct_line.center().y() + yoffset);
204 path.moveTo(direct_line.x1(), direct_line.y1());
205 path.lineTo(wp1);
206 path.lineTo(wp2);
207
208 // Place the label
209 label_br.translate(wp2 + QPointF((direct_line.dx() < 0 ? 1 : -1) * (label_x_padding + label_br.width() / 2),
210 (direct_line.dy() > 0 ? 1 : -1) * (label_br.height() + label_y_padding)));
211 // Place cardinality
212 cardinality_br.translate(intersect_point_start +
213 QPointF((direct_line.dx() < 0 ? 1 : -1) * (card_x_padding + cardinality_br.width() / 2),
214 (direct_line.dy() > 0 ? 1 : -1) * (cardinality_br.height() + card_y_padding)));
215
216 } else if ((intersect_norm_start.dy() == 0) && (intersect_norm_end.dy() == 0)) {
217 // Three segments, starting and ending horizontally
218 QPointF wp1 = QPointF(direct_line.center().x() - xoffset, direct_line.y1());
219 QPointF wp2 = QPointF(direct_line.center().x() - xoffset, direct_line.y2());
220
221 path.moveTo(direct_line.x1(), direct_line.y1());
222 path.lineTo(wp1);
223 path.lineTo(wp2);
224
225 // Place the label
226 label_br.translate(wp2 + QPointF((direct_line.dx() > 0 ? 1 : -1) * (label_x_padding + label_br.width() / 2),
227 (direct_line.dy() < 0 ? 1 : -1) * (label_br.height() + label_y_padding)));
228 cardinality_br.translate(intersect_point_start +
229 QPointF((direct_line.dx() > 0 ? 1 : -1) * (card_x_padding + cardinality_br.width() / 2),
230 (direct_line.dy() < 0 ? 1 : -1) * (cardinality_br.height() + card_y_padding)));
231
232 } else if (intersect_norm_start.dx() == 0) {
233 // Two segments, starting vertically, ending horizontally
234 QPointF wp1 = QPointF(direct_line.x1(), direct_line.y2());
235
236 path.moveTo(direct_line.x1(), direct_line.y1());
237 path.lineTo(wp1);
238
239 label_br.translate(wp1 + QPointF((direct_line.dx() > 0 ? 1 : -1) * (label_x_padding + label_br.width() / 2),
240 (direct_line.dy() < 0 ? 1 : -1) * (label_br.height() + label_y_padding)));
241 cardinality_br.translate(intersect_point_start +
242 QPointF((direct_line.dx() < 0 ? 1 : -1) * (card_x_padding + cardinality_br.width() / 2),
243 (direct_line.dy() > 0 ? 1 : -1) * (cardinality_br.height() + card_y_padding)));
244
245 } else if (intersect_norm_start.dy() == 0) {
246 // Two segments, starting horizontally, ending vertically
247 QPointF wp1 = QPointF(direct_line.x2(), direct_line.y1());
248 path.moveTo(direct_line.x1(), direct_line.y1());
249
250 path.lineTo(wp1);
251
252 label_br.translate(wp1 + QPointF((direct_line.dx() > 0 ? 1 : -1) * (label_x_padding + label_br.width() / 2),
253 (direct_line.dy() < 0 ? 1 : -1) * (label_br.height() + label_y_padding)));
254 cardinality_br.translate(intersect_point_start +
255 QPointF((direct_line.dx() < 0 ? 1 : -1) * (card_x_padding + cardinality_br.width() / 2),
256 (direct_line.dy() > 0 ? 1 : -1) * (cardinality_br.height() + card_y_padding)));
257 }
258
259 path.lineTo(intersect_point_end);
260 setPath(path);
261
262 m_rel_label_br = label_br;
263 m_rel_cardinality_br = cardinality_br;
264
265 // Why does a function called UpdatePosition add decorations to a line??
266 // =====================================================================
267 if (m_inheritance) {
268 m_marker = this->make_arrow_head(-intersect_norm_end.angle() / 180 * M_PI).translated(this->p2());
269 } else {
270 m_marker = this->make_rhombus(-intersect_norm_start.angle() / 180 * M_PI).translated(this->p1());
271 }
272}
QRectF boundingRect() const override

Member Data Documentation

◆ LastDegree

double dbse::SchemaGraphicSegmentedArrow::LastDegree
private

Definition at line 60 of file SchemaGraphicSegmentedArrow.hpp.

◆ LastRotation

double dbse::SchemaGraphicSegmentedArrow::LastRotation
private

Definition at line 61 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_arrow_size

qreal dbse::SchemaGraphicSegmentedArrow::m_arrow_size
private

Definition at line 58 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_cardinality

QString dbse::SchemaGraphicSegmentedArrow::m_cardinality
private

Definition at line 55 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_composite

bool dbse::SchemaGraphicSegmentedArrow::m_composite
private

Definition at line 53 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_connection_count

int dbse::SchemaGraphicSegmentedArrow::m_connection_count
private

Definition at line 48 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_default_color

QColor dbse::SchemaGraphicSegmentedArrow::m_default_color
private

Definition at line 56 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_end_item

SchemaGraphicObject* dbse::SchemaGraphicSegmentedArrow::m_end_item
private

Definition at line 47 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_inheritance

bool dbse::SchemaGraphicSegmentedArrow::m_inheritance
private

Definition at line 52 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_label_font

QFont dbse::SchemaGraphicSegmentedArrow::m_label_font
private

Definition at line 57 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_marker

QPolygonF dbse::SchemaGraphicSegmentedArrow::m_marker
private

Definition at line 49 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_name

QString dbse::SchemaGraphicSegmentedArrow::m_name
private

Definition at line 54 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_rel_cardinality_br

QRectF dbse::SchemaGraphicSegmentedArrow::m_rel_cardinality_br
private

Definition at line 51 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_rel_label_br

QRectF dbse::SchemaGraphicSegmentedArrow::m_rel_label_br
private

Definition at line 50 of file SchemaGraphicSegmentedArrow.hpp.

◆ m_start_item

SchemaGraphicObject* dbse::SchemaGraphicSegmentedArrow::m_start_item
private

Definition at line 46 of file SchemaGraphicSegmentedArrow.hpp.


The documentation for this class was generated from the following files: