Results 1 to 2 of 2

Thread: Re-engineering the Diagram Scene Example - Issues

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re-engineering the Diagram Scene Example - Issues

    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:

    ArrowGraphicsItem.cpp


    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:

    diagramsceneview.cpp

    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 itemScreenshot.jpg. 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

    Qt Code:
    1. void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
    2. QWidget *);
    To copy to clipboard, switch view to plain text mode 

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


    Qt Code:
    1. QPainterPath NewGraphicsItem::shape() const
    2. {
    3. //if the start and the end item collides we do not draw anything
    4. if (myStartItem->collidesWithItem(myEndItem))
    5. return QPainterPath();
    6.  
    7. QLineF centerLine(myStartItem->pos(),myEndItem->pos());
    8.  
    9.  
    10. QPolygonF startPolygon = myStartItem->polygon();
    11. QPolygonF endPolygon = myEndItem->polygon();
    12.  
    13. QPointF p1 = endPolygon.first() + myEndItem->pos();
    14. QPointF p2 = startPolygon.first() + myStartItem->pos();
    15.  
    16. QPointF p3;
    17. QPointF intersectPointFirst;
    18. QPointF intersectPointSecond;
    19. QLineF polyLine;
    20.  
    21.  
    22. for(int i = 1; i < startPolygon.count();++i)
    23. {
    24. p3 = startPolygon.at(i) + myStartItem->pos();
    25.  
    26. polyLine = QLineF(p2,p3);
    27.  
    28. QLineF::IntersectType intersectType = polyLine.intersect(centerLine,&intersectPointFirst);
    29.  
    30. if(intersectType == QLineF::BoundedIntersection)
    31. break;
    32. p2 = p3;
    33. }
    34.  
    35. for (int i = 1; i < endPolygon.count(); ++i)
    36. {
    37. p3 = endPolygon.at(i) + myEndItem->pos();
    38.  
    39. polyLine = QLineF(p1, p3);
    40.  
    41. QLineF::IntersectType intersectType =
    42. polyLine.intersect(centerLine, &intersectPointSecond);
    43. if (intersectType == QLineF::BoundedIntersection)
    44. break;
    45. p1 = p3;
    46. }
    47.  
    48.  
    49.  
    50. m_path->moveTo(intersectPointFirst);
    51.  
    52. m_path->lineTo(intersectPointSecond);
    53.  
    54. m_destinationHeadDirection = ArrowHeadDirectionEveryWhere;
    55.  
    56. return *m_path;
    57. }
    To copy to clipboard, switch view to plain text mode 

    Please Check the following attachment

    NewGraphicsItem.cpp
    NewGraphicsItem.h

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Re-engineering the Diagram Scene Example - Issues

    I can't see you calling prepareGeometryChange() anywhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. diagram scene example - intersection test
    By sajis997 in forum Newbie
    Replies: 12
    Last Post: 14th September 2011, 17:48
  2. elastic node re-engineering
    By sajis997 in forum Newbie
    Replies: 5
    Last Post: 6th August 2011, 00:05
  3. Reverse engineering tools
    By vvbkumar in forum General Programming
    Replies: 4
    Last Post: 29th September 2010, 17:48
  4. Extending the Diagram Scene Example
    By dosto.walla in forum Newbie
    Replies: 1
    Last Post: 7th October 2008, 18:02
  5. Reverse engineering of ui-file
    By wallyqt in forum Qt Tools
    Replies: 5
    Last Post: 18th November 2007, 22:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.