Skip to content

Commit

Permalink
Get class connections. Allow undo/redo of connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 8, 2015
1 parent 8a1542e commit 40d4915
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 143 deletions.
9 changes: 4 additions & 5 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -167,9 +167,8 @@ LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphi
setEndComponent(0);
}

LineAnnotation::LineAnnotation(QString annotation, bool inheritedShape, Component *pStartComponent, Component *pEndComponent,
GraphicsView *pGraphicsView)
: ShapeAnnotation(inheritedShape, pGraphicsView, 0)
LineAnnotation::LineAnnotation(QString annotation, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::ConnectionType;
Expand Down Expand Up @@ -880,7 +879,7 @@ void ConnectionArray::saveArrayIndex()
}
}
}
mpGraphicsView->createConnection(startComponentName, endComponentName);
mpGraphicsView->createConnection(mpConnectionLineAnnotation);
mpConnectionLineAnnotation->setToolTip(QString("<b>connect</b>(%1, %2)").arg(startComponentName, endComponentName));
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsPassive();
Expand All @@ -889,6 +888,6 @@ void ConnectionArray::saveArrayIndex()

void ConnectionArray::cancelArrayIndex()
{
mpGraphicsView->removeConnection();
mpGraphicsView->removeCurrentConnection();
reject();
}
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -60,7 +60,7 @@ class LineAnnotation : public ShapeAnnotation
LineAnnotation(GraphicsView *pGraphicsView);
LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
LineAnnotation(Component *pStartComponent, GraphicsView *pGraphicsView);
LineAnnotation(QString annotation, bool inheritedShape, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView);
LineAnnotation(QString annotation, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QPainterPath getShape() const;
QRectF boundingRect() const;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -1449,7 +1449,7 @@ void ShapeAnnotation::deleteConnection()
{
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
if (pLineAnnotation) {
mpGraphicsView->deleteConnection(pLineAnnotation->getStartComponentName(), pLineAnnotation->getEndComponentName(), true);
mpGraphicsView->deleteConnection(pLineAnnotation, true);
mpGraphicsView->deleteConnectionObject(pLineAnnotation);
deleteLater();
}
Expand Down
9 changes: 8 additions & 1 deletion OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -737,6 +737,13 @@ void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
connect(this, SIGNAL(transformHasChanged()), pConnectorLineAnnotation, SLOT(updateConnectionAnnotation()));
}

void Component::removeConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
{
disconnect(this, SIGNAL(transformChange()), pConnectorLineAnnotation, SLOT(handleComponentMoved()));
disconnect(this, SIGNAL(rotationChange()), pConnectorLineAnnotation, SLOT(handleComponentRotation()));
disconnect(this, SIGNAL(transformHasChanged()), pConnectorLineAnnotation, SLOT(updateConnectionAnnotation()));
}

void Component::emitAdded()
{
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
Expand Down Expand Up @@ -1596,7 +1603,7 @@ void Component::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
emit showTLMAttributes();
} else {
if (!mpParentComponent) { // if root component is double clicked then show parameters.
mpGraphicsView->removeConnection();
mpGraphicsView->removeCurrentConnection();
emit showParameters();
}
}
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -175,6 +175,7 @@ class Component : public QObject, public QGraphicsItem
QString getTransformationExtent();
void applyRotation(qreal angle);
void addConnectionDetails(LineAnnotation *pConnectorLineAnnotation);
void removeConnectionDetails(LineAnnotation *pConnectorLineAnnotation);
void emitAdded();
void emitTransformHasChanged();
void emitDeleted();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -2087,7 +2087,7 @@ void MainWindow::toggleShapesButton()
if (pModelWidget) {
GraphicsView *pGraphicsView = pModelWidget->getDiagramGraphicsView();
if (pGraphicsView->isCreatingConnection()) {
pGraphicsView->removeConnection();
pGraphicsView->removeCurrentConnection();
}
}
}
Expand Down
70 changes: 70 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -319,3 +319,73 @@ void DeleteShapeCommand::undo()
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setCanAddClassAnnotation(true);
}

AddConnectionCommand::AddConnectionCommand(LineAnnotation *pConnectionLineAnnotation, bool addConnection, GraphicsView *pGraphicsView,
QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpConnectionLineAnnotation = pConnectionLineAnnotation;
mAddConnection = addConnection;
mpGraphicsView = pGraphicsView;
setText(QString("Add Connection connect(%1, %2)").arg(mpConnectionLineAnnotation->getStartComponentName(),
mpConnectionLineAnnotation->getEndComponentName()));

mpConnectionLineAnnotation->setToolTip(QString("<b>connect</b>(%1, %2)").arg(mpConnectionLineAnnotation->getStartComponentName())
.arg(mpConnectionLineAnnotation->getEndComponentName()));
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsPassive();
}

/*!
* \brief AddConnectionCommand::redo
* Redo the AddConnectionCommand.
*/
void AddConnectionCommand::redo()
{
// Add the start component connection details.
Component *pStartComponent = mpConnectionLineAnnotation->getStartComponent();
if (pStartComponent->getRootParentComponent()) {
pStartComponent->getRootParentComponent()->addConnectionDetails(mpConnectionLineAnnotation);
} else {
pStartComponent->addConnectionDetails(mpConnectionLineAnnotation);
}
// Add the end component connection details.
Component *pEndComponent = mpConnectionLineAnnotation->getEndComponent();
if (pEndComponent->getParentComponent()) {
pEndComponent->getParentComponent()->addConnectionDetails(mpConnectionLineAnnotation);
} else {
pEndComponent->addConnectionDetails(mpConnectionLineAnnotation);
}
mpGraphicsView->addConnectionObject(mpConnectionLineAnnotation);
mpGraphicsView->addItem(mpConnectionLineAnnotation);
//mpLineAnnotation->emitAdded();
if (mAddConnection) {
mpGraphicsView->createConnection(mpConnectionLineAnnotation);
}
}

/*!
* \brief AddConnectionCommand::undo
* Undo the AddConnectionCommand.
*/
void AddConnectionCommand::undo()
{
// Remove the start component connection details.
Component *pStartComponent = mpConnectionLineAnnotation->getStartComponent();
if (pStartComponent->getRootParentComponent()) {
pStartComponent->getRootParentComponent()->removeConnectionDetails(mpConnectionLineAnnotation);
} else {
pStartComponent->removeConnectionDetails(mpConnectionLineAnnotation);
}
// Remove the end component connection details.
Component *pEndComponent = mpConnectionLineAnnotation->getEndComponent();
if (pEndComponent->getParentComponent()) {
pEndComponent->getParentComponent()->removeConnectionDetails(mpConnectionLineAnnotation);
} else {
pEndComponent->removeConnectionDetails(mpConnectionLineAnnotation);
}
mpGraphicsView->deleteConnectionObject(mpConnectionLineAnnotation);
mpGraphicsView->removeItem(mpConnectionLineAnnotation);
//mpLineAnnotation->emitDeleted();
mpGraphicsView->deleteConnection(mpConnectionLineAnnotation, true);
}
12 changes: 12 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -92,4 +92,16 @@ class DeleteShapeCommand : public QUndoCommand
GraphicsView *mpGraphicsView;
};

class AddConnectionCommand : public QUndoCommand
{
public:
AddConnectionCommand(LineAnnotation *pConnectionLineAnnotation, bool addConnection, GraphicsView *pGraphicsView, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
LineAnnotation *mpConnectionLineAnnotation;
bool mAddConnection;
GraphicsView *mpGraphicsView;
};

#endif // COMMANDS_H

0 comments on commit 40d4915

Please sign in to comment.