Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2dfba3c4 authored by Jan Hambrecht's avatar Jan Hambrecht

when deleting shape, detach them from any attached shape connections

parent effc7641
......@@ -1955,6 +1955,12 @@ bool KoShape::hasDependee(KoShape *shape) const
return d->dependees.contains(shape);
}
QList<KoShape*> KoShape::dependees() const
{
Q_D(const KoShape);
return d->dependees;
}
void KoShape::shapeChanged(ChangeType type, KoShape *shape)
{
Q_UNUSED(type);
......
......@@ -301,7 +301,7 @@ public:
/**
* @brief Add a connector point to the shape
*
*
* A connector is a place on the shape that allows a graphical connection to be made
* using a line, for example.
*
......@@ -318,7 +318,7 @@ public:
* are fixed at their default position.
* The function will insert a new connection point if the specified id was not used
* before.
*
*
* @param connectionPointId the id of the connection point to set
* @param point the connection point data
* @return false if specified connection point id is invalid, else true
......@@ -883,6 +883,9 @@ public:
/// Returns if the given shape is dependent on this shape
bool hasDependee(KoShape *shape) const;
/// Returns list of shapes depending on this shape
QList<KoShape*> dependees() const;
/// Returns additional snap data the shape wants to have snapping to
virtual KoSnapData snapData() const;
......
......@@ -2,6 +2,7 @@
*
* Copyright (C) 2006-2007, 2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2006-2008 Thorsten Zachmann <zachmann@kde.org>
* Copyright (C) 2011 Jan Hambrecht <jaham@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -27,12 +28,14 @@
#include "KoSelection.h"
#include "commands/KoShapeCreateCommand.h"
#include "commands/KoShapeDeleteCommand.h"
#include "commands/KoShapeConnectionChangeCommand.h"
#include "KoCanvasBase.h"
#include "KoShapeConfigWidgetBase.h"
#include "KoShapeConfigFactoryBase.h"
#include "KoShapeFactoryBase.h"
#include "KoShape.h"
#include "KoToolManager.h"
#include "KoConnectionShape.h"
#include <QObject>
......@@ -120,6 +123,21 @@ public:
}
return new KoShapeCreateCommand(shapeBasedDocument, shape, parent);
}
void handleAttachedConnections(KoShape *shape, KUndo2Command *parentCmd) {
foreach (KoShape *dependee, shape->dependees()) {
KoConnectionShape *connection = dynamic_cast<KoConnectionShape*>(dependee);
if (connection) {
if (shape == connection->firstShape()) {
new KoShapeConnectionChangeCommand(connection, KoConnectionShape::StartHandle,
shape, connection->firstConnectionId(), 0, -1, parentCmd);
} else if (shape == connection->secondShape()) {
new KoShapeConnectionChangeCommand(connection, KoConnectionShape::EndHandle,
shape, connection->secondConnectionId(), 0, -1, parentCmd);
}
}
}
}
};
KoShapeController::KoShapeController(KoCanvasBase *canvas, KoShapeBasedDocumentBase *shapeBasedDocument)
......@@ -146,12 +164,19 @@ KUndo2Command* KoShapeController::addShapeDirect(KoShape *shape, KUndo2Command *
KUndo2Command* KoShapeController::removeShape(KoShape *shape, KUndo2Command *parent)
{
return new KoShapeDeleteCommand(d->shapeBasedDocument, shape, parent);
KUndo2Command *cmd = new KoShapeDeleteCommand(d->shapeBasedDocument, shape, parent);
// detach shape from any attached connection shapes
d->handleAttachedConnections(shape, cmd);
return cmd;
}
KUndo2Command* KoShapeController::removeShapes(const QList<KoShape*> &shapes, KUndo2Command *parent)
{
return new KoShapeDeleteCommand(d->shapeBasedDocument, shapes, parent);
KUndo2Command *cmd = new KoShapeDeleteCommand(d->shapeBasedDocument, shapes, parent);
foreach (KoShape *shape, shapes) {
d->handleAttachedConnections(shape, cmd);
}
return cmd;
}
void KoShapeController::setShapeControllerBase(KoShapeBasedDocumentBase *shapeBasedDocument)
......
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