Skip to content

Commit db95916

Browse files
author
wonder
committedMay 6, 2007
- updated plugin template
- replaced plugin builder with a newer one in python (hopefully for all platforms) - replaced Makefile.am with CMakeLists.txt for building new plugins git-svn-id: http://svn.osgeo.org/qgis/trunk@6931 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 300ab29 commit db95916

File tree

12 files changed

+356
-440
lines changed

12 files changed

+356
-440
lines changed
 

‎src/plugins/plugin_builder.pl

Lines changed: 0 additions & 193 deletions
This file was deleted.

‎src/plugins/plugin_builder.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
2+
# A script to automate creation of a new QGIS plugin using the plugin_template
3+
# Copyright 2007 Martin Dobias
4+
#
5+
# Original authors of Perl version: Gary Sherman and Tim Sutton
6+
7+
import os, sys, shutil, re
8+
9+
def template_file(file):
10+
return os.path.join('plugin_template', file)
11+
12+
def plugin_file(pluginDir, file):
13+
return os.path.join(pluginDir, file)
14+
15+
# make sure we are in a the plugins directory otherwise the changes this script will make will
16+
# wreak havoc....
17+
18+
myDir = os.getcwd()
19+
print "Checking that we are in the <qgis dir>/src/plugins/ directory....",
20+
21+
pluginsDirectory = os.path.join('src','plugins')
22+
23+
if myDir[-len(pluginsDirectory):] == pluginsDirectory:
24+
print "yes"
25+
else:
26+
print "no"
27+
print myDir
28+
print "Please relocate to the plugins directory before attempting to run this script."
29+
sys.exit(1)
30+
31+
32+
# get the needed information from the user
33+
print "Enter the directory name under qgis/src/plugins/ where your new plugin will be created."
34+
print "We suggest using a lowercase underscore separated name e.g. clever_plugin"
35+
print "Directory for the new plugin:",
36+
37+
pluginDir = raw_input()
38+
39+
print
40+
print "Enter the name that will be used when creating the plugin library."
41+
print "The name should be entered as a mixed case name with no spaces. e.g. CleverTool"
42+
print "The plugin name will be used in the following ways:"
43+
print "1) it will be 'lower cased' and used as the root of the generated lib name"
44+
print " e.g. libqgis_plugin_clevertool"
45+
print "2) in its upper cased form it will be used as the basis for class names, in particular"
46+
print " CleverToolGuiBase <- The base class for the plugins configuration dialog / gui generated by uic"
47+
print " CleverToolGui <- The concrete class for the plugins configuration dialog"
48+
print "3) CleverTool <- The class that includes the plugin loader instructions and"
49+
print " and calls to your custom application logic"
50+
print "4) clevertool.h, clevertool.cpp etc. <- the filenames used to hold the above derived classes"
51+
print "Plugin name:",
52+
53+
pluginName = raw_input()
54+
pluginLCaseName = pluginName.lower()
55+
56+
print
57+
print "Enter a short description (typically one line)"
58+
print "e.g. The clever plugin does clever stuff in QGIS"
59+
print "Plugin description:",
60+
pluginDescription = raw_input()
61+
62+
print
63+
print "Enter the name of the application menu that will be created for your plugin"
64+
print "Clever Tools"
65+
print "Menu name:",
66+
menuName = raw_input()
67+
68+
print
69+
print "Enter the name of the menu entry (under the menu that you have just defined) that"
70+
print "will be used to invoke your plugin. e.g. Clever Plugin"
71+
print "Menu item name:",
72+
menuItemName = raw_input()
73+
74+
# print a summary of what's about to happen
75+
# and ask if we should proceed
76+
print
77+
print "Summary of plugin parameters:"
78+
print "---------------------------------------------"
79+
print "Plugin directory: ", pluginDir
80+
print "Name of the plugin: ", pluginName
81+
print "Description of the plugin:", pluginDescription
82+
print "Menu name: ", menuName
83+
print "Menu item name: ", menuItemName
84+
print
85+
print "Warning - Proceeding will make changes to CMakeLists.txt in this directory."
86+
print "Create the plugin? [y/n]:",
87+
88+
createIt = raw_input()
89+
90+
if createIt.lower() != 'y':
91+
print "Plugin creation cancelled, exiting"
92+
sys.exit(2)
93+
94+
# create the plugin and modify the build files
95+
96+
# create the new plugin directory
97+
os.mkdir(pluginDir)
98+
99+
# copy files to appropriate names
100+
shutil.copy(template_file('CMakeLists.txt'), pluginDir)
101+
shutil.copy(template_file('README.whatnext'), os.path.join(pluginDir, 'README'))
102+
shutil.copy(template_file('plugin.qrc'), os.path.join(pluginDir, pluginLCaseName + '.qrc'))
103+
shutil.copy(template_file('plugin.png'), os.path.join(pluginDir, pluginLCaseName + '.png'))
104+
shutil.copy(template_file('plugin.cpp'), os.path.join(pluginDir, pluginLCaseName + '.cpp'))
105+
shutil.copy(template_file('plugin.h'), os.path.join(pluginDir, pluginLCaseName + '.h'))
106+
shutil.copy(template_file('plugingui.cpp'), os.path.join(pluginDir, pluginLCaseName + 'gui.cpp'))
107+
shutil.copy(template_file('plugingui.h'), os.path.join(pluginDir, pluginLCaseName + 'gui.h'))
108+
shutil.copy(template_file('plugingui.ui'), os.path.join(pluginDir, pluginLCaseName + 'gui.ui'))
109+
110+
# Substitute the plugin specific vars in the various files
111+
# This is a brute force approach but its quick and dirty :)
112+
#
113+
114+
files = [ plugin_file(pluginDir, 'CMakeLists.txt'),
115+
plugin_file(pluginDir, pluginLCaseName + '.qrc'),
116+
plugin_file(pluginDir, pluginLCaseName + '.cpp'),
117+
plugin_file(pluginDir, pluginLCaseName + '.h'),
118+
plugin_file(pluginDir, pluginLCaseName + 'gui.cpp'),
119+
plugin_file(pluginDir, pluginLCaseName + 'gui.h'),
120+
plugin_file(pluginDir, pluginLCaseName + 'gui.ui') ]
121+
122+
# replace occurences of [pluginlcasename], [pluginname], [plugindescription], [menuname], [menutiem]
123+
# in template with the values from user
124+
replacements = [ ('\\[pluginlcasename\\]', pluginLCaseName),
125+
('\\[pluginname\\]', pluginName),
126+
('\\[plugindescription\\]', pluginDescription),
127+
('\\[menuname\\]', menuName),
128+
('\\[menuitemname\\]', menuItemName) ]
129+
130+
for file in files:
131+
132+
# read contents of the file
133+
f = open(file)
134+
content = f.read()
135+
f.close()
136+
137+
# replace everything neccessary
138+
for repl in replacements:
139+
content = re.sub(repl[0], repl[1], content)
140+
141+
# write changes to the file
142+
f = open(file, "w")
143+
f.write(content)
144+
f.close()
145+
146+
147+
# Add an entry to src/plugins/CMakeLists.txt
148+
f = open('CMakeLists.txt','a')
149+
f.write('\nSUBDIRS ('+pluginDir+')\n')
150+
f.close()
151+
152+
print "Your plugin %s has been created in %s, CMakeLists.txt has been modified." % (pluginName, pluginDir)
153+
print
154+
print "Once your plugin has successfully built, please see %s/README for" % (pluginDir)
155+
print "hints on how to get started."
156+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET ([pluginlcasename]_SRCS
6+
[pluginlcasename].cpp
7+
[pluginlcasename]gui.cpp
8+
)
9+
10+
SET ([pluginlcasename]_UIS [pluginlcasename]gui.ui)
11+
12+
SET ([pluginlcasename]_MOC_HDRS
13+
[pluginlcasename].h
14+
[pluginlcasename]gui.h
15+
)
16+
17+
SET ([pluginlcasename]_RCCS [pluginlcasename].qrc)
18+
19+
########################################################
20+
# Build
21+
22+
QT4_WRAP_UI ([pluginlcasename]_UIS_H ${[pluginlcasename]_UIS})
23+
24+
QT4_WRAP_CPP ([pluginlcasename]_MOC_SRCS ${[pluginlcasename]_MOC_HDRS})
25+
26+
QT4_ADD_RESOURCES([pluginlcasename]_RCC_SRCS ${[pluginlcasename]_RCCS})
27+
28+
ADD_LIBRARY ([pluginlcasename]plugin MODULE ${[pluginlcasename]_SRCS} ${[pluginlcasename]_MOC_SRCS} ${[pluginlcasename]_RCC_SRCS} ${[pluginlcasename]_UIS_H})
29+
30+
INCLUDE_DIRECTORIES(
31+
${CMAKE_CURRENT_BINARY_DIR}
32+
../../core ../../core/raster ../../core/renderer ../../core/symbology
33+
../../gui
34+
..
35+
)
36+
37+
TARGET_LINK_LIBRARIES([pluginlcasename]plugin
38+
${QT_LIBRARIES}
39+
qgis_core
40+
qgis_gui
41+
)
42+
43+
44+
########################################################
45+
# Install
46+
47+
INSTALL(TARGETS [pluginlcasename]plugin
48+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
49+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
50+

‎src/plugins/plugin_template/Makefile.am

Lines changed: 0 additions & 81 deletions
This file was deleted.

‎src/plugins/plugin_template/README.whatnext

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ QgsPlugin is an ABC that defines required behaviour your plugin must provide. Se
2424
What are all the files in my generated plugin directory for?
2525
-------------------------------------------------------------
2626

27-
Makefile.am
28-
This is the generated Makefile specification for your plugin. You will see that specifies c++ include paths (-I) and library linkages -l) to Qt4, GDAL, GEOS, QGIS Core, QGIS Ui, QGIS Gui and QGis Raster. You should add you application specific dependencies and source files to this Makefile.
27+
CMakeLists.txt
28+
This is the generated CMake file that builds the plugin. You should add you application specific dependencies and source files to this file.
2929

3030
[pluginlcasename].h
3131
[pluginlcasename].cpp
3232
This is the class that provides the 'glue' between your custom application logic and the QGIS application. You will see that a number of methods are already implemented for you - including some examples of how to add a raster or vector layer to the main application map canvas. This class is a concrete implementation of QgisPlugin (which defines required behaviour for a plugin). In particular, a plugin has a number of static methods and members so that the QgsPluginManager and plugin loader logic can identify each plugin, create an appropriate menu entry for it etc. Note there is nothing stopping you creating multiple toolbar icons and menu entries for a single plugin. By default though a single menu entry and toolbar button is created and its pre-configured to call the run() method in this class when selected. This default implementation provided for you by the plugin builder is well documented, so please refer to the code for further advice.
3333

34-
[pluginlcasename]guibase.ui
35-
[pluginlcasename]guibase.ui.h
36-
This is an Abstract Base Class implemented in Qt4 fashion as a Qt designer 'ui' file. It defines the look of the default plugin dialog without implementing any application logic. You can modify this form to suite your needs or completely remove it if your plugin does not need to display a user form (e.g. for custom MapTools).
34+
[pluginlcasename]gui.ui
35+
This is a Qt designer 'ui' file. It defines the look of the default plugin dialog without implementing any application logic. You can modify this form to suite your needs or completely remove it if your plugin does not need to display a user form (e.g. for custom MapTools).
3736

3837

3938
[pluginlcasename]gui.cpp
@@ -63,4 +62,4 @@ QGIS is distributed under the Gnu Public License. If you create a useful plugin
6362
Have fun and thank you for choosing QGIS.
6463

6564
The QGIS Team
66-
2006
65+
2007

‎src/plugins/plugin_template/plugin.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/***************************************************************************
22
[pluginlcasename].cpp
33
[plugindescription]
4-
54
-------------------
65
begin : [PluginDate]
76
copyright : [(C) Your Name and Date]
@@ -115,9 +114,7 @@ void [pluginname]::run()
115114
{
116115
[pluginname]Gui *myPluginGui=new [pluginname]Gui(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);
117116
myPluginGui->setAttribute(Qt::WA_DeleteOnClose);
118-
//listen for when the layer has been made so we can draw it
119-
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
120-
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
117+
121118
myPluginGui->show();
122119
}
123120

@@ -130,33 +127,6 @@ void [pluginname]::unload()
130127
delete mQActionPointer;
131128
}
132129

133-
//////////////////////////////////////////////////////////////////////
134-
//
135-
// END OF MANDATORY PLUGIN METHODS
136-
//
137-
//////////////////////////////////////////////////////////////////////
138-
//
139-
// The following methods are provided to demonstrate how you can
140-
// load a vector or raster layer into the main gui. Please delete
141-
// if you are not intending to use these. Note also that there are
142-
// ways in which layers can be loaded.
143-
//
144-
145-
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
146-
//layer
147-
void [pluginname]::drawRasterLayer(QString theQString)
148-
{
149-
mQGisIface->addRasterLayer(theQString);
150-
}
151-
152-
//!draw a vector layer in the qui - intended to respond to signal sent by
153-
// dialog when it as finished creating a layer. It needs to be given
154-
// vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
155-
void [pluginname]::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
156-
{
157-
mQGisIface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
158-
}
159-
160130

161131
//////////////////////////////////////////////////////////////////////////
162132
//

‎src/plugins/plugin_template/plugin.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/***************************************************************************
2-
plugin.h
3-
Functions:
4-
-------------------
2+
[pluginlcasename].h
3+
-------------------
54
begin : Jan 21, 2004
65
copyright : (C) 2004 by Tim Sutton
76
email : tim@linfiniti.com
@@ -84,23 +83,6 @@ public slots:
8483
//! show the help document
8584
void help();
8685

87-
//////////////////////////////////////////////////////////////////////
88-
//
89-
// END OF MANDATORY PLUGIN METHODS
90-
//
91-
//////////////////////////////////////////////////////////////////////
92-
//
93-
// The following methods are provided to demonstrate how you can
94-
// load a vector or raster layer into the main gui. Please delete
95-
// if you are not intending to use these. Note also that there are
96-
// other ways in which layers can be loaded.
97-
//
98-
99-
//!draw a raster layer in the qui
100-
void drawRasterLayer(QString);
101-
//! Add a vector layer given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
102-
void drawVectorLayer(QString,QString,QString);
103-
10486
private:
10587

10688
////////////////////////////////////////////////////////////////////

‎src/plugins/plugin_template/plugingui.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828

2929
void [pluginname]Gui::on_buttonBox_accepted()
3030
{
31-
//
32-
// If you have a produced a raster layer using your plugin, you can ask qgis to
33-
// add it to the view using:
34-
// emit drawRasterLayer(QString("layername"));
35-
// or for a vector layer
36-
// emit drawVectorLayer(QString("pathname"),QString("layername"),QString("provider name (either ogr or postgres"));
37-
//
3831
//close the dialog
3932
accept();
4033
}
@@ -48,3 +41,4 @@ void [pluginname]Gui::on_buttonBox_helpRequested()
4841
{
4942
QgsContextHelp::run(context_id);
5043
}
44+

‎src/plugins/plugin_template/plugingui.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#define [pluginname]GUI_H
1414

1515
#include <QDialog>
16-
#include <ui_[pluginlcasename]guibase.h>
16+
#include <ui_[pluginlcasename]gui.h>
1717

1818
/**
1919
@author Tim Sutton
2020
*/
21-
class [pluginname]Gui : public QDialog, private Ui::[pluginname]GuiBase
21+
class [pluginname]Gui : public QDialog, private Ui::[pluginname]Gui
2222
{
2323
Q_OBJECT
2424
public:
@@ -33,9 +33,6 @@ private slots:
3333
void on_buttonBox_rejected();
3434
void on_buttonBox_helpRequested();
3535

36-
signals:
37-
void drawRasterLayer(QString);
38-
void drawVectorrLayer(QString,QString,QString);
3936
};
4037

4138
#endif

‎src/plugins/plugin_template/plugingui.ui

Lines changed: 139 additions & 0 deletions
Large diffs are not rendered by default.

‎src/plugins/plugin_template/pluginguibase.ui

Lines changed: 0 additions & 76 deletions
This file was deleted.

‎src/plugins/plugin_template/pluginguibase.ui.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.