mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
class Plugin (a subclass of QgisPlugin) class PluginGuiBase (supplied as a simple qdialog ui) class PluginGui (the subclass of PluginGuiBase) The only thing the user would need to change in the makefile is the name of the .so so you just copy the plugin template dir to a new dir under plugins, change the .so name in the makefile add the plugin dir the configure.in and the plugin dir makefile. I will be adding a bash script file soon that automates the above process. This template development is in progress. git-svn-id: http://svn.osgeo.org/qgis/trunk@881 c8812cc2-4d05-0410-92ff-de0c093fc19c
187 lines
5.3 KiB
C++
187 lines
5.3 KiB
C++
/***************************************************************************
|
|
plugin.cpp
|
|
Import tool for various worldmap analysis output files
|
|
Functions:
|
|
|
|
-------------------
|
|
begin : Jan 21, 2004
|
|
copyright : (C) 2004 by Tim Sutton
|
|
email : tim@linfiniti.com
|
|
|
|
***************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* *
|
|
* 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$ */
|
|
|
|
// includes
|
|
|
|
#include "../../src/qgisapp.h"
|
|
#include "../../src/qgsmaplayer.h"
|
|
#include "../../src/qgsrasterlayer.h"
|
|
#include "plugin.h"
|
|
|
|
|
|
#include <qtoolbar.h>
|
|
#include <qmenubar.h>
|
|
#include <qmessagebox.h>
|
|
#include <qpopupmenu.h>
|
|
#include <qlineedit.h>
|
|
#include <qaction.h>
|
|
#include <qapplication.h>
|
|
#include <qcursor.h>
|
|
|
|
//non qt includes
|
|
#include <iostream>
|
|
#include <openmodellergui.h>
|
|
|
|
// xpm for creating the toolbar icon
|
|
#include "icon_om.xpm"
|
|
//
|
|
static const char *pluginVersion = "0.1";
|
|
/**
|
|
* 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
|
|
* @param _qI Pointer to the QGIS interface object
|
|
*/
|
|
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
|
|
qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace)
|
|
{
|
|
/** Initialize the plugin and set the required attributes */
|
|
pluginNameQString = "[pluginname]";
|
|
pluginVersionQString = "Version 0.1";
|
|
pluginDescriptionQString = "[plugindescription]";
|
|
|
|
}
|
|
|
|
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
|
|
*/
|
|
void Plugin::initGui()
|
|
{
|
|
// add a menu with 2 items
|
|
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindowPointer);
|
|
|
|
pluginMenu->insertItem(QIconSet(icon),"&[pluginname]", this, SLOT(run()));
|
|
|
|
menuBarPointer = ((QMainWindow *) qgisMainWindowPointer)->menuBar();
|
|
|
|
menuIdInt = qGisInterface->addMenu("&[menuname]", pluginMenu);
|
|
// Create the action for tool
|
|
QAction *myQActionPointer = new QAction("[menuitemname]", QIconSet(icon), "&Wmi",0, this, "run");
|
|
// Connect the action to the run
|
|
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
|
// Add the toolbar
|
|
toolBarPointer = new QToolBar((QMainWindow *) qgisMainWindowPointer, "[menuname]");
|
|
toolBarPointer->setLabel("[menuitemname]");
|
|
// Add the zoom previous tool to the toolbar
|
|
myQActionPointer->addTo(toolBarPointer);
|
|
|
|
|
|
}
|
|
|
|
// Slot called when the buffer menu item is activated
|
|
void Plugin::run()
|
|
{
|
|
PluginGui *myPluginGui=new PluginGui(qgisMainWindowPointer,"[menuitemname]",true,0);
|
|
//listen for when the layer has been made so we can draw it
|
|
connect(myOpenModellerGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
|
|
connect(myOpenModellerGui, SIGNAL(drawVectorLayer(QString)), this, SLOT(drawVectorLayer(QString)));
|
|
myOpenModellerGui->show();
|
|
}
|
|
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
|
|
//layer
|
|
void Plugin::drawRasterLayer(QString theQString)
|
|
{
|
|
qGisInterface->addRasterLayer(theQString);
|
|
}
|
|
//!draw a vector layer in the qui - intended to respond to signal sent by diolog when it as finished creating
|
|
//layer
|
|
void Plugin::drawVectorLayer(QString theQString)
|
|
{
|
|
qGisInterface->addVectorLayer(theQString);
|
|
}
|
|
// Unload the plugin by cleaning up the GUI
|
|
void Plugin::unload()
|
|
{
|
|
// remove the GUI
|
|
menuBarPointer->removeItem(menuIdInt);
|
|
delete toolBarPointer;
|
|
}
|
|
/**
|
|
* 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
|
|
extern "C" QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
|
|
{
|
|
return new Plugin(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.
|
|
extern "C" QString name()
|
|
{
|
|
return QString("[menuitemname]");
|
|
}
|
|
|
|
// Return the description
|
|
extern "C" QString description()
|
|
{
|
|
return QString("[plugindescription]");
|
|
}
|
|
|
|
// Return the type (either UI or MapLayer plugin)
|
|
extern "C" int type()
|
|
{
|
|
return QgisPlugin::UI;
|
|
}
|
|
|
|
// Return the version number for the plugin
|
|
extern "C" QString version()
|
|
{
|
|
return pluginVersion;
|
|
}
|
|
|
|
// Delete ourself
|
|
extern "C" void unload(QgisPlugin * thePluginPointer)
|
|
{
|
|
delete thePluginPointer;
|
|
}
|