[Qgis-developer] mapCanvasItem not able to display

Martin Dobias wonder.sk at gmail.com
Wed Oct 11 07:13:22 EDT 2006


On 10/10/06, nitin quick <quick.nitin at gmail.com> wrote:
> greetings,
> I have some peculiar pbm.
> In a plugin, i am receiving some data through Qthread and storing in a
> struct. I am showing these as customised qgsmapcanvasitem over map on
> qgsmapcanvas but i couldn;'t do . This code is part of a plugin for
> qgis0.7.9  .here is what i have done:
>
> [...]
>
> here i am creating object adding to list, but everytime i am creating
> new. hat ican take acre of. But nohig is getting visible despite i
> have put code for update(). I am not calling drawShape(qpainter &P) of
> mymapcanvasitem since it is protected , if i make it public, item do
> appear but is it propr way. Also this way i am not able to move them.

Hi,

first of all, I don't like the way you use drawShape function... it
should be used just for painting the canvas item, not for creating
other map canvas items. Why not to send a signal from the worker
thread and create a slot which will add new canvas item and update
canvas?

One more thought: do you call setVisible() or show() function in
canvas item construction to make your canvas item visible? It's hidden
by default.


> I also have query about function QgsMapCanvasItem::setRect(). why it
> is required.Do this has got anything to do with visibility of this
> objet. I have set complete map extent as visible in updateExtent()
> because i couldn't got reason for this.

You have to specify canvas item position and size to let Q3Canas know
what portion of canvas you'll use for drawing. Normally you use move()
and setSize() functions from Q3CanvasItem. As map canvas items usually
work with map coordinates and not canvas coordinates, setRect() is a
convenience function to make setting this rectangle easier. There's
also function updatePosition() which is called from map canvas when
extent has changed or canvas is being panned. The default
implementation sets item's position and size regarding to rectangle
set by setRect(). This is how e.g. QgsRubberBand works.

If you don't like this approach, you can override this behaviour by
using your custom updatePosition() function. This is used in
QgsVertexMarker.

Probably a tutorial on creating own map canvas items and map tools
would be good ... probably an inspiration for Tim? ;-)

Martin



More information about the Qgis-developer mailing list