~ubuntu-branches/ubuntu/saucy/qgis/saucy

« back to all changes in this revision

Viewing changes to src/plugins/dxf2shp_converter/dxf2shpconverter.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
 *Copyright (C) 2008 Paolo L. Scala, Barbara Rita Barricelli, Marco Padula *
 
3
 * CNR, Milan Unit (Information Technology),                               *
 
4
 * Construction Technologies Institute.\n";                                *
 
5
 *                                                                         *
 
6
 * email : Paolo L. Scala <scala@itc.cnr.it>                               *
 
7
 *                                                                         *
 
8
 *   This is a plugin generated from the QGIS plugin template              *
 
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, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 ***************************************************************************/
 
15
/*  $Id$ */
 
16
 
 
17
//
 
18
// QGIS Specific includes
 
19
//
 
20
 
 
21
#include <qgisinterface.h>
 
22
#include <qgisgui.h>
 
23
#include <qgsapplication.h>
 
24
#include <qgsvectorlayer.h>
 
25
 
 
26
#include "dxf2shpconverter.h"
 
27
#include "dxf2shpconvertergui.h"
 
28
 
 
29
//
 
30
// Qt4 Related Includes
 
31
//
 
32
 
 
33
#include <QAction>
 
34
#include <QFile>
 
35
#include <QToolBar>
 
36
 
 
37
static const char *const sIdent =
 
38
  "$Id: plugin.cpp 6935 2007-05-07 14:29:51Z wonder $";
 
39
static const QString sName = QObject::tr( "Dxf2Shp Converter" );
 
40
static const QString sDescription = QObject::tr( "Converts from dxf to shp file format" );
 
41
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
 
42
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
 
43
 
 
44
//////////////////////////////////////////////////////////////////////
 
45
//
 
46
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
 
47
//
 
48
//////////////////////////////////////////////////////////////////////
 
49
 
 
50
/**
 
51
 * Constructor for the plugin. The plugin is passed a pointer
 
52
 * an interface object that provides access to exposed functions in QGIS.
 
53
 * @param theQGisInterface - Pointer to the QGIS interface object
 
54
 */
 
55
dxf2shpConverter::dxf2shpConverter( QgisInterface *theQgisInterface ): QgisPlugin
 
56
    ( sName, sDescription, sPluginVersion, sPluginType ), mQGisIface
 
57
    ( theQgisInterface ) {}
 
58
 
 
59
dxf2shpConverter::~dxf2shpConverter()
 
60
{
 
61
 
 
62
}
 
63
 
 
64
/*
 
65
 * Initialize the GUI interface for the plugin - this is only called once when the plugin is
 
66
 * added to the plugin registry in the QGIS application.
 
67
 */
 
68
void dxf2shpConverter::initGui()
 
69
{
 
70
  // Create the action for tool
 
71
  mQActionPointer = new QAction( QIcon(), "Dxf2Shp Converter", this );
 
72
 
 
73
  // Set the icon
 
74
  setCurrentTheme( "" );
 
75
 
 
76
  // Set the what's this text
 
77
  mQActionPointer->setWhatsThis( tr( "Converts DXF files in Shapefile format" ) );
 
78
 
 
79
  // Connect the action to the run
 
80
  connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
 
81
 
 
82
  // Add the icon to the toolbar
 
83
  mQGisIface->addToolBarIcon( mQActionPointer );
 
84
  mQGisIface->addPluginToMenu( tr( "&Dxf2Shp" ), mQActionPointer );
 
85
 
 
86
  // this is called when the icon theme is changed
 
87
  connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
 
88
}
 
89
 
 
90
//method defined in interface
 
91
void dxf2shpConverter::help()
 
92
{
 
93
  //implement me!
 
94
}
 
95
 
 
96
// Slot called when the menu item is activated
 
97
// If you created more menu items / toolbar buttons in initiGui, you should
 
98
// create a separate handler for each action - this single run() method will
 
99
// not be enough
 
100
void dxf2shpConverter::run()
 
101
{
 
102
  dxf2shpConverterGui *myPluginGui =
 
103
    new dxf2shpConverterGui( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );
 
104
 
 
105
  myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
 
106
 
 
107
  connect( myPluginGui, SIGNAL( createLayer( QString, QString ) ), this, SLOT( addMyLayer( QString, QString ) ) );
 
108
 
 
109
  myPluginGui->show();
 
110
}
 
111
 
 
112
// Unload the plugin by cleaning up the GUI
 
113
void dxf2shpConverter::unload()
 
114
{
 
115
  // remove the GUI
 
116
  mQGisIface->removePluginMenu( tr( "&Dxf2Shp" ), mQActionPointer );
 
117
  mQGisIface->removeToolBarIcon( mQActionPointer );
 
118
  delete mQActionPointer;
 
119
}
 
120
 
 
121
void dxf2shpConverter::addMyLayer( QString myfname, QString mytitle )
 
122
{
 
123
  mQGisIface->addVectorLayer( myfname, mytitle, "ogr" );
 
124
}
 
125
 
 
126
//! Set icons to the current theme
 
127
void dxf2shpConverter::setCurrentTheme( QString theThemeName )
 
128
{
 
129
  QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/dxf2shp_converter.png";
 
130
  QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/dxf2shp_converter.png";
 
131
  QString myQrcPath = ":/dxf2shp_converter.png";
 
132
  if ( QFile::exists( myCurThemePath ) )
 
133
  {
 
134
    mQActionPointer->setIcon( QIcon( myCurThemePath ) );
 
135
  }
 
136
  else if ( QFile::exists( myDefThemePath ) )
 
137
  {
 
138
    mQActionPointer->setIcon( QIcon( myDefThemePath ) );
 
139
  }
 
140
  else if ( QFile::exists( myQrcPath ) )
 
141
  {
 
142
    mQActionPointer->setIcon( QIcon( myQrcPath ) );
 
143
  }
 
144
  else
 
145
  {
 
146
    mQActionPointer->setIcon( QIcon() );
 
147
  }
 
148
}
 
149
 
 
150
//////////////////////////////////////////////////////////////////////////
 
151
//
 
152
//
 
153
//  THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
 
154
//    YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
 
155
//      MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
 
156
//
 
157
//
 
158
//////////////////////////////////////////////////////////////////////////
 
159
 
 
160
 
 
161
/**
 
162
 * Required extern functions needed for every plugin
 
163
 * These functions can be called prior to creating an instance
 
164
 * of the plugin class
 
165
 */
 
166
// Class factory to return a new instance of the plugin class
 
167
QGISEXTERN QgisPlugin *classFactory( QgisInterface *theQgisInterfacePointer )
 
168
{
 
169
  return new dxf2shpConverter( theQgisInterfacePointer );
 
170
}
 
171
 
 
172
// Return the name of the plugin - note that we do not user class members as
 
173
// the class may not yet be insantiated when this method is called.
 
174
QGISEXTERN QString name()
 
175
{
 
176
  return sName;
 
177
}
 
178
 
 
179
// Return the description
 
180
QGISEXTERN QString description()
 
181
{
 
182
  return sDescription;
 
183
}
 
184
 
 
185
// Return the type (either UI or MapLayer plugin)
 
186
QGISEXTERN int type()
 
187
{
 
188
  return sPluginType;
 
189
}
 
190
 
 
191
// Return the version number for the plugin
 
192
QGISEXTERN QString version()
 
193
{
 
194
  return sPluginVersion;
 
195
}
 
196
 
 
197
// Delete ourself
 
198
QGISEXTERN void unload( QgisPlugin *thePluginPointer )
 
199
{
 
200
  delete thePluginPointer;
 
201
}