Skip to content

Commit

Permalink
Call unload() on QGIS exit also for python plugins.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9511 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Oct 21, 2008
1 parent daad899 commit 43f2596
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -4187,6 +4187,8 @@ void QgisApp::loadPythonSupport()

if ( mPythonUtils && mPythonUtils->isEnabled() )
{
QgsPluginRegistry::instance()->setPythonUtils(mPythonUtils);

mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
connect( mActionShowPythonDialog, SIGNAL( triggered() ), this, SLOT( showPythonDialog() ) );

Expand Down
27 changes: 25 additions & 2 deletions src/app/qgspluginregistry.cpp
Expand Up @@ -20,6 +20,8 @@
#include "qgspluginregistry.h"
#include "qgspluginmetadata.h"
#include "qgisplugin.h"
#include "qgspythonutils.h"
#include "qgslogger.h"

QgsPluginRegistry *QgsPluginRegistry::_instance = 0;
QgsPluginRegistry *QgsPluginRegistry::instance()
Expand All @@ -32,9 +34,16 @@ QgsPluginRegistry *QgsPluginRegistry::instance()
}

QgsPluginRegistry::QgsPluginRegistry()
: mPythonUtils(NULL)
{
// constructor does nothing
}

void QgsPluginRegistry::setPythonUtils(QgsPythonUtils* pythonUtils)
{
mPythonUtils = pythonUtils;
}

QString QgsPluginRegistry::library( QString pluginKey )
{
QgsPluginMetadata *pmd = plugins[pluginKey];
Expand Down Expand Up @@ -92,6 +101,20 @@ void QgsPluginRegistry::unloadAll()
for ( std::map<QString, QgsPluginMetadata*>::iterator it = plugins.begin();
it != plugins.end();
it++ )
if ( it->second->plugin() )
it->second->plugin()->unload();
{
if (isPythonPlugin(it->second->name()))
{
if (mPythonUtils)
mPythonUtils->unloadPlugin(it->second->library());
else
QgsDebugMsg("warning: python utils is NULL");
}
else
{
if ( it->second->plugin() )
it->second->plugin()->unload();
else
QgsDebugMsg("warning: plugin is NULL:" + it->second->name());
}
}
}
24 changes: 14 additions & 10 deletions src/app/qgspluginregistry.h
Expand Up @@ -21,6 +21,7 @@
#define QGSPLUGINREGISTRY_H
#include <map>
class QgsPluginMetadata;
class QgsPythonUtils;
class QgisPlugin;
class QString;
/**
Expand All @@ -31,29 +32,32 @@ class QString;
class QgsPluginRegistry
{
public:
//! Returns the instance pointer, creating the object on the first call
//! Returns the instance pointer, creating the object on the first call
static QgsPluginRegistry* instance();
//! Return the full path to the plugins library using the plugin name as a key
//! Return the full path to the plugins library using the plugin name as a key
QString library( QString pluginKey );
//! Retrieve the metadata for a plugin by name
//! Retrieve the metadata for a plugin by name
QgsPluginMetadata * pluginMetadata( QString name );
//! Retrieve a pointer to a loaded plugin by name
//! Retrieve a pointer to a loaded plugin by name
QgisPlugin * plugin( QString name );
//! Return whether the plugin is pythonic
//! Return whether the plugin is pythonic
bool isPythonPlugin( QString name );
//! Add a plugin to the map of loaded plugins
//! Add a plugin to the map of loaded plugins
void addPlugin( QString _library, QString _name, QgisPlugin * _plugin );
//! Add a plugin written in python
//! Add a plugin written in python
void addPythonPlugin( QString packageName, QString pluginName );
//! Remove a plugin from the list of loaded plugins
//! Remove a plugin from the list of loaded plugins
void removePlugin( QString name );
//! Unload plugins
//! Unload plugins
void unloadAll();
//! Save pointer for python utils (needed for unloading python plugins)
void setPythonUtils(QgsPythonUtils* pythonUtils);
protected:
//! protected constructor
//! protected constructor
QgsPluginRegistry();
private:
static QgsPluginRegistry* _instance;
std::map<QString, QgsPluginMetadata*> plugins;
QgsPythonUtils* mPythonUtils;
};
#endif //QgsPluginRegistry_H

0 comments on commit 43f2596

Please sign in to comment.