~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/grid_maker/plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
  plugin.cpp 
3
 
  Import tool for various worldmap analysis output files
4
 
Functions:
5
 
 
6
 
-------------------
7
 
begin                : Jan 21, 2004
8
 
copyright            : (C) 2004 by Tim Sutton
9
 
email                : tim@linfiniti.com
10
 
 
11
 
 ***************************************************************************/
12
 
 
13
 
/***************************************************************************
14
 
 *                                                                         *
15
 
 *   This program is free software; you can redistribute it and/or modify  *
16
 
 *   it under the terms of the GNU General Public License as published by  *
17
 
 *   the Free Software Foundation; either version 2 of the License, or     *
18
 
 *   (at your option) any later version.                                   *
19
 
 *                                                                         *
20
 
 ***************************************************************************/
21
 
/*  $Id: plugin.cpp 6301 2006-12-22 07:43:47Z g_j_m $ */
22
 
 
23
 
// includes
24
 
 
25
 
#include "qgisapp.h"
26
 
#include "qgisgui.h"
27
 
#include "qgsmaplayer.h"
28
 
#include "plugin.h"
29
 
 
30
 
#include <QAction>
31
 
 
32
 
//non qt includes
33
 
#include <iostream>
34
 
 
35
 
//the gui subclass
36
 
#include "plugingui.h"
37
 
 
38
 
// xpm for creating the toolbar icon
39
 
#include "icon.xpm"
40
 
// 
41
 
#ifdef WIN32
42
 
#define QGISEXTERN extern "C" __declspec( dllexport )
43
 
#else
44
 
#define QGISEXTERN extern "C"
45
 
#endif
46
 
 
47
 
 
48
 
static const char * const ident_ = "$Id: plugin.cpp 6301 2006-12-22 07:43:47Z g_j_m $";
49
 
 
50
 
static const QString name_ = QObject::tr("Graticule Creator");
51
 
static const QString description_ = QObject::tr("Builds a graticule");
52
 
static const QString version_ = QObject::tr("Version 0.1");
53
 
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
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
 
 * @param _qI Pointer to the QGIS interface object
59
 
 */
60
 
QgsGridMakerPlugin::QgsGridMakerPlugin(QgisApp * theQGisApp, 
61
 
                                       QgisIface * theQgisInterFace):
62
 
          QgisPlugin(name_,description_,version_,type_),
63
 
          qgisMainWindowPointer(theQGisApp), 
64
 
          qGisInterface(theQgisInterFace)
65
 
{
66
 
}
67
 
 
68
 
QgsGridMakerPlugin::~QgsGridMakerPlugin()
69
 
{
70
 
 
71
 
}
72
 
 
73
 
/* Following functions return name, description, version, and type for the plugin */
74
 
QString QgsGridMakerPlugin::name()
75
 
{
76
 
  return pluginNameQString;
77
 
}
78
 
 
79
 
QString QgsGridMakerPlugin::version()
80
 
{
81
 
  return pluginVersionQString;
82
 
 
83
 
}
84
 
 
85
 
QString QgsGridMakerPlugin::description()
86
 
{
87
 
  return pluginDescriptionQString;
88
 
 
89
 
}
90
 
 
91
 
int QgsGridMakerPlugin::type()
92
 
{
93
 
  return QgisPlugin::UI;
94
 
}
95
 
 
96
 
/*
97
 
 * Initialize the GUI interface for the plugin 
98
 
 */
99
 
void QgsGridMakerPlugin::initGui()
100
 
{
101
 
  // Create the action for tool
102
 
  myQActionPointer = new QAction(QIcon(icon), tr("&Graticule Creator"), this);
103
 
  myQActionPointer->setWhatsThis(tr("Creates a graticule (grid) and stores the result as a shapefile"));
104
 
  // Connect the action to the run
105
 
  connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
106
 
 
107
 
  // Add the icon to the toolbar
108
 
  qGisInterface->addToolBarIcon(myQActionPointer);
109
 
  qGisInterface->addPluginMenu(tr("&Graticules"), myQActionPointer);
110
 
 
111
 
}
112
 
//method defined in interface
113
 
void QgsGridMakerPlugin::help()
114
 
{
115
 
  //implement me!
116
 
}
117
 
 
118
 
// Slot called when the buffer menu item is activated
119
 
void QgsGridMakerPlugin::run()
120
 
{
121
 
  QgsGridMakerPluginGui *myPluginGui=new QgsGridMakerPluginGui(qgisMainWindowPointer, QgisGui::ModalDialogFlags);
122
 
  //listen for when the layer has been made so we can draw it
123
 
  connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
124
 
  connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
125
 
  myPluginGui->show();
126
 
}
127
 
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
128
 
//layer
129
 
void QgsGridMakerPlugin::drawRasterLayer(QString theQString)
130
 
{
131
 
  qGisInterface->addRasterLayer(theQString);
132
 
}
133
 
//!draw a vector layer in the qui - intended to respond to signal sent by diolog when it as finished creating a layer
134
 
////needs to be given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
135
 
void QgsGridMakerPlugin::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
136
 
{
137
 
 qGisInterface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
138
 
}
139
 
 
140
 
// Unload the plugin by cleaning up the GUI
141
 
void QgsGridMakerPlugin::unload()
142
 
{
143
 
  // remove the GUI
144
 
  qGisInterface->removePluginMenu(tr("&Graticules"),myQActionPointer);
145
 
  qGisInterface->removeToolBarIcon(myQActionPointer);
146
 
  delete myQActionPointer;
147
 
}
148
 
/** 
149
 
 * Required extern functions needed  for every plugin 
150
 
 * These functions can be called prior to creating an instance
151
 
 * of the plugin class
152
 
 */
153
 
// Class factory to return a new instance of the plugin class
154
 
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
155
 
{
156
 
  return new QgsGridMakerPlugin(theQGisAppPointer, theQgisInterfacePointer);
157
 
}
158
 
 
159
 
// Return the name of the plugin - note that we do not user class members as
160
 
// the class may not yet be insantiated when this method is called.
161
 
QGISEXTERN QString name()
162
 
{
163
 
    return name_;
164
 
}
165
 
 
166
 
// Return the description
167
 
QGISEXTERN QString description()
168
 
{
169
 
    return description_;
170
 
}
171
 
 
172
 
// Return the type (either UI or MapLayer plugin)
173
 
QGISEXTERN int type()
174
 
{
175
 
    return type_;
176
 
}
177
 
 
178
 
// Return the version number for the plugin
179
 
QGISEXTERN QString version()
180
 
{
181
 
  return version_;
182
 
}
183
 
 
184
 
// Delete ourself
185
 
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
186
 
{
187
 
  delete thePluginPointer;
188
 
}