~ubuntu-branches/ubuntu/quantal/qgis/quantal

« back to all changes in this revision

Viewing changes to plugins/georeferencer/plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Halasz
  • Date: 2005-11-05 16:04:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051105160445-l0g4isz5bc9yehet
Tags: 0.7.4-1
* New upstream release
* Build GRASS support in qgis-plugin-grass package (Closes: #248649)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *  File Name:               plugin.cpp 
 
3
 * 
 
4
 *  The georeferencer plugin is a tool for adding projection info to rasters
 
5
 *
 
6
 *--------------------------------------------------------------------------
 
7
 *    begin                : Jan 21, 2004
 
8
 *    copyright            : (C) 2004 by Tim Sutton
 
9
 *    email                : tim@linfiniti.com
 
10
 *
 
11
 ***************************************************************************/
 
12
 
 
13
/***************************************************************************
 
14
 *                                                                         *
 
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.                                   *
 
19
 *                                                                         *
 
20
 ***************************************************************************/
 
21
/*  $Id: plugin.cpp,v 1.1 2005/05/01 20:23:17 larsl Exp $ */
 
22
 
 
23
/***************************************************************************
 
24
 *   QGIS Programming conventions:
 
25
 *   
 
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')
 
30
 *
 
31
 *   Additional useful conventions:
 
32
 *
 
33
 *   theVariableName - a method parameter (prefix with 'the')
 
34
 *   myVariableName - a locally declared variable within a method ('my' prefix)
 
35
 * 
 
36
 *   DO: Use mixed case variable names - myVariableName
 
37
 *   DON'T: separate variable names using underscores: my_variable_name (NO!)
 
38
 *
 
39
 * **************************************************************************/
 
40
 
 
41
//
 
42
// Required qgis includes
 
43
// 
 
44
 
 
45
#include <qgisapp.h>
 
46
#include <qgsmaplayer.h>
 
47
#include <qgsrasterlayer.h>
 
48
#include "plugin.h"
 
49
 
 
50
//
 
51
// Required QT includes
 
52
//
 
53
 
 
54
#include <qtoolbar.h>
 
55
#include <qmenubar.h>
 
56
#include <qmessagebox.h>
 
57
#include <qpopupmenu.h>
 
58
#include <qlineedit.h>
 
59
#include <qaction.h>
 
60
#include <qapplication.h>
 
61
#include <qcursor.h>
 
62
 
 
63
//
 
64
//non qt includes
 
65
//
 
66
#include <iostream>
 
67
 
 
68
//
 
69
//the gui subclass
 
70
//
 
71
#include "plugingui.h"
 
72
 
 
73
//
 
74
// xpm for creating the toolbar icon
 
75
// 
 
76
#include "icon.h"
 
77
 
 
78
#ifdef WIN32
 
79
#define QGISEXTERN extern "C" __declspec( dllexport )
 
80
#else
 
81
#define QGISEXTERN extern "C"
 
82
#endif
 
83
 
 
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;
 
89
 
 
90
//////////////////////////////////////////////////////////////////////
 
91
//
 
92
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
 
93
//
 
94
//////////////////////////////////////////////////////////////////////
 
95
 
 
96
/**
 
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
 
101
 */
 
102
QgsGeorefPlugin::QgsGeorefPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterface):
 
103
                 mQGisApp(theQGisApp), 
 
104
                 mQGisIface(theQgisInterface),
 
105
                 QgisPlugin(sName,sDescription,sPluginVersion,sPluginType)
 
106
{
 
107
}
 
108
 
 
109
QgsGeorefPlugin::~QgsGeorefPlugin()
 
110
{
 
111
 
 
112
}
 
113
 
 
114
/*
 
115
 * Initialize the GUI interface for the plugin 
 
116
 */
 
117
void QgsGeorefPlugin::initGui()
 
118
{
 
119
  QIconSet iconset(qembed_findImage("icon"));
 
120
 
 
121
  QPopupMenu *pluginMenu = mQGisIface->getPluginMenu("&Georeferencer");
 
122
  mMenuId = pluginMenu->insertItem(QIconSet(iconset),"&Georeferencer", this, SLOT(run()));
 
123
 
 
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);
 
130
 
 
131
}
 
132
//method defined in interface
 
133
void QgsGeorefPlugin::help()
 
134
{
 
135
  //implement me!
 
136
}
 
137
 
 
138
// Slot called when the buffer menu item is activated
 
139
void QgsGeorefPlugin::run()
 
140
{
 
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)));
 
145
  myPluginGui->show();
 
146
}
 
147
 
 
148
// Unload the plugin by cleaning up the GUI
 
149
void QgsGeorefPlugin::unload()
 
150
{
 
151
  // remove the GUI
 
152
  mQGisIface->removePluginMenuItem("&Georeferencer",mMenuId);
 
153
  mQGisIface->removeToolBarIcon(mQActionPointer);
 
154
  delete mQActionPointer;
 
155
}
 
156
 
 
157
//////////////////////////////////////////////////////////////////////
 
158
//
 
159
//                  END OF MANDATORY PLUGIN METHODS
 
160
//
 
161
//////////////////////////////////////////////////////////////////////
 
162
//
 
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.
 
167
//
 
168
 
 
169
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
 
170
//layer
 
171
void QgsGeorefPlugin::drawRasterLayer(QString theQString)
 
172
{
 
173
  mQGisIface->addRasterLayer(theQString);
 
174
}
 
175
 
 
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)
 
180
{
 
181
  mQGisIface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
 
182
}
 
183
 
 
184
 
 
185
//////////////////////////////////////////////////////////////////////////
 
186
//
 
187
//
 
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
 
191
//
 
192
//
 
193
//////////////////////////////////////////////////////////////////////////
 
194
 
 
195
 
 
196
/** 
 
197
 * Required extern functions needed  for every plugin 
 
198
 * These functions can be called prior to creating an instance
 
199
 * of the plugin class
 
200
 */
 
201
// Class factory to return a new instance of the plugin class
 
202
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
 
203
{
 
204
  return new QgsGeorefPlugin(theQGisAppPointer, theQgisInterfacePointer);
 
205
}
 
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()
 
209
{
 
210
  return sName;
 
211
}
 
212
 
 
213
// Return the description
 
214
QGISEXTERN QString description()
 
215
{
 
216
  return sDescription;
 
217
}
 
218
 
 
219
// Return the type (either UI or MapLayer plugin)
 
220
QGISEXTERN int type()
 
221
{
 
222
  return sPluginType;
 
223
}
 
224
 
 
225
// Return the version number for the plugin
 
226
QGISEXTERN QString version()
 
227
{
 
228
  return sPluginVersion;
 
229
}
 
230
 
 
231
// Delete ourself
 
232
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
 
233
{
 
234
  delete thePluginPointer;
 
235
}