1
/***************************************************************************
2
*Copyright (C) 2008 Paolo L. Scala, Barbara Rita Barricelli, Marco Padula *
3
* CNR, Milan Unit (Information Technology), *
4
* Construction Technologies Institute.\n"; *
6
* email : Paolo L. Scala <scala@itc.cnr.it> *
8
* This is a plugin generated from the QGIS plugin template *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
14
***************************************************************************/
18
// QGIS Specific includes
21
#include <qgisinterface.h>
23
#include <qgsapplication.h>
24
#include <qgsvectorlayer.h>
26
#include "dxf2shpconverter.h"
27
#include "dxf2shpconvertergui.h"
30
// Qt4 Related Includes
37
static const char *const sIdent =
38
"$Id: plugin.cpp 6935 2007-05-07 14:29:51Z wonder $";
39
static const QString sName = QObject::tr( "Dxf2Shp Converter" );
40
static const QString sDescription = QObject::tr( "Converts from dxf to shp file format" );
41
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
42
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
44
//////////////////////////////////////////////////////////////////////
46
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
48
//////////////////////////////////////////////////////////////////////
51
* Constructor for the plugin. The plugin is passed a pointer
52
* an interface object that provides access to exposed functions in QGIS.
53
* @param theQGisInterface - Pointer to the QGIS interface object
55
dxf2shpConverter::dxf2shpConverter( QgisInterface *theQgisInterface ): QgisPlugin
56
( sName, sDescription, sPluginVersion, sPluginType ), mQGisIface
57
( theQgisInterface ) {}
59
dxf2shpConverter::~dxf2shpConverter()
65
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
66
* added to the plugin registry in the QGIS application.
68
void dxf2shpConverter::initGui()
70
// Create the action for tool
71
mQActionPointer = new QAction( QIcon(), "Dxf2Shp Converter", this );
74
setCurrentTheme( "" );
76
// Set the what's this text
77
mQActionPointer->setWhatsThis( tr( "Converts DXF files in Shapefile format" ) );
79
// Connect the action to the run
80
connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
82
// Add the icon to the toolbar
83
mQGisIface->addToolBarIcon( mQActionPointer );
84
mQGisIface->addPluginToMenu( tr( "&Dxf2Shp" ), mQActionPointer );
86
// this is called when the icon theme is changed
87
connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
90
//method defined in interface
91
void dxf2shpConverter::help()
96
// Slot called when the menu item is activated
97
// If you created more menu items / toolbar buttons in initiGui, you should
98
// create a separate handler for each action - this single run() method will
100
void dxf2shpConverter::run()
102
dxf2shpConverterGui *myPluginGui =
103
new dxf2shpConverterGui( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );
105
myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
107
connect( myPluginGui, SIGNAL( createLayer( QString, QString ) ), this, SLOT( addMyLayer( QString, QString ) ) );
112
// Unload the plugin by cleaning up the GUI
113
void dxf2shpConverter::unload()
116
mQGisIface->removePluginMenu( tr( "&Dxf2Shp" ), mQActionPointer );
117
mQGisIface->removeToolBarIcon( mQActionPointer );
118
delete mQActionPointer;
121
void dxf2shpConverter::addMyLayer( QString myfname, QString mytitle )
123
mQGisIface->addVectorLayer( myfname, mytitle, "ogr" );
126
//! Set icons to the current theme
127
void dxf2shpConverter::setCurrentTheme( QString theThemeName )
129
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/dxf2shp_converter.png";
130
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/dxf2shp_converter.png";
131
QString myQrcPath = ":/dxf2shp_converter.png";
132
if ( QFile::exists( myCurThemePath ) )
134
mQActionPointer->setIcon( QIcon( myCurThemePath ) );
136
else if ( QFile::exists( myDefThemePath ) )
138
mQActionPointer->setIcon( QIcon( myDefThemePath ) );
140
else if ( QFile::exists( myQrcPath ) )
142
mQActionPointer->setIcon( QIcon( myQrcPath ) );
146
mQActionPointer->setIcon( QIcon() );
150
//////////////////////////////////////////////////////////////////////////
153
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
154
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
155
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
158
//////////////////////////////////////////////////////////////////////////
162
* Required extern functions needed for every plugin
163
* These functions can be called prior to creating an instance
164
* of the plugin class
166
// Class factory to return a new instance of the plugin class
167
QGISEXTERN QgisPlugin *classFactory( QgisInterface *theQgisInterfacePointer )
169
return new dxf2shpConverter( theQgisInterfacePointer );
172
// Return the name of the plugin - note that we do not user class members as
173
// the class may not yet be insantiated when this method is called.
174
QGISEXTERN QString name()
179
// Return the description
180
QGISEXTERN QString description()
185
// Return the type (either UI or MapLayer plugin)
186
QGISEXTERN int type()
191
// Return the version number for the plugin
192
QGISEXTERN QString version()
194
return sPluginVersion;
198
QGISEXTERN void unload( QgisPlugin *thePluginPointer )
200
delete thePluginPointer;