Skip to content

Commit

Permalink
Update components when shapes are added/deleted.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 3, 2015
1 parent 36a2419 commit 0869ec5
Show file tree
Hide file tree
Showing 27 changed files with 538 additions and 263 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -84,7 +84,7 @@ BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsVi
mpComponent = 0;
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp
Expand Up @@ -82,7 +82,7 @@ EllipseAnnotation::EllipseAnnotation(ShapeAnnotation *pShapeAnnotation, Graphics
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
Expand Down
8 changes: 4 additions & 4 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -131,15 +131,15 @@ LineAnnotation::LineAnnotation(GraphicsView *pGraphicsView)
addPoint(QPointF(100, 100));
addPoint(QPointF(100, -100));
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
}

LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
Expand All @@ -161,7 +161,7 @@ LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphi
mLineColor = pShapeAnnotation->getLineColor();
}
// set the graphics view
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
// set the start component
setStartComponent(pStartComponent);
setEndComponent(0);
Expand Down Expand Up @@ -191,7 +191,7 @@ LineAnnotation::LineAnnotation(QString annotation, bool inheritedShape, Componen
mPoints = points;
mOrigin = QPointF(0, 0);
// set the graphics view
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
}

void LineAnnotation::parseShapeAnnotation(QString annotation)
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp
Expand Up @@ -82,7 +82,7 @@ PolygonAnnotation::PolygonAnnotation(ShapeAnnotation *pShapeAnnotation, Graphics
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -100,7 +100,7 @@ RectangleAnnotation::RectangleAnnotation(ShapeAnnotation *pShapeAnnotation, Grap
{
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
Expand Down
27 changes: 22 additions & 5 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -359,6 +359,7 @@ ShapeAnnotation::ShapeAnnotation(QGraphicsItem *pParent)
: QGraphicsItem(pParent)
{
mpGraphicsView = 0;
mpParentComponent = dynamic_cast<Component*>(pParent);
mpTransformation = 0;
mIsCustomShape = false;
mIsInheritedShape = false;
Expand Down Expand Up @@ -624,7 +625,7 @@ void ShapeAnnotation::applyFillPattern(QPainter *painter)
*/
QString ShapeAnnotation::getShapeAnnotation()
{
return QString();
return "";
}

/*!
Expand Down Expand Up @@ -1397,7 +1398,12 @@ void ShapeAnnotation::referenceShapeAdded()
{
ShapeAnnotation *pShapeAnnotation = qobject_cast<ShapeAnnotation*>(sender());
if (pShapeAnnotation) {
mpGraphicsView->scene()->addItem(this);
if (mpGraphicsView) {
mpGraphicsView->addItem(this);
} else if (mpParentComponent) {
mpParentComponent->shapeAdded();
setVisible(true);
}
}
}

Expand All @@ -1408,8 +1414,14 @@ void ShapeAnnotation::referenceShapeChanged()
{
ShapeAnnotation *pShapeAnnotation = qobject_cast<ShapeAnnotation*>(sender());
if (pShapeAnnotation) {
updateShape(pShapeAnnotation);
setTransform(pShapeAnnotation->getTransformation()->getTransformationMatrix());
if (mpGraphicsView) {
updateShape(pShapeAnnotation);
setTransform(pShapeAnnotation->getTransformation()->getTransformationMatrix());
} else if (mpParentComponent) {
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
}
}
}

Expand All @@ -1420,7 +1432,12 @@ void ShapeAnnotation::referenceShapeDeleted()
{
ShapeAnnotation *pShapeAnnotation = qobject_cast<ShapeAnnotation*>(sender());
if (pShapeAnnotation) {
mpGraphicsView->scene()->removeItem(this);
if (mpGraphicsView) {
mpGraphicsView->removeItem(this);
} else if (mpParentComponent) {
setVisible(false);
mpParentComponent->shapeDeleted();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -235,6 +235,7 @@ public slots:
void referenceShapeDeleted();
protected:
GraphicsView *mpGraphicsView;
Component *mpParentComponent;
Transformation *mpTransformation;
QList<QPointF> mPoints;
QList<LineGeometryType> mGeometries;
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp
Expand Up @@ -677,8 +677,10 @@ void ShapePropertiesDialog::removePoint()

void ShapePropertiesDialog::saveShapeProperties()
{
if (applyShapeProperties())
if (applyShapeProperties()) {
mpShapeAnnotation->emitChanged();
accept();
}
}

bool ShapePropertiesDialog::applyShapeProperties()
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -113,7 +113,7 @@ TextAnnotation::TextAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *
mpComponent = 0;
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
Expand Down Expand Up @@ -374,7 +374,7 @@ void TextAnnotation::initUpdateTextString()
if (mpComponent) {
if (mOriginalTextString.contains("%")) {
updateTextString();
connect(mpComponent->getRootParentComponent(), SIGNAL(componentDisplayTextChanged()), SLOT(updateTextString()), Qt::UniqueConnection);
connect(mpComponent->getRootParentComponent(), SIGNAL(displayTextChanged()), SLOT(updateTextString()), Qt::UniqueConnection);
}
}
}
Expand Down

0 comments on commit 0869ec5

Please sign in to comment.