Skip to content

Commit

Permalink
Allow creating initial state graphically.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Sep 27, 2017
1 parent 17caf92 commit 73e1f2a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
58 changes: 57 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -118,6 +118,7 @@ GraphicsView::GraphicsView(StringHandler::ViewType viewType, ModelWidget *parent
mpClickedState = 0;
setIsMovingComponentsAndShapes(false);
setRenderingLibraryPixmap(false);
mSkipFoucusOutEvent = false;
mpConnectionLineAnnotation = 0;
mpTransitionLineAnnotation = 0;
mpLineShapeAnnotation = 0;
Expand Down Expand Up @@ -1204,6 +1205,14 @@ void GraphicsView::createActions()
mpFlipVerticalAction->setShortcut(QKeySequence("v"));
mpFlipVerticalAction->setDisabled(isSystemLibrary);
connect(mpFlipVerticalAction, SIGNAL(triggered()), SLOT(flipVertical()));
// set initial state Action
mpSetInitialStateAction = new QAction(tr("Set Initial State"), this);
mpSetInitialStateAction->setStatusTip(tr("Sets the state as initial state"));
connect(mpSetInitialStateAction, SIGNAL(triggered()), SLOT(setInitialState()));
// cancel transition Action
mpCancelTransitionAction = new QAction(tr("Cancel Transition"), this);
mpCancelTransitionAction->setStatusTip(tr("Cancels the current transition"));
connect(mpCancelTransitionAction, SIGNAL(triggered()), SLOT(cancelTransition()));
}

/*!
Expand Down Expand Up @@ -1827,6 +1836,40 @@ void GraphicsView::flipVertical()
mpModelWidget->endMacro();
}

/*!
* \brief GraphicsView::setInitialState
* Sets the state as initial.
*/
void GraphicsView::setInitialState()
{
if (mpTransitionLineAnnotation) {
QString startComponentName;
if (mpTransitionLineAnnotation->getStartComponent()->getParentComponent()) {
startComponentName = QString(mpTransitionLineAnnotation->getStartComponent()->getRootParentComponent()->getName()).append(".")
.append(mpTransitionLineAnnotation->getStartComponent()->getName());
} else {
startComponentName = mpTransitionLineAnnotation->getStartComponent()->getName();
}
mpTransitionLineAnnotation->setStartComponentName(startComponentName);
mpTransitionLineAnnotation->setEndComponentName("");
mpTransitionLineAnnotation->setLineType(LineAnnotation::InitialStateType);
mpModelWidget->getUndoStack()->push(new AddInitialStateCommand(mpTransitionLineAnnotation, true));
mpModelWidget->updateModelText();
setIsCreatingTransition(false);
}
}

/*!
* \brief GraphicsView::cancelTransition
* Cancels the current transition.
*/
void GraphicsView::cancelTransition()
{
if (mpTransitionLineAnnotation) {
removeCurrentTransition();
}
}

/*!
* \brief GraphicsView::dragMoveEvent
* Defines what happens when dragged and moved an object in a GraphicsView.
Expand Down Expand Up @@ -2288,6 +2331,10 @@ void GraphicsView::focusOutEvent(QFocusEvent *event)
if (QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::CrossCursor) {
QApplication::restoreOverrideCursor();
}
if (mpTransitionLineAnnotation && !mSkipFoucusOutEvent) {
removeCurrentTransition();
}
mSkipFoucusOutEvent = false;
QGraphicsView::focusOutEvent(event);
}

Expand Down Expand Up @@ -2463,14 +2510,23 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
{
/* If we are creating the connection OR creating any shape then don't show context menu */
if (isCreatingConnection() ||
isCreatingTransition() ||
isCreatingLineShape() ||
isCreatingPolygonShape() ||
isCreatingRectangleShape() ||
isCreatingEllipseShape() ||
isCreatingTextShape()) {
return;
}
// if creating a transition
if (isCreatingTransition()) {
mSkipFoucusOutEvent = true;
QMenu menu(MainWindow::instance());
menu.addAction(mpSetInitialStateAction);
menu.addSeparator();
menu.addAction(mpCancelTransitionAction);
menu.exec(event->globalPos());
return;
}
// if some item is right clicked then don't show graphics view context menu
if (!itemAt(event->pos())) {
QMenu menu(MainWindow::instance());
Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -100,6 +100,7 @@ class GraphicsView : public QGraphicsView
Component *mpClickedState;
bool mIsMovingComponentsAndShapes;
bool mRenderingLibraryPixmap;
bool mSkipFoucusOutEvent;
QList<Component*> mComponentsList;
QList<LineAnnotation*> mConnectionsList;
QList<LineAnnotation*> mTransitionsList;
Expand Down Expand Up @@ -130,7 +131,8 @@ class GraphicsView : public QGraphicsView
QAction *mpRotateAntiClockwiseAction;
QAction *mpFlipHorizontalAction;
QAction *mpFlipVerticalAction;
QAction *mpAttributesAction;
QAction *mpSetInitialStateAction;
QAction *mpCancelTransitionAction;
public:
GraphicsView(StringHandler::ViewType viewType, ModelWidget *parent);
CoOrdinateSystem mCoOrdinateSystem;
Expand Down Expand Up @@ -298,6 +300,8 @@ public slots:
void rotateAntiClockwise();
void flipHorizontal();
void flipVertical();
void setInitialState();
void cancelTransition();
protected:
virtual void dragMoveEvent(QDragMoveEvent *event);
virtual void dropEvent(QDropEvent *event);
Expand Down

0 comments on commit 73e1f2a

Please sign in to comment.