<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 13, 2014 at 9:15 PM, Sandro Santilli <span dir="ltr"><<a href="mailto:strk@keybit.net" target="_blank">strk@keybit.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sat, Dec 13, 2014 at 08:42:40PM +0700, Martin Dobias wrote:<br>><br>
> The extent of canvas items (in map units) stays the same, just the position<br>
> and bounding rect (both in screen coordinates) change accordingly when<br>
> zooming/panning.<br>
<br>
</span>What's exactly the "bounding rect" ? How's it different from rect" ?<br>
Documentation doesn't say:<br>
<a href="http://qgis.org/api/classQgsMapCanvasItem.html#a8be640ba5958ed63df3a17a9c9b9792a" target="_blank">http://qgis.org/api/classQgsMapCanvasItem.html#a8be640ba5958ed63df3a17a9c9b9792a</a><br>
<a href="http://qgis.org/api/classQgsMapCanvasItem.html#ad0cd631ace28e2feb63166d28b704364" target="_blank">http://qgis.org/api/classQgsMapCanvasItem.html#ad0cd631ace28e2feb63166d28b704364</a><br>
<br>
>From QT documentation I understand "bounding rect" is the outer bounds<br>
of the item: <a href="http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#boundingRect" target="_blank">http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#boundingRect</a><br>
<br>
>From QGIS code I see that the parameter passed to setRect() is in<br>
map units and is used to set a mItemSize member which is then used to<br>
compute the output from boundingRect(), thus effectively "setRect()"<br>
involves changing the "bounding rect" too. But "rect()" returns a<br>
different value than "boundingRect".<br></blockquote><div><br></div><div>The Qt framework uses pos() and boundingRect() to understand where the items are located in the scene (QGraphicsScene). These are all screen coordinates - one can tell from the use of QPointF instead of QgsPoint (always used for map / layer coordinates).</div><div><br></div><div>The rect() and setRect() is just our added convenience functionality in QgsMapCanvasItem. The idea was that you just use setRect() to specify the item's position+size in map coordinates - and the pos() and boundingRect() will be set according to that. In addition, calls to updatePosition() from map canvas make sure that pos() and boundingRect() are kept in sync with changes to the canvas.</div><div><br></div><div>Some canvas items use that functionality (e.g. QgsRubberBand or QgsMapCanvasMap) and don't worry about the screen coordinates. For some items this default behavior is not useful, so they do not use setRect() and provide their own implementation of updatePosition() and boundingRect(). For example QgsVertexMarker, which is centered on a map coordinate, but its bounding box is independent from map coordinates / scale.</div><div><br></div><div>The design a bit clumsy I know... It would make more sense to have base class QgsMapCanvasItem without any setRect() and without default setPos() calls and boundingRect() implementation. And then have a derived class e.g. QgsMapCanvasMapCoordsItem with those extra facilities - so when someone would be creating a new item, they could decide which base class is more appropriate.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> > Once rotation enters the picture a simple QgsRectangle is not enough<br>
> > anymore to express what area is shown in the canvas item. That is,<br>
> > the canvas item output rectangle is not a rectangle in map coordinate<br>
> > space. Could the "rect" concept be changed to something different then ?<br>
> > Like a triplet: center,resolution,rotation ?<br>
><br>
> I don't think such triplet would work here well - we need to know the exact<br>
> bounds of canvas items (in screen coordinates) so that the underlying Qt<br>
> framework knows when it needs to repaint the individual items.<br>
<br>
</span>Only the visible bounds or the full item bounds ?<br>
In other words, are these "bounds" independent of canvas size in pixels ?<br></blockquote><div><br></div><div>The bounds are in screen coordinates = pixels.</div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> Why should canvas items keep rotation? Lots of canvas items do not care<br>
> about the rotation - and should not care, e.g. a cross marker should always<br>
> have the same appearance regardless of any map rotation.<br>
><br>
> It is also worth noting that not all canvas items do need to have the<br>
> position + bounding box calculated automatically from map coordinates. For<br>
> example, annotations only have one point fixed to a map coordinate, the<br>
> rest of the bounding rect is defined in screen coordinates (independent<br>
> from map).<br>
<br>
</span>Good point. So then why do we have this function at all:<br>
<br>
  void QgsMapCanvasItem::setRect( const QgsRectangle& rect )<br>
<br>
Which seems to take the "rect" in map coordinates ?<br>
(according to the internal use of toCanvasCoordinates method)<br></blockquote><div><br></div><div>Hopefully this is now clear from the notes above. The items that do not depend on "rect" in map coordinates can just ignore the existance of setRect() and provide their own implementation of updatePosition() and boundingRect().</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">><br>
> The map rotation functionality in the end is probably more complex than it<br>
> seemed to be. QEP explaining all the implications would be quite useful.<br>
<br>
</span>Indeed, I greatly understimated it.<br>
I'll try to draft a QEP.<br></blockquote><div><br></div><div>Thanks.</div><div><br></div><div>Cheers</div><div>Martin</div><div><br></div></div></div></div>