Skip to content

Commit 3271d3c

Browse files
author
timlinux
committed
Plugin builder should now successfully generate a compileable plugin framework - ready to be extended by the developer.
I have made a number of improvements over the old 0.7x plugin builder - most importantly the plugins tat are generated now each have their own unique user defined classname and all the filenames are renamed from a generic plugin* to [users plugin name]* git-svn-id: http://svn.osgeo.org/qgis/trunk@5198 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a9c915c commit 3271d3c

File tree

6 files changed

+96
-88
lines changed

6 files changed

+96
-88
lines changed

src/plugins/plugin_template/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ libqgis_plugin_[pluginlcasename]_la_CXXFLAGS = $(CXXFLAGS) \
7676
$(GEOS_CFLAGS) \
7777
-I../../core \
7878
-I../../ui \
79-
-I../../gui \
80-
» » » -I../../raster
79+
-I../../gui -I../../raster
80+
8181
libqgis_plugin_[pluginlcasename]_la_LDFLAGS = -avoid-version -module

src/plugins/plugin_template/plugin.cpp

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
/***************************************************************************
2-
plugin.cpp
3-
Import tool for various worldmap analysis output files
4-
Functions:
2+
[pluginlcasename].cpp
3+
[plugindescription]
54
6-
-------------------
7-
begin : Jan 21, 2004
8-
copyright : (C) 2004 by Tim Sutton
9-
email : tim@linfiniti.com
5+
-------------------
6+
begin : [PluginDate]
7+
copyright : [(C) Your Name and Date]
8+
email : [Your Email]
109
11-
***************************************************************************/
12-
13-
/***************************************************************************
10+
***************************************************************************
1411
* *
1512
* This program is free software; you can redistribute it and/or modify *
1613
* it under the terms of the GNU General Public License as published by *
@@ -20,30 +17,35 @@ email : tim@linfiniti.com
2017
***************************************************************************/
2118
/* $Id$ */
2219

23-
// includes
20+
//
21+
// QGIS Specific includes
22+
//
2423

2524
#include <qgisapp.h>
25+
#include <qgisgui.h>
2626
#include <qgsmaplayer.h>
2727
#include <qgsrasterlayer.h>
2828
#include "[pluginlcasename].h"
29+
//the gui subclass
30+
#include "[pluginlcasename]gui.h"
2931

32+
//
33+
// Qt4 Related Includes
34+
//
3035

31-
#include <q3toolbar.h>
32-
#include <qmenubar.h>
33-
#include <qmessagebox.h>
34-
#include <q3popupmenu.h>
35-
#include <qlineedit.h>
36-
#include <qaction.h>
37-
#include <qapplication.h>
38-
#include <qcursor.h>
36+
#include <QToolBar>
37+
#include <QMenuBar>
38+
#include <QMessageBox>
39+
#include <QMenu>
40+
#include <QLineEdit>
41+
#include <QAction>
42+
#include <QApplication>
43+
#include <QCursor>
3944

4045
//non qt includes
4146
#include <iostream>
4247

43-
//the gui subclass
44-
#include "[pluginlcasename]gui.h"
4548

46-
// xpm for creating the toolbar icon
4749
#ifdef WIN32
4850
#define QGISEXTERN extern "C" __declspec( dllexport )
4951
#else
@@ -70,9 +72,9 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
7072
*/
7173
[pluginname]::[pluginname](QgisApp * theQGisApp,
7274
QgisIface * theQgisInterface):
75+
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
7376
mQGisApp(theQGisApp),
74-
mQGisIface(theQgisInterface),
75-
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType)
77+
mQGisIface(theQgisInterface)
7678
{
7779
}
7880

@@ -86,18 +88,18 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
8688
*/
8789
void [pluginname]::initGui()
8890
{
89-
Q3PopupMenu *pluginMenu = qGisInterface->getPluginMenu("&[menuname]");
91+
QMenu *pluginMenu = mQGisIface->getPluginMenu("&[menuname]");
9092
//set teh icon from the resource file
91-
menuId = pluginMenu->insertItem(QIcon(":/[pluginlcasename]/[pluginlcasename].png"),"&[menuitemname]", this, SLOT(run()));
93+
mMenuId = pluginMenu->insertItem(QIcon(":/[pluginlcasename]/[pluginlcasename].png"),"&[menuitemname]", this, SLOT(run()));
9294

93-
pluginMenu->setWhatsThis(menuId, tr("Replace this with a short description of the what the plugin does"));
95+
pluginMenu->setWhatsThis(mMenuId, tr("Replace this with a short description of the what the plugin does"));
9496

9597
// Create the action for tool
96-
mQActionPointer = new QAction("[menuitemname]", QIcon(icon), "&icon",0, this, "run");
98+
mQActionPointer = new QAction(QIcon(":/[pluginlcasename]/[pluginlcasename].png"),"[menuitemname]", this);
9799
// Connect the action to the run
98100
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
99101
// Add the toolbar
100-
mToolBarPointer = new Q3ToolBar((Q3MainWindow *) mQGisApp, "[menuname]");
102+
mToolBarPointer = new QToolBar((QMainWindow *) mQGisApp, "[menuname]");
101103
mToolBarPointer->setLabel("[menuitemname]");
102104
// Add the to the toolbar
103105
mQGisIface->addToolBarIcon(mQActionPointer);
@@ -112,7 +114,7 @@ void [pluginname]::help()
112114
// Slot called when the buffer menu item is activated
113115
void [pluginname]::run()
114116
{
115-
[pluginname]Gui *myPluginGui=new [pluginname]Gui(mQGisApp,"[menuitemname]",true,0);
117+
[pluginname]Gui *myPluginGui=new [pluginname]Gui(mQGisApp, QgisGui::ModalDialogFlags);
116118
//listen for when the layer has been made so we can draw it
117119
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
118120
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
@@ -123,7 +125,7 @@ void [pluginname]::run()
123125
void [pluginname]::unload()
124126
{
125127
// remove the GUI
126-
mQGisIface->removePluginMenuItem("&[menuname]",menuId);
128+
mQGisIface->removePluginMenuItem("&[menuname]",mMenuId);
127129
mQGisIface->removeToolBarIcon(mQActionPointer);
128130
delete mQActionPointer;
129131
}

src/plugins/plugin_template/plugin.h

+16-10
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@
3434
* DON'T: separate variable names using underscores: my_variable_name (NO!)
3535
*
3636
* **************************************************************************/
37-
#ifndef [pluginname]
38-
#define [pluginname]
39-
#include "../qgisplugin.h"
40-
#include <qwidget.h>
37+
#ifndef [pluginname]_H
38+
#define [pluginname]_H
39+
40+
//QT4 includes
41+
#include <QObject>
4142

42-
#include "../../gui/qgisapp.h"
43+
//QGIS includes
44+
#include <qgisapp.h>
45+
#include "../qgisplugin.h"
4346

47+
//forward declarations
48+
class QToolBar;
4449

4550
/**
4651
* \class Plugin
@@ -49,7 +54,8 @@
4954
*/
5055
class [pluginname]:public QObject, public QgisPlugin
5156
{
52-
Q_OBJECT public:
57+
Q_OBJECT;
58+
public:
5359

5460
//////////////////////////////////////////////////////////////////////
5561
//
@@ -63,9 +69,9 @@ class [pluginname]:public QObject, public QgisPlugin
6369
* @param Pointer to the QgisApp object
6470
* @param Pointer to the QgisIface object.
6571
*/
66-
[pluginname](QgisApp * , QgisIface * );
72+
[pluginname](QgisApp * theApplication, QgisIface * theInterface);
6773
//! Destructor
68-
virtual ~ [pluginname]();
74+
virtual ~[pluginname]();
6975

7076
public slots:
7177
//! init the gui
@@ -106,7 +112,7 @@ public slots:
106112
//! Id of the plugin's menu. Used for unloading
107113
int mMenuId;
108114
//! Pointer to our toolbar
109-
Q3ToolBar *mToolBarPointer;
115+
QToolBar *mToolBarPointer;
110116
//! Pionter to QGIS main application object
111117
QgisApp *mQGisApp;
112118
//! Pointer to the QGIS interface object
@@ -120,4 +126,4 @@ public slots:
120126
////////////////////////////////////////////////////////////////////
121127
};
122128

123-
#endif
129+
#endif //[pluginname]_H

src/plugins/plugin_template/plugingui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* the Free Software Foundation; either version 2 of the License, or *
1010
* (at your option) any later version. *
1111
***************************************************************************/
12-
#include "plugingui.h"
12+
#include "[pluginlcasename]gui.h"
1313

1414
//qt includes
1515

@@ -21,7 +21,7 @@
2121
}
2222

2323
[pluginname]Gui::[pluginname]Gui( QWidget* parent, Qt::WFlags fl )
24-
: [pluginname]GuiBase( parent, fl )
24+
: QDialog ( parent, fl )
2525
{
2626
setupUi(this);
2727
}

src/plugins/plugin_template/plugingui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define [pluginname]GUI_H
1414

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

1818
/**
1919
@author Tim Sutton

src/plugins/qgisplugin.h

+42-42
Original file line numberDiff line numberDiff line change
@@ -46,74 +46,74 @@ class QgisPlugin
4646
};
4747
4848
@todo XXX this may be a hint that there should be subclasses
49-
*/
49+
*/
5050
typedef enum PLUGINTYPE
51-
{
52-
UI = 1, /* user interface plug-in */
53-
MAPLAYER /* map layer plug-in */
54-
};
51+
{
52+
UI = 1, /* user interface plug-in */
53+
MAPLAYER /* map layer plug-in */
54+
};
5555

5656

5757
QgisPlugin ( QString const & name = "",
58-
QString const & description = "",
59-
QString const & version = "",
60-
PLUGINTYPE const & type = MAPLAYER )
61-
: mName(name),
62-
mDescription(description),
63-
mVersion(version),
64-
mType(type)
65-
{}
58+
QString const & description = "",
59+
QString const & version = "",
60+
PLUGINTYPE const & type = MAPLAYER )
61+
: mName(name),
62+
mDescription(description),
63+
mVersion(version),
64+
mType(type)
65+
{}
6666

6767
virtual ~QgisPlugin()
68-
{}
68+
{}
6969

7070
//! Get the name of the plugin
7171
QString const & name() const
72-
{
73-
return mName;
74-
}
72+
{
73+
return mName;
74+
}
7575

7676
QString & name()
77-
{
78-
return mName;
79-
}
77+
{
78+
return mName;
79+
}
8080

8181
//! Version of the plugin
8282
QString const & version() const
83-
{
84-
return mVersion;
85-
}
83+
{
84+
return mVersion;
85+
}
8686

8787
//! Version of the plugin
88-
QString & version()
89-
{
90-
return mVersion;
91-
}
88+
QString & version()
89+
{
90+
return mVersion;
91+
}
9292

9393
//! A brief description of the plugin
9494
QString const & description() const
95-
{
96-
return mDescription;
97-
}
95+
{
96+
return mDescription;
97+
}
9898

9999
//! A brief description of the plugin
100100
QString & description()
101-
{
102-
return mDescription;
103-
}
101+
{
102+
return mDescription;
103+
}
104104

105105
//! Plugin type, either UI or map layer
106106
QgisPlugin::PLUGINTYPE const & type() const
107-
{
108-
return mType;
109-
}
107+
{
108+
return mType;
109+
}
110110

111111

112112
//! Plugin type, either UI or map layer
113113
QgisPlugin::PLUGINTYPE & type()
114-
{
115-
return mType;
116-
}
114+
{
115+
return mType;
116+
}
117117

118118
/// function to initialize connection to GUI
119119
virtual void initGui() = 0;
@@ -134,9 +134,9 @@ class QgisPlugin
134134

135135
/// UI or MAPLAYER plug-in
136136
/**
137-
@todo Really, might be indicative that this needs to split into
138-
maplayer vs. ui plug-in vs. other kind of plug-in
139-
*/
137+
@todo Really, might be indicative that this needs to split into
138+
maplayer vs. ui plug-in vs. other kind of plug-in
139+
*/
140140
PLUGINTYPE mType;
141141

142142
}; // class QgisPlugin

0 commit comments

Comments
 (0)