Skip to content

Commit

Permalink
#3354 - Allowing changing the shapes stacking order.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 15, 2015
1 parent 76227e3 commit b0489b2
Show file tree
Hide file tree
Showing 12 changed files with 659 additions and 6 deletions.
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -75,7 +75,7 @@ LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphi
{
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::ConnectionType;
setZValue(1000);
setZValue(2000);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand All @@ -97,7 +97,7 @@ LineAnnotation::LineAnnotation(QString annotation, bool inheritedShape, Componen
{
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::ConnectionType;
setZValue(1000);
setZValue(2000);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand Down
52 changes: 51 additions & 1 deletion OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -347,6 +347,7 @@ ShapeAnnotation::ShapeAnnotation(bool inheritedShape, GraphicsView *pGraphicsVie
: QGraphicsItem(pParent)
{
mpGraphicsView = pGraphicsView;
setZValue(mpGraphicsView->getShapesList().size() + 1);
mpTransformation = new Transformation(StringHandler::Diagram);
mIsCustomShape = true;
mIsInheritedShape = inheritedShape;
Expand Down Expand Up @@ -1359,7 +1360,43 @@ void ShapeAnnotation::deleteMe()
*/
void ShapeAnnotation::duplicate()
{
/* duplicate code is implement in each child shape class. */
/* duplicate code is implemented in each child shape class. */
}

/*!
* \brief ShapeAnnotation::bringToFront
* Brings the shape to front of all other shapes.
*/
void ShapeAnnotation::bringToFront()
{
mpGraphicsView->bringToFront(this);
}

/*!
* \brief ShapeAnnotation::bringForward
* Brings the shape one level forward.
*/
void ShapeAnnotation::bringForward()
{
mpGraphicsView->bringForward(this);
}

/*!
* \brief ShapeAnnotation::sendToBack
* Sends the shape to back of all other shapes.
*/
void ShapeAnnotation::sendToBack()
{
mpGraphicsView->sendToBack(this);
}

/*!
* \brief ShapeAnnotation::sendBackward
* Sends the shape one level backward.
*/
void ShapeAnnotation::sendBackward()
{
mpGraphicsView->sendBackward(this);
}

/*!
Expand Down Expand Up @@ -1838,6 +1875,11 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
menu.addAction(mpGraphicsView->getDeleteAction());
menu.addAction(mpGraphicsView->getDuplicateAction());
menu.addSeparator();
menu.addAction(mpGraphicsView->getBringToFrontAction());
menu.addAction(mpGraphicsView->getBringForwardAction());
menu.addAction(mpGraphicsView->getSendToBackAction());
menu.addAction(mpGraphicsView->getSendBackwardAction());
menu.addSeparator();
menu.addAction(mpGraphicsView->getRotateClockwiseAction());
menu.addAction(mpGraphicsView->getRotateAntiClockwiseAction());
}
Expand Down Expand Up @@ -1871,6 +1913,10 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
} else {
connect(mpGraphicsView->getDeleteAction(), SIGNAL(triggered()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView->getDuplicateAction(), SIGNAL(triggered()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()), Qt::UniqueConnection);
connect(mpGraphicsView->getBringForwardAction(), SIGNAL(triggered()), this, SLOT(bringForward()), Qt::UniqueConnection);
connect(mpGraphicsView->getSendToBackAction(), SIGNAL(triggered()), this, SLOT(sendToBack()), Qt::UniqueConnection);
connect(mpGraphicsView->getSendBackwardAction(), SIGNAL(triggered()), this, SLOT(sendBackward()), Qt::UniqueConnection);
connect(mpGraphicsView->getRotateClockwiseAction(), SIGNAL(triggered()), this, SLOT(rotateClockwiseMouseRightClick()), Qt::UniqueConnection);
connect(mpGraphicsView->getRotateAntiClockwiseAction(), SIGNAL(triggered()), this, SLOT(rotateAntiClockwiseMouseRightClick()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
Expand Down Expand Up @@ -1903,6 +1949,10 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
} else {
disconnect(mpGraphicsView->getDeleteAction(), SIGNAL(triggered()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView->getDuplicateAction(), SIGNAL(triggered()), this, SLOT(duplicate()));
disconnect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()));
disconnect(mpGraphicsView->getBringForwardAction(), SIGNAL(triggered()), this, SLOT(bringForward()));
disconnect(mpGraphicsView->getSendToBackAction(), SIGNAL(triggered()), this, SLOT(sendToBack()));
disconnect(mpGraphicsView->getSendBackwardAction(), SIGNAL(triggered()), this, SLOT(sendBackward()));
disconnect(mpGraphicsView->getRotateClockwiseAction(), SIGNAL(triggered()), this, SLOT(rotateClockwiseMouseRightClick()));
disconnect(mpGraphicsView->getRotateAntiClockwiseAction(), SIGNAL(triggered()), this, SLOT(rotateAntiClockwiseMouseRightClick()));
disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -191,6 +191,10 @@ public slots:
void deleteConnection();
void deleteMe();
virtual void duplicate();
void bringToFront();
void bringForward();
void sendToBack();
void sendBackward();
void rotateClockwiseKeyPress();
void rotateAntiClockwiseKeyPress();
void rotateClockwiseMouseRightClick();
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -45,7 +45,7 @@ Component::Component(QString annotation, QString name, QString className, Compon
: QGraphicsItem(pParent), mName(name), mClassName(className), mpComponentInfo(pComponentInfo), mType(type), mpOMCProxy(pOMCProxy),
mpGraphicsView(pGraphicsView), mpParentComponent(pParent)
{
setZValue(2000);
setZValue(3000);
mIsLibraryComponent = false;
mIsInheritedComponent = inheritedComponent;
mInheritedClassName = inheritedClassName;
Expand Down Expand Up @@ -178,7 +178,7 @@ void Component::initialize()
mpCoOrdinateSystem->setGrid(QPointF(2, 2));
//Construct the temporary polygon that is used when scaling
mpResizerRectangle = new QGraphicsRectItem;
mpResizerRectangle->setZValue(4000); // set to a very high value
mpResizerRectangle->setZValue(5000); // set to a very high value
if (mpGraphicsView) mpGraphicsView->scene()->addItem(mpResizerRectangle);
QPen pen;
pen.setStyle(Qt::DotLine);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/CornerItem.cpp
Expand Up @@ -323,7 +323,7 @@ void ResizerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
*/
OriginItem::OriginItem()
{
setZValue(3000);
setZValue(4000);
mActivePen = QPen(Qt::red, 2);
mActivePen.setCosmetic(true);
mPassivePen = QPen(Qt::transparent);
Expand Down
100 changes: 100 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -782,6 +782,90 @@ void GraphicsView::deleteShapeObject(ShapeAnnotation *pShape)
mShapesList.removeOne(pShape);
}

/*!
* \brief GraphicsView::bringToFront
* \param pShape
* Brings the shape to front of all other shapes.
*/
void GraphicsView::bringToFront(ShapeAnnotation *pShape)
{
deleteShapeObject(pShape);
int i = 0;
// update the shapes z index
for (; i < mShapesList.size() ; i++) {
mShapesList.at(i)->setZValue(i + 1);
}
pShape->setZValue(i + 1);
mShapesList.append(pShape);
// update class annotation.
addClassAnnotation();
setCanAddClassAnnotation(true);
}

/*!
* \brief GraphicsView::bringForward
* \param pShape
* Brings the shape one level forward.
*/
void GraphicsView::bringForward(ShapeAnnotation *pShape)
{
int shapeIndex = mShapesList.indexOf(pShape);
if (shapeIndex == -1 || shapeIndex == mShapesList.size() - 1) { // if the shape is already at top.
return;
}
// swap the shapes in the list
mShapesList.swap(shapeIndex, shapeIndex + 1);
// update the shapes z index
for (int i = 0 ; i < mShapesList.size() ; i++) {
mShapesList.at(i)->setZValue(i + 1);
}
// update class annotation.
addClassAnnotation();
setCanAddClassAnnotation(true);
}

/*!
* \brief GraphicsView::sendToBack
* \param pShape
* Sends the shape to back of all other shapes.
*/
void GraphicsView::sendToBack(ShapeAnnotation *pShape)
{
deleteShapeObject(pShape);
int i = 0;
pShape->setZValue(i + 1);
mShapesList.prepend(pShape);
// update the shapes z index
for (i = 1 ; i < mShapesList.size() ; i++) {
mShapesList.at(i)->setZValue(i + 1);
}
// update class annotation.
addClassAnnotation();
setCanAddClassAnnotation(true);
}

/*!
* \brief GraphicsView::sendBackward
* \param pShape
* Sends the shape one level backward.
*/
void GraphicsView::sendBackward(ShapeAnnotation *pShape)
{
int shapeIndex = mShapesList.indexOf(pShape);
if (shapeIndex <= 0) { // if the shape is already at bottom.
return;
}
// swap the shapes in the list
mShapesList.swap(shapeIndex - 1, shapeIndex);
// update the shapes z index
for (int i = 0 ; i < mShapesList.size() ; i++) {
mShapesList.at(i)->setZValue(i + 1);
}
// update class annotation.
addClassAnnotation();
setCanAddClassAnnotation(true);
}

void GraphicsView::removeAllComponents()
{
mComponentsList.clear();
Expand Down Expand Up @@ -1021,6 +1105,22 @@ void GraphicsView::createActions()
mpDuplicateAction->setStatusTip(Helper::duplicateTip);
mpDuplicateAction->setShortcut(QKeySequence("Ctrl+d"));
mpDuplicateAction->setDisabled(isSystemLibrary);
// Bring To Front Action
mpBringToFrontAction = new QAction(QIcon(":/Resources/icons/bring-to-front.svg"), tr("Bring to Front"), this);
mpBringToFrontAction->setStatusTip(tr("Brings the item to front"));
mpBringToFrontAction->setDisabled(isSystemLibrary);
// Bring Forward Action
mpBringForwardAction = new QAction(QIcon(":/Resources/icons/bring-forward.svg"), tr("Bring Forward"), this);
mpBringForwardAction->setStatusTip(tr("Brings the item one level forward"));
mpBringForwardAction->setDisabled(isSystemLibrary);
// Send To Back Action
mpSendToBackAction = new QAction(QIcon(":/Resources/icons/send-to-back.svg"), tr("Send to Back"), this);
mpSendToBackAction->setStatusTip(tr("Sends the item to back"));
mpSendToBackAction->setDisabled(isSystemLibrary);
// Send Backward Action
mpSendBackwardAction = new QAction(QIcon(":/Resources/icons/send-backward.svg"), tr("Send Backward"), this);
mpSendBackwardAction->setStatusTip(tr("Sends the item one level backward"));
mpSendBackwardAction->setDisabled(isSystemLibrary);
// Rotate ClockWise Action
mpRotateClockwiseAction = new QAction(QIcon(":/Resources/icons/rotateclockwise.svg"), tr("Rotate Clockwise"), this);
mpRotateClockwiseAction->setStatusTip(tr("Rotates the item clockwise"));
Expand Down
13 changes: 13 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -128,6 +128,10 @@ class GraphicsView : public QGraphicsView
QAction *mpPropertiesAction;
QAction *mpDeleteConnectionAction;
QAction *mpDeleteAction;
QAction *mpBringToFrontAction;
QAction *mpBringForwardAction;
QAction *mpSendToBackAction;
QAction *mpSendBackwardAction;
QAction *mpDuplicateAction;
QAction *mpRotateClockwiseAction;
QAction *mpRotateAntiClockwiseAction;
Expand Down Expand Up @@ -162,9 +166,14 @@ class GraphicsView : public QGraphicsView
void setItemsFlags(bool enable);
void setIsMovingComponentsAndShapes(bool enable);
bool isMovingComponentsAndShapes();
QList<ShapeAnnotation*> getShapesList() {return mShapesList;}
QAction* getDeleteConnectionAction();
QAction* getDeleteAction();
QAction* getDuplicateAction();
QAction* getBringToFrontAction() {return mpBringToFrontAction;}
QAction* getBringForwardAction() {return mpBringForwardAction;}
QAction* getSendToBackAction() {return mpSendToBackAction;}
QAction* getSendBackwardAction() {return mpSendBackwardAction;}
QAction* getRotateClockwiseAction();
QAction* getRotateAntiClockwiseAction();
QAction* getFlipHorizontalAction();
Expand All @@ -185,6 +194,10 @@ class GraphicsView : public QGraphicsView
void deleteConnectionObject(LineAnnotation *pConnectionLineAnnotation);
void addShapeObject(ShapeAnnotation *pShape);
void deleteShapeObject(ShapeAnnotation *pShape);
void bringToFront(ShapeAnnotation *pShape);
void bringForward(ShapeAnnotation *pShape);
void sendToBack(ShapeAnnotation *pShape);
void sendBackward(ShapeAnnotation *pShape);
void removeAllComponents();
void removeAllShapes();
void removeAllConnections();
Expand Down

0 comments on commit b0489b2

Please sign in to comment.