2828 * See the full OSMC Public License conditions for more details.
2929 *
3030 * Main Authors 2010: Syed Adeel Asghar, Sonia Tariq
31- *
31+ * Contributors 2011: Abhinn Kothari
3232 */
3333
3434#include " Component.h"
@@ -39,11 +39,16 @@ Component::Component(QString value, QString name, QString className, QPointF pos
3939 mIsConnector(connector), mpOMCProxy(omc), mpGraphicsView(graphicsView)
4040{
4141 mIsLibraryComponent = false ;
42+ mpComponentProperties=0 ;
43+ // QList<ComponentsProperties*> components = mpOMCProxy->getComponents(className);
4244 mpParentComponent = pParent;
4345 mIconParametersList .append (mpOMCProxy->getParameters (mpGraphicsView->mpParentProjectTab ->mModelNameStructure ,
4446 mClassName , mName ));
4547
4648 parseAnnotationString (this , value);
49+ mpTransformation = new Transformation (this );
50+ setTransform (mpTransformation->getTransformationMatrix ());
51+
4752 // if component is an icon
4853 if ((mType == StringHandler::ICON))
4954 {
@@ -72,6 +77,10 @@ Component::Component(QString value, QString name, QString className, QPointF pos
7277 }
7378 // if everything is fine with icon then add it to scene
7479 mpGraphicsView->scene ()->addItem (this );
80+
81+
82+ if (mType == StringHandler::ICON && mIsConnector ==true )
83+ connect (this , SIGNAL (componentClicked (Component*)), mpGraphicsView, SLOT (addConnector (Component*)));
7584}
7685
7786/* Called for inheritance annotation instance */
@@ -118,7 +127,10 @@ Component::Component(QString value, QString transformationString,ComponentsPrope
118127
119128 // if type is diagram then allow connections not for icon view
120129 if (mpParentComponent->mType == StringHandler::ICON)
130+ {
131+
121132 connect (this , SIGNAL (componentClicked (Component*)), mpGraphicsView, SLOT (addConnector (Component*)));
133+ }
122134}
123135
124136/* Used for Library Component */
@@ -229,7 +241,10 @@ Component::~Component()
229241{
230242 // delete all the list of shapes
231243 foreach (ShapeAnnotation *shape, mpShapesList)
244+ {
245+
232246 delete shape;
247+ }
233248
234249// // delete the list of all components
235250// foreach(Component *component, mpComponentsList)
@@ -240,10 +255,29 @@ Component::~Component()
240255// delete component;
241256}
242257
258+ bool Component::getIsConnector ()
259+ {
260+ return mIsConnector ;
261+ }
262+
243263// ! Parses the result of getIconAnnotation command.
244264// ! @param value is the result of getIconAnnotation command obtained from OMC.
245265bool Component::parseAnnotationString (Component *item, QString value, bool libraryIcon)
246266{
267+ int i =0 ;
268+
269+ foreach (ShapeAnnotation *shape, mpShapesList)
270+ {
271+ qDebug () << " in parseannotation " << getName () <<mpShapesList.size ()<<shape->getShapeAnnotation ();
272+ mpShapesList.removeOne (shape);
273+ delete shape;
274+ }
275+
276+ /* if(!item->getName().isEmpty())
277+ {
278+
279+ qDebug() << "in parseannotation "<< getName() <<mpShapesList.size();
280+ }*/
247281 value = StringHandler::removeFirstLastCurlBrackets (value);
248282 if (value.isEmpty ())
249283 {
@@ -343,6 +377,7 @@ bool Component::parseAnnotationString(Component *item, QString value, bool libra
343377 item->mpShapesList .append (bitmapAnnotation);
344378 }
345379 }
380+
346381}
347382
348383QRectF Component::boundingRect () const
@@ -382,6 +417,11 @@ void Component::createActions()
382417 mpIconPropertiesAction = new QAction (QIcon (" :/Resources/icons/tool.png" ), tr (" Properties" ), mpGraphicsView);
383418 mpIconPropertiesAction->setStatusTip (tr (" Shows the item properties" ));
384419 connect (mpIconPropertiesAction, SIGNAL (triggered ()), SLOT (openIconProperties ()));
420+
421+ // to set/unset the connect mode of a connector
422+ // mpIsConnectModeAction = new QAction(QIcon(":/Resources/icons/tool.png"), tr("Connect/Unconnect Mode"), mpGraphicsView);
423+ // mpIsConnectModeAction->setStatusTip(tr("Shows the item properties"));
424+ // connect(mpIsConnectModeAction, SIGNAL(triggered()), SLOT(changeConnectMode()));
385425}
386426
387427void Component::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@@ -393,9 +433,30 @@ void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
393433
394434void Component::mousePressEvent (QGraphicsSceneMouseEvent *event)
395435{
436+ MainWindow *pMainWindow =mpGraphicsView->mpParentProjectTab ->mpParentProjectTabWidget ->mpParentMainWindow ;
437+
396438 // if user is viewing the component in Icon View
397439 if ((mpGraphicsView->mIconType == StringHandler::ICON) or (mpGraphicsView->mpParentProjectTab ->isReadOnly ()))
398440 return ;
441+
442+ if (mIsConnector ==true )
443+ {
444+ // if(event->button()==Qt::LeftButton && !this->flags().testFlag((QGraphicsItem::ItemIsMovable)))
445+ if (event->button ()==Qt::LeftButton && pMainWindow->connectAction ->isChecked ())
446+ {
447+ emit componentClicked (this );
448+
449+ }
450+ else
451+ {
452+
453+ QGraphicsItem::mousePressEvent (event);
454+ }
455+
456+ }
457+
458+ else
459+ {
399460 // if we are creating the connector then make sure user can not select and move components
400461 if ((mpGraphicsView->mIsCreatingConnector ) and !mpParentComponent)
401462 {
@@ -408,14 +469,17 @@ void Component::mousePressEvent(QGraphicsSceneMouseEvent *event)
408469 setComponentFlags ();
409470 }
410471
411- if (event->button () == Qt::LeftButton)
472+ if (event->button () == Qt::LeftButton && pMainWindow-> connectAction -> isChecked () )
412473 {
413474 emit componentClicked (this );
414475 }
415476
416477 // call the mouse press event only if component is the root component
417478 if (!mpParentComponent)
479+ {
418480 QGraphicsItem::mousePressEvent (event);
481+ }
482+ }
419483}
420484
421485// ! Event when mouse cursor enters component icon.
@@ -453,13 +517,19 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
453517 menu.addAction (pComponent->mpGraphicsView ->mpRotateIconAction );
454518 menu.addAction (pComponent->mpGraphicsView ->mpRotateAntiIconAction );
455519 menu.addAction (pComponent->mpGraphicsView ->mpResetRotation );
520+ // menu.addAction(pComponent->mpGraphicsView->mpHorizontalFlipAction);
521+ // menu.addAction(pComponent->mpGraphicsView->mpVerticalFlipAction);
456522 menu.addSeparator ();
457523 menu.addAction (pComponent->mpGraphicsView ->mpDeleteIconAction );
524+ // menu.addAction(pComponent->mpGraphicsView->mpCopyComponentAction);
458525 if (pComponent->mType == StringHandler::ICON)
459526 {
460527 menu.addSeparator ();
461528 menu.addAction (pComponent->mpIconAttributesAction );
462529 menu.addAction (pComponent->mpIconPropertiesAction );
530+ menu.addSeparator ();
531+ // if(mIsConnector==true)
532+ // menu.addAction(pComponent->mpIsConnectModeAction);
463533 }
464534 menu.exec (event->screenPos ());
465535}
@@ -474,10 +544,13 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
474544 {
475545 setSelectionBoxActive ();
476546 setCursor (Qt::SizeAllCursor);
547+ connect (mpGraphicsView->mpHorizontalFlipAction , SIGNAL (triggered ()), SLOT (flipHorizontal ()));
548+ connect (mpGraphicsView->mpVerticalFlipAction , SIGNAL (triggered ()), SLOT (flipVertical ()));
477549 connect (mpGraphicsView->mpRotateIconAction , SIGNAL (triggered ()), SLOT (rotateClockwise ()));
478550 connect (mpGraphicsView->mpRotateAntiIconAction , SIGNAL (triggered ()), SLOT (rotateAntiClockwise ()));
479551 connect (mpGraphicsView->mpResetRotation , SIGNAL (triggered ()), SLOT (resetRotation ()));
480552 connect (mpGraphicsView->mpDeleteIconAction , SIGNAL (triggered ()), SLOT (deleteMe ()));
553+ connect (mpGraphicsView->mpCopyComponentAction , SIGNAL (triggered ()), SLOT (copyComponent ()));
481554 connect (mpGraphicsView, SIGNAL (keyPressDelete ()), SLOT (deleteMe ()));
482555 connect (mpGraphicsView, SIGNAL (keyPressUp ()), SLOT (moveUp ()));
483556 connect (mpGraphicsView, SIGNAL (keyPressDown ()), SLOT (moveDown ()));
@@ -490,10 +563,13 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
490563 {
491564 setSelectionBoxPassive ();
492565 unsetCursor ();
566+ disconnect (mpGraphicsView->mpHorizontalFlipAction , SIGNAL (triggered ()),this , SLOT (flipHorizontal ()));
567+ disconnect (mpGraphicsView->mpVerticalFlipAction , SIGNAL (triggered ()),this , SLOT (flipVertical ()));
493568 disconnect (mpGraphicsView->mpRotateIconAction , SIGNAL (triggered ()), this , SLOT (rotateClockwise ()));
494569 disconnect (mpGraphicsView->mpRotateAntiIconAction , SIGNAL (triggered ()), this , SLOT (rotateAntiClockwise ()));
495570 disconnect (mpGraphicsView->mpResetRotation , SIGNAL (triggered ()), this , SLOT (resetRotation ()));
496571 disconnect (mpGraphicsView->mpDeleteIconAction , SIGNAL (triggered ()), this , SLOT (deleteMe ()));
572+ disconnect (mpGraphicsView->mpCopyComponentAction , SIGNAL (triggered ()), this , SLOT (copyComponent ()));
497573 disconnect (mpGraphicsView, SIGNAL (keyPressDelete ()), this , SLOT (deleteMe ()));
498574 disconnect (mpGraphicsView, SIGNAL (keyPressUp ()), this , SLOT (moveUp ()));
499575 disconnect (mpGraphicsView, SIGNAL (keyPressDown ()), this , SLOT (moveDown ()));
@@ -746,14 +822,70 @@ void Component::deleteMe()
746822 mpGraphicsView->addClassAnnotation ();
747823 }
748824 delete (this );
825+
826+
827+ }
828+
829+ void Component::copyComponent ()
830+ {
831+ GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast <QObject*>(sender ()));
832+
833+ Component *newComponent;
834+ QString name = mpGraphicsView->getUniqueComponentName (this ->getName ().toLower ());
835+ QPointF point;
836+ point= QPointF ((this ->pos ().x ()) +1.0 ,(this ->pos ().y ()) +1.0 );
837+ newComponent = new Component (this ,name,point,this ->mType ,this ->getIsConnector (),mpGraphicsView);
838+ // remove the component from the scene
839+ // mpGraphicsView->scene()->removeItem(this);
840+ // if the signal is not send by graphicsview then call addclassannotation
841+ // if (!pGraphicsView)
842+ // {
843+ // if (mpGraphicsView->mIconType == StringHandler::ICON)
844+ // mpGraphicsView->addClassAnnotation();
845+ // }
846+ // delete(this);
847+ mpGraphicsView->addComponentObject (newComponent);
848+
849+ QClipboard *clipboard = QApplication::clipboard ();
850+
851+
852+ clipboard->setText (this ->getName ());
853+
854+ // if(!clipboard->text().isEmpty())
855+ // mpGraphicsView->mpPasteComponentAction->setDisabled(false);
856+
857+
749858}
750859
860+
861+
751862void Component::openIconProperties ()
752863{
753864 IconProperties *iconProperties = new IconProperties (this , mpGraphicsView->mpParentProjectTab ->mpParentProjectTabWidget ->mpParentMainWindow );
754865 iconProperties->show ();
755866}
756867
868+ void Component::changeConnectMode ()
869+ {
870+ if (!this ->flags ().testFlag ((QGraphicsItem::ItemIsMovable)))
871+ setFlag (QGraphicsItem::ItemIsMovable);
872+ else
873+ setFlag (QGraphicsItem::ItemIsMovable, false );
874+
875+ if (!this ->flags ().testFlag ((QGraphicsItem::ItemIsSelectable)))
876+ setFlag (QGraphicsItem::ItemIsSelectable);
877+ else
878+ setFlag (QGraphicsItem::ItemIsSelectable,false );
879+
880+ if (!this ->flags ().testFlag ((QGraphicsItem::ItemSendsGeometryChanges)))
881+ setFlag (QGraphicsItem::ItemSendsGeometryChanges);
882+ else
883+ setFlag (QGraphicsItem::ItemSendsGeometryChanges,false );
884+
885+
886+
887+ }
888+
757889void Component::openIconAttributes ()
758890{
759891 IconAttributes *iconAttributes = new IconAttributes (this , mpGraphicsView->mpParentProjectTab ->mpParentProjectTabWidget ->mpParentMainWindow );
@@ -839,7 +971,12 @@ QString Component::getClassName()
839971
840972Component* Component::getParentComponent ()
841973{
974+ if (!mpParentComponent)
975+ return this ;
976+ else
842977 return mpParentComponent;
978+
979+
843980}
844981
845982Component* Component::getRootParentComponent ()
0 commit comments