[Qgis-developer] Re: creating a new vector layer supporting all
line, point n polygon
nitin quick
quick.nitin at gmail.com
Fri Aug 25 07:51:18 EDT 2006
hello evrybody,
today i discovered sth lse is also going wrong with plugin. After using
plugin, displaying points, whenever i start another tool which generate a
new mesage window( like measure line, measure areaa) it cleans the canvas
and shapes marked with plugin are gone.
I think are implemented to work this way. How can i avoid such behaviour?
regards
quickNitin
On 8/24/06, nitin quick <quick.nitin at gmail.com> wrote:
>
> i found what wrong i was doing. i was calling updateCanvas( ) inside
> drawShape() function which in turn was resulting in call to drawShape().
> Second, slot defining visibility rectangle was not connnected.
>
>
> On 8/24/06, nitin quick <quick.nitin at gmail.com> wrote:
> >
> > Hello everybody,
> > As against my previous approach, i followed a newer one.
> > Let user put/mark on canvas as QgsMapCanvasItem and mouse interactivity
> > using QgsMapCanvasTool.
> > But i have some issue which i couldn't sort out.
> > a. When i click on canvas ,after loading plugin , point symbol donot
> > apears until i refesh.
> > Header file look like this:-
> > /*----------vp.h-------------*/
> > class vP:public QgsMapCanvasItem, public QgsMapTool, public QgisPlugin
> > {
> > Q_OBJECT;
> > public:
> > vP(QgisApp * theApplication, QgisIface * theInterface);
> > //! Destructor
> > virtual ~vP();
> > //! Mouse move event for overriding
> > virtual void canvasMoveEvent(QMouseEvent * e) { }
> >
> > //! Mouse press event for overriding
> > virtual void canvasPressEvent(QMouseEvent * e) { }
> >
> > //! Mouse release event for overriding
> > virtual void canvasReleaseEvent(QMouseEvent * e);
> >
> > void drawShape(QPainter & p);
> >
> > void updatePixmap();
> >
> > public slots:
> > //! init the gui
> > virtual void initGui();
> > //! Show the dialog box
> > void run();
> > //! unload the plugin
> > void unload();
> > //! show the help document
> > void help();
> >
> > //!draw a raster layer in the qui
> > void drawRasterLayer(QString);
> > //! Add a vector layer given vectorLayerPath, baseName, providerKey
> > ("ogr" or "postgres");
> > void drawVectorLayer(QString,QString,QString);
> > //!will receive signal pbnOk clicked
> > void recvOkClicked();
> > private:
> > int mPluginType;
> > //! Pointer to our toolbar
> > QToolBar *mToolBarPointer;
> > //! Pionter to QGIS main application object
> > QgisApp *mQGisApp;
> > //! Pointer to the QGIS interface object
> > QgisIface *mQGisIface;
> > //!pointer to the qaction for this plugin
> > QAction * mQActionPointer;
> > //! container for storing location of elements, later will be made
> > of appropriate struct
> > QList<float > elementList;
> >
> > };
> >
> > here is code for drawShape()
> > [CODE]
> > //!This will draw the elements on to canvas
> > void vP::drawShape(QPainter &p)
> > {
> > double temp_x, temp_y;
> > QgsPoint qPoint(0.0,0.0);
> > QPoint cPoint(0,0);
> > //loading image to pixmap which will be displayed on points
> > QString myFileNameQString= "/home1/qgis/images/vP/hit.png";
> > QPixmap myQPixmap;
> > myQPixmap.load(myFileNameQString);
> >
> > //displaying it at position where the points are marked
> > //currently drwing all points which are is in list but only point
> > which is added latest should be drawn
> > QListIterator<float> listIterator(elementList);
> > cout<<"\n";
> > while(listIterator.hasNext())
> > { temp_x=listIterator.next();
> > //cout<<"\t"<<temp_x<<" ";
> > if(listIterator.hasNext())
> > { temp_y=listIterator.next(); //cout<<temp_y;
> > qPoint.setX(temp_x);
> > qPoint.setY(temp_y);
> > cPoint=QgsMapCanvasItem::toCanvasCoords(qPoint);
> > p.drawPixmap(cPoint.x(),cPoint.y(),myQPixmap);
> > show();
> >
> > }
> > cout<<"vp.cpp-205\t";
> > }
> > updateCanvas();
> >
> > //update();
> > cout<<"vp.cpp-210\n";
> > }
> > [/CODE]
> >
> > I had observer that this function drawShape() is continuously being
> > called. I myself has not made any connection to it.
> >
> > Code for canvasReleaseEvent() is :-
> > void vP::canvasReleaseEvent(QMouseEvent * e)
> > {
> > QgsPoint point =
> > mQGisIface->getMapCanvas()->getCoordinateTransform()->toMapCoordinates(e->x(),
> > e->y());
> > if (e->button() == Qt::LeftButton)
> > {
> > show();//why here-find out priority at 5
> > //!make data available for storage
> > cout<<"\nelement bein added "<<point.x()<<" "<<point.y()<<"vp.cpp-171";
> > elementList.append(point.x());
> > elementList.append(point.y());
> > }
> > }
> >
> > 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?
> > regards
> > quickNitin
> >
> >
> > On 8/21/06, nitin quick < quick.nitin at gmail.com> wrote:
> > >
> > > hello everybody,
> > > 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.
> > > For this purpose i am thinking of few steps:
> > > 1. Creating a new vector layer:
> > > 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?
> > > 2. Add projection information ( if this is independent of underlying
> > > map's projection information)
> > > 3. Displaying it and editing it.
> > >
> > > Any advices on how i can carry out this task more effectively is
> > > welcome.
> > >
> > > regards
> > > quickNitin
> > >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20060825/bcffd64b/attachment.html
More information about the Qgis-developer
mailing list