2
//////////////////////////////////////////////////////////////////////////////
4
// begin : Aug 24, 2008
5
// copyright : (C) 2008 by Mateusz Loskot
6
// email : mateusz@loskot.net
8
//////////////////////////////////////////////////////////////////////////////
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,
13
// or (at your option) any later version.
15
//////////////////////////////////////////////////////////////////////////////
17
// qgis::plugin::ogrconv
21
#include <qgisinterface.h>
23
#include <qgsapplication.h>
24
#include <qgslogger.h>
34
static const char * const sIdent = "$Id$";
35
static const QString sName = QObject::tr( "OGR Layer Converter" );
36
static const QString sDescription = QObject::tr( "Translates vector layers between formats supported by OGR library" );
37
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
38
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
40
//////////////////////////////////////////////////////////////////////////////
41
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
42
//////////////////////////////////////////////////////////////////////////////
44
OgrPlugin::OgrPlugin( QgisInterface * theQgisInterface ) :
45
QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ),
46
mQGisIface( theQgisInterface ),
49
assert( 0 != mQGisIface );
52
OgrPlugin::~OgrPlugin()
56
void OgrPlugin::initGui()
58
// Create the action for tool
59
mQActionPointer = new QAction( QIcon(), tr( "Run OGR Layer Converter" ), this );
62
setCurrentTheme( "" );
64
// Set the what's this text
65
mQActionPointer->setWhatsThis( tr( "Translates vector layers between formats supported by OGR library" ) );
67
// Connect the action to the run
68
connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
70
// Add the icon to the toolbar
71
mQGisIface->addToolBarIcon( mQActionPointer );
72
mQGisIface->addPluginToMenu( tr( "OG&R Converter" ), mQActionPointer );
74
// this is called when the icon theme is changed
75
connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
78
//method defined in interface
79
void OgrPlugin::help()
86
assert( 0 != mQGisIface );
88
Dialog* ogrDialog = new Dialog( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );
89
ogrDialog->setAttribute( Qt::WA_DeleteOnClose );
93
void OgrPlugin::unload()
95
assert( 0 != mQGisIface );
97
// TODO: Who is responsible for OGR cleanup?
101
mQGisIface->removePluginMenu( "OG&R Converter", mQActionPointer );
102
mQGisIface->removeToolBarIcon( mQActionPointer );
103
delete mQActionPointer;
106
//! Set icons to the current theme
107
void OgrPlugin::setCurrentTheme( QString theThemeName )
109
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/ogr_converter.png";
110
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/ogr_converter.png";
111
QString myQrcPath = ":/ogr_converter.png";
112
if ( QFile::exists( myCurThemePath ) )
114
mQActionPointer->setIcon( QIcon( myCurThemePath ) );
116
else if ( QFile::exists( myDefThemePath ) )
118
mQActionPointer->setIcon( QIcon( myDefThemePath ) );
120
else if ( QFile::exists( myQrcPath ) )
122
mQActionPointer->setIcon( QIcon( myQrcPath ) );
126
mQActionPointer->setIcon( QIcon() );
130
/////////////////////////////////////////////////////////////////////////////
131
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
132
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
133
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
134
/////////////////////////////////////////////////////////////////////////////
136
// Required extern functions needed for every plugin
137
// These functions can be called prior to creating an instance
138
// of the plugin class.
140
// Class factory to return a new instance of the plugin class
141
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
143
return new OgrPlugin( theQgisInterfacePointer );
146
// Return the name of the plugin - note that we do not user class members as
147
// the class may not yet be insantiated when this method is called.
148
QGISEXTERN QString name()
153
// Return the description
154
QGISEXTERN QString description()
159
// Return the type (either UI or MapLayer plugin)
160
QGISEXTERN int type()
165
// Return the version number for the plugin
166
QGISEXTERN QString version()
168
return sPluginVersion;
172
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
174
delete thePluginPointer;