PDA

View Full Version : prepareGeometryChange problem



stefan
9th August 2008, 09:55
I created two objects (node and line - derived from QGraphicsItem). Each line has pointers to its starting and ending node, and each node has pointer to QGraphicsItem in LinkedItems vector.
Problem is when i move node i want to update line item, but i canot call prepareGeometryChange method because is protected. what's the reason of that? does anybody have an idea how to do this?

void itdNode::move(qint32 _x, qint32 _y)
{
for (qint32 iItem=0;iItem<LinkedItems.size();iItem++)
{
// LinkedItems[iItem]->prepareGeometryChange();
}
prepareGeometryChange();
x=_x;
y=_y;
update();
for (qint32 iItem=0;iItem<LinkedItems.size();iItem++)
{
LinkedItems[iItem]->update();
}
}
void itdNode::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
move(mouseEvent->scenePos().x(),mouseEvent->scenePos().y());
}

Benne Gesserit
9th August 2008, 15:14
Do you realy need to call prepareGeometryChange()? Why? If I am not wrong ,you only need to call that when the boundingRect changes ,does the boundingRect of a line change when you move a node?
Anyway,if you need to call that ,declare itdNode as a friend in line class ( friend class Line ; or whatever the name of the class is) .

stefan
10th August 2008, 09:30
LinkedItems is vector of pointers to QGraphicsItem, so i should in QGraphicsItem class declare friend node class. The best way is to create myItem class which inhertis QGraphicsItem, and has friends (Node, Line, etc.). Then node and line classes inherits myItem. I think that that would do the trick.

class itdItem : public QGraphicsItem
{
friend class itdLine;
friend class itdNode;
}
class itdLine : public itdItem
class itdNode: public itdItem
now i can create in each (new or existing) object a list of pointers to linked items. cool ;)

thank you for your friendly friend suggestion ;)