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 ()
SchemaGraphicObjectGetStartItem () const
SchemaGraphicObjectGetEndItem () const
bool GetInheritanceMode ()
void RemoveArrow ()
void SetLabelScene (SchemaGraphicsScene *Scene)

Protected Member Functions

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

Private Attributes

SchemaGraphicObjectStart
SchemaGraphicObjectEnd
QPolygonF ArrowHead
bool Inheritance
bool Composite
QString Name
QString Cardinality
QGraphicsSimpleTextItem * Label
double LastDegree
double LastRotation

Detailed Description

Definition at line 18 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.

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

◆ ~SchemaGraphicArrow()

dbse::SchemaGraphicArrow::~SchemaGraphicArrow ( )

Definition at line 42 of file SchemaGraphicArrow.cpp.

43{
44}

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(),
50 QSizeF ( line().p2().x() - line().p1().x(),
51 line().p2().y() - line().p1().y() ) ).normalized().adjusted (
52 -extra, -extra, extra, extra );
53}

◆ GetEndItem()

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

Definition at line 77 of file SchemaGraphicArrow.cpp.

78{
79 return End;
80}

◆ GetInheritanceMode()

bool dbse::SchemaGraphicArrow::GetInheritanceMode ( )

Definition at line 82 of file SchemaGraphicArrow.cpp.

83{
84 return Inheritance;
85}

◆ 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 104 of file SchemaGraphicArrow.cpp.

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

◆ RemoveArrow()

void dbse::SchemaGraphicArrow::RemoveArrow ( )

Remove Super class

Remove relationship

Definition at line 87 of file SchemaGraphicArrow.cpp.

88{
89 if ( Inheritance )
90 {
92 }
93 else
94 {
96 }
97}

◆ SetLabelScene()

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

Definition at line 99 of file SchemaGraphicArrow.cpp.

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

◆ 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 ),
61 path.addText ( line().p1() + QPoint ( -10, -10 ), QFont ( "Helvetica [Cronyx]", 10 ),
63 return path;
64}

◆ UpdatePosition()

void dbse::SchemaGraphicArrow::UpdatePosition ( )

Definition at line 66 of file SchemaGraphicArrow.cpp.

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

Member Data Documentation

◆ ArrowHead

QPolygonF dbse::SchemaGraphicArrow::ArrowHead
private

Definition at line 42 of file SchemaGraphicArrow.hpp.

◆ Cardinality

QString dbse::SchemaGraphicArrow::Cardinality
private

Definition at line 46 of file SchemaGraphicArrow.hpp.

◆ Composite

bool dbse::SchemaGraphicArrow::Composite
private

Definition at line 44 of file SchemaGraphicArrow.hpp.

◆ End

SchemaGraphicObject* dbse::SchemaGraphicArrow::End
private

Definition at line 41 of file SchemaGraphicArrow.hpp.

◆ Inheritance

bool dbse::SchemaGraphicArrow::Inheritance
private

Definition at line 43 of file SchemaGraphicArrow.hpp.

◆ Label

QGraphicsSimpleTextItem* dbse::SchemaGraphicArrow::Label
private

Definition at line 47 of file SchemaGraphicArrow.hpp.

◆ LastDegree

double dbse::SchemaGraphicArrow::LastDegree
private

Definition at line 48 of file SchemaGraphicArrow.hpp.

◆ LastRotation

double dbse::SchemaGraphicArrow::LastRotation
private

Definition at line 49 of file SchemaGraphicArrow.hpp.

◆ Name

QString dbse::SchemaGraphicArrow::Name
private

Definition at line 45 of file SchemaGraphicArrow.hpp.

◆ Start

SchemaGraphicObject* dbse::SchemaGraphicArrow::Start
private

Definition at line 40 of file SchemaGraphicArrow.hpp.


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