1
/***************************************************************************
2
* File Name: plugin.cpp
4
* The georeferencer plugin is a tool for adding projection info to rasters
6
*--------------------------------------------------------------------------
8
* copyright : (C) 2004 by Tim Sutton
9
* email : tim@linfiniti.com
11
***************************************************************************/
13
/***************************************************************************
15
* This program is free software; you can redistribute it and/or modify *
16
* it under the terms of the GNU General Public License as published by *
17
* the Free Software Foundation; either version 2 of the License, or *
18
* (at your option) any later version. *
20
***************************************************************************/
21
/* $Id: plugin.cpp,v 1.1 2005/05/01 20:23:17 larsl Exp $ */
23
/***************************************************************************
24
* QGIS Programming conventions:
26
* mVariableName - a class level member variable
27
* sVariableName - a static class level member variable
28
* variableName() - accessor for a class member (no 'get' in front of name)
29
* setVariableName() - mutator for a class member (prefix with 'set')
31
* Additional useful conventions:
33
* theVariableName - a method parameter (prefix with 'the')
34
* myVariableName - a locally declared variable within a method ('my' prefix)
36
* DO: Use mixed case variable names - myVariableName
37
* DON'T: separate variable names using underscores: my_variable_name (NO!)
39
* **************************************************************************/
42
// Required qgis includes
46
#include <qgsmaplayer.h>
47
#include <qgsrasterlayer.h>
51
// Required QT includes
56
#include <qmessagebox.h>
57
#include <qpopupmenu.h>
58
#include <qlineedit.h>
60
#include <qapplication.h>
71
#include "plugingui.h"
74
// xpm for creating the toolbar icon
79
#define QGISEXTERN extern "C" __declspec( dllexport )
81
#define QGISEXTERN extern "C"
84
static const char * const sIdent = "$Id: plugin.cpp,v 1.1 2005/05/01 20:23:17 larsl Exp $";
85
static const char * const sName = "Georeferencer";
86
static const char * const sDescription = "The georeferencer plugin is a tool for adding projection info to rasters";
87
static const char * const sPluginVersion = "Version 0.1";
88
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
90
//////////////////////////////////////////////////////////////////////
92
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
94
//////////////////////////////////////////////////////////////////////
97
* Constructor for the plugin. The plugin is passed a pointer to the main app
98
* and an interface object that provides access to exposed functions in QGIS.
99
* @param theQGisApp - Pointer to the QGIS main window
100
* @param theQGisInterface - Pointer to the QGIS interface object
102
QgsGeorefPlugin::QgsGeorefPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterface):
103
mQGisApp(theQGisApp),
104
mQGisIface(theQgisInterface),
105
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType)
109
QgsGeorefPlugin::~QgsGeorefPlugin()
115
* Initialize the GUI interface for the plugin
117
void QgsGeorefPlugin::initGui()
119
QIconSet iconset(qembed_findImage("icon"));
121
QPopupMenu *pluginMenu = mQGisIface->getPluginMenu("&Georeferencer");
122
mMenuId = pluginMenu->insertItem(QIconSet(iconset),"&Georeferencer", this, SLOT(run()));
124
// Create the action for tool
125
mQActionPointer = new QAction("Georeferencer", iconset, "&icon",0, this, "run");
126
// Connect the action to the run
127
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
128
// Add the to the toolbar
129
mQGisIface->addToolBarIcon(mQActionPointer);
132
//method defined in interface
133
void QgsGeorefPlugin::help()
138
// Slot called when the buffer menu item is activated
139
void QgsGeorefPlugin::run()
141
QgsGeorefPluginGui *myPluginGui=new QgsGeorefPluginGui(mQGisApp,"Georeferencer",true,0);
142
//listen for when the layer has been made so we can draw it
143
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
144
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
148
// Unload the plugin by cleaning up the GUI
149
void QgsGeorefPlugin::unload()
152
mQGisIface->removePluginMenuItem("&Georeferencer",mMenuId);
153
mQGisIface->removeToolBarIcon(mQActionPointer);
154
delete mQActionPointer;
157
//////////////////////////////////////////////////////////////////////
159
// END OF MANDATORY PLUGIN METHODS
161
//////////////////////////////////////////////////////////////////////
163
// The following methods are provided to demonstrate how you can
164
// load a vector or raster layer into the main gui. Please delete
165
// if you are not intending to use these. Note also that there are
166
// ways in which layers can be loaded.
169
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
171
void QgsGeorefPlugin::drawRasterLayer(QString theQString)
173
mQGisIface->addRasterLayer(theQString);
176
//!draw a vector layer in the qui - intended to respond to signal sent by
177
// dialog when it as finished creating a layer. It needs to be given
178
// vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
179
void QgsGeorefPlugin::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
181
mQGisIface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
185
//////////////////////////////////////////////////////////////////////////
188
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
189
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
190
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
193
//////////////////////////////////////////////////////////////////////////
197
* Required extern functions needed for every plugin
198
* These functions can be called prior to creating an instance
199
* of the plugin class
201
// Class factory to return a new instance of the plugin class
202
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
204
return new QgsGeorefPlugin(theQGisAppPointer, theQgisInterfacePointer);
206
// Return the name of the plugin - note that we do not user class members as
207
// the class may not yet be insantiated when this method is called.
208
QGISEXTERN QString name()
213
// Return the description
214
QGISEXTERN QString description()
219
// Return the type (either UI or MapLayer plugin)
220
QGISEXTERN int type()
225
// Return the version number for the plugin
226
QGISEXTERN QString version()
228
return sPluginVersion;
232
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
234
delete thePluginPointer;