[Qgis-developer] mapCanvasItem not able to display

nitin quick quick.nitin at gmail.com
Tue Oct 10 10:43:24 EDT 2006


greetings,
I have some peculiar pbm.
In a plugin, i am receiving some data through Qthread and storing in a
struct. I am showing these as customised qgsmapcanvasitem over map on
qgsmapcanvas but i couldn;'t do . This code is part of a plugin for
qgis0.7.9  .here is what i have done:

void Plot::drawShape(QPainter & p)
{

// 	if(p.isActive())
// 		cout<<"\nPainter is not active cpp=271";
// 	else
// 		cout<<"\n Painter is aCtive";
	 p.setPen(Qt::SolidLine);
	 p.setBrush(Qt::SolidPattern);
	 int flag=0;
	int temp1=0,temp2=0;
	//-------------------------doing a code for displaying
objects-------------------------
	
	for(int i=0 ;i <4; i++)
	{	MyMapCanvasItem *tempItem;
		if(mth.mData.id[i]>0)
		{
		 QgsPoint qpt(mth.mData.x[i]/10,mth.mData.y[i]/10);
		 QPoint pt=toCanvasCoords(qpt);
               //creating new object here
		 tempItem=new
MyMapCanvasItem((int)mth.mData.id[i],pt.x(),pt.y(),mQGisIface->getMapCanvas());
		
		tempItem->setBrush(Qt::red);
		QListIterator<MyMapCanvasItem*> itr(myItemList);
		while(itr.hasNext())                      //comparing whether it
already exists
		{	
			temp1=(itr.next())->myId();
			temp2=tempItem->myId();
			if(temp1==temp2)
				flag==1;
			cout<<temp1<<temp2<<" ";
		}
		cout<<"\n";
		
		 if(flag==1)      //if yes then just set new position of it
		 {	 QgsPoint qpt(mth.mData.x[i]/10,mth.mData.y[i]/10);
		 	QPoint pt=toCanvasCoords(qpt);
			tempItem->setX(	pt.x());	
			tempItem->setY(pt.y());
			tempItem->canvas()->update();
			update();
			flag=0;
			//tempItem->show();
		 }
		 else   //else add it to master list of objects
		 {
		  myItemList.append(tempItem);
			tempItem->setBrush(Qt::red);
			tempItem->canvas()->update();// so that update is called.
			update();
		}
		
		
		cout<<"\n";
	}
	update();
....

here i am creating object adding to list, but everytime i am creating
new. hat ican take acre of. But nohig is getting visible despite i
have put code for update(). I am not calling drawShape(qpainter &P) of
mymapcanvasitem since it is protected , if i make it public, item do
appear but is it propr way. Also this way i am not able to move them.

I also have query about function QgsMapCanvasItem::setRect(). why it
is required.Do this has got anything to do with visibility of this
objet. I have set complete map extent as visible in updateExtent()
because i couldn't got reason for this.


Earlier  i was drawing pixmap there in position of MyMapCanvasItem
object handling drawing. This way i want to let user hav right click
option menu ( sort of context menu ) over these canvasItem and do some
operations realtive to these objects like changing their color,
displaying dome lable with it.( i will go through  new tool for right
click. Will plugin tool  affect such functionality in some way).
I have tried this context menu type operation on simple qt application
over canvas item recognising them through rtti().
Please help me in this regards, i am stuck with it for quite some time now.

quickNitin



More information about the Qgis-developer mailing list