Skip to content

Commit 164eabb

Browse files
committed
Track the shapes duplication operation in undo stack.
1 parent d4e9180 commit 164eabb

File tree

8 files changed

+48
-68
lines changed

8 files changed

+48
-68
lines changed

OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include "BitmapAnnotation.h"
40+
#include "Commands.h"
4041

4142
BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView)
4243
: ShapeAnnotation(false, pGraphicsView, 0)
@@ -199,17 +200,16 @@ void BitmapAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
199200
void BitmapAnnotation::duplicate()
200201
{
201202
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", mpGraphicsView);
203+
pBitmapAnnotation->updateShape(this);
202204
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
203205
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
204206
pBitmapAnnotation->setOrigin(mOrigin + gridStep);
205-
pBitmapAnnotation->setRotationAngle(mRotation);
206207
pBitmapAnnotation->initializeTransformation();
207-
pBitmapAnnotation->setExtents(getExtents());
208-
pBitmapAnnotation->setFileName(getFileName());
209-
pBitmapAnnotation->setImageSource(getImageSource());
210-
pBitmapAnnotation->setImage(getImage());
211208
pBitmapAnnotation->drawCornerItems();
212209
pBitmapAnnotation->setCornerItemsActiveOrPassive();
213210
pBitmapAnnotation->update();
214-
mpGraphicsView->addClassAnnotation();
211+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pBitmapAnnotation, mpGraphicsView));
212+
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
213+
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
214+
mpGraphicsView->getModelWidget()->updateModelicaText();
215215
}

OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include "EllipseAnnotation.h"
40+
#include "Commands.h"
4041

4142
EllipseAnnotation::EllipseAnnotation(QString annotation, GraphicsView *pGraphicsView)
4243
: ShapeAnnotation(false, pGraphicsView, 0)
@@ -224,21 +225,16 @@ void EllipseAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
224225
void EllipseAnnotation::duplicate()
225226
{
226227
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation("", mpGraphicsView);
228+
pEllipseAnnotation->updateShape(this);
227229
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
228230
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
229231
pEllipseAnnotation->setOrigin(mOrigin + gridStep);
230-
pEllipseAnnotation->setRotationAngle(mRotation);
231232
pEllipseAnnotation->initializeTransformation();
232-
pEllipseAnnotation->setLineColor(getLineColor());
233-
pEllipseAnnotation->setFillColor(getFillColor());
234-
pEllipseAnnotation->setLinePattern(getLinePattern());
235-
pEllipseAnnotation->setFillPattern(getFillPattern());
236-
pEllipseAnnotation->setLineThickness(getLineThickness());
237-
pEllipseAnnotation->setExtents(getExtents());
238-
pEllipseAnnotation->setStartAngle(getStartAngle());
239-
pEllipseAnnotation->setEndAngle(getEndAngle());
240233
pEllipseAnnotation->drawCornerItems();
241234
pEllipseAnnotation->setCornerItemsActiveOrPassive();
242235
pEllipseAnnotation->update();
243-
mpGraphicsView->addClassAnnotation();
236+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pEllipseAnnotation, mpGraphicsView));
237+
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pEllipseAnnotation, mpGraphicsView);
238+
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
239+
mpGraphicsView->getModelWidget()->updateModelicaText();
244240
}

OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include "LineAnnotation.h"
40+
#include "Commands.h"
4041

4142
LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
4243
: ShapeAnnotation(false, pGraphicsView, 0)
@@ -725,26 +726,18 @@ void LineAnnotation::updateConnectionAnnotation()
725726
void LineAnnotation::duplicate()
726727
{
727728
LineAnnotation *pLineAnnotation = new LineAnnotation("", mpGraphicsView);
729+
pLineAnnotation->updateShape(this);
728730
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
729731
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
730732
pLineAnnotation->setOrigin(mOrigin + gridStep);
731-
pLineAnnotation->setRotationAngle(mRotation);
732733
pLineAnnotation->initializeTransformation();
733-
pLineAnnotation->setLineColor(getLineColor());
734-
pLineAnnotation->setLinePattern(getLinePattern());
735-
pLineAnnotation->setLineThickness(getLineThickness());
736-
pLineAnnotation->setStartArrow(getStartArrow());
737-
pLineAnnotation->setEndArrow(getEndArrow());
738-
pLineAnnotation->setArrowSize(getArrowSize());
739-
pLineAnnotation->setSmooth(getSmooth());
740-
QList<QPointF> points = getPoints();
741-
for (int i = 0 ; i < points.size() ; i++) {
742-
pLineAnnotation->addPoint(points[i]);
743-
}
744734
pLineAnnotation->drawCornerItems();
745735
pLineAnnotation->setCornerItemsActiveOrPassive();
746736
pLineAnnotation->update();
747-
mpGraphicsView->addClassAnnotation();
737+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pLineAnnotation, mpGraphicsView));
738+
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pLineAnnotation, mpGraphicsView);
739+
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
740+
mpGraphicsView->getModelWidget()->updateModelicaText();
748741
}
749742

750743
ConnectionArray::ConnectionArray(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, QWidget *pParent)

OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include "PolygonAnnotation.h"
40+
#include "Commands.h"
4041

4142
PolygonAnnotation::PolygonAnnotation(QString annotation, GraphicsView *pGraphicsView)
4243
: ShapeAnnotation(false, pGraphicsView, 0)
@@ -279,20 +280,16 @@ void PolygonAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
279280
void PolygonAnnotation::duplicate()
280281
{
281282
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation("", mpGraphicsView);
283+
pPolygonAnnotation->updateShape(this);
282284
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
283285
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
284286
pPolygonAnnotation->setOrigin(mOrigin + gridStep);
285-
pPolygonAnnotation->setRotationAngle(mRotation);
286287
pPolygonAnnotation->initializeTransformation();
287-
pPolygonAnnotation->setLineColor(getLineColor());
288-
pPolygonAnnotation->setFillColor(getFillColor());
289-
pPolygonAnnotation->setLinePattern(getLinePattern());
290-
pPolygonAnnotation->setFillPattern(getFillPattern());
291-
pPolygonAnnotation->setLineThickness(getLineThickness());
292-
pPolygonAnnotation->setSmooth(getSmooth());
293-
pPolygonAnnotation->setPoints(getPoints());
294288
pPolygonAnnotation->drawCornerItems();
295289
pPolygonAnnotation->setCornerItemsActiveOrPassive();
296290
pPolygonAnnotation->update();
297-
mpGraphicsView->addClassAnnotation();
291+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pPolygonAnnotation, mpGraphicsView));
292+
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pPolygonAnnotation, mpGraphicsView);
293+
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
294+
mpGraphicsView->getModelWidget()->updateModelicaText();
298295
}

OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include "RectangleAnnotation.h"
40+
#include "Commands.h"
4041

4142
RectangleAnnotation::RectangleAnnotation(QString annotation, GraphicsView *pGraphicsView)
4243
: ShapeAnnotation(false, pGraphicsView, 0)
@@ -219,21 +220,16 @@ void RectangleAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
219220
void RectangleAnnotation::duplicate()
220221
{
221222
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation("", mpGraphicsView);
223+
pRectangleAnnotation->updateShape(this);
222224
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
223225
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
224226
pRectangleAnnotation->setOrigin(mOrigin + gridStep);
225-
pRectangleAnnotation->setRotationAngle(mRotation);
226227
pRectangleAnnotation->initializeTransformation();
227-
pRectangleAnnotation->setLineColor(getLineColor());
228-
pRectangleAnnotation->setFillColor(getFillColor());
229-
pRectangleAnnotation->setLinePattern(getLinePattern());
230-
pRectangleAnnotation->setFillPattern(getFillPattern());
231-
pRectangleAnnotation->setLineThickness(getLineThickness());
232-
pRectangleAnnotation->setBorderPattern(getBorderPattern());
233-
pRectangleAnnotation->setExtents(getExtents());
234-
pRectangleAnnotation->setRadius(getRadius());
235228
pRectangleAnnotation->drawCornerItems();
236229
pRectangleAnnotation->setCornerItemsActiveOrPassive();
237230
pRectangleAnnotation->update();
238-
mpGraphicsView->addClassAnnotation();
231+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pRectangleAnnotation, mpGraphicsView));
232+
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pRectangleAnnotation, mpGraphicsView);
233+
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
234+
mpGraphicsView->getModelWidget()->updateModelicaText();
239235
}

OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include "TextAnnotation.h"
40+
#include "Commands.h"
4041

4142
/*!
4243
* \class TextAnnotation
@@ -484,24 +485,16 @@ void TextAnnotation::updateTextString()
484485
void TextAnnotation::duplicate()
485486
{
486487
TextAnnotation *pTextAnnotation = new TextAnnotation("", mpGraphicsView);
488+
pTextAnnotation->updateShape(this);
487489
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
488490
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
489491
pTextAnnotation->setOrigin(mOrigin + gridStep);
490-
pTextAnnotation->setRotationAngle(mRotation);
491492
pTextAnnotation->initializeTransformation();
492-
pTextAnnotation->setLineColor(getLineColor());
493-
pTextAnnotation->setFillColor(getFillColor());
494-
pTextAnnotation->setLinePattern(getLinePattern());
495-
pTextAnnotation->setFillPattern(getFillPattern());
496-
pTextAnnotation->setLineThickness(getLineThickness());
497-
pTextAnnotation->setExtents(getExtents());
498-
pTextAnnotation->setTextString(getTextString());
499-
pTextAnnotation->setFontSize(getFontSize());
500-
pTextAnnotation->setFontName(getFontName());
501-
pTextAnnotation->setTextStyles(getTextStyles());
502-
pTextAnnotation->setTextHorizontalAlignment(getTextHorizontalAlignment());
503493
pTextAnnotation->drawCornerItems();
504494
pTextAnnotation->setCornerItemsActiveOrPassive();
505495
pTextAnnotation->update();
506-
mpGraphicsView->addClassAnnotation();
496+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pTextAnnotation, mpGraphicsView));
497+
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pTextAnnotation, mpGraphicsView);
498+
mpGraphicsView->getModelWidget()->updateClassAnnotationIfNeeded();
499+
mpGraphicsView->getModelWidget()->updateModelicaText();
507500
}

OMEdit/OMEditGUI/Modeling/Commands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void AddShapeCommand::redo()
6262
mpGraphicsView->addShapeToList(mpShapeAnnotation);
6363
mpGraphicsView->addItem(mpShapeAnnotation);
6464
mpShapeAnnotation->emitAdded();
65-
mpGraphicsView->addClassAnnotation();
65+
mpGraphicsView->setAddClassAnnotationNeeded(true);
6666
}
6767

6868
/*!
@@ -74,7 +74,7 @@ void AddShapeCommand::undo()
7474
mpGraphicsView->deleteShapeFromList(mpShapeAnnotation);
7575
mpGraphicsView->removeItem(mpShapeAnnotation);
7676
mpShapeAnnotation->emitDeleted();
77-
mpGraphicsView->addClassAnnotation();
77+
mpGraphicsView->setAddClassAnnotationNeeded(true);
7878
}
7979

8080
UpdateShapeCommand::UpdateShapeCommand(ShapeAnnotation *pShapeAnnotation, QString oldAnnotaton, QString newAnnotation,

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ void GraphicsView::createRectangleShape(QPointF point)
765765
pMainWindow->getRectangleShapeAction()->setChecked(false);
766766
pMainWindow->getConnectModeAction()->setChecked(true);
767767
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpRectangleShapeAnnotation, this);
768-
addClassAnnotation();
768+
mpModelWidget->updateClassAnnotationIfNeeded();
769+
mpModelWidget->updateModelicaText();
769770
}
770771
}
771772

@@ -797,7 +798,8 @@ void GraphicsView::createEllipseShape(QPointF point)
797798
pMainWindow->getEllipseShapeAction()->setChecked(false);
798799
pMainWindow->getConnectModeAction()->setChecked(true);
799800
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpEllipseShapeAnnotation, this);
800-
addClassAnnotation();
801+
mpModelWidget->updateClassAnnotationIfNeeded();
802+
mpModelWidget->updateModelicaText();
801803
}
802804
}
803805

@@ -830,7 +832,8 @@ void GraphicsView::createTextShape(QPointF point)
830832
pMainWindow->getTextShapeAction()->setChecked(false);
831833
pMainWindow->getConnectModeAction()->setChecked(true);
832834
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpTextShapeAnnotation, this);
833-
addClassAnnotation();
835+
mpModelWidget->updateClassAnnotationIfNeeded();
836+
mpModelWidget->updateModelicaText();
834837
mpTextShapeAnnotation->showShapeProperties();
835838
}
836839
}
@@ -1663,7 +1666,8 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
16631666
pMainWindow->getLineShapeAction()->setChecked(false);
16641667
pMainWindow->getConnectModeAction()->setChecked(true);
16651668
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpLineShapeAnnotation, this);
1666-
addClassAnnotation();
1669+
mpModelWidget->updateClassAnnotationIfNeeded();
1670+
mpModelWidget->updateModelicaText();
16671671
return;
16681672
} else if (isCreatingPolygonShape()) {
16691673
// finish creating the polygon
@@ -1680,7 +1684,8 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
16801684
pMainWindow->getPolygonShapeAction()->setChecked(false);
16811685
pMainWindow->getConnectModeAction()->setChecked(true);
16821686
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpPolygonShapeAnnotation, this);
1683-
addClassAnnotation();
1687+
mpModelWidget->updateClassAnnotationIfNeeded();
1688+
mpModelWidget->updateModelicaText();
16841689
return;
16851690
}
16861691
ShapeAnnotation *pShapeAnnotation = dynamic_cast<ShapeAnnotation*>(itemAt(event->pos()));

0 commit comments

Comments
 (0)