Skip to content

Commit

Permalink
Fixes #3032. Adjust position based on the coordinate system of the co…
Browse files Browse the repository at this point in the history
…mponent.
  • Loading branch information
adeas31 committed Mar 14, 2016
1 parent 6247798 commit 2805502
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -363,7 +363,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
drawComponent();
}
// transformation
mTransformation = Transformation(mpGraphicsView->getViewType());
mTransformation = Transformation(mpGraphicsView->getViewType(), this);
mTransformation.parseTransformationString(transformation, boundingRect().width(), boundingRect().height());
if (transformation.isEmpty()) {
// snap to grid while creating component
Expand Down
14 changes: 13 additions & 1 deletion OMEdit/OMEditGUI/Component/Transformation.cpp
Expand Up @@ -36,16 +36,19 @@
*/

#include "Transformation.h"
#include "Component.h"

Transformation::Transformation()
{
mValid = false;
mpComponent = 0;
initialize(StringHandler::Diagram);
}

Transformation::Transformation(StringHandler::ViewType viewType)
Transformation::Transformation(StringHandler::ViewType viewType, Component *pComponent)
{
mValid = true;
mpComponent = pComponent;
initialize(viewType);
}

Expand Down Expand Up @@ -161,6 +164,7 @@ void Transformation::parseTransformationString(QString value, qreal width, qreal
void Transformation::updateTransformation(const Transformation &transformation)
{
mValid = transformation.isValid();
mpComponent = transformation.getComponent();
mViewType = transformation.getViewType();
mWidth = transformation.getWidth();
mHeight = transformation.getHeight();
Expand Down Expand Up @@ -341,6 +345,10 @@ QTransform Transformation::getTransformationMatrixDiagram()
mPositionDiagram.setX(mOriginDiagram.x() + ((mExtent1Diagram.x() + mExtent2Diagram.x()) / 2));
// calculate Y position
mPositionDiagram.setY(mOriginDiagram.y() + ((mExtent1Diagram.y() + mExtent2Diagram.y()) / 2));
/* Ticket #3032. Adjust position based on the coordinate system of the component. */
if (mpComponent) {
mPositionDiagram = mPositionDiagram - (mpComponent->boundingRect().center() * mpComponent->getCoOrdinateSystem().getInitialScale());
}
// get scale
qreal tempwidth = fabs(mExtent1Diagram.x() - mExtent2Diagram.x());
qreal sx = tempwidth / mWidth;
Expand Down Expand Up @@ -400,6 +408,10 @@ QTransform Transformation::getTransformationMatrixIcon()
mPositionIcon.setX(mOriginIcon.x() + ((mExtent1Icon.x() + mExtent2Icon.x()) / 2));
// calculate Y position
mPositionIcon.setY(mOriginIcon.y() + ((mExtent1Icon.y() + mExtent2Icon.y()) / 2));
/* Ticket #3032. Adjust position based on the coordinate system of the component. */
if (mpComponent) {
mPositionIcon = mPositionIcon - (mpComponent->boundingRect().center() * mpComponent->getCoOrdinateSystem().getInitialScale());
}
// get scale
qreal tempwidth = fabs(mExtent1Icon.x() - mExtent2Icon.x());
qreal sx = tempwidth / mWidth;
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Component/Transformation.h
Expand Up @@ -48,12 +48,13 @@ class Transformation
{
public:
Transformation();
Transformation(StringHandler::ViewType viewType);
Transformation(StringHandler::ViewType viewType, Component *pComponent = 0);
Transformation(const Transformation &transformation);
void initialize(StringHandler::ViewType viewType);
void parseTransformationString(QString value, qreal width, qreal height);
void updateTransformation(const Transformation &transformation);
QTransform getTransformationMatrix();
Component* getComponent() const {return mpComponent;}
bool isValid() const {return mValid;}
bool getVisible() const {return mVisible;}
void adjustPosition(qreal x, qreal y);
Expand All @@ -69,6 +70,7 @@ class Transformation
QPointF getPosition();
private:
bool mValid;
Component *mpComponent;
StringHandler::ViewType mViewType;
qreal mWidth;
qreal mHeight;
Expand Down

0 comments on commit 2805502

Please sign in to comment.