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 13 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 10 of file SchemaGraphicArrow.cpp.

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

◆ ~SchemaGraphicArrow()

dbse::SchemaGraphicArrow::~SchemaGraphicArrow ( )

Definition at line 37 of file SchemaGraphicArrow.cpp.

38{
39}

Member Function Documentation

◆ boundingRect()

QRectF dbse::SchemaGraphicArrow::boundingRect ( ) const

Definition at line 41 of file SchemaGraphicArrow.cpp.

42{
43 qreal extra = ( pen().width() + 20 ) / 2.0 + 10;
44 return QRectF ( line().p1(),
45 QSizeF ( line().p2().x() - line().p1().x(),
46 line().p2().y() - line().p1().y() ) ).normalized().adjusted (
47 -extra, -extra, extra, extra );
48}

◆ GetEndItem()

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

Definition at line 72 of file SchemaGraphicArrow.cpp.

73{
74 return End;
75}

◆ GetInheritanceMode()

bool dbse::SchemaGraphicArrow::GetInheritanceMode ( )

Definition at line 77 of file SchemaGraphicArrow.cpp.

78{
79 return Inheritance;
80}

◆ GetStartItem()

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

Definition at line 67 of file SchemaGraphicArrow.cpp.

68{
69 return Start;
70}

◆ paint()

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

Draw Rhombus

Definition at line 99 of file SchemaGraphicArrow.cpp.

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

◆ RemoveArrow()

void dbse::SchemaGraphicArrow::RemoveArrow ( )

Remove Super class

Remove relationship

Definition at line 82 of file SchemaGraphicArrow.cpp.

83{
84 if ( Inheritance )
85 {
87 }
88 else
89 {
91 }
92}

◆ SetLabelScene()

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

Definition at line 94 of file SchemaGraphicArrow.cpp.

95{
96 Scene->addItem ( Label );
97}

◆ shape()

QPainterPath dbse::SchemaGraphicArrow::shape ( ) const

Definition at line 50 of file SchemaGraphicArrow.cpp.

51{
52 QPainterPath path = QGraphicsLineItem::shape();
53 path.addPolygon ( ArrowHead );
54 path.addText ( line().p2() + QPoint ( 10, 10 ), QFont ( "Helvetica [Cronyx]", 10 ),
56 path.addText ( line().p1() + QPoint ( -10, -10 ), QFont ( "Helvetica [Cronyx]", 10 ),
58 return path;
59}

◆ UpdatePosition()

void dbse::SchemaGraphicArrow::UpdatePosition ( )

Definition at line 61 of file SchemaGraphicArrow.cpp.

62{
63 QLineF line ( mapFromItem ( Start, 0, 0 ), mapFromItem ( End, 0, 0 ) );
64 setLine ( line );
65}

Member Data Documentation

◆ ArrowHead

QPolygonF dbse::SchemaGraphicArrow::ArrowHead
private

Definition at line 37 of file SchemaGraphicArrow.hpp.

◆ Cardinality

QString dbse::SchemaGraphicArrow::Cardinality
private

Definition at line 41 of file SchemaGraphicArrow.hpp.

◆ Composite

bool dbse::SchemaGraphicArrow::Composite
private

Definition at line 39 of file SchemaGraphicArrow.hpp.

◆ End

SchemaGraphicObject* dbse::SchemaGraphicArrow::End
private

Definition at line 36 of file SchemaGraphicArrow.hpp.

◆ Inheritance

bool dbse::SchemaGraphicArrow::Inheritance
private

Definition at line 38 of file SchemaGraphicArrow.hpp.

◆ Label

QGraphicsSimpleTextItem* dbse::SchemaGraphicArrow::Label
private

Definition at line 42 of file SchemaGraphicArrow.hpp.

◆ LastDegree

double dbse::SchemaGraphicArrow::LastDegree
private

Definition at line 43 of file SchemaGraphicArrow.hpp.

◆ LastRotation

double dbse::SchemaGraphicArrow::LastRotation
private

Definition at line 44 of file SchemaGraphicArrow.hpp.

◆ Name

QString dbse::SchemaGraphicArrow::Name
private

Definition at line 40 of file SchemaGraphicArrow.hpp.

◆ Start

SchemaGraphicObject* dbse::SchemaGraphicArrow::Start
private

Definition at line 35 of file SchemaGraphicArrow.hpp.


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