tags:

views:

377

answers:

2

Hi,

I am customising QuantumGIS that uses Qt's Qpainter to draw and paint...

I am trying to draw a polyline on the canvas that is coming as a update through message queues..the draw is very fine...but in the polyline or polygon objects that i get as an update also include an angle field that is to be used for rotation of an object. The problem is that when i try to rotate the line just before the polyline is drawn by the qpainter using painter.rotate() method,the line is rotated fine but the position of the line drawn changes..and it changes at every zoom and pan of the Qgis canvas.. Before setting painter.rotate() i am saving the painter state and after drawing- again restoring its state which i believe is analogous to OpenGL's push/popMatrix functions. Does the Qpainter's save restore functions work similar to push/popMatrix functions of opengl??

here is a code snippet:

p->save();
  //p->rotate(45);
  p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
  p->drawPolyline( pa );
  p->restore();

Help is appreciated. Thanks.

A: 

your best bet would be to ask this question in the QGIS Mailing List

dassouki
+1  A: 

Read the documentation and you see that QPainter::save() only "Saves the current painter state". It does not reset the transformation. Your problem was because the original transformation matrix gets mixed with your own scale or rotate. Your code snippet is too minimal to understand the context of the painting, but I reckon you need to reset or modify the transformation suitably before your polyline painting, perhaps using QPainter::setTransform().

I recommend also reading Coordinate Transformations section in QPainter documentation, as well as trying the related example.

Ariya Hidayat