QGIS/plugins/spit/qgsspitplugin.cpp
gsherman 96a0e85577 * Fixed bug that caused qgis to crash when a plugin was unloaded. All plugins
must now have a QAction member pointer that is created when the GUI is
  initialized in initGui(). This pointer is used in the unload() method to
  remove the QAction and associated icon from the plugins toolbar.

* Updated splash for upcoming 0.5 release


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1956 c8812cc2-4d05-0410-92ff-de0c093fc19c
2004-08-30 00:53:35 +00:00

155 lines
4.2 KiB
C++

/***************************************************************************
qgsspitplugin.cpp
Shapefile to PostgreSQL Import Tool plugin
-------------------
begin : Jan 30, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.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 <iostream>
#include <vector>
#include "../../src/qgisapp.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>
#include "qgsspitplugin.h"
#include "qgsspit.h"
// xpm for creating the toolbar icon
#include "spiticon.xpm"
#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
#else
#define QGISEXTERN extern "C"
#endif
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),
QgisPlugin(name_, description_, version_, type_ )
{
}
QgsSpitPlugin::~QgsSpitPlugin()
{
}
/*
* Initialize the GUI interface for the plugin
*/
void QgsSpitPlugin::initGui()
{
// add a menu with 2 items
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindow);
pluginMenu->insertItem(QIconSet(spitIcon),"&Import Shapefiles to PostgreSQL", this, SLOT(spit()));
// pluginMenu->insertItem("&Unload SPIT Plugin", this, SLOT(unload()));
menu = ((QMainWindow *) qgisMainWindow)->menuBar();
//menuId = menu->insertItem("&Spit", pluginMenu);
menuId = qI->addMenu("&Spit", pluginMenu);
// Create the action for tool
spitAction = new QAction("Import Shapefiles to PostgreSQL", QIconSet(spitIcon), "&SPIT",
0, this, "spit");
// Connect the action to the spit slot
connect(spitAction, SIGNAL(activated()), this, SLOT(spit()));
// Add the icon to the toolbar
qI->addToolBarIcon(spitAction);
}
// Slot called when the shapefile to postgres menu item is activated
void QgsSpitPlugin::spit()
{
QgsSpit *spitDlg = new QgsSpit();
spitDlg->show();
}
// Unload the plugin by cleaning up the GUI
void QgsSpitPlugin::unload()
{
// remove the GUI
menu->removeItem(menuId);
qI->removeToolBarIcon(spitAction);
delete spitAction;
}
/**
* 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
QGISEXTERN QgisPlugin * classFactory(QgisApp * qgis, QgisIface * qI)
{
return new QgsSpitPlugin(qgis, qI);
}
// Return the name of the plugin
QGISEXTERN QString name()
{
return name_;
}
// Return the description
QGISEXTERN QString description()
{
return description_;
}
// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return type_;
}
// Return the version
QGISEXTERN QString version()
{
return version_;
}
// Delete ourself
QGISEXTERN void unload(QgisPlugin * p)
{
delete p;
}