[Qgis-developer] Re: flickering on display through plugin

Martin Dobias wonder.sk at gmail.com
Thu Jun 29 04:57:31 EDT 2006


Hi again,

sorry for the delayed answer.

I don't understand well what exactly is the problem with setting the
rectangle of the canvas item?

There are two possibilities for setting the rectangle:
- default handling - if your canvas item is a shape like polyline or
polygon (or a collection of them), you can just set mRect which will
cover the whole area they occupate. This rect is in map coordinates.
Default updatePosition() will calculate the rectangle in canvas
coordinates everytime it's needed and you don't have to care about
using move() and setSize() functions.

- custom handling - you can override updatePosition() with your own
function that will calculate position and size of the canvas item (in
canvas coordinates) manually and call move() and setSize() functions.
This is suitable for objects which don't change their position and
size with different scale (e.g. vertex markers).

It's important to have clear the difference between map (geographic)
coordinates and canvas coordinates and when are they used. Generally
map coordinates are always stored in classes like QgsPoint and
QgsRect, while canvas coordinates are stored in QPoint and QRect.

One more note on how does Qt canvas work: position and size of the
canvas item is AFAIK used only for determining whether to draw the
item. If so, drawShape is called which can draw to whole canvas and
not only the rectangle of the item. Thus coordinate [0,0] is top left
corner of the canvas, not the item.


Martin

On 6/26/06, nitin quick <quick.nitin at gmail.com> wrote:
>
> hello everybody,
> as per advice by Martin, i have implemented plugin by inheriting
> QgsMapCanvasItem.Some of the code i am listing below.A small problem is
> occuring. It is that box into which canvas item is visible, i am not able to
> set. I need some guidance here. I have tried to understand from code of
> QgsGeoRefDataPoint and QgsRubberBand but i couldn't get the same output.
> Depending on map display is varying. It has become flicker free but
> continuous movemnet is not there as ponts are given as input for location.
>
> void Cock::drawShape(QPainter & p)
> {
>     show();
>     if(p.isActive())
>         cout<<"\nPainter is not active -cock.cpp=271 ";
>     else
>         cout<<"\n Painter is aCtive";
>      p.setPen(Qt::SolidLine);
>      p.setBrush(Qt::SolidPattern);
>
>     //QLine *line;
>     int x,y;
> /* mth is thread class object which read from fifo and stores all points in
> a list listPoint.
>     QListIterator<int> itr(this-> mth.listPoint);
>     itr.toBack();
>     x=itr.previous();
>     y=itr.previous();
>     p.drawEllipse(y,x,5,5);
>     //line= new QLine(y,x,y+1,x+1);
>
>
> }
> /* code i tried similar to QgsGeoRefDataPoint an QVertexMarker*/
> void Cock::updatePosition()
> {
>      int x,y;
>     QListIterator<int> itr(this->mth.listPoint);
>     itr.toBack();
>     x=itr.previous();
>     y=itr.previous();
>     move(x,y);
>     setSize(5,5);
>     show();
>
> }
> /* this slot is called when thread reading data sends signal indicating
> availability of data*/
> void Cock::updatePixmap()
> {
>
>     setVisible(1);
>     updateCanvas();
> }
>
> thankyou Martin for your very useful help.
> regards
> quick nitin
>
> On 6/26/06, Martin Dobias <wonder.sk at gmail.com > wrote:
> > Hi,
> >
> > do you call setVisible() (or show()) in your map canvas item? Because
> > canvas items are not shown by default.
> >
> > Also you need to tell canvas the position and size of the item - this
> > can be done by setting mRect or by overriding updatePosition (where
> > you calculate the rectangle by yourself and call move() and setSize()
> > ). Such rectangle is used by canvas to decide whether the item is
> > visible and should be drawn.
> >
> > For more examples, here are all classes currently in QGIS code which
> > inherit from QgsMapCanvasItem.
> >
> > QgsRubberBand - for drawing any kind of polyline or polygon
> > QgsVertexMarker - displays a simple icon on desired position
> > QgsGeorefDataPoint - marks a point and shows its coordinates (in
> > georeferencer plugin)
> > QgsGrassEditLayer - displays a pixmap (in grass plugin)
> >
> > If you will still experience problems then post you code here, maybe
> > we could help you.
> >
> >
> > Martin
> >



More information about the Qgis-developer mailing list