Hello forum,

There are three functions i confused to use, when to use, they are:

1. mapFromItem(....)

2. mapToItem(...)

3. mapFromParent(....)

4. mapFromScene(...)


Please take a look at the attached image. Screenshot-3.jpg


You can see that a small ellipse is positioned inside the large ellipse.


While defining the bounding rectangle for each of them, it of its center point is defined to be at (0,0) as follows:


Bounding rectangle for the large ellipse
Qt Code:
  1. QRectF RootGraphicsItem::boundingRect() const
  2. {
  3.  
  4. //!get the bounding rectangle of the enclosing text
  5. QRectF rect = m_textGraphicsItem->boundingRect();
  6.  
  7. // qDebug() << "************** the bounding rectangle of the text graphics item: *************" << endl;
  8. // qDebug() << "Top left: " << rect.topLeft() << endl;
  9. // qDebug() << "Center: " << rect.center() << endl;
  10. // qDebug() << "Bottom right: " << rect.bottomRight() << endl;
  11.  
  12. //the following condition decides if the boundary needs
  13. //to be changed
  14. if( rect.width() < m_drawRectMinimumWidth )
  15. rect.setWidth(m_drawRectMinimumWidth);
  16.  
  17. if(rect.height() < m_drawRectMinimumHeight)
  18. rect.setHeight(m_drawRectMinimumHeight);
  19.  
  20. //set the rectangle width with the text item spacing
  21. rect.setWidth(rect.width() + getTextItemSpacing() );
  22.  
  23. //the bounding rectangle will have its center at (0,0)
  24. rect.translate(-rect.center());
  25.  
  26.  
  27. // qDebug() << "After the adjustments" << endl;
  28. // qDebug() << "Center: " << rect.center() << endl;
  29. // qDebug() << "Top Left: " << rect.topLeft() << endl;
  30. // qDebug() << "Bottom Right: " << rect.bottomRight() << endl;
  31.  
  32.  
  33.  
  34. //and return the rectangle
  35. return rect;
  36. }
To copy to clipboard, switch view to plain text mode 


and Bounding rectangle for the small ellipse

Qt Code:
  1. QRectF H3DHierarchyArrowDockGraphicsItem::boundingRect() const
  2. {
  3. QRectF rect(0,0,sizeNormal.width(),sizeNormal.height());
  4.  
  5. //center will be (0,0)
  6. rect.translate(-rect.center());
  7.  
  8. return rect;
  9. }
To copy to clipboard, switch view to plain text mode 


Now when i layout the smaller one in the function of large one's function definition, which of the mapping function i should be using ?


Right now i am doing it as follows, seems like a hard-coding to me, What you guys think ?


Qt Code:
  1. void RootGraphicsItem::layoutChildItems()
  2. {
  3. ...................................
  4.  
  5. ...................................
  6. x = 0.0;
  7.  
  8. //the first bounding rectangle is large ellipse's bounding rectangle
  9. // and the second one is the small ellipses bounding rectangle
  10. y = (boundingRect().height()/2.0) - (m_dockOutGraphicsItem->boundingRect().height()/2.0);
  11.  
  12.  
  13. m_dockOutGraphicsItem->setPos(x,-y);
  14.  
  15. ...................................
  16.  
  17. ...................................
  18. }
To copy to clipboard, switch view to plain text mode 


The arrangement is functional, but might be more accurate if i do the mapping before setting the position. since i am rendering in big ellipses coordinate system now, do i have to call mapToItem(...). I called it as follows:

Qt Code:
  1. m_dockOutGraphicsItem->setPos(mapFromItem(m_dockOutGraphicsItem,x,-y));
To copy to clipboard, switch view to plain text mode 

Bu the effect is the same, so what is the use of this mapping and when to use it.

A more explanation will be very helpful, any reference ?


Regards
Sajjad