[Qgis-developer] QgsVertexMarker modified class: Plot moving points over a map at fixed rate

Luca Pascale pascale.luca.it at gmail.com
Thu Jul 2 06:29:10 EDT 2009


Hi all,

I have made a py plugin that plot points at a given position over an
underlying map.
At a given rate (1 time per second for example) the points change position
and move over the map.
I have used QgsVertexMarker to do this.

Now I am trying to plot instead of the "icon" make available by
QgsVertexMarker class, a custom image loaded from a file.
SO I modified the class in the following way:


   - add ICON_CUSTOM to the enum


enum IconType
    {
      ICON_NONE,
      ICON_CROSS,
      ICON_X,
      ICON_BOX,
      ICON_CUSTOM
    };


   - add the method

void QgsVertexMarker::setIconFileName (QString fname)
{
  mFileName=fname;

}


   - modify the QgsVertexMarker::paint

void QgsVertexMarker::paint( QPainter* p )
{
  qreal s = ( mIconSize - 1 ) / 2;

  QPen pen( mColor );
  pen.setWidth( mPenWidth );
  p->setPen( pen );

  switch ( mIconType )
  {
    case ICON_NONE:
      break;

    case ICON_CROSS:
      p->drawLine( QLineF( -s, 0, s, 0 ) );
      p->drawLine( QLineF( 0, -s, 0, s ) );
      break;

    case ICON_X:
      p->drawLine( QLineF( -s, -s, s, s ) );
      p->drawLine( QLineF( -s, s, s, -s ) );
      break;

    case ICON_BOX:
      p->drawLine( QLineF( -s, -s, s, -s ) );
      p->drawLine( QLineF( s, -s, s, s ) );
      p->drawLine( QLineF( s, s, -s, s ) );
      p->drawLine( QLineF( -s, s, -s, -s ) );
      break;
    case ICON_CUSTOM:

      QPixmap pixmap(QSize(22,22));
      pixmap.load(mFileName);
      p->drawPixmap(0,0,pixmap);
      break;
  }
}



   - update the binding file .sip

The problem now is that the icon (png file) is not plotted correctly until I
refresh the map canvas.
See the attached images.
notcorrectvisualization.png is what I obtain on the screen
and
correctvisualization.png is waht I obtain after pushed the refresh button.

Any suggestion to solve ??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090702/53826627/attachment.html


More information about the Qgis-developer mailing list