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

#include <SchemaGraphicArrow.hpp>

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

Public Member Functions

 SchemaGraphicArrow (SchemaGraphicObject *StartItem, SchemaGraphicObject *EndItem, bool IsInheritance, bool IsComposite, QString ArrowName, QString ArrowCardinality, QGraphicsItem *parent=nullptr)
 Including QT Headers.
 ~SchemaGraphicArrow ()
QRectF boundingRect () const
QPainterPath shape () const
void UpdatePosition ()
SchemaGraphicObject * GetStartItem () const
SchemaGraphicObject * GetEndItem () const
bool GetInheritanceMode ()
void RemoveArrow ()
void SetLabelScene (SchemaGraphicsScene *Scene)

Protected Member Functions

void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)

Private Attributes

SchemaGraphicObject * Start
SchemaGraphicObject * End
QPolygonF ArrowHead
bool Inheritance
bool Composite
QString Name
QString Cardinality
QGraphicsSimpleTextItem * Label
double LastDegree
double LastRotation

Detailed Description

Definition at line 17 of file SchemaGraphicArrow.hpp.

Constructor & Destructor Documentation

◆ SchemaGraphicArrow()

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

Including QT Headers.

Including Schema Editor Including C++ Headers

Definition at line 15 of file SchemaGraphicArrow.cpp.

22 : QGraphicsLineItem(parent)
23 , Start(StartItem)
24 , End(EndItem)
25 , Inheritance(IsInheritance)
26 , Composite(IsComposite)
27 , Name(ArrowName)
28 , Cardinality(ArrowCardinality)
29 , Label(nullptr)
30 , LastDegree(0)
31 , LastRotation(0)
32{
33 // setPen(QPen(Qt::black,2,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
34 setFlag(ItemIsSelectable, true);
35 // LabelString = Name + " - " + Cardinality;
36
37 if (!Start->collidesWithItem(End) && !Inheritance) {
38 Label = new QGraphicsSimpleTextItem(Name + " - " + Cardinality);
39 Label->setParentItem(this);
40 }
41}
SchemaGraphicObject * Start
SchemaGraphicObject * End
QGraphicsSimpleTextItem * Label

◆ ~SchemaGraphicArrow()

dbse::SchemaGraphicArrow::~SchemaGraphicArrow ( )

Definition at line 43 of file SchemaGraphicArrow.cpp.

43{}

Member Function Documentation

◆ boundingRect()

QRectF dbse::SchemaGraphicArrow::boundingRect ( ) const

Definition at line 46 of file SchemaGraphicArrow.cpp.

47{
48 qreal extra = (pen().width() + 20) / 2.0 + 10;
49 return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(), line().p2().y() - line().p1().y()))
50 .normalized()
51 .adjusted(-extra, -extra, extra, extra);
52}

◆ GetEndItem()

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

Definition at line 78 of file SchemaGraphicArrow.cpp.

79{
80 return End;
81}

◆ GetInheritanceMode()

bool dbse::SchemaGraphicArrow::GetInheritanceMode ( )

Definition at line 84 of file SchemaGraphicArrow.cpp.

85{
86 return Inheritance;
87}

◆ GetStartItem()

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

Definition at line 72 of file SchemaGraphicArrow.cpp.

73{
74 return Start;
75}

◆ paint()

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

Draw Rhombus

Definition at line 106 of file SchemaGraphicArrow.cpp.

107{
108 Q_UNUSED(option)
109 Q_UNUSED(widget)
110
111 if (Start->collidesWithItem(End)) {
112 return;
113 }
114
115 QPen myPen = pen();
116 myPen.setColor(Qt::black);
117
118 QFont Font("Helvetica [Cronyx]", 10);
119 qreal arrowSize = 10;
120 painter->setFont(Font);
121 painter->setPen(myPen);
122 painter->setBrush(Qt::black);
123
124 QLineF centerLine(Start->mapToScene(Start->boundingRect().center()), End->mapToScene(End->boundingRect().center()));
125 QPolygonF startPolygon = QPolygonF(Start->boundingRect());
126 QPolygonF endPolygon = QPolygonF(End->boundingRect());
127 QPointF p1 = endPolygon.first() + End->pos();
128 QPointF p2;
129 QPointF intersectPointStart;
130 QPointF intersectPointEnd;
131 QLineF polyLine;
132
133 for (int i = 1; i < endPolygon.count(); ++i) {
134 p2 = endPolygon.at(i) + End->pos();
135 polyLine = QLineF(p1, p2);
136 QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointEnd);
137
138 if (intersectType == QLineF::BoundedIntersection) {
139 break;
140 }
141
142 p1 = p2;
143 }
144
145 p1 = startPolygon.first() + Start->pos();
146
147 for (int i = 1; i < startPolygon.count(); ++i) {
148 p2 = startPolygon.at(i) + Start->pos();
149 polyLine = QLineF(p1, p2);
150 QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointStart);
151
152 if (intersectType == QLineF::BoundedIntersection) {
153 break;
154 }
155
156 p1 = p2;
157 }
158
159 setLine(QLineF(intersectPointEnd, intersectPointStart));
160
161 double angle = ::acos(line().dx() / line().length());
162
163 if (line().dy() >= 0) {
164 angle = (M_PI * 2) - angle;
165 }
166
167 QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, cos(angle + M_PI / 3) * arrowSize);
168 QPointF arrowP2 =
169 line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, cos(angle + M_PI - M_PI / 3) * arrowSize);
170 QPointF middlePoint = QPointF((arrowP1.x() + arrowP2.x()) / 2, (arrowP1.y() + arrowP2.y()) / 2);
171 QPointF arrowP3 = QPointF(line().p1().x() - 2 * (line().p1().x() - middlePoint.x()),
172 line().p1().y() - 2 * (line().p1().y() - middlePoint.y()));
173 ArrowHead.clear();
174 ArrowHead << line().p1() << arrowP1 << arrowP2;
175
176 QFontMetrics Metrics(Font);
177 Metrics.boundingRect(Name + " - " + Cardinality);
178
179 painter->drawLine(line());
180 qreal degree = (angle * 180) / M_PI;
181
182 if (Label) {
183
184 Label->setRotation(-degree + LastDegree);
185
186 if (degree >= 90 && degree < 270) {
187 Label->setTransformOriginPoint(Label->boundingRect().center());
188 Label->setRotation(-180);
189 Label->setTransformOriginPoint(0, 0);
190 LastRotation = 180;
191 Label->setPos(line().p2() + QPointF(-5 * cos(angle), 5 * sin(angle)));
192 } else {
193 Label->setTransformOriginPoint(Label->boundingRect().center());
194 Label->setRotation(360);
195 Label->setTransformOriginPoint(0, 0);
196 LastRotation = -180;
197
198 if (Composite) {
199 Label->setPos(line().p1() + QPointF(20 * cos(angle), -20 * sin(angle)));
200 } else {
201 Label->setPos(line().p1() + QPointF(5 * cos(angle), -5 * sin(angle)));
202 }
203 }
204
205 LastDegree = degree;
206 }
207
208 if (Inheritance) {
209 painter->drawPolygon(ArrowHead);
210 } else if (Composite) {
212 ArrowHead.clear();
213 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
214 painter->drawPolygon(ArrowHead);
215 }
216}
QRectF boundingRect() const override

◆ RemoveArrow()

void dbse::SchemaGraphicArrow::RemoveArrow ( )

Remove Super class

Remove relationship

Definition at line 90 of file SchemaGraphicArrow.cpp.

91{
92 if (Inheritance) {
94 } else {
96 }
97}

◆ SetLabelScene()

void dbse::SchemaGraphicArrow::SetLabelScene ( SchemaGraphicsScene * Scene)

Definition at line 100 of file SchemaGraphicArrow.cpp.

101{
102 Scene->addItem(Label);
103}

◆ shape()

QPainterPath dbse::SchemaGraphicArrow::shape ( ) const

Definition at line 55 of file SchemaGraphicArrow.cpp.

56{
57 QPainterPath path = QGraphicsLineItem::shape();
58 path.addPolygon(ArrowHead);
59 path.addText(line().p2() + QPoint(10, 10), QFont("Helvetica [Cronyx]", 10), Cardinality);
60 path.addText(line().p1() + QPoint(-10, -10), QFont("Helvetica [Cronyx]", 10), Cardinality);
61 return path;
62}

◆ UpdatePosition()

void dbse::SchemaGraphicArrow::UpdatePosition ( )

Definition at line 65 of file SchemaGraphicArrow.cpp.

66{
67 QLineF line(mapFromItem(Start, 0, 0), mapFromItem(End, 0, 0));
68 setLine(line);
69}

Member Data Documentation

◆ ArrowHead

QPolygonF dbse::SchemaGraphicArrow::ArrowHead
private

Definition at line 46 of file SchemaGraphicArrow.hpp.

◆ Cardinality

QString dbse::SchemaGraphicArrow::Cardinality
private

Definition at line 50 of file SchemaGraphicArrow.hpp.

◆ Composite

bool dbse::SchemaGraphicArrow::Composite
private

Definition at line 48 of file SchemaGraphicArrow.hpp.

◆ End

SchemaGraphicObject* dbse::SchemaGraphicArrow::End
private

Definition at line 45 of file SchemaGraphicArrow.hpp.

◆ Inheritance

bool dbse::SchemaGraphicArrow::Inheritance
private

Definition at line 47 of file SchemaGraphicArrow.hpp.

◆ Label

QGraphicsSimpleTextItem* dbse::SchemaGraphicArrow::Label
private

Definition at line 51 of file SchemaGraphicArrow.hpp.

◆ LastDegree

double dbse::SchemaGraphicArrow::LastDegree
private

Definition at line 52 of file SchemaGraphicArrow.hpp.

◆ LastRotation

double dbse::SchemaGraphicArrow::LastRotation
private

Definition at line 53 of file SchemaGraphicArrow.hpp.

◆ Name

QString dbse::SchemaGraphicArrow::Name
private

Definition at line 49 of file SchemaGraphicArrow.hpp.

◆ Start

SchemaGraphicObject* dbse::SchemaGraphicArrow::Start
private

Definition at line 44 of file SchemaGraphicArrow.hpp.


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