How to manage multi QGraphicsItem
Hello,
I've a class Scene extending QGraphicsSceneand to catch click mouse i'm using the function mousePressEvent ( QGraphicsSceneMouseEvent* event ). This function is coded like:
Code:
// set local variables and check if existing station clicked
qreal x = event->scenePos().x();
qreal y = event->scenePos().y();
GraphItem _item = dynamic_cast<GraphItem*> ( itemAt ( x, y ) );
if ( GraphItem == 0 && event->button() == Qt::LeftButton ) {
m_undoStack->push ( new CommandGraphItemAdd ( this, x, y ) );
emit message
( QString ( "GraphItem add at %1,%2" ).
arg ( x
).
arg ( y
) );
}
this->update();
}
My problem is how to create various QGraphicItem into the mousePressEvent function ? For example i click a button into menu option and a point is selecting, or a circle or other.
My solution is using a switch that reads a value (for example an int value, it set when a button is clicked), but for me isn't optimal solution. What do you think?Exist any different solution?
tnx so much
Re: How to manage multi QGraphicsItem
May be you could use factory pattern for creating the graphics items so that you could keep the changes minimal later.
Re: How to manage multi QGraphicsItem
JackHammer, I don't know this pattern and this is a way to learn a new thing about programming...so I’m looking for it.
Tnx so much for your answer. I'll inform you for news. Bye ;)