- Promoted name, description, version, and type strings to QgisPlugin base

class.

- Type now a formal enumerated typedef

- Propogated changes forward to existing plug-ins


git-svn-id: http://svn.osgeo.org/qgis/trunk@994 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mcoletti 2004-03-08 23:50:05 +00:00
parent c7efec252e
commit 2e54ed8648
16 changed files with 304 additions and 400 deletions

View File

@ -18,19 +18,19 @@ plugin_LTLIBRARIES = exampleplugin.la
%.cpp: %.ui
$(UIC) -o $@ -impl $*.h $<
exampleplugin_la_SOURCES = exampleplugin.cpp \
$(example_UI)
nodist_exampleplugin_la_SOURCES = $(example_MOC)
example_MOC = exampleplugin.moc.cpp
example_UI =
# UI dependencies
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I../../src
exampleplugin_la_LIBADD = $(QT_LDADD)
exampleplugin_la_LDFLAGS = -avoid-version -module

View File

@ -29,115 +29,107 @@
#include "matrix1.xpm"
// qgis includes
#include "../../src/qgsmaplayer.h"
static const char * const ident_ = "$Id$";
static const char *pluginVersion = "0.1";
static const char * const name_ = "Example Plug-in";
static const char * const description_ = "This example plugin installs menu items and a toolbar";
static const char * const version_ = "Version 0.0";
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
/**
* 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 qgis Pointer to the QGIS main window
* @parma _qI Pointer to the QGIS interface object
*/
ExamplePlugin::ExamplePlugin(QgisApp * qgis, QgisIface * _qI):qgisMainWindow(qgis), qI(_qI)
ExamplePlugin::ExamplePlugin(QgisApp * qgis, QgisIface * _qI)
: qgisMainWindow(qgis), qI(_qI), QgisPlugin( name_, description_, version_, type_ )
{
/** Initialize the plugin and set the required attributes */
pName = "Example Plugin";
pVersion = "Version 0.0";
pDescription = "This example plugin installs menu items and a toolbar";
// see if we can popup a message box in qgis on load
QMessageBox::information(qgisMainWindow, "Message From Plugin", "This message is from within the example plugin.");
// see if we can popup a message box in qgis on load
QMessageBox::information(qgisMainWindow, "Message From Plugin",
"This message is from within the example plugin.");
// Zoom the map canvas to the full extent of all layers
qI->zoomFull();
// Zoom the map canvas to the full extent of all layers
qI->zoomFull();
QMessageBox::information(qgisMainWindow, "Message From Plugin", "Click Ok to zoom previous");
// zoom the map back to previous extent
qI->zoomPrevious();
// call a function defined in the QgisIface class and send its value to stdout
QgsMapLayer * myMapLayer = qI->activeLayer();
std::cout << "Current map layer is: " << myMapLayer->name() << std::endl;
QMessageBox::information(qgisMainWindow, "Message From Plugin", "Click Ok to zoom previous");
// zoom the map back to previous extent
qI->zoomPrevious();
// call a function defined in the QgisIface class and send its value to stdout
QgsMapLayer *myMapLayer = qI->activeLayer();
std::cout << "Current map layer is: " << myMapLayer->name() << std::endl;
}
ExamplePlugin::~ExamplePlugin()
{
}
/* Following functions return name, description, version, and type for the plugin */
QString ExamplePlugin::name()
{
return pName;
}
QString ExamplePlugin::version()
{
return pVersion;
}
QString ExamplePlugin::description()
{
return pDescription;
}
int ExamplePlugin::type()
{
return QgisPlugin::UI;
}
/*
* Initialize the GUI interface for the plugin
*/
void ExamplePlugin::initGui()
{
// add a test menu with 3 items
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindow);
// add a test menu with 3 items
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindow);
pluginMenu->insertItem("&Open", this, SLOT(open()));
pluginMenu->insertItem("&New", this, SLOT(newThing()));
pluginMenu->insertItem("&Unload Example Plugin", this, SLOT(unload()));
menu = ((QMainWindow *) qgisMainWindow)->menuBar();
pluginMenu->insertItem("&Open", this, SLOT(open()));
pluginMenu->insertItem("&New", this, SLOT(newThing()));
pluginMenu->insertItem("&Unload Example Plugin", this, SLOT(unload()));
menuId = menu->insertItem("&ExamplePluginMenu", pluginMenu);
/* Add a test toolbar with one tool (a zoom previous tool) */
// Create the action for tool
QAction *zoomPreviousAction = new QAction("Zoom Previous", QIconSet(icon_matrix), "&Zoom Previous",
CTRL + Key_S, qgisMainWindow, "zoomPrevious");
// Connect the action to the zoomPrevous slot
connect(zoomPreviousAction, SIGNAL(activated()), this, SLOT(zoomPrevious()));
// Add the toolbar
toolBar = new QToolBar((QMainWindow *) qgisMainWindow, "zoom operations");
toolBar->setLabel("Zoom Operations");
// Add the zoom previous tool to the toolbar
zoomPreviousAction->addTo(toolBar);
menu = ((QMainWindow *) qgisMainWindow)->menuBar();
menuId = menu->insertItem("&ExamplePluginMenu", pluginMenu);
/* Add a test toolbar with one tool (a zoom previous tool) */
// Create the action for tool
QAction *zoomPreviousAction = new QAction("Zoom Previous", QIconSet(icon_matrix), "&Zoom Previous",
CTRL + Key_S, qgisMainWindow, "zoomPrevious");
// Connect the action to the zoomPrevous slot
connect(zoomPreviousAction, SIGNAL(activated()), this, SLOT(zoomPrevious()));
// Add the toolbar
toolBar = new QToolBar((QMainWindow *) qgisMainWindow, "zoom operations");
toolBar->setLabel("Zoom Operations");
// Add the zoom previous tool to the toolbar
zoomPreviousAction->addTo(toolBar);
}
// Slot called when open is selected on the menu
void ExamplePlugin::open()
{
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the open menu");
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the open menu");
}
// Slot called when new is selected on the menu
void ExamplePlugin::newThing()
{
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the new menu");
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the new menu");
}
// Slot called when the zoomPrevious button is clicked
void ExamplePlugin::zoomPrevious()
{
qI->zoomPrevious();
qI->zoomPrevious();
}
// Unload the plugin bye cleaning up the GUI
void ExamplePlugin::unload()
{
// remove the GUI
menu->removeItem(menuId);
// cleanup anything else that needs to be nuked
delete toolBar;
// remove the GUI
menu->removeItem(menuId);
// cleanup anything else that needs to be nuked
delete toolBar;
}
/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
@ -146,26 +138,29 @@ void ExamplePlugin::unload()
// Class factory to return a new instance of the plugin class
extern "C" QgisPlugin * classFactory(QgisApp * qgis, QgisIface * qI)
{
return new ExamplePlugin(qgis, qI);
return new ExamplePlugin(qgis, qI);
}
// Return the name of the plugin
extern "C" QString name()
{
return QString("Test Plugin");
return name_;
}
// Return the description
extern "C" QString description()
{
return QString("Default QGIS Test Plugin");
return description_;
}
// Return the type (either UI or MapLayer plugin)
extern "C" int type()
{
return QgisPlugin::UI;
return type_;
}
// Delete ourself
extern "C" void unload(QgisPlugin * p)
{
delete p;
delete p;
}

View File

@ -34,65 +34,41 @@ class QPopupMenu;
* After the UI elements are initialized the plugin zooms the map canvas to the
* full extent of all layers.
*/
class ExamplePlugin : public QObject, public QgisPlugin{
Q_OBJECT
public:
class ExamplePlugin:public QObject, public QgisPlugin
{
Q_OBJECT public:
/**
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
* QGIS when it attempts to instantiate the plugin.
* @param qgis Pointer to the QgisApp object
* @param qI Pointer to the QgisIface object.
*/
ExamplePlugin(QgisApp *qgis, QgisIface *qI);
/**
* Virtual function to return the name of the plugin. The name will be used when presenting a list
* of installable plugins to the user
*/
virtual QString name();
/**
* Virtual function to return the version of the plugin.
*/
virtual QString version();
/**
* Virtual function to return a description of the plugins functions
*/
virtual QString description();
/**
* Return the plugin type
*/
virtual int type();
ExamplePlugin(QgisApp * qgis, QgisIface * qI);
//! init the gui
virtual void initGui();
//! Destructor
virtual ~ExamplePlugin();
public slots:
virtual ~ ExamplePlugin();
public slots:
//! open something
void open();
void open();
//! create something new
void newThing();
void newThing();
//! zoom the map to the previous extent
void zoomPrevious();
void zoomPrevious();
//! unload the plugin
void unload();
private:
//! Name of the plugin
QString pName;
//! Version
QString pVersion;
//! Descrption of the plugin
QString pDescription;
//! Plugin type as defined in QgisPlugin::PLUGINTYPE
int ptype;
int ptype;
//! Id of the plugin's menu. Used for unloading
int menuId;
//! Pointer to our toolbar
QToolBar *toolBar;
//! Pointer to our menu
QMenuBar *menu;
QMenuBar *menu;
//! Pionter to QGIS main application object
QgisApp *qgisMainWindow;
QgisApp *qgisMainWindow;
//! Pointer to the QGIS interface object
QgisIface *qI;
QgisIface *qI;
};
#endif

View File

@ -21,7 +21,7 @@ plugin_LTLIBRARIES = pggeoprocessingplugin.la
%.cpp: %.ui
$(UIC) -o $@ -impl $*.h $<
pggeoprocessingplugin_la_SOURCES = qgspggeoprocessing.cpp \
qgspggeoprocessing.h \
qgsdlgpgbuffer.cpp \
@ -30,9 +30,9 @@ pggeoprocessingplugin_la_SOURCES = qgspggeoprocessing.cpp \
../../src/qgsvectorlayer.cpp \
../../src/qgsfield.cpp \
$(pggeoprocessing_UI)
nodist_pggeoprocessingplugin_la_SOURCES = $(pggeoprocessing_MOC)
pggeoprocessing_MOC = qgspggeoprocessing.moc.cpp \
../../src/qgsmaplayer.moc.cpp \
../../src/qgsvectorlayer.moc.cpp \
@ -41,7 +41,7 @@ pggeoprocessing_MOC = qgspggeoprocessing.moc.cpp \
pggeoprocessing_UI = qgsdlgpgbufferbase.h \
qgsdlgpgbufferbase.cpp
pggeoprocessing_UIC = qgsdlgpgbufferbase.ui
# UI dependencies
@ -50,7 +50,7 @@ qgsdlgpgbufferbase.h: qgsdlgpgbufferbase.ui
BUILT_SOURCES = $(pggeoprocessing_MOC) $(pggeoprocessing_UI)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(PGDB) -I$(PG_INC) $(DEBUG_QGIS)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(PGDB) -I$(PG_INC) $(DEBUG_QGIS) -I../../src
pggeoprocessingplugin_la_LIBADD = $(QT_LDADD) $(PG_LIB)
pggeoprocessingplugin_la_LDFLAGS = -avoid-version -module

View File

@ -42,20 +42,27 @@ email : sherman at mrcc.com
// xpm for creating the toolbar icon
#include "icon_buffer.xpm"
static const char *pluginVersion = "0.1";
static const char * const ident_ = "$Id$";
static const char * const name_ = "PostgresSQL Geoprocessing";
static const char * const description_ = "Geoprocessing functions for working with PostgreSQL/PostGIS layers";
static const char * const version_ = "Version 0.1";
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
/**
* 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 qgis Pointer to the QGIS main window
* @parma _qI Pointer to the QGIS interface object
*/
QgsPgGeoprocessing::QgsPgGeoprocessing(QgisApp * qgis, QgisIface * _qI):qgisMainWindow(qgis), qI(_qI)
QgsPgGeoprocessing::QgsPgGeoprocessing(QgisApp * qgis, QgisIface * _qI)
: qgisMainWindow(qgis), qI(_qI),
QgisPlugin( name_, description_, version_, type_ )
{
/** Initialize the plugin and set the required attributes */
pName = "PostgreSQL Geoprocessing";
pVersion = "Version 0.1";
pDescription = "Geoprocessing functions for working with PostgreSQL/PostGIS layers";
}
QgsPgGeoprocessing::~QgsPgGeoprocessing()
@ -63,28 +70,6 @@ QgsPgGeoprocessing::~QgsPgGeoprocessing()
}
/* Following functions return name, description, version, and type for the plugin */
QString QgsPgGeoprocessing::name()
{
return pName;
}
QString QgsPgGeoprocessing::version()
{
return pVersion;
}
QString QgsPgGeoprocessing::description()
{
return pDescription;
}
int QgsPgGeoprocessing::type()
{
return QgisPlugin::UI;
}
/*
* Initialize the GUI interface for the plugin
@ -437,25 +422,25 @@ extern "C" QgisPlugin * classFactory(QgisApp * qgis, QgisIface * qI)
// Return the name of the plugin
extern "C" QString name()
{
return QString("PostgreSQL Geoprocessing");
return name_;
}
// Return the description
extern "C" QString description()
{
return QString("Geoprocessing functions for working with PostgreSQL/PostGIS layers");
return description_;
}
// Return the type (either UI or MapLayer plugin)
extern "C" int type()
{
return QgisPlugin::UI;
return type_;
}
// Return the version number for the plugin
extern "C" QString version()
{
return pluginVersion;
return version_;
}
// Delete ourself

View File

@ -51,23 +51,7 @@ class QgsPgGeoprocessing:public QObject, public QgisPlugin
* @param qI Pointer to the QgisIface object.
*/
QgsPgGeoprocessing(QgisApp * qgis, QgisIface * qI);
/**
* Virtual function to return the name of the plugin. The name will be used when presenting a list
* of installable plugins to the user
*/
virtual QString name();
/**
* Virtual function to return the version of the plugin.
*/
virtual QString version();
/**
* Virtual function to return a description of the plugins functions
*/
virtual QString description();
/**
* Return the plugin type
*/
virtual int type();
//! init the gui
virtual void initGui();
//! Destructor
@ -94,14 +78,6 @@ class QgsPgGeoprocessing:public QObject, public QgisPlugin
bool gistAvailable;
bool projAvailable;
//! Name of the plugin
QString pName;
//! Version
QString pVersion;
//! Descrption of the plugin
QString pDescription;
//! Plugin type as defined in QgisPlugin::PLUGINTYPE
int ptype;
//! Id of the plugin's menu. Used for unloading
int menuId;
//! Pointer to our toolbar

View File

@ -47,7 +47,7 @@ openmodellerguibase.cpp: openmodellerguibase.h openmodellerguibase.ui
BUILT_SOURCES = $(openmodeller_MOC) $(openmodeller_UI)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS) -I../../src
#-lom is libopenmodeller which should be in to /usr/lib/libom.so.0.0
libopenmodellerplugin_la_LIBADD = $(QT_LDADD) -L/usr/lib/ -lom -lm

View File

@ -44,7 +44,14 @@ email : tim@linfiniti.com
// xpm for creating the toolbar icon
#include "icon_om.xpm"
//
static const char *pluginVersion = "0.1";
static const char * const ident_ = "$Id$";
static const char * const name_ = "openMOdeller Wizard";
static const char * const description_ = "Plugin to run openModeller in QGIS.";
static const char * const version_ = "Version 0.1";
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
/**
* 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.
@ -52,13 +59,10 @@ static const char *pluginVersion = "0.1";
* @param _qI Pointer to the QGIS interface object
*/
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace)
qgisMainWindowPointer(theQGisApp),
qGisInterface(theQgisInterFace),
QgisPlugin( name_, description_, version_, type_ )
{
/** Initialize the plugin and set the required attributes */
pluginNameQString = "openModeller Wizard";
pluginVersionQString = "Version 0.1";
pluginDescriptionQString = "Plugin to run openModeller in QGIS.";
}
Plugin::~Plugin()
@ -66,28 +70,6 @@ Plugin::~Plugin()
}
/* Following functions return name, description, version, and type for the plugin */
QString Plugin::name()
{
return pluginNameQString;
}
QString Plugin::version()
{
return pluginVersionQString;
}
QString Plugin::description()
{
return pluginDescriptionQString;
}
int Plugin::type()
{
return QgisPlugin::UI;
}
/*
* Initialize the GUI interface for the plugin
@ -152,25 +134,25 @@ extern "C" QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * th
// the class may not yet be insantiated when this method is called.
extern "C" QString name()
{
return QString("openModeller Wizard");
return name_;
}
// Return the description
extern "C" QString description()
{
return QString("This is a plugin to run openModeller in QGIS");
return description_;
}
// Return the type (either UI or MapLayer plugin)
extern "C" int type()
{
return QgisPlugin::UI;
return type_;
}
// Return the version number for the plugin
extern "C" QString version()
{
return pluginVersion;
return version_;
}
// Delete ourself

View File

@ -40,24 +40,7 @@ class Plugin:public QObject, public QgisPlugin
* @param qI Pointer to the QgisIface object.
*/
Plugin(QgisApp * , QgisIface * );
/**
* Virtual function to return the name of the plugin. The name will be used when presenting a list
* of installable plugins to the user
*/
virtual QString name();
/**
* Virtual function to return the version of the plugin.
*/
virtual QString version();
/**
* Virtual function to return a description of the plugins functions
*/
virtual QString description();
/**
* Return the plugin type
*/
virtual int type();
//! init the gui
virtual void initGui();
//! Destructor
virtual ~ Plugin();
@ -73,13 +56,6 @@ class Plugin:public QObject, public QgisPlugin
private:
//! Name of the plugin
QString pluginNameQString;
//! Version
QString pluginVersionQString;
//! Descrption of the plugin
QString pluginDescriptionQString;
//! Plugin type as defined in QgisPlugin::PLUGINTYPE
int pluginType;
//! Id of the plugin's menu. Used for unloading
int menuIdInt;

View File

@ -50,7 +50,7 @@ pluginguibase.cpp: pluginguibase.h pluginguibase.ui
BUILT_SOURCES = $(plugin_MOC) $(plugin_UI)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS) -I../../src
lib[pluginname]plugin_la_LIBADD = $(QT_LDADD)
lib[pluginname]plugin_la_LDFLAGS = -avoid-version -module

View File

@ -46,7 +46,14 @@ email : tim@linfiniti.com
// xpm for creating the toolbar icon
#include "icon.xpm"
//
static const char *pluginVersion = "0.1";
static const char * const ident_ = "$Id$";
static const char * const name_ = "PostgresSQL Geoprocessing";
static const char * const description_ = "Geoprocessing functions for working with PostgreSQL/PostGIS layers";
static const char * const version_ = "Version 0.1";
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
/**
* 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.
@ -54,13 +61,10 @@ static const char *pluginVersion = "0.1";
* @param _qI Pointer to the QGIS interface object
*/
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace)
qgisMainWindowPointer(theQGisApp),
qGisInterface(theQgisInterFace),
QgisPlugin(name_,description_,version_,type_)
{
/** Initialize the plugin and set the required attributes */
pluginNameQString = "[pluginname]";
pluginVersionQString = "Version 0.1";
pluginDescriptionQString = "[plugindescription]";
}
Plugin::~Plugin()
@ -68,29 +72,6 @@ Plugin::~Plugin()
}
/* Following functions return name, description, version, and type for the plugin */
QString Plugin::name()
{
return pluginNameQString;
}
QString Plugin::version()
{
return pluginVersionQString;
}
QString Plugin::description()
{
return pluginDescriptionQString;
}
int Plugin::type()
{
return QgisPlugin::UI;
}
/*
* Initialize the GUI interface for the plugin
*/
@ -161,25 +142,25 @@ extern "C" QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * th
// the class may not yet be insantiated when this method is called.
extern "C" QString name()
{
return QString("[menuitemname]");
return name_;
}
// Return the description
extern "C" QString description()
{
return QString("[plugindescription]");
return description_;
}
// Return the type (either UI or MapLayer plugin)
extern "C" int type()
{
return QgisPlugin::UI;
return type_;
}
// Return the version number for the plugin
extern "C" QString version()
{
return pluginVersion;
return version_;
}
// Delete ourself

View File

@ -39,23 +39,6 @@ class Plugin:public QObject, public QgisPlugin
* @param qI Pointer to the QgisIface object.
*/
Plugin(QgisApp * , QgisIface * );
/**
* Virtual function to return the name of the plugin. The name will be used when presenting a list
* of installable plugins to the user
*/
virtual QString name();
/**
* Virtual function to return the version of the plugin.
*/
virtual QString version();
/**
* Virtual function to return a description of the plugins functions
*/
virtual QString description();
/**
* Return the plugin type
*/
virtual int type();
//! init the gui
virtual void initGui();
//! Destructor
@ -73,14 +56,6 @@ class Plugin:public QObject, public QgisPlugin
void help();
private:
//! Name of the plugin
QString pluginNameQString;
//! Version
QString pluginVersionQString;
//! Descrption of the plugin
QString pluginDescriptionQString;
//! Plugin type as defined in QgisPlugin::PLUGINTYPE
int pluginType;
//! Id of the plugin's menu. Used for unloading
int menuIdInt;

View File

@ -1,76 +1,165 @@
/*! \mainpage Quantum GIS - Plugin API
*
* \section about About QGis Plugins
* Plugins provide additional functionality to QGis. Plugins must
* implement several required methods in order to be registered with
* QGis. These methods include:
* <ul>name
* <li>version
* <li>description
* </ul>
*
* All QGis plugins must inherit from the abstract base class QgisPlugin. A
* This list will grow as the API is expanded.
*
* In addition, a plugin must implement the classFactory and unload
* functions. Note that these functions must be declared as extern "C" in
* order to be resolved properly and prevent C++ name mangling.
*/
*
* \section about About QGis Plugins
* Plugins provide additional functionality to QGis. Plugins must
* implement several required methods in order to be registered with
* QGis. These methods include:
* <ul>name
* <li>version
* <li>description
* </ul>
*
* All QGis plugins must inherit from the abstract base class QgisPlugin. A
* This list will grow as the API is expanded.
*
* In addition, a plugin must implement the classFactory and unload
* functions. Note that these functions must be declared as extern "C" in
* order to be resolved properly and prevent C++ name mangling.
*/
#ifndef QGISPLUGIN_H
#define QGISPLUGIN_H
#ifndef qgisplugin_h
#define qgisplugin_h
#include <qstring.h>
#include <qwidget.h>
#include <qmainwindow.h>
#include "../src/qgisapp.h"
#include <qgisapp.h>
//#include "qgisplugingui.h"
/*! \class QgisPlugin
* \brief Abstract base class from which all plugins must inherit
*
*/
class QgisPlugin {
public:
//! Get the name of the plugin
virtual QString name() = 0;
//! Version of the plugin
virtual QString version() =0;
//! A brief description of the plugin
virtual QString description() = 0;
//! Plugin type, either UI or map layer
virtual int type()=0;
virtual void initGui()=0;
//! Unload the plugin and cleanup the gui
virtual void unload()=0;
//! Interface to gui element collection object
//virtual QgisPluginGui *gui()=0;
//! Element types that can be added to the interface
/* enum ELEMENTS {
MENU,
MENU_ITEM,
TOOLBAR,
TOOLBAR_BUTTON,
};
*/
enum PLUGINTYPE{
UI,
MAPLAYER
};
};
* \brief Abstract base class from which all plugins must inherit
*
*/
class QgisPlugin
{
public:
//! Interface to gui element collection object
//virtual QgisPluginGui *gui()=0;
//! Element types that can be added to the interface
/* enum ELEMENTS {
MENU,
MENU_ITEM,
TOOLBAR,
TOOLBAR_BUTTON,
};
@todo XXX this may be a hint that there should be subclasses
*/
typedef enum PLUGINTYPE
{
UI, /* user interface plug-in */
MAPLAYER /* map layer plug-in */
};
QgisPlugin ( QString const & name = "",
QString const & description = "",
QString const & version = "",
PLUGINTYPE const & type = MAPLAYER )
: mName(name),
mDescription(description),
mVersion(version),
mType(type)
{}
virtual ~QgisPlugin()
{}
//! Get the name of the plugin
QString const & name() const
{
return mName;
}
QString & name()
{
return mName;
}
//! Version of the plugin
QString const & version() const
{
return mVersion;
}
//! Version of the plugin
QString & version()
{
return mVersion;
}
//! A brief description of the plugin
QString const & description() const
{
return mDescription;
}
//! A brief description of the plugin
QString & description()
{
return mDescription;
}
//! Plugin type, either UI or map layer
QgisPlugin::PLUGINTYPE const & type() const
{
return mType;
}
//! Plugin type, either UI or map layer
QgisPlugin::PLUGINTYPE & type()
{
return mType;
}
/// function to initialize connection to GUI
virtual void initGui() = 0;
//! Unload the plugin and cleanup the GUI
virtual void unload() = 0;
private:
/// plug-in name
QString mName;
/// description
QString mDescription;
/// version
QString mVersion;
/// UI or MAPLAYER plug-in
/**
@todo Really, might be indicative that this needs to split into
maplayer vs. ui plug-in vs. other kind of plug-in
*/
PLUGINTYPE mType;
}; // class QgisPlugin
// Typedefs used by qgis main app
//! Typedef for the function that returns a generic pointer to a plugin object
typedef QgisPlugin* create_t(QgisApp *, QgisInterface *);
typedef QgisPlugin *create_t(QgisApp *, QgisInterface *);
//! Typedef for the function to unload a plugin and free its resources
typedef void unload_t(QgisPlugin *);
//! Typedef for getting the name of the plugin without instantiating it
typedef QString name_t();
//! Typedef for getting the description without instantiating the plugin
typedef QString description_t();
//! Typedef for getting the plugin type without instantiating the plugin
typedef int type_t();
//! Typedef for getting the plugin version without instantiating the plugin
typedef QString version_t();
#endif //qgisplugin_h

View File

@ -66,7 +66,7 @@ qgsmessageviewerbase.h: qgsmessageviewerbase.ui
BUILT_SOURCES = $(spit_MOC) $(spit_UI)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(GDAL_CFLAGS) $(QT_CXXFLAGS) $(PGDB) -I$(PG_INC)
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(GDAL_CFLAGS) $(QT_CXXFLAGS) $(PGDB) -I$(PG_INC) -I../../src
spitplugin_la_LIBADD = $(QT_LDADD) $(PG_LIB) $(GDAL_LIB)
spitplugin_la_LDFLAGS = -avoid-version -module

View File

@ -36,20 +36,26 @@
// xpm for creating the toolbar icon
#include "spiticon.xpm"
static const char *pluginVersion = "0.1";
static const char * const ident_ = "$Id$";
static const char * const name_ = "SPIT";
static const char * const description_ = "Shapefile to PostgreSQL/PostGIS Import Tool";
static const char * const version_ = "Version 0.1";
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
/**
* 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 qgis Pointer to the QGIS main window
* @parma _qI Pointer to the QGIS interface object
*/
QgsSpitPlugin::QgsSpitPlugin(QgisApp * qgis, QgisIface * _qI):qgisMainWindow(qgis), qI(_qI)
QgsSpitPlugin::QgsSpitPlugin(QgisApp * qgis, QgisIface * _qI)
: qgisMainWindow(qgis),
qI(_qI),
QgisPlugin(name_, description_, version_, type_ )
{
/** Initialize the plugin and set the required attributes */
pName = "SPIT";
pVersion = "Version 0.1";
pDescription = "Shapefile to PostgreSQL/PostGIS Import Tool";
}
QgsSpitPlugin::~QgsSpitPlugin()
@ -57,29 +63,6 @@ QgsSpitPlugin::~QgsSpitPlugin()
}
/* Following functions return name, description, version, and type for the plugin */
QString QgsSpitPlugin::name()
{
return pName;
}
QString QgsSpitPlugin::version()
{
return pVersion;
}
QString QgsSpitPlugin::description()
{
return pDescription;
}
int QgsSpitPlugin::type()
{
return QgisPlugin::UI;
}
/*
* Initialize the GUI interface for the plugin
*/
@ -139,26 +122,28 @@ extern "C" QgisPlugin * classFactory(QgisApp * qgis, QgisIface * qI)
// Return the name of the plugin
extern "C" QString name()
{
return QString("SPIT - Shapefile to PostgreSQL Import Tool");
return name_;
}
// Return the description
extern "C" QString description()
{
return QString("Import ESRI Shapefiles to PostgreSQL/PostGIS layer");
return description_;
}
// Return the type (either UI or MapLayer plugin)
extern "C" int type()
{
return QgisPlugin::UI;
return type_;
}
// Return the version
extern "C" QString version()
{
return pluginVersion;
return version_;
}
// Delete ourself
extern "C" void unload(QgisPlugin * p)
{

View File

@ -50,23 +50,7 @@ class QgsSpitPlugin:public QObject, public QgisPlugin
* @param qI Pointer to the QgisIface object.
*/
QgsSpitPlugin(QgisApp * qgis, QgisIface * qI);
/**
* Virtual function to return the name of the plugin. The name will be used when presenting a list
* of installable plugins to the user
*/
virtual QString name();
/**
* Virtual function to return the version of the plugin.
*/
virtual QString version();
/**
* Virtual function to return a description of the plugins functions
*/
virtual QString description();
/**
* Return the plugin type
*/
virtual int type();
//! init the gui
virtual void initGui();
//! Destructor