/
plugin.cpp
213 lines (183 loc) · 6.63 KB
/
plugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***************************************************************************
[pluginlcasename].cpp
[plugindescription]
-------------------
begin : [PluginDate]
copyright : [(C) Your Name and Date]
email : [Your Email]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
//
// QGIS Specific includes
//
#include <qgisapp.h>
#include <qgisgui.h>
#include <qgsmaplayer.h>
#include <qgsrasterlayer.h>
#include "[pluginlcasename].h"
//the gui subclass
#include "[pluginlcasename]gui.h"
//
// Qt4 Related Includes
//
#include <QToolBar>
#include <QMenuBar>
#include <QMessageBox>
#include <QMenu>
#include <QLineEdit>
#include <QAction>
#include <QApplication>
#include <QCursor>
//non qt includes
#include <iostream>
#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
#else
#define QGISEXTERN extern "C"
#endif
static const char * const sIdent = "$Id$";
static const char * const sName = "[menuitemname]";
static const char * const sDescription = "[plugindescription]";
static const char * const sPluginVersion = "Version 0.1";
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
//////////////////////////////////////////////////////////////////////
//
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
//
//////////////////////////////////////////////////////////////////////
/**
* Constructor for the plugin. The plugin is passed a pointer to the main app
* and an interface object that provides access to exposed functions in QGIS.
* @param theQGisApp - Pointer to the QGIS main window
* @param theQGisInterface - Pointer to the QGIS interface object
*/
[pluginname]::[pluginname](QgisApp * theQGisApp,
QgisIface * theQgisInterface):
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
mQGisApp(theQGisApp),
mQGisIface(theQgisInterface)
{
}
[pluginname]::~[pluginname]()
{
}
/*
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
* added to the plugin registry in the QGIS application.
*/
void [pluginname]::initGui()
{
// Create the action for tool
mQActionPointer = new QAction(QIcon(":/[pluginlcasename]/[pluginlcasename].png"),"[menuitemname]", this);
// Set the what's this text
mQActionPointer->setWhatsThis(tr("Replace this with a short description of the what the plugin does"));
// Connect the action to the run
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
// Add the toolbar
mToolBarPointer = new QToolBar((QMainWindow *) mQGisApp, "[menuname]");
mToolBarPointer->setLabel("[menuitemname]");
// Add the to the toolbar
mQGisIface->addToolBarIcon(mQActionPointer);
mQGisIface->addPluginMenu("&[menuname]", mQActionPointer);
}
//method defined in interface
void [pluginname]::help()
{
//implement me!
}
// Slot called when the menu item is activated
// If you created more menu items / toolbar buttons in initiGui, you should
// create a separate handler for each action - this single run() method will
// not be enough
void [pluginname]::run()
{
[pluginname]Gui *myPluginGui=new [pluginname]Gui(mQGisApp, QgisGui::ModalDialogFlags);
//listen for when the layer has been made so we can draw it
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
myPluginGui->show();
}
// Unload the plugin by cleaning up the GUI
void [pluginname]::unload()
{
// remove the GUI
mQGisIface->removePluginMenu("&[menuname]",mQActionPointer);
mQGisIface->removeToolBarIcon(mQActionPointer);
delete mQActionPointer;
}
//////////////////////////////////////////////////////////////////////
//
// END OF MANDATORY PLUGIN METHODS
//
//////////////////////////////////////////////////////////////////////
//
// The following methods are provided to demonstrate how you can
// load a vector or raster layer into the main gui. Please delete
// if you are not intending to use these. Note also that there are
// ways in which layers can be loaded.
//
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
//layer
void [pluginname]::drawRasterLayer(QString theQString)
{
mQGisIface->addRasterLayer(theQString);
}
//!draw a vector layer in the qui - intended to respond to signal sent by
// dialog when it as finished creating a layer. It needs to be given
// vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
void [pluginname]::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
{
mQGisIface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
}
//////////////////////////////////////////////////////////////////////////
//
//
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
//
//
//////////////////////////////////////////////////////////////////////////
/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
* of the plugin class
*/
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
{
return new [pluginname](theQGisAppPointer, theQgisInterfacePointer);
}
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
{
return sName;
}
// Return the description
QGISEXTERN QString description()
{
return sDescription;
}
// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return sPluginType;
}
// Return the version number for the plugin
QGISEXTERN QString version()
{
return sPluginVersion;
}
// Delete ourself
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
{
delete thePluginPointer;
}