[Qgis-user] problem in plugin writing
Bijay Panda
bijaykumar.mail at gmail.com
Thu Feb 12 03:05:28 PST 2009
Hi All,
I am new to QGIS.I am writing a plugin to simply draw a simple stuff in
mapCanvas in ubuntu linux.
I already created a plugin toolButton .I want to draw a triangle or
rectangle when my pluging will be selected.
I followed following process.
1)create a toolBarIcon in initGui()
2)took a slot to render the drawig stuffs.
3)inside that slot i called Qpainter to paint something.
4)connect that slot inside initGui() to mapCanvas.
5)I am loading lib libraries into plugin folder(/usr/lib/qgis)
#include "qgspointconverterplugin.h"
#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
#else
#define QGISEXTERN extern "C"
#endif
QgsPointConverterPlugin::QgsPointConverterPlugin(QgisInterface* iface):
mIface(iface), qGisInterface( iface)
{
}
QgsPointConverterPlugin::~QgsPointConverterPlugin()
{
}
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::unload()
{
mIface->removeToolBarIcon(mAction);
mIface->removePluginMenu(tr("&Convert to point"), mAction);
delete mAction;
}
void QgsPointConverterPlugin::refreshCanvas()
{
qGisInterface->mapCanvas()->refresh();
}
void QgsPointConverterPlugin::run()
{
/*QgsScaleBarPluginGui *myPluginGui = new QgsScaleBarPluginGui(
qGisInterface->mainWindow(), QgisGui::ModalDialogFlags );
myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
myPluginGui->setPreferredSize( mPreferredSize );
myPluginGui->setSnapping( mSnapping );
myPluginGui->setPlacementLabels( mPlacementLabels );
myPluginGui->setPlacement( mPlacementIndex );
myPluginGui->setEnabled( mEnabled );
myPluginGui->setStyleLabels( mStyleLabels );
myPluginGui->setStyle( mStyleIndex );
myPluginGui->setColour( mColour );*/
/*connect( myPluginGui, SIGNAL( changePreferredSize( int ) ), this, SLOT(
setPreferredSize( int ) ) );
connect( myPluginGui, SIGNAL( changeSnapping( bool ) ), this, SLOT(
setSnapping( bool ) ) );
connect( myPluginGui, SIGNAL( changePlacement( int ) ), this, SLOT(
setPlacement( int ) ) );
connect( myPluginGui, SIGNAL( changeEnabled( bool ) ), this, SLOT(
setEnabled( bool ) ) );
connect( myPluginGui, SIGNAL( changeStyle( int ) ), this, SLOT( setStyle(
int ) ) );
connect( myPluginGui, SIGNAL( changeColour( QColor ) ), this, SLOT(
setColour( QColor ) ) );
connect( myPluginGui, SIGNAL( refreshCanvas() ), this, SLOT(
refreshCanvas() ) );
myPluginGui->show();*/
}
void QgsPointConverterPlugin::render(QPainter *painter)//
{
qWarning("in method convertToPoint");
QPen myForegroundPen( mColour, 2 );
QPen myBackgroundPen( Qt::white, 4 );
QPolygon polygon( 4 );
painter->setPen( myBackgroundPen );
polygon.putPoints( 0,
4,10,20,30,40,50,60);
painter->drawPolyline( polygon );
//QPainter *painter;
/* QPainter paint( this );
paint.setPen( Qt::blue );
paint.drawRect(20,30,40,45 );*/
/*QPolygon pa( 4 );
pa.setPoint( 0, 10, 10 );
pa.setPoint( 1, 20, 10);
pa.setPoint( 2, 20, 20 );
pa.setPoint( 3, 10,20 );
painter->drawPolygon( pa );*/
}
QGISEXTERN QgisPlugin* classFactory(QgisInterface* iface)
{
return new QgsPointConverterPlugin(iface);
}
QGISEXTERN QString name()
{
return "point converter plugin";
}
QGISEXTERN QString description()
{
return "A plugin that converts vector layers to delimited text point
files";
}
QGISEXTERN QString version()
{
return "0.00001";
}
// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return QgisPlugin::UI;
}
// Delete ourself
QGISEXTERN void unload(QgisPlugin* theQgsPointConverterPluginPointer)
{
//disconnect( qGisInterface->mapCanvas(), SIGNAL( renderComplete( QPainter
* ) ),
//this, SLOT( renderScaleBar( QPainter * ) ) );
// refreshCanvas();
//delete myQActionPointer;
delete theQgsPointConverterPluginPointer;
}
But it's not drawing anything,rather application crashes when i load my
plugin.
can any one plz help me out.
--
Thanks & Regards
Bijay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20090212/8d6ea75d/attachment.html>
More information about the Qgis-user
mailing list