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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-04-24 15:12:20 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120424151220-r88g00af5fpn5fc3
Tags: 1.7.4+1.7.5~20120320-1
The "Sometimes they come back" release.

* Branching from Qgis tree and adapting to current Debian Policy and
  standards. The target tree is currently set to release-1.7.
  (closes: #661491, #606304, #615683, #616182, #600308)
* Policy bumped to 3.9.3.
* Moving to debhelper compatibility level 9.
* Source format is now 3.0 with quilt support.
* Merged with 2bf42287 upstream git snapshot.
* Migrated to dh_python2 instead of python-central.
  (closes: #617048)
* Snapshot in qgis.org release-1.7: c936d031
* Added an automagic creation of a lintian override for sqlite embedding.
  This is required for uploading currently.
* Added missing ${misc:Depends} to make lintian happy.
* Copyright notes updated and debian/copyright moved to format 1.0.
* More licenses notices now reported in debian/copyright. Thanks ftpmasters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id$
2
 
//////////////////////////////////////////////////////////////////////////////
3
 
//
4
 
// begin                : Aug 24, 2008
5
 
// copyright            : (C) 2008 by Mateusz Loskot
6
 
// email                : mateusz@loskot.net
7
 
//
8
 
//////////////////////////////////////////////////////////////////////////////
9
 
//
10
 
// This program is free software; you can redistribute it and/or modify
11
 
// it under the terms of the GNU General Public License as published by
12
 
// the Free Software Foundation; either version 2 of the License,
13
 
// or (at your option) any later version.
14
 
//
15
 
//////////////////////////////////////////////////////////////////////////////
16
 
 
17
 
// qgis::plugin::ogrconv
18
 
#include "plugin.h"
19
 
#include "dialog.h"
20
 
// QGIS
21
 
#include <qgisinterface.h>
22
 
#include <qgisgui.h>
23
 
#include <qgsapplication.h>
24
 
#include <qgslogger.h>
25
 
// Qt
26
 
#include <QAction>
27
 
#include <QFile>
28
 
#include <QToolBar>
29
 
// std
30
 
#include <cassert>
31
 
 
32
 
#include <ogr_api.h>
33
 
 
34
 
static const char * const sIdent = "$Id$";
35
 
static const QString sName = QObject::tr( "OGR Layer Converter" );
36
 
static const QString sDescription = QObject::tr( "Translates vector layers between formats supported by OGR library" );
37
 
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
38
 
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
39
 
 
40
 
//////////////////////////////////////////////////////////////////////////////
41
 
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
42
 
//////////////////////////////////////////////////////////////////////////////
43
 
 
44
 
OgrPlugin::OgrPlugin( QgisInterface * theQgisInterface ) :
45
 
    QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ),
46
 
    mQGisIface( theQgisInterface ),
47
 
    mQActionPointer( 0 )
48
 
{
49
 
  assert( 0 != mQGisIface );
50
 
}
51
 
 
52
 
OgrPlugin::~OgrPlugin()
53
 
{
54
 
}
55
 
 
56
 
void OgrPlugin::initGui()
57
 
{
58
 
  // Create the action for tool
59
 
  mQActionPointer = new QAction( QIcon(), tr( "Run OGR Layer Converter" ), this );
60
 
 
61
 
  // Set the icon
62
 
  setCurrentTheme( "" );
63
 
 
64
 
  // Set the what's this text
65
 
  mQActionPointer->setWhatsThis( tr( "Translates vector layers between formats supported by OGR library" ) );
66
 
 
67
 
  // Connect the action to the run
68
 
  connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
69
 
 
70
 
  // Add the icon to the toolbar
71
 
  mQGisIface->addToolBarIcon( mQActionPointer );
72
 
  mQGisIface->addPluginToMenu( tr( "OG&R Converter" ), mQActionPointer );
73
 
 
74
 
  // this is called when the icon theme is changed
75
 
  connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
76
 
}
77
 
 
78
 
//method defined in interface
79
 
void OgrPlugin::help()
80
 
{
81
 
  //implement me!
82
 
}
83
 
 
84
 
void OgrPlugin::run()
85
 
{
86
 
  assert( 0 != mQGisIface );
87
 
 
88
 
  Dialog* ogrDialog = new Dialog( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );
89
 
  ogrDialog->setAttribute( Qt::WA_DeleteOnClose );
90
 
  ogrDialog->show();
91
 
}
92
 
 
93
 
void OgrPlugin::unload()
94
 
{
95
 
  assert( 0 != mQGisIface );
96
 
 
97
 
  // TODO: Who is responsible for OGR cleanup?
98
 
  //OGRCleanupAll();
99
 
 
100
 
  // remove the GUI
101
 
  mQGisIface->removePluginMenu( "OG&R Converter", mQActionPointer );
102
 
  mQGisIface->removeToolBarIcon( mQActionPointer );
103
 
  delete mQActionPointer;
104
 
}
105
 
 
106
 
//! Set icons to the current theme
107
 
void OgrPlugin::setCurrentTheme( QString theThemeName )
108
 
{
109
 
  QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/ogr_converter.png";
110
 
  QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/ogr_converter.png";
111
 
  QString myQrcPath = ":/ogr_converter.png";
112
 
  if ( QFile::exists( myCurThemePath ) )
113
 
  {
114
 
    mQActionPointer->setIcon( QIcon( myCurThemePath ) );
115
 
  }
116
 
  else if ( QFile::exists( myDefThemePath ) )
117
 
  {
118
 
    mQActionPointer->setIcon( QIcon( myDefThemePath ) );
119
 
  }
120
 
  else if ( QFile::exists( myQrcPath ) )
121
 
  {
122
 
    mQActionPointer->setIcon( QIcon( myQrcPath ) );
123
 
  }
124
 
  else
125
 
  {
126
 
    mQActionPointer->setIcon( QIcon() );
127
 
  }
128
 
}
129
 
 
130
 
/////////////////////////////////////////////////////////////////////////////
131
 
//  THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
132
 
//    YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
133
 
//      MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
134
 
/////////////////////////////////////////////////////////////////////////////
135
 
 
136
 
// Required extern functions needed  for every plugin
137
 
// These functions can be called prior to creating an instance
138
 
// of the plugin class.
139
 
 
140
 
// Class factory to return a new instance of the plugin class
141
 
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
142
 
{
143
 
  return new OgrPlugin( theQgisInterfacePointer );
144
 
}
145
 
 
146
 
// Return the name of the plugin - note that we do not user class members as
147
 
// the class may not yet be insantiated when this method is called.
148
 
QGISEXTERN QString name()
149
 
{
150
 
  return sName;
151
 
}
152
 
 
153
 
// Return the description
154
 
QGISEXTERN QString description()
155
 
{
156
 
  return sDescription;
157
 
}
158
 
 
159
 
// Return the type (either UI or MapLayer plugin)
160
 
QGISEXTERN int type()
161
 
{
162
 
  return sPluginType;
163
 
}
164
 
 
165
 
// Return the version number for the plugin
166
 
QGISEXTERN QString version()
167
 
{
168
 
  return sPluginVersion;
169
 
}
170
 
 
171
 
// Delete ourself
172
 
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
173
 
{
174
 
  delete thePluginPointer;
175
 
}