Skip to content

Commit e322df0

Browse files
committed
Allow undo/redo for component attributes.
1 parent 54b69c4 commit e322df0

File tree

14 files changed

+299
-160
lines changed

14 files changed

+299
-160
lines changed

OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,6 @@ void LineAnnotation::updateConnectionAnnotation()
717717
pOMCProxy->updateConnection(getStartComponentName(), getEndComponentName(),
718718
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), annotationString);
719719
}
720-
// make the model modified
721-
mpGraphicsView->getModelWidget()->setModelModified();
722720
}
723721

724722
void LineAnnotation::duplicate()

OMEdit/OMEditGUI/Component/Component.cpp

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@
4646
*/
4747
/*!
4848
* \brief ComponentInfo::ComponentInfo
49-
* \param value
5049
* \param pParent
5150
*/
52-
ComponentInfo::ComponentInfo(QString value, QObject *pParent)
51+
ComponentInfo::ComponentInfo(QObject *pParent)
5352
: QObject(pParent)
5453
{
5554
mClassName = "";
@@ -63,17 +62,52 @@ ComponentInfo::ComponentInfo(QString value, QObject *pParent)
6362
mVariabilityMap.insert("constant", "constant");
6463
mVariabilityMap.insert("discrete", "discrete");
6564
mVariabilityMap.insert("parameter", "parameter");
66-
mVariabilityMap.insert("unspecified", "default");
65+
mVariabilityMap.insert("unspecified", "");
6766
mVariability = "";
6867
mIsInner = false;
6968
mIsOuter = false;
7069
mCasualityMap.insert("input", "input");
7170
mCasualityMap.insert("output", "output");
72-
mCasualityMap.insert("unspecified", "none");
71+
mCasualityMap.insert("unspecified", "");
7372
mCasuality = "";
7473
mArrayIndex = "";
7574
mIsArray = false;
76-
parseComponentInfoString(value);
75+
}
76+
77+
/*!
78+
* \brief ComponentInfo::ComponentInfo
79+
* \param pComponentInfo
80+
* \param pParent
81+
*/
82+
ComponentInfo::ComponentInfo(ComponentInfo *pComponentInfo, QObject *pParent)
83+
: QObject(pParent)
84+
{
85+
updateComponentInfo(pComponentInfo);
86+
}
87+
88+
void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
89+
{
90+
mClassName = pComponentInfo->getClassName();
91+
mName = pComponentInfo->getName();
92+
mComment = pComponentInfo->getComment();
93+
mIsProtected = pComponentInfo->getProtected();
94+
mIsFinal = pComponentInfo->getFinal();
95+
mIsFlow = pComponentInfo->getFlow();
96+
mIsStream = pComponentInfo->getStream();
97+
mIsReplaceable = pComponentInfo->getReplaceable();
98+
mVariabilityMap.insert("constant", "constant");
99+
mVariabilityMap.insert("discrete", "discrete");
100+
mVariabilityMap.insert("parameter", "parameter");
101+
mVariabilityMap.insert("unspecified", "");
102+
mVariability = pComponentInfo->getVariablity();
103+
mIsInner = pComponentInfo->getInner();
104+
mIsOuter = pComponentInfo->getOuter();
105+
mCasualityMap.insert("input", "input");
106+
mCasualityMap.insert("output", "output");
107+
mCasualityMap.insert("unspecified", "");
108+
mCasuality = pComponentInfo->getCausality();
109+
mArrayIndex = pComponentInfo->getArrayIndex();
110+
mIsArray = pComponentInfo->isArray();
77111
}
78112

79113
/*!
@@ -733,7 +767,7 @@ void Component::applyRotation(qreal angle)
733767
angle = 0;
734768
}
735769
mTransformation.setRotateAngle(angle);
736-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
770+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
737771
}
738772

739773
void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
@@ -979,8 +1013,6 @@ void Component::updatePlacementAnnotation()
9791013
pOMCProxy->updateComponent(mpComponentInfo->getName(), mpComponentInfo->getClassName(),
9801014
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getPlacementAnnotation());
9811015
}
982-
// set the model modified
983-
mpGraphicsView->getModelWidget()->setModelModified();
9841016
/* When something is changed in the icon layer then update the LibraryTreeItem in the Library Browser */
9851017
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
9861018
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
@@ -1218,7 +1250,8 @@ void Component::finishResizeComponent()
12181250
*/
12191251
void Component::resizedComponent()
12201252
{
1221-
UpdateComponentCommand *pUpdateComponentCommand = new UpdateComponentCommand(this, mOldTransformation, mTransformation, mpGraphicsView);
1253+
UpdateComponentTransformationsCommand *pUpdateComponentCommand = new UpdateComponentTransformationsCommand(this, mOldTransformation,
1254+
mTransformation);
12221255
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateComponentCommand);
12231256
mpGraphicsView->getModelWidget()->updateModelicaText();
12241257
}
@@ -1297,7 +1330,7 @@ void Component::flipHorizontal()
12971330
mTransformation.setExtent1(QPointF(extent1.x(), extent2.y()));
12981331
mTransformation.setExtent2(QPointF(extent2.x(), extent1.y()));
12991332
}
1300-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1333+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13011334
showResizerItems();
13021335
}
13031336

@@ -1320,7 +1353,7 @@ void Component::flipVertical()
13201353
mTransformation.setExtent1(QPointF(extent2.x(), extent1.y()));
13211354
mTransformation.setExtent2(QPointF(extent1.x(), extent2.y()));
13221355
}
1323-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1356+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13241357
showResizerItems();
13251358
}
13261359

@@ -1334,7 +1367,7 @@ void Component::moveUp()
13341367
{
13351368
Transformation oldTransformation = mTransformation;
13361369
mTransformation.adjustPosition(0, mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
1337-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1370+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13381371
}
13391372

13401373
/*!
@@ -1347,7 +1380,7 @@ void Component::moveShiftUp()
13471380
{
13481381
Transformation oldTransformation = mTransformation;
13491382
mTransformation.adjustPosition(0, mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5);
1350-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1383+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13511384
}
13521385

13531386
/*!
@@ -1360,7 +1393,7 @@ void Component::moveCtrlUp()
13601393
{
13611394
Transformation oldTransformation = mTransformation;
13621395
mTransformation.adjustPosition(0, 1);
1363-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1396+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13641397
}
13651398

13661399
/*!
@@ -1373,7 +1406,7 @@ void Component::moveDown()
13731406
{
13741407
Transformation oldTransformation = mTransformation;
13751408
mTransformation.adjustPosition(0, -mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
1376-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1409+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13771410
}
13781411

13791412
/*!
@@ -1386,7 +1419,7 @@ void Component::moveShiftDown()
13861419
{
13871420
Transformation oldTransformation = mTransformation;
13881421
mTransformation.adjustPosition(0, -(mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5));
1389-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1422+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
13901423
}
13911424

13921425
/*!
@@ -1399,7 +1432,7 @@ void Component::moveCtrlDown()
13991432
{
14001433
Transformation oldTransformation = mTransformation;
14011434
mTransformation.adjustPosition(0, -1);
1402-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1435+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14031436
}
14041437

14051438
/*!
@@ -1412,7 +1445,7 @@ void Component::moveLeft()
14121445
{
14131446
Transformation oldTransformation = mTransformation;
14141447
mTransformation.adjustPosition(-mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), 0);
1415-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1448+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14161449
}
14171450

14181451
/*!
@@ -1425,7 +1458,7 @@ void Component::moveShiftLeft()
14251458
{
14261459
Transformation oldTransformation = mTransformation;
14271460
mTransformation.adjustPosition(-(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5), 0);
1428-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1461+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14291462
}
14301463

14311464
/*!
@@ -1438,7 +1471,7 @@ void Component::moveCtrlLeft()
14381471
{
14391472
Transformation oldTransformation = mTransformation;
14401473
mTransformation.adjustPosition(-1, 0);
1441-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1474+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14421475
}
14431476

14441477
/*!
@@ -1451,7 +1484,7 @@ void Component::moveRight()
14511484
{
14521485
Transformation oldTransformation = mTransformation;
14531486
mTransformation.adjustPosition(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), 0);
1454-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1487+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14551488
}
14561489

14571490
/*!
@@ -1464,7 +1497,7 @@ void Component::moveShiftRight()
14641497
{
14651498
Transformation oldTransformation = mTransformation;
14661499
mTransformation.adjustPosition(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5, 0);
1467-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1500+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14681501
}
14691502

14701503
/*!
@@ -1477,7 +1510,7 @@ void Component::moveCtrlRight()
14771510
{
14781511
Transformation oldTransformation = mTransformation;
14791512
mTransformation.adjustPosition(1, 0);
1480-
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
1513+
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
14811514
}
14821515

14831516
//! Slot that opens up the component parameters dialog.

OMEdit/OMEditGUI/Component/Component.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,37 @@ class ComponentInfo : public QObject
6868
{
6969
Q_OBJECT
7070
public:
71-
ComponentInfo(QString value, QObject *pParent = 0);
71+
ComponentInfo(QObject *pParent = 0);
72+
ComponentInfo(ComponentInfo *pComponentInfo, QObject *pParent = 0);
73+
void updateComponentInfo(const ComponentInfo *pComponentInfo);
7274
void parseComponentInfoString(QString value);
7375
void setClassName(QString className) {mClassName = className;}
74-
QString getClassName() {return mClassName;}
76+
QString getClassName() const {return mClassName;}
7577
void setName(QString name) {mName = name;}
76-
QString getName() {return mName;}
78+
QString getName() const {return mName;}
7779
void setComment(QString comment) {mComment = comment;}
78-
QString getComment() {return StringHandler::removeFirstLastQuotes(mComment);}
80+
QString getComment() const {return StringHandler::removeFirstLastQuotes(mComment);}
7981
void setProtected(bool protect) {mIsProtected = protect;}
80-
bool getProtected() {return mIsProtected;}
82+
bool getProtected() const {return mIsProtected;}
8183
void setFinal(bool final) {mIsFinal = final;}
82-
bool getFinal() {return mIsFinal;}
83-
bool getFlow() {return mIsFlow;}
84-
bool getStream() {return mIsStream;}
84+
bool getFinal() const {return mIsFinal;}
85+
void setFlow(bool flow) {mIsFlow = flow;}
86+
bool getFlow() const {return mIsFlow;}
87+
void setStream(bool stream) {mIsStream = stream;}
88+
bool getStream() const {return mIsStream;}
8589
void setReplaceable(bool replaceable) {mIsReplaceable = replaceable;}
86-
bool getReplaceable() {return mIsReplaceable;}
90+
bool getReplaceable() const {return mIsReplaceable;}
8791
void setVariablity(QString variability) {mVariability = variability;}
88-
QString getVariablity() {return mVariability;}
92+
QString getVariablity() const {return mVariability;}
8993
void setInner(bool inner) {mIsInner = inner;}
90-
bool getInner() {return mIsInner;}
94+
bool getInner() const {return mIsInner;}
9195
void setOuter(bool outer) {mIsOuter = outer;}
92-
bool getOuter() {return mIsOuter;}
96+
bool getOuter() const {return mIsOuter;}
9397
void setCausality(QString causality) {mCasuality = causality;}
94-
QString getCausality() {return mCasuality;}
98+
QString getCausality() const {return mCasuality;}
9599
void setArrayIndex(QString arrayIndex);
96-
QString getArrayIndex() {return mArrayIndex;}
97-
bool isArray() {return mIsArray;}
100+
QString getArrayIndex() const {return mArrayIndex;}
101+
bool isArray() const {return mIsArray;}
98102
private:
99103
QString mClassName;
100104
QString mName;

0 commit comments

Comments
 (0)