From c32f7c04eb3d45e2a833b7d6ae13606616df0f51 Mon Sep 17 00:00:00 2001 From: gsherman Date: Mon, 14 Oct 2002 15:43:42 +0000 Subject: [PATCH] stub classes for plugin support git-svn-id: http://svn.osgeo.org/qgis/trunk@138 c8812cc2-4d05-0410-92ff-de0c093fc19c --- plugins/qgisplugin.h | 49 +++++++++++++++++++++++++++++++--- plugins/qgisplugingui.h | 22 +++++++++++++++ plugins/qgispluginguielement.h | 17 ++++++++++++ plugins/qgispluginmenu.h | 20 ++++++++++++++ plugins/qgisplugintoolbar.h | 20 ++++++++++++++ plugins/qgistestplugin.cpp | 32 +++++++++++----------- 6 files changed, 142 insertions(+), 18 deletions(-) create mode 100644 plugins/qgisplugingui.h create mode 100644 plugins/qgispluginguielement.h create mode 100644 plugins/qgispluginmenu.h create mode 100644 plugins/qgisplugintoolbar.h diff --git a/plugins/qgisplugin.h b/plugins/qgisplugin.h index 53eb08f92f3..d51bd86830b 100644 --- a/plugins/qgisplugin.h +++ b/plugins/qgisplugin.h @@ -1,13 +1,56 @@ +/*! \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: +* +* +* 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. +*/ +#include #ifndef qgisplugin_h #define qgisplugin_h #include +/*! \class QgisPlugin +* \brief Abstract base class from which all plugins must inherit +* +*/ class QgisPlugin{ public: - virtual QString pluginName() = 0; - virtual QString pluginVersion() =0; - virtual QString pluginDescription() = 0; +//! 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; + + //! Element types that can be added to the interface + enum ELEMENTS { + MENU, + MENU_ITEM, + TOOLBAR, + TOOLBAR_BUTTON, + }; }; + +// Typedefs + +//! Typedef for function that returns a generic pointer to a plugin object typedef QgisPlugin* create_t(); +//! Typedef for the function to unload a plugin and free its resources typedef void unload_t(QgisPlugin *); +//! Element type corresponding to one of the values in the ELEMENTS enum +typedef int QGIS_GUI_TYPE; + #endif //qgisplugin_h diff --git a/plugins/qgisplugingui.h b/plugins/qgisplugingui.h new file mode 100644 index 00000000000..a51a578b0eb --- /dev/null +++ b/plugins/qgisplugingui.h @@ -0,0 +1,22 @@ +#include +class QgisPluginGuiElement; + +/*! \class QgisPluginGui +* \brief Class to encapsulate the gui elements of a plugin +* +* QgsPluginGui encapsulates all the GUI elements a plugin supports, +* including menu items, toolbar buttons, and associated graphics +*/ +class QgisPluginGui { +public: +//! Constructor + QgisPluginGui(); + //! Returns the number of GUI elements in the plugin + int elementCount(); + //! Returns a specific GUI element by index from the vector + QgisPluginGuiElement element(int index); + //! Adds a new element + void addElement(QgisPluginGuiElement); +private: + std::vector elements; +}; diff --git a/plugins/qgispluginguielement.h b/plugins/qgispluginguielement.h new file mode 100644 index 00000000000..24b2006a8af --- /dev/null +++ b/plugins/qgispluginguielement.h @@ -0,0 +1,17 @@ +/*! \class QgisPluginGuiElement +* \brief Base class for a GUI element (menu, toolbar, etc) of a plugin +* +* QgsPluginGuiElement provides information about a GUI element that +* will be added to the QGis interface when the plugin is loaded +*/ +class QgisPluginGuiElement { +public: +//! Constructor + QgisPluginGuiElement(); + //! Type of element (see ELEMENTS enum in qgisplugin.h) + virtual QGIS_GUI_TYPE type(); + //! destructor + virtual ~QgisPluginGuiElement(); +private: + +}; diff --git a/plugins/qgispluginmenu.h b/plugins/qgispluginmenu.h new file mode 100644 index 00000000000..5322d8a80af --- /dev/null +++ b/plugins/qgispluginmenu.h @@ -0,0 +1,20 @@ +#include +#include "qgispluginguielement" +/*! \class QgisPluginMenu +* \brief Class to define a plugin menu +* +* +* +*/ +class QgisPluginMenu : public QgisPluginGuiElement { +public: +//! Constructor + QgisPluginMenu(); + //! Type of element (see ELEMENTS enum in qgisplugin.h) + QGIS_GUI_TYPE type(); + //! destructor + virtual ~QgisPluginMenu(); +private: + //! Map to define slot called when a menu item is activated + std::map itemSlots; +}; diff --git a/plugins/qgisplugintoolbar.h b/plugins/qgisplugintoolbar.h new file mode 100644 index 00000000000..cbde372d5e3 --- /dev/null +++ b/plugins/qgisplugintoolbar.h @@ -0,0 +1,20 @@ +#include +#include "qgispluginguielement" +/*! \class QgisPluginToolbar +* \brief Class to define a plugin toolbar +* +* +* +*/ +class QgisPluginToolbar : public QgisPluginGuiElement { +public: +//! Constructor + QgisPluginToolbar(); + //! Type of element (see ELEMENTS enum in qgisplugin.h) + QGIS_GUI_TYPE type(); + //! destructor + virtual ~QgisPluginToolbar(); +private: + //! Map to define slot called when a toolbar button is activated + std::map toolSlots; +}; diff --git a/plugins/qgistestplugin.cpp b/plugins/qgistestplugin.cpp index b63545d82d4..3ba676cf1a1 100644 --- a/plugins/qgistestplugin.cpp +++ b/plugins/qgistestplugin.cpp @@ -16,38 +16,40 @@ #ifndef qgisplugintest_h #define qgisplugintest_h #include "qgisplugin.h" +#include "qgisplugingui.h" class QgisTestPlugin : public QgisPlugin{ public: QgisTestPlugin(); - virtual QString pluginName(); - virtual QString pluginVersion(); - virtual QString pluginDescription(); + virtual QString name(); + virtual QString version(); + virtual QString description(); + virtual QgisPluginGui *gui(); virtual ~QgisTestPlugin(); private: - QString name; - QString version; - QString description; + QString pName; + QString pVersion; + QString pDescription; }; #endif QgisTestPlugin::QgisTestPlugin(){ - name = "Test Plugin"; - version = "Version 0.0"; - description = "This test plugin does nothing but tell you its name, version, and description"; + pName = "Test Plugin"; + pVersion = "Version 0.0"; + pDescription = "This test plugin does nothing but tell you its name, version, and description"; } QgisTestPlugin::~QgisTestPlugin(){ } -QString QgisTestPlugin::pluginName(){ - return name; +QString QgisTestPlugin::name(){ + return pName; } -QString QgisTestPlugin::pluginVersion(){ - return version; +QString QgisTestPlugin::version(){ + return pVersion; } -QString QgisTestPlugin::pluginDescription(){ - return description; +QString QgisTestPlugin::description(){ + return pDescription; } extern "C" QgisPlugin * classFactory(){