~ubuntu-branches/ubuntu/quantal/qgis/quantal

« back to all changes in this revision

Viewing changes to plugins/spit/qgsspitplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Halasz
  • Date: 2004-12-21 09:46:27 UTC
  • Revision ID: james.westby@ubuntu.com-20041221094627-r9lb6mlz2o3yp8gn
Tags: upstream-0.6.0
ImportĀ upstreamĀ versionĀ 0.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          qgsspitplugin.cpp 
 
3
 Shapefile to PostgreSQL Import Tool plugin 
 
4
                             -------------------
 
5
    begin                : Jan 30, 2004
 
6
    copyright            : (C) 2004 by Gary E.Sherman
 
7
    email                : sherman at mrcc.com
 
8
  
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *   This program is free software; you can redistribute it and/or modify  *
 
14
 *   it under the terms of the GNU General Public License as published by  *
 
15
 *   the Free Software Foundation; either version 2 of the License, or     *
 
16
 *   (at your option) any later version.                                   *
 
17
 *                                                                         *
 
18
 ***************************************************************************/
 
19
 /*  $Id: qgsspitplugin.cpp,v 1.11.6.1 2004/12/03 17:17:36 gsherman Exp $ */
 
20
 
 
21
// includes
 
22
#include <iostream>
 
23
#include <vector>
 
24
#include "../../src/qgisapp.h"
 
25
 
 
26
#include <qtoolbar.h>
 
27
#include <qmenubar.h>
 
28
#include <qmessagebox.h>
 
29
#include <qpopupmenu.h>
 
30
#include <qlineedit.h>
 
31
#include <qaction.h>
 
32
#include <qapplication.h>
 
33
#include <qcursor.h>
 
34
#include "qgsspitplugin.h"
 
35
#include "qgsspit.h"
 
36
// xpm for creating the toolbar icon
 
37
#include "spiticon.xpm"
 
38
 
 
39
#ifdef WIN32
 
40
#define QGISEXTERN extern "C" __declspec( dllexport )
 
41
#else
 
42
#define QGISEXTERN extern "C"
 
43
#endif
 
44
 
 
45
static const char * const ident_ = "$Id: qgsspitplugin.cpp,v 1.11.6.1 2004/12/03 17:17:36 gsherman Exp $";
 
46
 
 
47
static const char * const name_ = "SPIT";
 
48
static const char * const description_ = "Shapefile to PostgreSQL/PostGIS Import Tool";
 
49
static const char * const version_ = "Version 0.1";
 
50
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
 
51
 
 
52
 
 
53
 
 
54
/**
 
55
* Constructor for the plugin. The plugin is passed a pointer to the main app
 
56
* and an interface object that provides access to exposed functions in QGIS.
 
57
* @param qgis Pointer to the QGIS main window
 
58
* @parma _qI Pointer to the QGIS interface object
 
59
*/
 
60
QgsSpitPlugin::QgsSpitPlugin(QgisApp * qgis, QgisIface * _qI)
 
61
    : qgisMainWindow(qgis), 
 
62
      qI(_qI),
 
63
      QgisPlugin(name_, description_, version_, type_ )
 
64
{
 
65
}
 
66
 
 
67
QgsSpitPlugin::~QgsSpitPlugin()
 
68
{
 
69
 
 
70
}
 
71
 
 
72
/*
 
73
* Initialize the GUI interface for the plugin 
 
74
*/
 
75
void QgsSpitPlugin::initGui()
 
76
{
 
77
    // add a menu with 2 items
 
78
    QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindow);
 
79
    int menuId =  pluginMenu->insertItem(QIconSet(spitIcon),
 
80
         "&Import Shapefiles to PostgreSQL", this, SLOT(spit()));
 
81
    pluginMenu->setWhatsThis(menuId,"Import shapefiles into a PostGIS-enabled PostgreSQL database. "
 
82
        "The schema and field names can be customized on import"); 
 
83
  //  pluginMenu->insertItem("&Unload SPIT Plugin", this, SLOT(unload()));
 
84
 
 
85
    menu = ((QMainWindow *) qgisMainWindow)->menuBar();
 
86
 
 
87
    //menuId = menu->insertItem("&Spit", pluginMenu);
 
88
    menuId = qI->addMenu("&Spit", pluginMenu);
 
89
     // Create the action for tool
 
90
    spitAction = new QAction("Import Shapefiles to PostgreSQL", QIconSet(spitIcon), "&SPIT",
 
91
                                              0, this, "spit");
 
92
    spitAction->setWhatsThis("Import shapefiles into a PostGIS-enabled PostgreSQL database. "
 
93
        "The schema and field names can be customized on import"); 
 
94
    // Connect the action to the spit slot
 
95
    connect(spitAction, SIGNAL(activated()), this, SLOT(spit()));
 
96
     // Add the icon to the toolbar
 
97
  qI->addToolBarIcon(spitAction); 
 
98
 
 
99
}
 
100
 
 
101
// Slot called when the shapefile to postgres menu item is activated
 
102
void QgsSpitPlugin::spit()
 
103
{
 
104
 QgsSpit *spitDlg = new QgsSpit();
 
105
 spitDlg->show();
 
106
}
 
107
 
 
108
 
 
109
// Unload the plugin by cleaning up the GUI
 
110
void QgsSpitPlugin::unload()
 
111
{
 
112
    // remove the GUI
 
113
    menu->removeItem(menuId);
 
114
    qI->removeToolBarIcon(spitAction);
 
115
    delete spitAction;
 
116
}
 
117
 
 
118
/** 
 
119
* Required extern functions needed  for every plugin 
 
120
* These functions can be called prior to creating an instance
 
121
* of the plugin class
 
122
*/
 
123
// Class factory to return a new instance of the plugin class
 
124
QGISEXTERN QgisPlugin * classFactory(QgisApp * qgis, QgisIface * qI)
 
125
{
 
126
    return new QgsSpitPlugin(qgis, qI);
 
127
}
 
128
 
 
129
// Return the name of the plugin
 
130
QGISEXTERN QString name()
 
131
{
 
132
    return name_;
 
133
}
 
134
 
 
135
// Return the description
 
136
QGISEXTERN QString description()
 
137
{
 
138
    return description_;
 
139
}
 
140
 
 
141
// Return the type (either UI or MapLayer plugin)
 
142
QGISEXTERN int type()
 
143
{
 
144
    return type_;
 
145
}
 
146
 
 
147
// Return the version
 
148
QGISEXTERN QString version()
 
149
{
 
150
  return version_;
 
151
}
 
152
 
 
153
 
 
154
// Delete ourself
 
155
QGISEXTERN void unload(QgisPlugin * p)
 
156
{
 
157
    delete p;
 
158
}