PDA

View Full Version : Re-engineering the Diagram Scene Example - Issues



sajis997
25th January 2012, 01:16
Hello forum,

I have made some changes to test inside the diagram scene example to make the concept work in the main application i am working on.

Lets take a look inside the original example and flag the things that i have changed and the rest that remained same

1. Arrow class - (CHANGED) A new Super class is created called ArrowGraphicsItem as follows:

7316


The subclass of the above class will decide based on the over-ridden shape() function if the specialized subclasses will render line arrow or some other customized cubic arrows.

To make the view crispy enough almost all the functionalities has been moved to a new class called DiagramSceneView and the declaration of the class is as follows:

7317

Now i have another new class that Specialize the ArrowGraphicsItem and it is actually will try to implement the Arrow class using the QPainterPath and this is where i m getting stuck . The class declaration of the specialized arrow graphics item is as follows:

I am getting some artifact when i re-implemented the specialized arrow class with the painter path instead of the graphics line item7318. If we take look at the original Arrow class in the Diagram Scene Example we can see that it has sub-classed the QLineGraphicsItem . The change that i am doing is that i have sub-classed the ArrowGraphicsItem and i have to make some changes inside the following function of the Arrow class



void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
QWidget *);


The above function is removed and move its implementation into the shape() instead as follows:




QPainterPath NewGraphicsItem::shape() const
{
//if the start and the end item collides we do not draw anything
if (myStartItem->collidesWithItem(myEndItem))
return QPainterPath();

QLineF centerLine(myStartItem->pos(),myEndItem->pos());


QPolygonF startPolygon = myStartItem->polygon();
QPolygonF endPolygon = myEndItem->polygon();

QPointF p1 = endPolygon.first() + myEndItem->pos();
QPointF p2 = startPolygon.first() + myStartItem->pos();

QPointF p3;
QPointF intersectPointFirst;
QPointF intersectPointSecond;
QLineF polyLine;


for(int i = 1; i < startPolygon.count();++i)
{
p3 = startPolygon.at(i) + myStartItem->pos();

polyLine = QLineF(p2,p3);

QLineF::IntersectType intersectType = polyLine.intersect(centerLine,&intersectPointFirst);

if(intersectType == QLineF::BoundedIntersection)
break;
p2 = p3;
}

for (int i = 1; i < endPolygon.count(); ++i)
{
p3 = endPolygon.at(i) + myEndItem->pos();

polyLine = QLineF(p1, p3);

QLineF::IntersectType intersectType =
polyLine.intersect(centerLine, &intersectPointSecond);
if (intersectType == QLineF::BoundedIntersection)
break;
p1 = p3;
}



m_path->moveTo(intersectPointFirst);

m_path->lineTo(intersectPointSecond);

m_destinationHeadDirection = ArrowHeadDirectionEveryWhere;

return *m_path;
}


Please Check the following attachment

7320
7319

I think i am doing something wrong in the shape() and updatePositoin() function of NewGraphicsItem.
Please go through and help me to get around this issue.



Regards
Sajjad

wysota
30th January 2012, 10:38
I can't see you calling prepareGeometryChange() anywhere.