Commit 23cdbd76 authored by Jan Hambrecht's avatar Jan Hambrecht

merge insertConnectionPoint and setConnectionPointPosition into new function setConnectionPoint

parent 010cd870
......@@ -752,12 +752,14 @@ int KoShape::addConnectionPoint(const KoConnectionPoint &point)
return nextConnectionPointId;
}
bool KoShape::insertConnectionPoint(const KoConnectionPoint &point, int connectionPointId)
bool KoShape::setConnectionPoint(int connectionPointId, const KoConnectionPoint &point)
{
Q_D(KoShape);
if (connectionPointId < 0 || d->connectors.contains(connectionPointId))
if (connectionPointId < 0)
return false;
const bool insertPoint = !hasConnectionPoint(connectionPointId);
switch(connectionPointId) {
case KoConnectionPoint::TopConnectionPoint:
case KoConnectionPoint::RightConnectionPoint:
......@@ -766,6 +768,8 @@ bool KoShape::insertConnectionPoint(const KoConnectionPoint &point, int connecti
{
KoConnectionPoint::PointId id = static_cast<KoConnectionPoint::PointId>(connectionPointId);
KoConnectionPoint p = KoConnectionPoint::defaultConnectionPoint(id);
p.escapeDirection = point.escapeDirection;
p.align = point.align;
d->setConnectionPoint(connectionPointId, p);
break;
}
......@@ -779,6 +783,8 @@ bool KoShape::insertConnectionPoint(const KoConnectionPoint &point, int connecti
}
}
if(!insertPoint)
d->shapeChanged(ConnectionPointChanged);
return true;
}
......@@ -798,25 +804,6 @@ KoConnectionPoint KoShape::connectionPoint(int connectionPointId) const
return p;
}
bool KoShape::setConnectionPointPosition(int connectionPointId, const QPointF &newPosition)
{
// do not allow to change position of default connection points
if (connectionPointId < KoConnectionPoint::FirstCustomConnectionPoint)
return false;
Q_D(KoShape);
if (!d->connectors.contains(connectionPointId))
return false;
KoConnectionPoint p = connectionPoint(connectionPointId);
// convert glue point from shape coordinates to factors of size
p.position = KoFlake::toRelative(newPosition, size());
d->setConnectionPoint(connectionPointId, p);
d->shapeChanged(ConnectionPointChanged);
return true;
}
KoConnectionPoints KoShape::connectionPoints() const
{
Q_D(const KoShape);
......
......@@ -324,16 +324,19 @@ public:
int addConnectionPoint(const KoConnectionPoint &point);
/**
* Tries to insert connection point with specified id.
* Sets data of connection point with specified id.
*
* The position of the connector is restricted to the bounding rectangle of the shape.
* When setting a default connection point, the new position is ignored, as these
* are fixed at their default position.
* The function will insert a new connection point if the specified id was not used
* before.
*
* @param point the position of the connector in shape coordinates
* @param connectionPointId the id of the connection point to insert
* @return true if inserting connection point was successful;
* false if connection point did already exists or id is invalid
* @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
*/
bool insertConnectionPoint(const KoConnectionPoint &point, int connectionPointId);
bool setConnectionPoint(int connectionPointId, const KoConnectionPoint &point);
/// Checks if a connection point with the specified id exists
bool hasConnectionPoint(int connectionPointId) const;
......@@ -341,17 +344,6 @@ public:
/// Returns connection point with specified connection point id
KoConnectionPoint connectionPoint(int connectionPointId) const;
/**
* Sets new position for specified custom connection point
*
* The position of the connector is restricted to the bounding rectangle of the shape.
*
* @param connectionPointId the id of the custom connection point to change
* @param newPosition the new position of the custom connection point in shape coordinates
* @return true if position could be changed, else false
*/
bool setConnectionPointPosition(int connectionPointId, const QPointF &newPosition);
/**
* Return a list of the connection points that have been added to this shape.
* All the points are relative to the shape position, see absolutePosition().
......
......@@ -36,7 +36,7 @@ void AddConnectionPointCommand::redo()
if(m_connectionPointId < 0) {
m_connectionPointId = m_shape->addConnectionPoint(m_connectionPoint);
} else {
m_shape->insertConnectionPoint(m_connectionPoint, m_connectionPointId);
m_shape->setConnectionPoint(m_connectionPointId, m_connectionPoint);
}
updateRoi();
......
......@@ -35,7 +35,9 @@ MoveConnectionPointCommand::~MoveConnectionPointCommand()
void MoveConnectionPointCommand::redo()
{
updateRoi(m_oldPosition);
m_shape->setConnectionPointPosition(m_connectionPointId, m_newPosition);
KoConnectionPoint cp = m_shape->connectionPoint(m_connectionPointId);
cp.position = m_newPosition;
m_shape->setConnectionPoint(m_connectionPointId, cp);
updateRoi(m_newPosition);
QUndoCommand::redo();
......@@ -46,7 +48,9 @@ void MoveConnectionPointCommand::undo()
QUndoCommand::undo();
updateRoi(m_oldPosition);
m_shape->setConnectionPointPosition(m_connectionPointId, m_oldPosition);
KoConnectionPoint cp = m_shape->connectionPoint(m_connectionPointId);
cp.position = m_oldPosition;
m_shape->setConnectionPoint(m_connectionPointId, cp);
updateRoi(m_newPosition);
}
......
......@@ -45,13 +45,17 @@ void MoveConnectionPointStrategy::paint(QPainter& painter, const KoViewConverter
void MoveConnectionPointStrategy::handleMouseMove(const QPointF& mouseLocation, Qt::KeyboardModifiers /*modifiers*/)
{
m_newPosition = m_shape->documentToShape(mouseLocation);
m_shape->setConnectionPointPosition(m_connectionPointId, m_newPosition);
KoConnectionPoint cp = m_shape->connectionPoint(m_connectionPointId);
cp.position = m_newPosition;
m_shape->setConnectionPoint(m_connectionPointId, cp);
}
void MoveConnectionPointStrategy::cancelInteraction()
{
KoInteractionStrategy::cancelInteraction();
m_shape->setConnectionPointPosition(m_connectionPointId, m_oldPosition);
KoConnectionPoint cp = m_shape->connectionPoint(m_connectionPointId);
cp.position = m_oldPosition;
m_shape->setConnectionPoint(m_connectionPointId, cp);
}
void MoveConnectionPointStrategy::finishInteraction(Qt::KeyboardModifiers /*modifiers*/)
......
......@@ -46,7 +46,7 @@ void RemoveConnectionPointCommand::undo()
{
QUndoCommand::undo();
m_shape->insertConnectionPoint(m_connectionPoint, m_connectionPointId);
m_shape->setConnectionPoint(m_connectionPointId, m_connectionPoint);
updateRoi();
}
......
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