~ubuntu-branches/ubuntu/hardy/qgis/hardy

« back to all changes in this revision

Viewing changes to plugins/plugin_template/plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
  plugin.cpp 
3
 
  Import tool for various worldmap analysis output files
4
 
Functions:
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.12.2.1 2005/09/17 23:32:11 timlinux Exp $ */
22
 
 
23
 
// includes
24
 
 
25
 
#include <qgisapp.h>
26
 
#include <qgsmaplayer.h>
27
 
#include <qgsrasterlayer.h>
28
 
#include "plugin.h"
29
 
 
30
 
 
31
 
#include <qtoolbar.h>
32
 
#include <qmenubar.h>
33
 
#include <qmessagebox.h>
34
 
#include <qpopupmenu.h>
35
 
#include <qlineedit.h>
36
 
#include <qaction.h>
37
 
#include <qapplication.h>
38
 
#include <qcursor.h>
39
 
 
40
 
//non qt includes
41
 
#include <iostream>
42
 
 
43
 
//the gui subclass
44
 
#include "plugingui.h"
45
 
 
46
 
// xpm for creating the toolbar icon
47
 
#include "icon.xpm"
48
 
#ifdef WIN32
49
 
#define QGISEXTERN extern "C" __declspec( dllexport )
50
 
#else
51
 
#define QGISEXTERN extern "C"
52
 
#endif
53
 
 
54
 
static const char * const sIdent = "$Id: plugin.cpp,v 1.12.2.1 2005/09/17 23:32:11 timlinux Exp $";
55
 
static const char * const sName = "[menuitemname]";
56
 
static const char * const sDescription = "[plugindescription]";
57
 
static const char * const sPluginVersion = "Version 0.1";
58
 
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
59
 
 
60
 
//////////////////////////////////////////////////////////////////////
61
 
//
62
 
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
63
 
//
64
 
//////////////////////////////////////////////////////////////////////
65
 
 
66
 
/**
67
 
 * Constructor for the plugin. The plugin is passed a pointer to the main app
68
 
 * and an interface object that provides access to exposed functions in QGIS.
69
 
 * @param theQGisApp - Pointer to the QGIS main window
70
 
 * @param theQGisInterface - Pointer to the QGIS interface object
71
 
 */
72
 
[pluginname]::[pluginname](QgisApp * theQGisApp, 
73
 
                                       QgisIface * theQgisInterface):
74
 
                 mQGisApp(theQGisApp), 
75
 
                 mQGisIface(theQgisInterface),
76
 
                 QgisPlugin(sName,sDescription,sPluginVersion,sPluginType)
77
 
{
78
 
}
79
 
 
80
 
[pluginname]::~[pluginname]()
81
 
{
82
 
 
83
 
}
84
 
 
85
 
/*
86
 
 * Initialize the GUI interface for the plugin 
87
 
 */
88
 
void [pluginname]::initGui()
89
 
{
90
 
  QPopupMenu *pluginMenu = mQGisIface->getPluginMenu("&[menuname]");
91
 
  mMenuId = pluginMenu->insertItem(QIconSet(icon),"&[menuitemname]", this, SLOT(run()));
92
 
 
93
 
  pluginMenu->setWhatsThis(mMenuId, tr("Replace this with a short description of the what the plugin does"));
94
 
 
95
 
  // Create the action for tool
96
 
  mQActionPointer = new QAction("[menuitemname]", QIconSet(icon), "&icon",0, this, "run");
97
 
  // Connect the action to the run
98
 
  connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
99
 
  // Add the toolbar
100
 
  mToolBarPointer = new QToolBar((QMainWindow *) mQGisApp, "[menuname]");
101
 
  mToolBarPointer->setLabel("[menuitemname]");
102
 
  // Add the to the toolbar
103
 
  mQGisIface->addToolBarIcon(mQActionPointer);
104
 
 
105
 
}
106
 
//method defined in interface
107
 
void [pluginname]::help()
108
 
{
109
 
  //implement me!
110
 
}
111
 
 
112
 
// Slot called when the buffer menu item is activated
113
 
void [pluginname]::run()
114
 
{
115
 
  [pluginname]Gui *myPluginGui=new [pluginname]Gui(mQGisApp,"[menuitemname]",true,0);
116
 
  //listen for when the layer has been made so we can draw it
117
 
  connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
118
 
  connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
119
 
  myPluginGui->show();
120
 
}
121
 
 
122
 
// Unload the plugin by cleaning up the GUI
123
 
void [pluginname]::unload()
124
 
{
125
 
  // remove the GUI
126
 
  mQGisIface->removePluginMenuItem("&[menuname]",mMenuId);
127
 
  mQGisIface->removeToolBarIcon(mQActionPointer);
128
 
  delete mQActionPointer;
129
 
}
130
 
 
131
 
//////////////////////////////////////////////////////////////////////
132
 
//
133
 
//                  END OF MANDATORY PLUGIN METHODS
134
 
//
135
 
//////////////////////////////////////////////////////////////////////
136
 
//
137
 
// The following methods are provided to demonstrate how you can 
138
 
// load a vector or raster layer into the main gui. Please delete
139
 
// if you are not intending to use these. Note also that there are
140
 
// ways in which layers can be loaded.
141
 
//
142
 
 
143
 
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
144
 
//layer
145
 
void [pluginname]::drawRasterLayer(QString theQString)
146
 
{
147
 
  mQGisIface->addRasterLayer(theQString);
148
 
}
149
 
 
150
 
//!draw a vector layer in the qui - intended to respond to signal sent by 
151
 
// dialog when it as finished creating a layer. It needs to be given 
152
 
// vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
153
 
void [pluginname]::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
154
 
{
155
 
  mQGisIface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
156
 
}
157
 
 
158
 
 
159
 
//////////////////////////////////////////////////////////////////////////
160
 
//
161
 
//
162
 
//  THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
163
 
//    YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
164
 
//      MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
165
 
//
166
 
//
167
 
//////////////////////////////////////////////////////////////////////////
168
 
 
169
 
 
170
 
/** 
171
 
 * Required extern functions needed  for every plugin 
172
 
 * These functions can be called prior to creating an instance
173
 
 * of the plugin class
174
 
 */
175
 
// Class factory to return a new instance of the plugin class
176
 
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
177
 
{
178
 
  return new [pluginname](theQGisAppPointer, theQgisInterfacePointer);
179
 
}
180
 
// Return the name of the plugin - note that we do not user class members as
181
 
// the class may not yet be insantiated when this method is called.
182
 
QGISEXTERN QString name()
183
 
{
184
 
  return sName;
185
 
}
186
 
 
187
 
// Return the description
188
 
QGISEXTERN QString description()
189
 
{
190
 
  return sDescription;
191
 
}
192
 
 
193
 
// Return the type (either UI or MapLayer plugin)
194
 
QGISEXTERN int type()
195
 
{
196
 
  return sPluginType;
197
 
}
198
 
 
199
 
// Return the version number for the plugin
200
 
QGISEXTERN QString version()
201
 
{
202
 
  return sPluginVersion;
203
 
}
204
 
 
205
 
// Delete ourself
206
 
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
207
 
{
208
 
  delete thePluginPointer;
209
 
}