Skip to content

Commit 43f2596

Browse files
author
wonder
committedOct 21, 2008
Call unload() on QGIS exit also for python plugins.
git-svn-id: http://svn.osgeo.org/qgis/trunk@9511 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent daad899 commit 43f2596

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,6 +4187,8 @@ void QgisApp::loadPythonSupport()
41874187

41884188
if ( mPythonUtils && mPythonUtils->isEnabled() )
41894189
{
4190+
QgsPluginRegistry::instance()->setPythonUtils(mPythonUtils);
4191+
41904192
mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
41914193
connect( mActionShowPythonDialog, SIGNAL( triggered() ), this, SLOT( showPythonDialog() ) );
41924194

‎src/app/qgspluginregistry.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "qgspluginregistry.h"
2121
#include "qgspluginmetadata.h"
2222
#include "qgisplugin.h"
23+
#include "qgspythonutils.h"
24+
#include "qgslogger.h"
2325

2426
QgsPluginRegistry *QgsPluginRegistry::_instance = 0;
2527
QgsPluginRegistry *QgsPluginRegistry::instance()
@@ -32,9 +34,16 @@ QgsPluginRegistry *QgsPluginRegistry::instance()
3234
}
3335

3436
QgsPluginRegistry::QgsPluginRegistry()
37+
: mPythonUtils(NULL)
3538
{
3639
// constructor does nothing
3740
}
41+
42+
void QgsPluginRegistry::setPythonUtils(QgsPythonUtils* pythonUtils)
43+
{
44+
mPythonUtils = pythonUtils;
45+
}
46+
3847
QString QgsPluginRegistry::library( QString pluginKey )
3948
{
4049
QgsPluginMetadata *pmd = plugins[pluginKey];
@@ -92,6 +101,20 @@ void QgsPluginRegistry::unloadAll()
92101
for ( std::map<QString, QgsPluginMetadata*>::iterator it = plugins.begin();
93102
it != plugins.end();
94103
it++ )
95-
if ( it->second->plugin() )
96-
it->second->plugin()->unload();
104+
{
105+
if (isPythonPlugin(it->second->name()))
106+
{
107+
if (mPythonUtils)
108+
mPythonUtils->unloadPlugin(it->second->library());
109+
else
110+
QgsDebugMsg("warning: python utils is NULL");
111+
}
112+
else
113+
{
114+
if ( it->second->plugin() )
115+
it->second->plugin()->unload();
116+
else
117+
QgsDebugMsg("warning: plugin is NULL:" + it->second->name());
118+
}
119+
}
97120
}

‎src/app/qgspluginregistry.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define QGSPLUGINREGISTRY_H
2222
#include <map>
2323
class QgsPluginMetadata;
24+
class QgsPythonUtils;
2425
class QgisPlugin;
2526
class QString;
2627
/**
@@ -31,29 +32,32 @@ class QString;
3132
class QgsPluginRegistry
3233
{
3334
public:
34-
//! Returns the instance pointer, creating the object on the first call
35+
//! Returns the instance pointer, creating the object on the first call
3536
static QgsPluginRegistry* instance();
36-
//! Return the full path to the plugins library using the plugin name as a key
37+
//! Return the full path to the plugins library using the plugin name as a key
3738
QString library( QString pluginKey );
38-
//! Retrieve the metadata for a plugin by name
39+
//! Retrieve the metadata for a plugin by name
3940
QgsPluginMetadata * pluginMetadata( QString name );
40-
//! Retrieve a pointer to a loaded plugin by name
41+
//! Retrieve a pointer to a loaded plugin by name
4142
QgisPlugin * plugin( QString name );
42-
//! Return whether the plugin is pythonic
43+
//! Return whether the plugin is pythonic
4344
bool isPythonPlugin( QString name );
44-
//! Add a plugin to the map of loaded plugins
45+
//! Add a plugin to the map of loaded plugins
4546
void addPlugin( QString _library, QString _name, QgisPlugin * _plugin );
46-
//! Add a plugin written in python
47+
//! Add a plugin written in python
4748
void addPythonPlugin( QString packageName, QString pluginName );
48-
//! Remove a plugin from the list of loaded plugins
49+
//! Remove a plugin from the list of loaded plugins
4950
void removePlugin( QString name );
50-
//! Unload plugins
51+
//! Unload plugins
5152
void unloadAll();
53+
//! Save pointer for python utils (needed for unloading python plugins)
54+
void setPythonUtils(QgsPythonUtils* pythonUtils);
5255
protected:
53-
//! protected constructor
56+
//! protected constructor
5457
QgsPluginRegistry();
5558
private:
5659
static QgsPluginRegistry* _instance;
5760
std::map<QString, QgsPluginMetadata*> plugins;
61+
QgsPythonUtils* mPythonUtils;
5862
};
5963
#endif //QgsPluginRegistry_H

0 commit comments

Comments
 (0)
Please sign in to comment.