Hello everybody,<br>As against my previous approach, i followed a newer one.<br>Let user put/mark on canvas as QgsMapCanvasItem and mouse interactivity using QgsMapCanvasTool.<br>But i have some issue which i couldn't sort out.
<br>a. When i click on canvas ,after loading plugin , point symbol donot apears until i refesh.<br>Header file look like this:-<br>/*----------vp.h-------------*/<br>class vP:public QgsMapCanvasItem, public QgsMapTool, public QgisPlugin
<br>{<br> Q_OBJECT;<br> public:<br> vP(QgisApp * theApplication, QgisIface * theInterface);<br> //! Destructor<br> virtual ~vP();<br> //! Mouse move event for overriding<br> virtual void canvasMoveEvent(QMouseEvent * e) { }
<br><br> //! Mouse press event for overriding<br> virtual void canvasPressEvent(QMouseEvent * e) { }<br><br> //! Mouse release event for overriding<br> virtual void canvasReleaseEvent(QMouseEvent * e);<br>
<br> void drawShape(QPainter & p);<br><br> void updatePixmap();<br><br>public slots:<br> //! init the gui<br> virtual void initGui();<br> //! Show the dialog box<br> void run();<br> //! unload the plugin<br>
void unload();<br> //! show the help document<br> void help();<br> <br> //!draw a raster layer in the qui<br> void drawRasterLayer(QString);<br> //! Add a vector layer given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
<br> void drawVectorLayer(QString,QString,QString);<br> //!will receive signal pbnOk clicked<br> void recvOkClicked();<br>private:<br> int mPluginType;<br> //! Pointer to our toolbar<br> QToolBar *mToolBarPointer;
<br> //! Pionter to QGIS main application object<br> QgisApp *mQGisApp;<br> //! Pointer to the QGIS interface object<br> QgisIface *mQGisIface;<br> //!pointer to the qaction for this plugin<br> QAction * mQActionPointer;
<br> //! container for storing location of elements, later will be made of appropriate struct<br> QList<float > elementList;<br><br>};<br><br>here is code for drawShape()<br> [CODE]<br> //!This will draw the elements on to canvas
<br>void vP::drawShape(QPainter &p)<br>{<br> double temp_x, temp_y;<br> QgsPoint qPoint(0.0,0.0);<br> QPoint cPoint(0,0);<br> //loading image to pixmap which will be displayed on points<br> QString myFileNameQString= "/home1/qgis/images/vP/hit.png";
<br> QPixmap myQPixmap;<br> myQPixmap.load(myFileNameQString);<br> <br> //displaying it at position where the points are marked<br> //currently drwing all points which are is in list but only point which is added latest should be drawn
<br> QListIterator<float> listIterator(elementList);<br> cout<<"\n";<br> while(listIterator.hasNext())<br> { temp_x=listIterator.next();<br> //cout<<"\t"<<temp_x<<" ";
<br> if(listIterator.hasNext())<br> { temp_y=listIterator.next(); //cout<<temp_y;<br> qPoint.setX(temp_x);<br> qPoint.setY(temp_y);<br> cPoint=QgsMapCanvasItem::toCanvasCoords(qPoint);
<br> p.drawPixmap(cPoint.x(),cPoint.y(),myQPixmap);<br> show();<br> <br> }<br> cout<<"vp.cpp-205\t";<br> }<br> updateCanvas();<br> <br> //update();
<br> cout<<"vp.cpp-210\n";<br> }<br>[/CODE]<br><br>I had observer that this function drawShape() is continuously being called. I myself has not made any connection to it.<br><br>Code for canvasReleaseEvent() is :-
<br>void vP::canvasReleaseEvent(QMouseEvent * e)<br>{<br> QgsPoint point = mQGisIface->getMapCanvas()->getCoordinateTransform()->toMapCoordinates(e->x(), e->y());<br>if (e->button() == Qt::LeftButton)<br>
{<br> show();//why here-find out priority@5<br> //!make data available for storage <br> cout<<"\nelement bein added "<<point.x()<<" "<<point.y()<<"vp.cpp -171";
<br> elementList.append(point.x());<br> elementList.append(point.y()); <br> }<br>}<br><br>All advices are welcome. Also i keep stucking at such situations where i i have to display on canvas through interactivity with user. Will anyone guide me in improving here?
<br>regards<br>quickNitin<br><br><div><span class="gmail_quote">On 8/21/06, <b class="gmail_sendername">nitin quick</b> <<a href="mailto:quick.nitin@gmail.com">quick.nitin@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>hello everybody,<br>Currently i am trying to create a application which
let me overlay( creation of some objects using mouse like marking
something on map) some shapes over current map.<br>For this purpose i am thinking of few steps:
<br>1. Creating a new vector layer:<br> Issue: here issue is layer supports only either lineor point or polygon but usually i want to have all of these available to me. How i can sort out this issue?<br>
2. Add projection information ( if this is independent of underlying map's projection information)<br>3. Displaying it and editing it.<br><br>Any advices on how i can carry out this task more effectively is welcome.<br><br>
regards<br>quickNitin<br>
</div></blockquote></div><br>