Skip to content

Commit

Permalink
Allow undo/redo for component attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 24, 2015
1 parent d56f65a commit 2d5f225
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 160 deletions.
2 changes: 0 additions & 2 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -717,8 +717,6 @@ void LineAnnotation::updateConnectionAnnotation()
pOMCProxy->updateConnection(getStartComponentName(), getEndComponentName(),
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), annotationString);
}
// make the model modified
mpGraphicsView->getModelWidget()->setModelModified();
}

void LineAnnotation::duplicate()
Expand Down
79 changes: 56 additions & 23 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -46,10 +46,9 @@
*/
/*!
* \brief ComponentInfo::ComponentInfo
* \param value
* \param pParent
*/
ComponentInfo::ComponentInfo(QString value, QObject *pParent)
ComponentInfo::ComponentInfo(QObject *pParent)
: QObject(pParent)
{
mClassName = "";
Expand All @@ -63,17 +62,52 @@ ComponentInfo::ComponentInfo(QString value, QObject *pParent)
mVariabilityMap.insert("constant", "constant");
mVariabilityMap.insert("discrete", "discrete");
mVariabilityMap.insert("parameter", "parameter");
mVariabilityMap.insert("unspecified", "default");
mVariabilityMap.insert("unspecified", "");
mVariability = "";
mIsInner = false;
mIsOuter = false;
mCasualityMap.insert("input", "input");
mCasualityMap.insert("output", "output");
mCasualityMap.insert("unspecified", "none");
mCasualityMap.insert("unspecified", "");
mCasuality = "";
mArrayIndex = "";
mIsArray = false;
parseComponentInfoString(value);
}

/*!
* \brief ComponentInfo::ComponentInfo
* \param pComponentInfo
* \param pParent
*/
ComponentInfo::ComponentInfo(ComponentInfo *pComponentInfo, QObject *pParent)
: QObject(pParent)
{
updateComponentInfo(pComponentInfo);
}

void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
{
mClassName = pComponentInfo->getClassName();
mName = pComponentInfo->getName();
mComment = pComponentInfo->getComment();
mIsProtected = pComponentInfo->getProtected();
mIsFinal = pComponentInfo->getFinal();
mIsFlow = pComponentInfo->getFlow();
mIsStream = pComponentInfo->getStream();
mIsReplaceable = pComponentInfo->getReplaceable();
mVariabilityMap.insert("constant", "constant");
mVariabilityMap.insert("discrete", "discrete");
mVariabilityMap.insert("parameter", "parameter");
mVariabilityMap.insert("unspecified", "");
mVariability = pComponentInfo->getVariablity();
mIsInner = pComponentInfo->getInner();
mIsOuter = pComponentInfo->getOuter();
mCasualityMap.insert("input", "input");
mCasualityMap.insert("output", "output");
mCasualityMap.insert("unspecified", "");
mCasuality = pComponentInfo->getCausality();
mArrayIndex = pComponentInfo->getArrayIndex();
mIsArray = pComponentInfo->isArray();
}

/*!
Expand Down Expand Up @@ -733,7 +767,7 @@ void Component::applyRotation(qreal angle)
angle = 0;
}
mTransformation.setRotateAngle(angle);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
Expand Down Expand Up @@ -979,8 +1013,6 @@ void Component::updatePlacementAnnotation()
pOMCProxy->updateComponent(mpComponentInfo->getName(), mpComponentInfo->getClassName(),
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getPlacementAnnotation());
}
// set the model modified
mpGraphicsView->getModelWidget()->setModelModified();
/* When something is changed in the icon layer then update the LibraryTreeItem in the Library Browser */
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
Expand Down Expand Up @@ -1218,7 +1250,8 @@ void Component::finishResizeComponent()
*/
void Component::resizedComponent()
{
UpdateComponentCommand *pUpdateComponentCommand = new UpdateComponentCommand(this, mOldTransformation, mTransformation, mpGraphicsView);
UpdateComponentTransformationsCommand *pUpdateComponentCommand = new UpdateComponentTransformationsCommand(this, mOldTransformation,
mTransformation);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateComponentCommand);
mpGraphicsView->getModelWidget()->updateModelicaText();
}
Expand Down Expand Up @@ -1297,7 +1330,7 @@ void Component::flipHorizontal()
mTransformation.setExtent1(QPointF(extent1.x(), extent2.y()));
mTransformation.setExtent2(QPointF(extent2.x(), extent1.y()));
}
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
showResizerItems();
}

Expand All @@ -1320,7 +1353,7 @@ void Component::flipVertical()
mTransformation.setExtent1(QPointF(extent2.x(), extent1.y()));
mTransformation.setExtent2(QPointF(extent1.x(), extent2.y()));
}
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
showResizerItems();
}

Expand All @@ -1334,7 +1367,7 @@ void Component::moveUp()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1347,7 +1380,7 @@ void Component::moveShiftUp()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1360,7 +1393,7 @@ void Component::moveCtrlUp()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, 1);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1373,7 +1406,7 @@ void Component::moveDown()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1386,7 +1419,7 @@ void Component::moveShiftDown()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -(mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1399,7 +1432,7 @@ void Component::moveCtrlDown()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -1);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1412,7 +1445,7 @@ void Component::moveLeft()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1425,7 +1458,7 @@ void Component::moveShiftLeft()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1438,7 +1471,7 @@ void Component::moveCtrlLeft()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-1, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1451,7 +1484,7 @@ void Component::moveRight()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1464,7 +1497,7 @@ void Component::moveShiftRight()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

/*!
Expand All @@ -1477,7 +1510,7 @@ void Component::moveCtrlRight()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(1, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
}

//! Slot that opens up the component parameters dialog.
Expand Down
34 changes: 19 additions & 15 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -68,33 +68,37 @@ class ComponentInfo : public QObject
{
Q_OBJECT
public:
ComponentInfo(QString value, QObject *pParent = 0);
ComponentInfo(QObject *pParent = 0);
ComponentInfo(ComponentInfo *pComponentInfo, QObject *pParent = 0);
void updateComponentInfo(const ComponentInfo *pComponentInfo);
void parseComponentInfoString(QString value);
void setClassName(QString className) {mClassName = className;}
QString getClassName() {return mClassName;}
QString getClassName() const {return mClassName;}
void setName(QString name) {mName = name;}
QString getName() {return mName;}
QString getName() const {return mName;}
void setComment(QString comment) {mComment = comment;}
QString getComment() {return StringHandler::removeFirstLastQuotes(mComment);}
QString getComment() const {return StringHandler::removeFirstLastQuotes(mComment);}
void setProtected(bool protect) {mIsProtected = protect;}
bool getProtected() {return mIsProtected;}
bool getProtected() const {return mIsProtected;}
void setFinal(bool final) {mIsFinal = final;}
bool getFinal() {return mIsFinal;}
bool getFlow() {return mIsFlow;}
bool getStream() {return mIsStream;}
bool getFinal() const {return mIsFinal;}
void setFlow(bool flow) {mIsFlow = flow;}
bool getFlow() const {return mIsFlow;}
void setStream(bool stream) {mIsStream = stream;}
bool getStream() const {return mIsStream;}
void setReplaceable(bool replaceable) {mIsReplaceable = replaceable;}
bool getReplaceable() {return mIsReplaceable;}
bool getReplaceable() const {return mIsReplaceable;}
void setVariablity(QString variability) {mVariability = variability;}
QString getVariablity() {return mVariability;}
QString getVariablity() const {return mVariability;}
void setInner(bool inner) {mIsInner = inner;}
bool getInner() {return mIsInner;}
bool getInner() const {return mIsInner;}
void setOuter(bool outer) {mIsOuter = outer;}
bool getOuter() {return mIsOuter;}
bool getOuter() const {return mIsOuter;}
void setCausality(QString causality) {mCasuality = causality;}
QString getCausality() {return mCasuality;}
QString getCausality() const {return mCasuality;}
void setArrayIndex(QString arrayIndex);
QString getArrayIndex() {return mArrayIndex;}
bool isArray() {return mIsArray;}
QString getArrayIndex() const {return mArrayIndex;}
bool isArray() const {return mIsArray;}
private:
QString mClassName;
QString mName;
Expand Down

0 comments on commit 2d5f225

Please sign in to comment.