Skip to content

Commit

Permalink
Track the shapes duplication operation in undo stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 20, 2015
1 parent d4e9180 commit 164eabb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 68 deletions.
12 changes: 6 additions & 6 deletions OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -37,6 +37,7 @@
*/

#include "BitmapAnnotation.h"
#include "Commands.h"

BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
Expand Down Expand Up @@ -199,17 +200,16 @@ void BitmapAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
void BitmapAnnotation::duplicate()
{
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", mpGraphicsView);
pBitmapAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pBitmapAnnotation->setOrigin(mOrigin + gridStep);
pBitmapAnnotation->setRotationAngle(mRotation);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->setExtents(getExtents());
pBitmapAnnotation->setFileName(getFileName());
pBitmapAnnotation->setImageSource(getImageSource());
pBitmapAnnotation->setImage(getImage());
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
pBitmapAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pBitmapAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
mpGraphicsView->getModelWidget()->updateModelicaText();
}
16 changes: 6 additions & 10 deletions OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp
Expand Up @@ -37,6 +37,7 @@
*/

#include "EllipseAnnotation.h"
#include "Commands.h"

EllipseAnnotation::EllipseAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
Expand Down Expand Up @@ -224,21 +225,16 @@ void EllipseAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
void EllipseAnnotation::duplicate()
{
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation("", mpGraphicsView);
pEllipseAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pEllipseAnnotation->setOrigin(mOrigin + gridStep);
pEllipseAnnotation->setRotationAngle(mRotation);
pEllipseAnnotation->initializeTransformation();
pEllipseAnnotation->setLineColor(getLineColor());
pEllipseAnnotation->setFillColor(getFillColor());
pEllipseAnnotation->setLinePattern(getLinePattern());
pEllipseAnnotation->setFillPattern(getFillPattern());
pEllipseAnnotation->setLineThickness(getLineThickness());
pEllipseAnnotation->setExtents(getExtents());
pEllipseAnnotation->setStartAngle(getStartAngle());
pEllipseAnnotation->setEndAngle(getEndAngle());
pEllipseAnnotation->drawCornerItems();
pEllipseAnnotation->setCornerItemsActiveOrPassive();
pEllipseAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pEllipseAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pEllipseAnnotation, mpGraphicsView);
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
mpGraphicsView->getModelWidget()->updateModelicaText();
}
19 changes: 6 additions & 13 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -37,6 +37,7 @@
*/

#include "LineAnnotation.h"
#include "Commands.h"

LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
Expand Down Expand Up @@ -725,26 +726,18 @@ void LineAnnotation::updateConnectionAnnotation()
void LineAnnotation::duplicate()
{
LineAnnotation *pLineAnnotation = new LineAnnotation("", mpGraphicsView);
pLineAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pLineAnnotation->setOrigin(mOrigin + gridStep);
pLineAnnotation->setRotationAngle(mRotation);
pLineAnnotation->initializeTransformation();
pLineAnnotation->setLineColor(getLineColor());
pLineAnnotation->setLinePattern(getLinePattern());
pLineAnnotation->setLineThickness(getLineThickness());
pLineAnnotation->setStartArrow(getStartArrow());
pLineAnnotation->setEndArrow(getEndArrow());
pLineAnnotation->setArrowSize(getArrowSize());
pLineAnnotation->setSmooth(getSmooth());
QList<QPointF> points = getPoints();
for (int i = 0 ; i < points.size() ; i++) {
pLineAnnotation->addPoint(points[i]);
}
pLineAnnotation->drawCornerItems();
pLineAnnotation->setCornerItemsActiveOrPassive();
pLineAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pLineAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pLineAnnotation, mpGraphicsView);
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
mpGraphicsView->getModelWidget()->updateModelicaText();
}

ConnectionArray::ConnectionArray(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, QWidget *pParent)
Expand Down
15 changes: 6 additions & 9 deletions OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp
Expand Up @@ -37,6 +37,7 @@
*/

#include "PolygonAnnotation.h"
#include "Commands.h"

PolygonAnnotation::PolygonAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
Expand Down Expand Up @@ -279,20 +280,16 @@ void PolygonAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
void PolygonAnnotation::duplicate()
{
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation("", mpGraphicsView);
pPolygonAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pPolygonAnnotation->setOrigin(mOrigin + gridStep);
pPolygonAnnotation->setRotationAngle(mRotation);
pPolygonAnnotation->initializeTransformation();
pPolygonAnnotation->setLineColor(getLineColor());
pPolygonAnnotation->setFillColor(getFillColor());
pPolygonAnnotation->setLinePattern(getLinePattern());
pPolygonAnnotation->setFillPattern(getFillPattern());
pPolygonAnnotation->setLineThickness(getLineThickness());
pPolygonAnnotation->setSmooth(getSmooth());
pPolygonAnnotation->setPoints(getPoints());
pPolygonAnnotation->drawCornerItems();
pPolygonAnnotation->setCornerItemsActiveOrPassive();
pPolygonAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pPolygonAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pPolygonAnnotation, mpGraphicsView);
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
mpGraphicsView->getModelWidget()->updateModelicaText();
}
16 changes: 6 additions & 10 deletions OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -37,6 +37,7 @@
*/

#include "RectangleAnnotation.h"
#include "Commands.h"

RectangleAnnotation::RectangleAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
Expand Down Expand Up @@ -219,21 +220,16 @@ void RectangleAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
void RectangleAnnotation::duplicate()
{
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation("", mpGraphicsView);
pRectangleAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pRectangleAnnotation->setOrigin(mOrigin + gridStep);
pRectangleAnnotation->setRotationAngle(mRotation);
pRectangleAnnotation->initializeTransformation();
pRectangleAnnotation->setLineColor(getLineColor());
pRectangleAnnotation->setFillColor(getFillColor());
pRectangleAnnotation->setLinePattern(getLinePattern());
pRectangleAnnotation->setFillPattern(getFillPattern());
pRectangleAnnotation->setLineThickness(getLineThickness());
pRectangleAnnotation->setBorderPattern(getBorderPattern());
pRectangleAnnotation->setExtents(getExtents());
pRectangleAnnotation->setRadius(getRadius());
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
pRectangleAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pRectangleAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pRectangleAnnotation, mpGraphicsView);
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
mpGraphicsView->getModelWidget()->updateModelicaText();
}
19 changes: 6 additions & 13 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -37,6 +37,7 @@
*/

#include "TextAnnotation.h"
#include "Commands.h"

/*!
* \class TextAnnotation
Expand Down Expand Up @@ -484,24 +485,16 @@ void TextAnnotation::updateTextString()
void TextAnnotation::duplicate()
{
TextAnnotation *pTextAnnotation = new TextAnnotation("", mpGraphicsView);
pTextAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pTextAnnotation->setOrigin(mOrigin + gridStep);
pTextAnnotation->setRotationAngle(mRotation);
pTextAnnotation->initializeTransformation();
pTextAnnotation->setLineColor(getLineColor());
pTextAnnotation->setFillColor(getFillColor());
pTextAnnotation->setLinePattern(getLinePattern());
pTextAnnotation->setFillPattern(getFillPattern());
pTextAnnotation->setLineThickness(getLineThickness());
pTextAnnotation->setExtents(getExtents());
pTextAnnotation->setTextString(getTextString());
pTextAnnotation->setFontSize(getFontSize());
pTextAnnotation->setFontName(getFontName());
pTextAnnotation->setTextStyles(getTextStyles());
pTextAnnotation->setTextHorizontalAlignment(getTextHorizontalAlignment());
pTextAnnotation->drawCornerItems();
pTextAnnotation->setCornerItemsActiveOrPassive();
pTextAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pTextAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pTextAnnotation, mpGraphicsView);
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
mpGraphicsView->getModelWidget()->updateModelicaText();
}
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -62,7 +62,7 @@ void AddShapeCommand::redo()
mpGraphicsView->addShapeToList(mpShapeAnnotation);
mpGraphicsView->addItem(mpShapeAnnotation);
mpShapeAnnotation->emitAdded();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setAddClassAnnotationNeeded(true);
}

/*!
Expand All @@ -74,7 +74,7 @@ void AddShapeCommand::undo()
mpGraphicsView->deleteShapeFromList(mpShapeAnnotation);
mpGraphicsView->removeItem(mpShapeAnnotation);
mpShapeAnnotation->emitDeleted();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setAddClassAnnotationNeeded(true);
}

UpdateShapeCommand::UpdateShapeCommand(ShapeAnnotation *pShapeAnnotation, QString oldAnnotaton, QString newAnnotation,
Expand Down
15 changes: 10 additions & 5 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -765,7 +765,8 @@ void GraphicsView::createRectangleShape(QPointF point)
pMainWindow->getRectangleShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpRectangleShapeAnnotation, this);
addClassAnnotation();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelicaText();
}
}

Expand Down Expand Up @@ -797,7 +798,8 @@ void GraphicsView::createEllipseShape(QPointF point)
pMainWindow->getEllipseShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpEllipseShapeAnnotation, this);
addClassAnnotation();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelicaText();
}
}

Expand Down Expand Up @@ -830,7 +832,8 @@ void GraphicsView::createTextShape(QPointF point)
pMainWindow->getTextShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpTextShapeAnnotation, this);
addClassAnnotation();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelicaText();
mpTextShapeAnnotation->showShapeProperties();
}
}
Expand Down Expand Up @@ -1663,7 +1666,8 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
pMainWindow->getLineShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpLineShapeAnnotation, this);
addClassAnnotation();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelicaText();
return;
} else if (isCreatingPolygonShape()) {
// finish creating the polygon
Expand All @@ -1680,7 +1684,8 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
pMainWindow->getPolygonShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpPolygonShapeAnnotation, this);
addClassAnnotation();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelicaText();
return;
}
ShapeAnnotation *pShapeAnnotation = dynamic_cast<ShapeAnnotation*>(itemAt(event->pos()));
Expand Down

0 comments on commit 164eabb

Please sign in to comment.