I solved the problem finally with the code:
QVariant saItemSteelNode
::itemChange(GraphicsItemChange change,
const QVariant &value
) {
double s;
if(Settings::snapOn()==1)
{
s=Settings::snapSize();
newPos.setX(floor(newPos.x()/s)*s);
newPos.setY(floor(newPos.y()/s)*s);
};
//check collision with other nodes
p.addEllipse(newPos,diameter/2.0+1,diameter/2.0+1);
QList<QGraphicsItem*> sl=scene()->items(p);
sl=saScene::refineItems(sl,saItemSteelNode::TypeSteelNode);
sl.removeAll(this);
if(sl.count()>0)//collision
{
newPos=pos();
};
emit itemPositionChanged();
return newPos;
};
return value;
}
QVariant saItemSteelNode::itemChange(GraphicsItemChange change, const QVariant &value)
{
double s;
if (change == QGraphicsItem::ItemPositionChange) {
QPointF newPos = value.toPointF();
if(Settings::snapOn()==1)
{
s=Settings::snapSize();
newPos.setX(floor(newPos.x()/s)*s);
newPos.setY(floor(newPos.y()/s)*s);
};
//check collision with other nodes
QPainterPath p;
p.addEllipse(newPos,diameter/2.0+1,diameter/2.0+1);
QList<QGraphicsItem*> sl=scene()->items(p);
sl=saScene::refineItems(sl,saItemSteelNode::TypeSteelNode);
sl.removeAll(this);
if(sl.count()>0)//collision
{
newPos=pos();
};
emit itemPositionChanged();
return newPos;
};
return QGraphicsItem::itemChange(change,value);
return value;
}
To copy to clipboard, switch view to plain text mode
Bookmarks