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

« back to all changes in this revision

Viewing changes to src/plugins/quick_print/quickprintplugin.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
  quickprint.cpp
 
3
  Quick Print is a plugin to quickly print a map with minimal effort.
 
4
  -------------------
 
5
         begin                : Jan 2008
 
6
         copyright            : (c) Tim Sutton, 2008
 
7
         email                : tim@linfiniti.com
 
8
 
 
9
 ***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
/*  $Id: plugin.cpp 7796 2007-12-16 22:11:38Z homann $ */
 
18
 
 
19
//
 
20
// QGIS Specific includes
 
21
//
 
22
 
 
23
#include <qgisinterface.h>
 
24
#include <qgisgui.h>
 
25
#include "quickprintplugin.h"
 
26
#include "quickprintgui.h"
 
27
#include <qgsapplication.h>
 
28
 
 
29
//
 
30
// Qt4 Related Includes
 
31
//
 
32
 
 
33
#include <QAction>
 
34
#include <QFile>
 
35
#include <QToolBar>
 
36
 
 
37
 
 
38
static const char * const sIdent = "$Id: plugin.cpp 7796 2007-12-16 22:11:38Z homann $";
 
39
static const QString sName = QObject::tr( "Quick Print" );
 
40
static const QString sDescription = QObject::tr( "Quick Print is a plugin to quickly print a map with minimal effort." );
 
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
QuickPrintPlugin::QuickPrintPlugin( QgisInterface * theQgisInterface ):
 
56
    QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ),
 
57
    mQGisIface( theQgisInterface )
 
58
{
 
59
  mpMapCanvas = mQGisIface->mapCanvas();
 
60
}
 
61
 
 
62
QuickPrintPlugin::~QuickPrintPlugin()
 
63
{
 
64
 
 
65
}
 
66
 
 
67
/*
 
68
 * Initialize the GUI interface for the plugin - this is only called once when the plugin is
 
69
 * added to the plugin registry in the QGIS application.
 
70
 */
 
71
void QuickPrintPlugin::initGui()
 
72
{
 
73
 
 
74
  // Create the action for tool
 
75
  mQActionPointer = new QAction( QIcon(), tr( "Quick Print" ), this );
 
76
  // Set the icon
 
77
  setCurrentTheme( "" );
 
78
  // Set the what's this text
 
79
  mQActionPointer->setWhatsThis( tr( "Provides a way to quickly produce a map with minimal user input." ) );
 
80
  // Connect the action to the run
 
81
  connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
 
82
  // Add the icon to the toolbar
 
83
  mQGisIface->addToolBarIcon( mQActionPointer );
 
84
  mQGisIface->addPluginToMenu( tr( "&Quick Print" ), mQActionPointer );
 
85
 
 
86
  // this is called when the icon theme is changed
 
87
  connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
 
88
}
 
89
//method defined in interface
 
90
void QuickPrintPlugin::help()
 
91
{
 
92
  //implement me!
 
93
}
 
94
 
 
95
// Slot called when the menu item is activated
 
96
// If you created more menu items / toolbar buttons in initiGui, you should
 
97
// create a separate handler for each action - this single run() method will
 
98
// not be enough
 
99
void QuickPrintPlugin::run()
 
100
{
 
101
  QuickPrintGui *mypPluginGui = new QuickPrintGui(
 
102
    mpMapCanvas,
 
103
    mQGisIface->mainWindow(),
 
104
    QgisGui::ModalDialogFlags );
 
105
  mypPluginGui->setAttribute( Qt::WA_DeleteOnClose );
 
106
  mypPluginGui->exec(); //gui will decide when to call print
 
107
 
 
108
}
 
109
 
 
110
// Unload the plugin by cleaning up the GUI
 
111
void QuickPrintPlugin::unload()
 
112
{
 
113
  // remove the GUI
 
114
  mQGisIface->removePluginMenu( "&Quick Print", mQActionPointer );
 
115
  mQGisIface->removeToolBarIcon( mQActionPointer );
 
116
  delete mQActionPointer;
 
117
}
 
118
 
 
119
//! Set icons to the current theme
 
120
void QuickPrintPlugin::setCurrentTheme( QString theThemeName )
 
121
{
 
122
  QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/quick_print.png";
 
123
  QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/quick_print.png";
 
124
  QString myQrcPath = ":/quick_print.png";
 
125
  if ( QFile::exists( myCurThemePath ) )
 
126
  {
 
127
    mQActionPointer->setIcon( QIcon( myCurThemePath ) );
 
128
  }
 
129
  else if ( QFile::exists( myDefThemePath ) )
 
130
  {
 
131
    mQActionPointer->setIcon( QIcon( myDefThemePath ) );
 
132
  }
 
133
  else if ( QFile::exists( myQrcPath ) )
 
134
  {
 
135
    mQActionPointer->setIcon( QIcon( myQrcPath ) );
 
136
  }
 
137
  else
 
138
  {
 
139
    mQActionPointer->setIcon( QIcon() );
 
140
  }
 
141
}
 
142
 
 
143
//////////////////////////////////////////////////////////////////////////
 
144
//
 
145
//
 
146
//  THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
 
147
//    YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
 
148
//      MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
 
149
//
 
150
//
 
151
//////////////////////////////////////////////////////////////////////////
 
152
 
 
153
 
 
154
/**
 
155
 * Required extern functions needed  for every plugin
 
156
 * These functions can be called prior to creating an instance
 
157
 * of the plugin class
 
158
 */
 
159
// Class factory to return a new instance of the plugin class
 
160
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
 
161
{
 
162
  return new QuickPrintPlugin( theQgisInterfacePointer );
 
163
}
 
164
// Return the name of the plugin - note that we do not user class members as
 
165
// the class may not yet be insantiated when this method is called.
 
166
QGISEXTERN QString name()
 
167
{
 
168
  return sName;
 
169
}
 
170
 
 
171
// Return the description
 
172
QGISEXTERN QString description()
 
173
{
 
174
  return sDescription;
 
175
}
 
176
 
 
177
// Return the type (either UI or MapLayer plugin)
 
178
QGISEXTERN int type()
 
179
{
 
180
  return sPluginType;
 
181
}
 
182
 
 
183
// Return the version number for the plugin
 
184
QGISEXTERN QString version()
 
185
{
 
186
  return sPluginVersion;
 
187
}
 
188
 
 
189
// Delete ourself
 
190
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
 
191
{
 
192
  delete thePluginPointer;
 
193
}