[Qgis-user] problem in writing plugin in c++

Tim Sutton tim at linfiniti.com
Thu Feb 19 15:38:10 PST 2009


Hi

On Thursday 19 February 2009 08:20:51 Bijay Panda wrote:
> Hi All,
> I am new to Qgis.I want to write a plugin to simply draw circle or a
> polygon  in screen
> when i load that plugin through plugin manager..Already i ve gone
> through the process of writing plugins in c++.I also tested the point
> converter plugin,but i want to start from a simple one like just to
> draw somthing on screen which can be scaled(zoom in and out)..I
> already tried it like below
>
> void QgsPointConverterPlugin::initGui()
> {
>   // myQActionPointer = new QAction( QIcon( ":/scale_bar.png" ), tr(
> "&Scale Bar" ), this );
>   mAction = new QAction(tr("&Convert to point"), this);
>   connect(mAction, SIGNAL(activated()), this, SLOT( run() ) );
>   connect( qGisInterface->mapCanvas(), SIGNAL( renderComplete(
> QPainter * ) ), this, SLOT( render(QPainter * )) );
>
>   mIface->addToolBarIcon(mAction);
>   mIface->addPluginToMenu(tr("&Convert to point"), mAction);
> }
>
> void QgsPointConverterPlugin::render(QPainter *painter)
> {
>
>   painter->setRenderHint(QPainter::Antialiasing, true);
>   painter->setPen(QPen(Qt::black, 12, Qt::DashDotLine, Qt::RoundCap));
>   painter->setBrush(QBrush(Qt::green, Qt::SolidPattern));
>   painter->drawEllipse(10, 10, 100, 140);
> }
>
> It draws a ellipse which can't be scaled(zooming in and out not
> working).It's like a static drawing(which has no effect with scaling )
> above a layer of data .But I want it to be scaled as a normal layer .
> Can any one help me out plz.

This kind of question is better asked on the developer list. I will quickly 
answer by saying that the approach you are taking simply draws a graphic on 
the screen always at a fixed size (painter->drawEllipse(10, 10, 100, 140);). If 
you want scaling you either need to implement the appropriate logic to draw 
your circle based on current map scale, or you need to create a true 
geographic feature as a maplayer and add it to the mapcanvas. Note also that 
most gis data formats do not support geometry type of circle - you will need 
to express the circle as a polygon probably to get the desired effect you are 
after.

Regards,

-- 
Tim Sutton, Linfiniti Consulting
==============================================
* QGIS Project Steering Committee Member (Release  Manager)
* Visit http://linfiniti.com for more information 
   about the QGIS and FOSS services we provide.
* Skype: timlinux Irc: timlinux on #qgis at freenode.net
==============================================

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20090220/6bd1277a/attachment.sig>


More information about the Qgis-user mailing list