[Qgis-developer] mapCanvasItem not able to display

Martin Dobias wonder.sk at gmail.com
Thu Oct 12 08:03:53 EDT 2006


On 10/11/06, nitin quick <quick.nitin at gmail.com> wrote:
> I had managed to show points by making drawShape() (if show() do not
> help much) a public function in custonItem class . And yes
> custom-qgsCanvasItem::drawShape() do not get called on update().

You have made drawShape() a public function and call it directly? This
is not good since it violates the principles of canvas items. If
drawShape() is not called on update(), there must be another problem.
If you're using custom canvas item for drawing a point on the map, why
not to use directly QgsVertexMarker or use that code and customize it?

Basically a custom map canvas item should work like this:

1. creation: constructed with pointer to map canvas
  MyItem::MyItem(QgsMapCanvas* canvas)
  : QgsMapCanvasItem(canvas) // call constructor of the base class
  { /* some construction */ }

2. set position, visibility and update:
 - option A: using default updatePosition()
    when you want to redraw item:
    1. if item's position or shape changed, call setRect(...)
    2. to change visibility (hidden by default!): show() or hide() or
setVisibility(bool)
    3. to update both item and canvas: updateCanvas()
 - option B: using custom updatePosition()
    override updatePosition() which calls move() and setSize() with
appropriate values
    when you want to redraw item: the same as with option A, just use
    updatePosition() to update position and size instead of setRect()

3. drawing - in drawShape() - this function is called when canvas gets
updated, the item is visible and is scheduled for update
   use toCanvasCoords convenience function to convert from map coordinates
   to canvas coordinates which are used by QPainter

> Also Whatever elements i am drawing, i have set rtti() value 1234 but
> in mouse press event collision list, it donot appear. Only rtti it
> shows id 5, 11111.

That could mean that your canvas item is not bound to map canvas if
you can't find the item in the list of all items.

> Is there any issue in implementation of custom-qgscanvasitem class? as
> i see it is pretty straight also i had tried this as dummy it is
> working well.

Please check whether your code follows the rules I've mentioned above.
If you still can't get it to work, try to post your plugin (or at
least implementation of your custom canvas item) so I can take a look.

Martin



More information about the Qgis-developer mailing list