Skip to content

Commit

Permalink
Better handling of inherited classes for graphical objects.
Browse files Browse the repository at this point in the history
Added undo/redo for adding & deleting graphical objects.
  • Loading branch information
adeas31 committed Sep 16, 2015
1 parent a576051 commit 38c4ab8
Show file tree
Hide file tree
Showing 28 changed files with 1,697 additions and 728 deletions.
37 changes: 32 additions & 5 deletions OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -50,8 +50,16 @@ BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, Co
setRotation(mRotation);
}

BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, bool inheritedShape, GraphicsView *pGraphicsView)
: ShapeAnnotation(inheritedShape, pGraphicsView, 0)
BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pParent), mpComponent(pParent)
{
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
}

BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
mpComponent = 0;
mClassFileName = classFileName;
Expand All @@ -62,11 +70,22 @@ BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, bo
ShapeAnnotation::setUserDefaults();
parseShapeAnnotation(annotation);
setShapeFlags(true);
mpGraphicsView->addShapeObject(this);
mpGraphicsView->scene()->addItem(this);
connect(this, SIGNAL(updateClassAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
mpComponent = 0;
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateClassAnnotation()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

void BitmapAnnotation::parseShapeAnnotation(QString annotation)
{
GraphicItem::parseShapeAnnotation(annotation);
Expand Down Expand Up @@ -147,9 +166,17 @@ QString BitmapAnnotation::getShapeAnnotation()
return QString("Bitmap(").append(annotationString.join(",")).append(")");
}

void BitmapAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
{
// set the default values
GraphicItem::setDefaults(pShapeAnnotation);
FilledShape::setDefaults(pShapeAnnotation);
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

void BitmapAnnotation::duplicate()
{
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", false, mpGraphicsView);
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", mpGraphicsView);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pBitmapAnnotation->setOrigin(mOrigin + gridStep);
Expand Down
5 changes: 4 additions & 1 deletion OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h
Expand Up @@ -49,13 +49,16 @@ class BitmapAnnotation : public ShapeAnnotation
Q_OBJECT
public:
BitmapAnnotation(QString classFileName, QString annotation, Component *pParent);
BitmapAnnotation(QString classFileName, QString annotation, bool inheritedShape, GraphicsView *pGraphicsView);
BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView);
BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void drawBitmapAnnotaion(QPainter *painter);
QString getShapeAnnotation();
void updateShape(ShapeAnnotation *pShapeAnnotation);
private:
Component *mpComponent;
public slots:
Expand Down
36 changes: 31 additions & 5 deletions OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp
Expand Up @@ -50,8 +50,16 @@ EllipseAnnotation::EllipseAnnotation(QString annotation, Component *pParent)
setRotation(mRotation);
}

EllipseAnnotation::EllipseAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView)
: ShapeAnnotation(inheritedShape, pGraphicsView, 0)
EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
}

EllipseAnnotation::EllipseAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
// set the default values
GraphicItem::setDefaults();
Expand All @@ -61,11 +69,21 @@ EllipseAnnotation::EllipseAnnotation(QString annotation, bool inheritedShape, Gr
ShapeAnnotation::setUserDefaults();
parseShapeAnnotation(annotation);
setShapeFlags(true);
mpGraphicsView->addShapeObject(this);
mpGraphicsView->scene()->addItem(this);
connect(this, SIGNAL(updateClassAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateClassAnnotation()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

void EllipseAnnotation::parseShapeAnnotation(QString annotation)
{
GraphicItem::parseShapeAnnotation(annotation);
Expand Down Expand Up @@ -177,9 +195,17 @@ QString EllipseAnnotation::getShapeAnnotation()
return QString("Ellipse(").append(annotationString.join(",")).append(")");
}

void EllipseAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
{
// set the default values
GraphicItem::setDefaults(pShapeAnnotation);
FilledShape::setDefaults(pShapeAnnotation);
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

void EllipseAnnotation::duplicate()
{
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation("", false, mpGraphicsView);
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation("", mpGraphicsView);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pEllipseAnnotation->setOrigin(mOrigin + gridStep);
Expand Down
5 changes: 4 additions & 1 deletion OMEdit/OMEditGUI/Annotations/EllipseAnnotation.h
Expand Up @@ -49,13 +49,16 @@ class EllipseAnnotation : public ShapeAnnotation
Q_OBJECT
public:
EllipseAnnotation(QString annotation, Component *pParent);
EllipseAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView);
EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
EllipseAnnotation(QString annotation, GraphicsView *pGraphicsView);
EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void drawEllipseAnnotaion(QPainter *painter);
QString getShapeAnnotation();
void updateShape(ShapeAnnotation *pShapeAnnotation);
public slots:
void duplicate();
};
Expand Down
76 changes: 44 additions & 32 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -41,7 +41,7 @@
LineAnnotation::LineAnnotation(QString annotation, Component *pParent)
: ShapeAnnotation(pParent)
{
mLineType = LineAnnotation::ComponentType;
setLineType(LineAnnotation::ComponentType);
setStartComponent(0);
setEndComponent(0);
// set the default values
Expand All @@ -52,10 +52,21 @@ LineAnnotation::LineAnnotation(QString annotation, Component *pParent)
setRotation(mRotation);
}

LineAnnotation::LineAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView)
: ShapeAnnotation(inheritedShape, pGraphicsView, 0)
LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
setLineType(LineAnnotation::ComponentType);
setStartComponent(0);
setEndComponent(0);
setPos(mOrigin);
setRotation(mRotation);
}

LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
mLineType = LineAnnotation::ShapeType;
setLineType(LineAnnotation::ShapeType);
setStartComponent(0);
setEndComponent(0);
// set the default values
Expand All @@ -65,11 +76,21 @@ LineAnnotation::LineAnnotation(QString annotation, bool inheritedShape, Graphics
ShapeAnnotation::setUserDefaults();
parseShapeAnnotation(annotation);
setShapeFlags(true);
mpGraphicsView->addShapeObject(this);
mpGraphicsView->scene()->addItem(this);
connect(this, SIGNAL(updateClassAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateClassAnnotation()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
Expand Down Expand Up @@ -544,31 +565,6 @@ void LineAnnotation::moveAllPoints(qreal offsetX, qreal offsetY)
}
}

LineAnnotation::LineType LineAnnotation::getLineType()
{
return mLineType;
}

void LineAnnotation::setStartComponentName(QString name)
{
mStartComponentName = name;
}

QString LineAnnotation::getStartComponentName()
{
return mStartComponentName;
}

void LineAnnotation::setEndComponentName(QString name)
{
mEndComponentName = name;
}

QString LineAnnotation::getEndComponentName()
{
return mEndComponentName;
}

/*!
Sets the shape flags.
*/
Expand All @@ -588,6 +584,22 @@ void LineAnnotation::setShapeFlags(bool enable)
}
}

void LineAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
{
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(pShapeAnnotation);
setLineType(pLineAnnotation->getLineType());
setStartComponent(pLineAnnotation->getStartComponent());
setEndComponent(pLineAnnotation->getEndComponent());
// set the default values
GraphicItem::setDefaults(pShapeAnnotation);
mPoints.clear();
QList<QPointF> points = pShapeAnnotation->getPoints();
for (int i = 0 ; i < points.size() ; i++) {
addPoint(points[i]);
}
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

void LineAnnotation::handleComponentMoved()
{
if (mPoints.size() < 2) {
Expand Down Expand Up @@ -665,7 +677,7 @@ void LineAnnotation::updateConnectionAnnotation()

void LineAnnotation::duplicate()
{
LineAnnotation *pLineAnnotation = new LineAnnotation("", false, mpGraphicsView);
LineAnnotation *pLineAnnotation = new LineAnnotation("", mpGraphicsView);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pLineAnnotation->setOrigin(mOrigin + gridStep);
Expand Down
16 changes: 10 additions & 6 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -54,7 +54,9 @@ class LineAnnotation : public ShapeAnnotation
ShapeType /* Line is a custom shape. */
};
LineAnnotation(QString annotation, Component *pParent);
LineAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView);
LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
LineAnnotation(QString annotation, GraphicsView *pGraphicsView);
LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
LineAnnotation(Component *pStartComponent, GraphicsView *pGraphicsView);
LineAnnotation(QString annotation, bool inheritedShape, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
Expand All @@ -76,12 +78,14 @@ class LineAnnotation : public ShapeAnnotation
void updateStartPoint(QPointF point);
void updateEndPoint(QPointF point);
void moveAllPoints(qreal offsetX, qreal offsetY);
LineType getLineType();
void setStartComponentName(QString name);
QString getStartComponentName();
void setEndComponentName(QString name);
QString getEndComponentName();
void setLineType(LineType lineType) {mLineType = lineType;}
LineType getLineType() {return mLineType;}
void setStartComponentName(QString name) {mStartComponentName = name;}
QString getStartComponentName() {return mStartComponentName;}
void setEndComponentName(QString name) {mEndComponentName = name;}
QString getEndComponentName() {return mEndComponentName;}
void setShapeFlags(bool enable);
void updateShape(ShapeAnnotation *pShapeAnnotation);
private:
LineType mLineType;
Component *mpStartComponent;
Expand Down
38 changes: 33 additions & 5 deletions OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp
Expand Up @@ -50,8 +50,16 @@ PolygonAnnotation::PolygonAnnotation(QString annotation, Component *pParent)
setRotation(mRotation);
}

PolygonAnnotation::PolygonAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView)
: ShapeAnnotation(inheritedShape, pGraphicsView, 0)
PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pParent)
{
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
}

PolygonAnnotation::PolygonAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
// set the default values
GraphicItem::setDefaults();
Expand All @@ -61,11 +69,21 @@ PolygonAnnotation::PolygonAnnotation(QString annotation, bool inheritedShape, Gr
ShapeAnnotation::setUserDefaults();
parseShapeAnnotation(annotation);
setShapeFlags(true);
mpGraphicsView->addShapeObject(this);
mpGraphicsView->scene()->addItem(this);
connect(this, SIGNAL(updateClassAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateClassAnnotation()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

void PolygonAnnotation::parseShapeAnnotation(QString annotation)
{
GraphicItem::parseShapeAnnotation(annotation);
Expand Down Expand Up @@ -232,9 +250,19 @@ void PolygonAnnotation::updateEndPoint(QPointF point)
mPoints.replace(mPoints.size() - 2, point);
}

void PolygonAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
{
// set the default values
GraphicItem::setDefaults(pShapeAnnotation);
FilledShape::setDefaults(pShapeAnnotation);
mPoints.clear();
setPoints(pShapeAnnotation->getPoints());
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

void PolygonAnnotation::duplicate()
{
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation("", false, mpGraphicsView);
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation("", mpGraphicsView);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
pPolygonAnnotation->setOrigin(mOrigin + gridStep);
Expand Down
5 changes: 4 additions & 1 deletion OMEdit/OMEditGUI/Annotations/PolygonAnnotation.h
Expand Up @@ -49,7 +49,9 @@ class PolygonAnnotation : public ShapeAnnotation
Q_OBJECT
public:
PolygonAnnotation(QString annotation, Component *pParent);
PolygonAnnotation(QString annotation, bool inheritedShape, GraphicsView *pGraphicsView);
PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
PolygonAnnotation(QString annotation, GraphicsView *pGraphicsView);
PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QPainterPath getShape() const;
QRectF boundingRect() const;
Expand All @@ -61,6 +63,7 @@ class PolygonAnnotation : public ShapeAnnotation
void removePoint(int index);
void clearPoints();
void updateEndPoint(QPointF point);
void updateShape(ShapeAnnotation *pShapeAnnotation);
public slots:
void duplicate();
};
Expand Down

0 comments on commit 38c4ab8

Please sign in to comment.