1
/***************************************************************************
3
Quick Print is a plugin to quickly print a map with minimal effort.
6
copyright : (c) Tim Sutton, 2008
7
email : tim@linfiniti.com
9
***************************************************************************
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. *
16
***************************************************************************/
17
/* $Id: plugin.cpp 7796 2007-12-16 22:11:38Z homann $ */
20
// QGIS Specific includes
23
#include <qgisinterface.h>
25
#include "quickprintplugin.h"
26
#include "quickprintgui.h"
27
#include <qgsapplication.h>
30
// Qt4 Related Includes
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;
44
//////////////////////////////////////////////////////////////////////
46
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
48
//////////////////////////////////////////////////////////////////////
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
55
QuickPrintPlugin::QuickPrintPlugin( QgisInterface * theQgisInterface ):
56
QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ),
57
mQGisIface( theQgisInterface )
59
mpMapCanvas = mQGisIface->mapCanvas();
62
QuickPrintPlugin::~QuickPrintPlugin()
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.
71
void QuickPrintPlugin::initGui()
74
// Create the action for tool
75
mQActionPointer = new QAction( QIcon(), tr( "Quick Print" ), this );
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 );
86
// this is called when the icon theme is changed
87
connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
89
//method defined in interface
90
void QuickPrintPlugin::help()
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
99
void QuickPrintPlugin::run()
101
QuickPrintGui *mypPluginGui = new QuickPrintGui(
103
mQGisIface->mainWindow(),
104
QgisGui::ModalDialogFlags );
105
mypPluginGui->setAttribute( Qt::WA_DeleteOnClose );
106
mypPluginGui->exec(); //gui will decide when to call print
110
// Unload the plugin by cleaning up the GUI
111
void QuickPrintPlugin::unload()
114
mQGisIface->removePluginMenu( "&Quick Print", mQActionPointer );
115
mQGisIface->removeToolBarIcon( mQActionPointer );
116
delete mQActionPointer;
119
//! Set icons to the current theme
120
void QuickPrintPlugin::setCurrentTheme( QString theThemeName )
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 ) )
127
mQActionPointer->setIcon( QIcon( myCurThemePath ) );
129
else if ( QFile::exists( myDefThemePath ) )
131
mQActionPointer->setIcon( QIcon( myDefThemePath ) );
133
else if ( QFile::exists( myQrcPath ) )
135
mQActionPointer->setIcon( QIcon( myQrcPath ) );
139
mQActionPointer->setIcon( QIcon() );
143
//////////////////////////////////////////////////////////////////////////
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
151
//////////////////////////////////////////////////////////////////////////
155
* Required extern functions needed for every plugin
156
* These functions can be called prior to creating an instance
157
* of the plugin class
159
// Class factory to return a new instance of the plugin class
160
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
162
return new QuickPrintPlugin( theQgisInterfacePointer );
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()
171
// Return the description
172
QGISEXTERN QString description()
177
// Return the type (either UI or MapLayer plugin)
178
QGISEXTERN int type()
183
// Return the version number for the plugin
184
QGISEXTERN QString version()
186
return sPluginVersion;
190
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
192
delete thePluginPointer;