2004-01-31 03:33:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
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
|
2004-02-14 18:01:56 +00:00
|
|
|
#include "spiticon.xpm"
|
2004-01-31 03:33:00 +00:00
|
|
|
|
2004-08-16 19:07:09 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#define QGISEXTERN extern "C" __declspec( dllexport )
|
|
|
|
#else
|
|
|
|
#define QGISEXTERN extern "C"
|
|
|
|
#endif
|
|
|
|
|
2004-03-08 23:50:05 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-01-31 03:33:00 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-03-08 23:50:05 +00:00
|
|
|
QgsSpitPlugin::QgsSpitPlugin(QgisApp * qgis, QgisIface * _qI)
|
|
|
|
: qgisMainWindow(qgis),
|
|
|
|
qI(_qI),
|
|
|
|
QgisPlugin(name_, description_, version_, type_ )
|
2004-01-31 03:33:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QgsSpitPlugin::~QgsSpitPlugin()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the GUI interface for the plugin
|
|
|
|
*/
|
|
|
|
void QgsSpitPlugin::initGui()
|
|
|
|
{
|
|
|
|
// add a menu with 2 items
|
|
|
|
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindow);
|
|
|
|
|
2004-04-23 23:07:41 +00:00
|
|
|
pluginMenu->insertItem(QIconSet(spitIcon),"&Import Shapefiles to PostgreSQL", this, SLOT(spit()));
|
2004-02-07 04:08:10 +00:00
|
|
|
// pluginMenu->insertItem("&Unload SPIT Plugin", this, SLOT(unload()));
|
2004-01-31 03:33:00 +00:00
|
|
|
|
|
|
|
menu = ((QMainWindow *) qgisMainWindow)->menuBar();
|
|
|
|
|
2004-02-06 07:04:05 +00:00
|
|
|
//menuId = menu->insertItem("&Spit", pluginMenu);
|
|
|
|
menuId = qI->addMenu("&Spit", pluginMenu);
|
2004-01-31 03:33:00 +00:00
|
|
|
// Create the action for tool
|
2004-08-30 00:53:35 +00:00
|
|
|
spitAction = new QAction("Import Shapefiles to PostgreSQL", QIconSet(spitIcon), "&SPIT",
|
2004-01-31 03:33:00 +00:00
|
|
|
0, this, "spit");
|
2004-04-23 23:07:41 +00:00
|
|
|
// Connect the action to the spit slot
|
2004-01-31 03:33:00 +00:00
|
|
|
connect(spitAction, SIGNAL(activated()), this, SLOT(spit()));
|
2004-08-28 18:47:51 +00:00
|
|
|
// Add the icon to the toolbar
|
|
|
|
qI->addToolBarIcon(spitAction);
|
2004-01-31 03:33:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2004-08-30 00:53:35 +00:00
|
|
|
qI->removeToolBarIcon(spitAction);
|
|
|
|
delete spitAction;
|
2004-01-31 03:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2004-08-16 19:07:09 +00:00
|
|
|
QGISEXTERN QgisPlugin * classFactory(QgisApp * qgis, QgisIface * qI)
|
2004-01-31 03:33:00 +00:00
|
|
|
{
|
|
|
|
return new QgsSpitPlugin(qgis, qI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the name of the plugin
|
2004-08-16 19:07:09 +00:00
|
|
|
QGISEXTERN QString name()
|
2004-01-31 03:33:00 +00:00
|
|
|
{
|
2004-03-08 23:50:05 +00:00
|
|
|
return name_;
|
2004-01-31 03:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the description
|
2004-08-16 19:07:09 +00:00
|
|
|
QGISEXTERN QString description()
|
2004-01-31 03:33:00 +00:00
|
|
|
{
|
2004-03-08 23:50:05 +00:00
|
|
|
return description_;
|
2004-01-31 03:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the type (either UI or MapLayer plugin)
|
2004-08-16 19:07:09 +00:00
|
|
|
QGISEXTERN int type()
|
2004-01-31 03:33:00 +00:00
|
|
|
{
|
2004-03-08 23:50:05 +00:00
|
|
|
return type_;
|
2004-01-31 03:33:00 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 05:46:44 +00:00
|
|
|
// Return the version
|
2004-08-16 19:07:09 +00:00
|
|
|
QGISEXTERN QString version()
|
2004-02-12 05:46:44 +00:00
|
|
|
{
|
2004-03-08 23:50:05 +00:00
|
|
|
return version_;
|
2004-02-12 05:46:44 +00:00
|
|
|
}
|
2004-03-08 23:50:05 +00:00
|
|
|
|
|
|
|
|
2004-01-31 03:33:00 +00:00
|
|
|
// Delete ourself
|
2004-08-16 19:07:09 +00:00
|
|
|
QGISEXTERN void unload(QgisPlugin * p)
|
2004-01-31 03:33:00 +00:00
|
|
|
{
|
|
|
|
delete p;
|
|
|
|
}
|