3535
3636Component::Component (QString value, QString name, QString className, QPointF position, int type, bool connector,
3737 OMCProxy *omc, GraphicsView *graphicsView, Component *pParent)
38- : ShapeAnnotation(pParent), mAnnotationString(value), mName(name), mClassName(className), mType(type),
38+ : ShapeAnnotation(graphicsView, pParent), mAnnotationString(value), mName(name), mClassName(className), mType(type),
3939 mIsConnector(connector), mpOMCProxy(omc), mpGraphicsView(graphicsView)
4040{
4141 mIsLibraryComponent = false ;
@@ -44,17 +44,25 @@ Component::Component(QString value, QString name, QString className, QPointF pos
4444
4545 parseAnnotationString (this , value);
4646 // if component is an icon
47- if (mType == StringHandler::ICON)
47+ if (( mType == StringHandler::ICON) )
4848 {
49- scale (Helper::globalIconXScale, Helper::globalIconYScale);
5049 setPos (position);
51- setComponentFlags ();
52- setAcceptHoverEvents (true );
53- getClassComponents (mClassName , mType );
54- createActions ();
50+ if (mpGraphicsView->mpParentProjectTab ->isReadOnly ())
51+ {
52+ scale (Helper::globalDiagramXScale, Helper::globalDiagramYScale);
53+ getClassComponents (mClassName , mType );
54+ }
55+ else
56+ {
57+ scale (Helper::globalIconXScale, Helper::globalIconYScale);
58+ setComponentFlags ();
59+ setAcceptHoverEvents (true );
60+ getClassComponents (mClassName , mType );
61+ createActions ();
62+ }
5563 }
5664 // if component is a diagram
57- else if (mType == StringHandler::DIAGRAM)
65+ else if (( mType == StringHandler::DIAGRAM) )
5866 {
5967 scale (Helper::globalDiagramXScale, Helper::globalDiagramYScale);
6068 setPos (position);
@@ -121,7 +129,7 @@ Component::Component(QString value, QString className, OMCProxy *omc, Component
121129 mType = StringHandler::ICON;
122130 mIsConnector = false ;
123131
124- parseAnnotationString (this , value);
132+ parseAnnotationString (this , value, true );
125133 getClassComponents (mClassName , mType );
126134}
127135
@@ -137,7 +145,12 @@ Component::Component(QString value, QString className, Component *pParent)
137145 mpComponentProperties = 0 ;
138146 mType = StringHandler::ICON;
139147 mIsConnector = false ;
140- parseAnnotationString (this , mAnnotationString );
148+ parseAnnotationString (this , mAnnotationString , true );
149+
150+ // ! @todo Since for some components we get empty annotations but its inherited componets does have annotations
151+ // ! @todo so set the parent give the parent bounding box the value of inherited class boundingbox.
152+ if (mRectangle .width () > 1 )
153+ getRootParentComponent ()->mRectangle = mRectangle ;
141154}
142155
143156/* Used for Library Component. Called for component annotation instance */
@@ -151,13 +164,19 @@ Component::Component(QString value, QString className, QString transformationStr
151164 mpOMCProxy = pParent->mpOMCProxy ;
152165 mType = StringHandler::ICON;
153166 mIsConnector = false ;
154- parseAnnotationString (this , mAnnotationString );
167+ parseAnnotationString (this , mAnnotationString , true );
155168 mpTransformation = new Transformation (this );
169+ setTransform (mpTransformation->getTransformationMatrix ());
170+
171+ // ! @todo Since for some components we get empty annotations but its inherited componets does have annotations
172+ // ! @todo so set the parent give the parent bounding box the value of inherited class boundingbox.
173+ if (mRectangle .width () > 1 )
174+ getRootParentComponent ()->mRectangle = mRectangle ;
156175}
157176
158177Component::Component (Component *pComponent, QString name, QPointF position, int type, bool connector,
159178 GraphicsView *graphicsView, Component *pParent)
160- : ShapeAnnotation(pParent), mName(name), mType(type), mIsConnector(connector), mpGraphicsView(graphicsView)
179+ : ShapeAnnotation(graphicsView, pParent), mName(name), mType(type), mIsConnector(connector), mpGraphicsView(graphicsView)
161180{
162181 mpParentComponent = pParent;
163182 mClassName = pComponent->mClassName ;
@@ -171,18 +190,26 @@ Component::Component(Component *pComponent, QString name, QPointF position, int
171190
172191 parseAnnotationString (this , mAnnotationString );
173192 // if component is an icon
174- if (mType == StringHandler::ICON)
193+ if (( mType == StringHandler::ICON) )
175194 {
176- scale (Helper::globalIconXScale, Helper::globalIconYScale);
177195 setPos (position);
178- setComponentFlags ();
179- setAcceptHoverEvents (true );
180- copyClassComponents (pComponent);
181- createSelectionBox ();
182- createActions ();
196+ if (mpGraphicsView->mpParentProjectTab ->isReadOnly ())
197+ {
198+ scale (Helper::globalDiagramXScale, Helper::globalDiagramYScale);
199+ copyClassComponents (pComponent);
200+ }
201+ else
202+ {
203+ scale (Helper::globalIconXScale, Helper::globalIconYScale);
204+ setComponentFlags ();
205+ setAcceptHoverEvents (true );
206+ copyClassComponents (pComponent);
207+ createSelectionBox ();
208+ createActions ();
209+ }
183210 }
184211 // if component is a diagram
185- else if (mType == StringHandler::DIAGRAM)
212+ else if (( mType == StringHandler::DIAGRAM) )
186213 {
187214 scale (Helper::globalDiagramXScale, Helper::globalDiagramYScale);
188215 setPos (position);
@@ -210,7 +237,7 @@ Component::~Component()
210237
211238// ! Parses the result of getIconAnnotation command.
212239// ! @param value is the result of getIconAnnotation command obtained from OMC.
213- bool Component::parseAnnotationString (Component *item, QString value)
240+ bool Component::parseAnnotationString (Component *item, QString value, bool libraryIcon )
214241{
215242 value = StringHandler::removeFirstLastCurlBrackets (value);
216243 if (value.isEmpty ())
@@ -292,12 +319,16 @@ bool Component::parseAnnotationString(Component *item, QString value)
292319 EllipseAnnotation *ellipseAnnotation = new EllipseAnnotation (shape, item);
293320 item->mpShapesList .append (ellipseAnnotation);
294321 }
295- if (shape.startsWith (" Text" ))
322+ // don't parse the text annotation for library icon
323+ if (!libraryIcon)
296324 {
297- shape = shape.mid (QString (" Text" ).length ());
298- shape = StringHandler::removeFirstLastBrackets (shape);
299- TextAnnotation *textAnnotation = new TextAnnotation (shape, item);
300- item->mpShapesList .append (textAnnotation);
325+ if (shape.startsWith (" Text" ))
326+ {
327+ shape = shape.mid (QString (" Text" ).length ());
328+ shape = StringHandler::removeFirstLastBrackets (shape);
329+ TextAnnotation *textAnnotation = new TextAnnotation (shape, item);
330+ item->mpShapesList .append (textAnnotation);
331+ }
301332 }
302333 }
303334}
@@ -349,7 +380,7 @@ void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
349380void Component::mousePressEvent (QGraphicsSceneMouseEvent *event)
350381{
351382 // if user is viewing the component in Icon View
352- if (mpGraphicsView->mIconType == StringHandler::DIAGRAM)
383+ if (( mpGraphicsView->mIconType == StringHandler::DIAGRAM) or (mpGraphicsView-> mpParentProjectTab -> isReadOnly ()) )
353384 return ;
354385 // if we are creating the connector then make sure user can not select and move components
355386 if ((mpGraphicsView->mIsCreatingConnector ) and !mpParentComponent)
@@ -652,73 +683,6 @@ void Component::deleteMe()
652683 delete (this );
653684}
654685
655- // ! Slot that moves component one pixel upwards
656- // ! @see moveDown()
657- // ! @see moveLeft()
658- // ! @see moveRight()
659- void Component::moveUp ()
660- {
661- this ->setPos (this ->pos ().x (), this ->mapFromScene (this ->mapToScene (this ->pos ())).y ()+1 );
662- mpGraphicsView->scene ()->update ();
663- }
664-
665- // ! Slot that moves component one pixel downwards
666- // ! @see moveUp()
667- // ! @see moveLeft()
668- // ! @see moveRight()
669- void Component::moveDown ()
670- {
671- this ->setPos (this ->pos ().x (), this ->mapFromScene (this ->mapToScene (this ->pos ())).y ()-1 );
672- mpGraphicsView->scene ()->update ();
673- }
674-
675- // ! Slot that moves component one pixel leftwards
676- // ! @see moveUp()
677- // ! @see moveDown()
678- // ! @see moveRight()
679- void Component::moveLeft ()
680- {
681- this ->setPos (this ->mapFromScene (this ->mapToScene (this ->pos ())).x ()-1 , this ->pos ().y ());
682- mpGraphicsView->scene ()->update ();
683- }
684-
685- // ! Slot that moves component one pixel rightwards
686- // ! @see moveUp()
687- // ! @see moveDown()
688- // ! @see moveLeft()
689- void Component::moveRight ()
690- {
691- this ->setPos (this ->mapFromScene (this ->mapToScene (this ->pos ())).x ()+1 , this ->pos ().y ());
692- mpGraphicsView->scene ()->update ();
693- }
694-
695- void Component::rotateClockwise ()
696- {
697- qreal rotation = this ->rotation ();
698- qreal rotateIncrement = 90 ;
699-
700- if (rotation == -270 )
701- this ->setRotation (0 );
702- else
703- this ->setRotation (rotation - rotateIncrement);
704- }
705-
706- void Component::rotateAntiClockwise ()
707- {
708- qreal rotation = this ->rotation ();
709- qreal rotateIncrement = -90 ;
710-
711- if (rotation == 270 )
712- this ->setRotation (0 );
713- else
714- this ->setRotation (rotation - rotateIncrement);
715- }
716-
717- void Component::resetRotation ()
718- {
719- this ->setRotation (0 );
720- }
721-
722686void Component::openIconProperties ()
723687{
724688 IconProperties *iconProperties = new IconProperties (this , mpGraphicsView->mpParentProjectTab ->mpParentProjectTabWidget ->mpParentMainWindow );
0 commit comments