Hello ,
Create Two elliptical items in the scene and connect them with a line. Line drawing can be done in one of the two ways. Either you use the one that came along with the original diagram scene example or the one i have added - move the the mouse with the control modifier and the line will be drawn. When you release the control modifier
it will do the usual checking if there is any item under the event position and take the steps to draw the line arrow or not.
Once the items are connected, try to move the elliptical items and then you will see the problem - the arrow is not properly attached to the elliptical items and at times the arrow disappears.
I have removed the diagramscene.h - which was a subclass of QGraphicsScene, instead i have created a class called diagramsceneview - a subclass of QGraphicsView and moved all the functionalities to this class here. You have to remove the diagramscene class from your copy of the diagramscene example as well and add the one i have attached.
Then you have to make the following changes inside th diagramitem.h file
enum DiagramType
{
Step,
Conditional,
StartEnd,
Io ,
Ellipse // add the ellipse type
};
enum DiagramType
{
Step,
Conditional,
StartEnd,
Io ,
Ellipse // add the ellipse type
};
To copy to clipboard, switch view to plain text mode
In the constructor of diagramitem.cpp do the following:
case Ellipse:
{
//declare an ellipse with the bounding rectange
// QGraphicsEllipseItem item(-100,-50,200,100);
myPolygon = item.shape().toFillPolygon();
}
break;
case Ellipse:
{
//declare an ellipse with the bounding rectange
// QGraphicsEllipseItem item(-100,-50,200,100);
QGraphicsEllipseItem item(0,0,200,100);
myPolygon = item.shape().toFillPolygon();
}
break;
To copy to clipboard, switch view to plain text mode
And at last in the createToolBox() function of mainwindow.cpp add the following:
layout->addWidget(createCellWidget(tr("Ellipse"),DiagramItem::Ellipse),2,0);
layout->addWidget(createCellWidget(tr("Ellipse"),DiagramItem::Ellipse),2,0);
To copy to clipboard, switch view to plain text mode
So you are good to compile and run and see the problem, the problem is because of the following
// QGraphicsEllipseItem item(-100,-50,200,100);
// QGraphicsEllipseItem item(-100,-50,200,100);
QGraphicsEllipseItem item(0,0,200,100);
To copy to clipboard, switch view to plain text mode
As you can see that i have commented the first line to recreate the problem here which i am having in my own project where i am trying to implement this intersection test between line and polygonal shape. If you uncomment it and then comment the next one instead , everything works just fine. This is where i think is the problem. My question is how do i get rid of this in my projeject?
Let me know how it went along at your side.
Regards
Sajjad
Bookmarks