Commit c1b35335 authored by Jan Hambrecht's avatar Jan Hambrecht

add support for notifying dependent shape of changes


svn path=/trunk/koffice/; revision=746713
parent 0d39cdc9
......@@ -67,13 +67,15 @@ KoConnectionShape::KoConnectionShape()
KoConnectionShape::~KoConnectionShape()
{
if( d->shape1 )
d->shape1->removeDependee( this );
if( d->shape2 )
d->shape2->removeDependee( this );
delete d;
}
void KoConnectionShape::paint( QPainter&, const KoViewConverter& ) {
// TODO find a better place to update the connections (maybe inside the shape manager?)
if( isParametricShape() )
updateConnections();
}
void KoConnectionShape::saveOdf( KoShapeSavingContext & context ) const
......@@ -98,6 +100,8 @@ bool KoConnectionShape::loadOdf( const KoXmlElement & element, KoShapeLoadingCon
{
QString shapeId1 = element.attributeNS( KoXmlNS::draw, "start-shape", "" );
d->shape1 = context.shapeById( shapeId1 );
if( d->shape1 )
d->shape1->addDependee( this );
d->connectionPointIndex1 = element.attributeNS( KoXmlNS::draw, "start-glue-point", "" ).toInt();
}
else
......@@ -110,6 +114,8 @@ bool KoConnectionShape::loadOdf( const KoXmlElement & element, KoShapeLoadingCon
{
QString shapeId2 = element.attributeNS( KoXmlNS::draw, "end-shape", "" );
d->shape2 = context.shapeById( shapeId2 );
if( d->shape2 )
d->shape2->addDependee( this );
d->connectionPointIndex2 = element.attributeNS( KoXmlNS::draw, "end-glue-point", "" ).toInt();
}
else
......@@ -241,13 +247,21 @@ void KoConnectionShape::updatePath( const QSizeF &size )
void KoConnectionShape::setConnection1( KoShape * shape1, int connectionPointIndex1 )
{
if( d->shape1 )
d->shape1->removeDependee( this );
d->shape1 = shape1;
if( d->shape1 )
d->shape1->addDependee( this );
d->connectionPointIndex1 = connectionPointIndex1;
}
void KoConnectionShape::setConnection2( KoShape * shape2, int connectionPointIndex2 )
{
if( d->shape2 )
d->shape2->removeDependee( this );
d->shape2 = shape2;
if( d->shape2 )
d->shape2->addDependee( this );
d->connectionPointIndex2 = connectionPointIndex2;
}
......@@ -432,3 +446,9 @@ void KoConnectionShape::shapeChanged(ChangeType type)
return;
}
}
void KoConnectionShape::notifyShapeChanged( KoShape *, ChangeType )
{
if( isParametricShape() )
updateConnections();
}
......@@ -102,6 +102,9 @@ protected:
private:
// reimplemented
virtual void notifyShapeChanged( KoShape * shape, ChangeType type );
double scalarProd( const QPointF &v1, const QPointF &v2 );
double crossProd( const QPointF &v1, const QPointF &v2 );
......
......@@ -91,6 +91,8 @@ public:
if(parent)
parent->model()->childChanged(me, type);
me->shapeChanged(type);
foreach( KoShape * shape, dependees )
shape->notifyShapeChanged( me, type );
}
QSizeF size; // size in pt
......@@ -117,6 +119,7 @@ public:
KoShapeBorderModel *border; ///< points to a border, or 0 if there is no border
QList<KoShapeConnection*> connections;
KoShape *me;
QList<KoShape*> dependees; ///< list of shape dependent on this shape
};
KoShape::KoShape()
......@@ -956,3 +959,21 @@ void KoShape::applyConversion(QPainter &painter, const KoViewConverter &converte
painter.scale(zoomX, zoomY);
}
void KoShape::addDependee( KoShape * shape )
{
if( ! d->dependees.contains( shape ) )
d->dependees.append( shape );
}
void KoShape::removeDependee( KoShape * shape )
{
int index = d->dependees.indexOf( shape );
if( index >= 0 )
d->dependees.removeAt( index );
}
void KoShape::notifyShapeChanged( KoShape * shape, ChangeType type )
{
Q_UNUSED( shape );
Q_UNUSED( type );
}
......@@ -617,6 +617,15 @@ public:
/// checks recursively if the shape or one of its parents is not visible or locked
bool isEditable() const;
/// Removes connection point with given index
void removeConnectionPoint( int index );
/// Adds a shape which depends on this shape
void addDependee( KoShape * shape );
/// Removes as shape depending on this shape
void removeDependee( KoShape * shape );
protected:
/* ** loading saving helper methods */
......@@ -704,6 +713,9 @@ protected:
*/
virtual void shapeChanged(ChangeType type) { Q_UNUSED(type); }
/// This is called whenever a shape this shape depends on has changed
virtual void notifyShapeChanged( KoShape * shape, ChangeType type );
/**
* Set the property collision detection.
* Setting this to true will result in calls to shapeChanged() with the CollisionDetected
......@@ -732,9 +744,6 @@ protected:
*/
void removeConnection(KoShapeConnection *connection);
/// Removes connection point with given index
void removeConnectionPoint( int index );
private:
friend class KoShapeManager;
void addShapeManager( KoShapeManager * manager );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment